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