001/* 002 * VM-Operator 003 * Copyright (C) 2024 Michael N. Lipp 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <https://www.gnu.org/licenses/>. 017 */ 018 019package org.jdrupes.vmoperator.common; 020 021import io.kubernetes.client.Discovery.APIResource; 022import io.kubernetes.client.openapi.ApiException; 023import io.kubernetes.client.openapi.models.V1Pod; 024import io.kubernetes.client.openapi.models.V1PodList; 025import io.kubernetes.client.util.generic.options.ListOptions; 026import java.util.Collection; 027import java.util.List; 028 029/** 030 * A stub for pods (v1). 031 */ 032@SuppressWarnings("PMD.DataflowAnomalyAnalysis") 033public class K8sV1PodStub extends K8sGenericStub<V1Pod, V1PodList> { 034 035 /** The pods' context. */ 036 public static final APIResource CONTEXT 037 = new APIResource("", List.of("v1"), "v1", "Pod", true, "pods", "pod"); 038 039 /** 040 * Instantiates a new stub. 041 * 042 * @param client the client 043 * @param namespace the namespace 044 * @param name the name 045 */ 046 protected K8sV1PodStub(K8sClient client, String namespace, String name) { 047 super(V1Pod.class, V1PodList.class, client, CONTEXT, namespace, name); 048 } 049 050 /** 051 * Gets the stub for the given namespace and name. 052 * 053 * @param client the client 054 * @param namespace the namespace 055 * @param name the name 056 * @return the kpod stub 057 */ 058 public static K8sV1PodStub get(K8sClient client, String namespace, 059 String name) { 060 return new K8sV1PodStub(client, namespace, name); 061 } 062 063 /** 064 * Get the stubs for the objects in the given namespace that match 065 * the criteria from the given options. 066 * 067 * @param client the client 068 * @param namespace the namespace 069 * @param options the options 070 * @return the collection 071 * @throws ApiException the api exception 072 */ 073 public static Collection<K8sV1PodStub> list(K8sClient client, 074 String namespace, ListOptions options) throws ApiException { 075 return K8sGenericStub.list(V1Pod.class, V1PodList.class, client, 076 CONTEXT, namespace, options, (clnt, nscp, 077 name) -> new K8sV1PodStub(clnt, nscp, name)); 078 } 079}