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.V1PersistentVolumeClaim;
024import io.kubernetes.client.openapi.models.V1PersistentVolumeClaimList;
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 K8sV1PvcStub extends
034        K8sGenericStub<V1PersistentVolumeClaim, V1PersistentVolumeClaimList> {
035
036    /** The pods' context. */
037    public static final APIResource CONTEXT
038        = new APIResource("", List.of("v1"), "v1", "PersistentVolumeClaim",
039            true, "persistentvolumeclaims", "persistentvolumeclaim");
040
041    /**
042     * Instantiates a new stub.
043     *
044     * @param client the client
045     * @param namespace the namespace
046     * @param name the name
047     */
048    protected K8sV1PvcStub(K8sClient client, String namespace, String name) {
049        super(V1PersistentVolumeClaim.class, V1PersistentVolumeClaimList.class,
050            client, CONTEXT, namespace, name);
051    }
052
053    /**
054     * Gets the stub for the given namespace and name.
055     *
056     * @param client the client
057     * @param namespace the namespace
058     * @param name the name
059     * @return the kpod stub
060     */
061    public static K8sV1PvcStub get(K8sClient client, String namespace,
062            String name) {
063        return new K8sV1PvcStub(client, namespace, name);
064    }
065
066    /**
067     * Get the stubs for the objects in the given namespace that match
068     * the criteria from the given options.
069     *
070     * @param client the client
071     * @param namespace the namespace
072     * @param options the options
073     * @return the collection
074     * @throws ApiException the api exception
075     */
076    public static Collection<K8sV1PvcStub> list(K8sClient client,
077            String namespace, ListOptions options) throws ApiException {
078        return K8sGenericStub.list(V1PersistentVolumeClaim.class,
079            V1PersistentVolumeClaimList.class, client, CONTEXT, namespace,
080            options, (clnt, nscp, name) -> new K8sV1PvcStub(clnt, nscp, name));
081    }
082}