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.V1Node;
024import io.kubernetes.client.openapi.models.V1NodeList;
025import io.kubernetes.client.util.generic.options.ListOptions;
026import java.util.Collection;
027import java.util.List;
028
029/**
030 * A stub for nodes (v1).
031 */
032@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
033public class K8sV1NodeStub extends K8sClusterGenericStub<V1Node, V1NodeList> {
034
035    public static final APIResource CONTEXT = new APIResource("", List.of("v1"),
036        "v1", "Node", true, "nodes", "node");
037
038    /**
039     * Instantiates a new stub.
040     *
041     * @param client the client
042     * @param name the name
043     */
044    protected K8sV1NodeStub(K8sClient client, String name) {
045        super(V1Node.class, V1NodeList.class, client, CONTEXT, name);
046    }
047
048    /**
049     * Gets the stub for the given name.
050     *
051     * @param client the client
052     * @param name the name
053     * @return the config map stub
054     */
055    public static K8sV1NodeStub get(K8sClient client, String name) {
056        return new K8sV1NodeStub(client, name);
057    }
058
059    /**
060     * Get the stubs for the objects that match
061     * the criteria from the given options.
062     *
063     * @param client the client
064     * @param options the options
065     * @return the collection
066     * @throws ApiException the api exception
067     */
068    public static Collection<K8sV1NodeStub> list(K8sClient client,
069            ListOptions options) throws ApiException {
070        return K8sClusterGenericStub.list(V1Node.class, V1NodeList.class,
071            client, CONTEXT, options, K8sV1NodeStub::getGeneric);
072    }
073
074    /**
075     * Provide {@link GenericSupplier}.
076     */
077    @SuppressWarnings({ "PMD.UnusedFormalParameter",
078        "PMD.UnusedPrivateMethod" })
079    private static K8sV1NodeStub getGeneric(Class<V1Node> objectClass,
080            Class<V1NodeList> objectListClass, K8sClient client,
081            APIResource context, String name) {
082        return new K8sV1NodeStub(client, name);
083    }
084
085}