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