Search in sources :

Example 66 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.

the class CacheTest method testMultiIndexFuncCacheStore.

@Test
public void testMultiIndexFuncCacheStore() {
    String testIndexFuncName = "test-idx-func";
    Cache<V1Pod> podCache = new Cache<>();
    podCache.addIndexFunc(testIndexFuncName, (V1Pod pod) -> {
        return Arrays.asList(pod.getSpec().getNodeName());
    });
    V1Pod testPod = new V1Pod().metadata(new V1ObjectMeta().namespace("ns").name("n")).spec(new V1PodSpec().nodeName("node1"));
    podCache.add(testPod);
    List<V1Pod> namespaceIndexedPods = podCache.byIndex(Caches.NAMESPACE_INDEX, "ns");
    assertEquals(1, namespaceIndexedPods.size());
    List<V1Pod> nodeNameIndexedPods = podCache.byIndex(testIndexFuncName, "node1");
    assertEquals(1, nodeNameIndexedPods.size());
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Pod(io.kubernetes.client.openapi.models.V1Pod) V1PodSpec(io.kubernetes.client.openapi.models.V1PodSpec) Test(org.junit.Test)

Example 67 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.

the class YamlTest method testLoad.

@Test
public void testLoad() {
    for (int i = 0; i < kinds.length; i++) {
        String className = classNames[i];
        try {
            Object obj = Yaml.load(new StringReader(input.replace("XXXX", kinds[i]).replace("YYYY", apiVersions[i])));
            Method m = obj.getClass().getMethod("getMetadata");
            V1ObjectMeta metadata = (V1ObjectMeta) m.invoke(obj);
            assertEquals("foo", metadata.getName());
            assertEquals(className, obj.getClass().getSimpleName());
        } catch (Exception ex) {
            assertNull("Unexpected exception: " + ex.toString(), ex);
        }
    }
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) StringReader(java.io.StringReader) Method(java.lang.reflect.Method) IOException(java.io.IOException) Test(org.junit.Test)

Example 68 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.

the class YamlTest method testLoadAll.

@Test
public void testLoadAll() throws IOException {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < kinds.length; i++) {
        sb.append(input.replace("XXXX", kinds[i]).replace("YYYY", apiVersions[i]));
        sb.append("\n---\n");
    }
    List<Object> list = null;
    list = (List<Object>) Yaml.loadAll(sb.toString());
    for (int i = 0; i < kinds.length; i++) {
        String className = classNames[i];
        try {
            Object obj = list.get(i);
            Method m = obj.getClass().getMethod("getMetadata");
            V1ObjectMeta metadata = (V1ObjectMeta) m.invoke(obj);
            assertEquals("foo", metadata.getName());
            assertEquals(className, obj.getClass().getSimpleName());
        } catch (Exception ex) {
            assertNull("Unexpected exception: " + ex.toString(), ex);
        }
    }
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) Method(java.lang.reflect.Method) IOException(java.io.IOException) Test(org.junit.Test)

Example 69 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.

the class CertManagerExample method main.

public static void main(String[] args) throws IOException {
    GenericKubernetesApi<V1beta1Issuer, V1beta1IssuerList> issuerApi = new GenericKubernetesApi<>(V1beta1Issuer.class, V1beta1IssuerList.class, "cert-manager.io", "v1beta1", "issuers", ClientBuilder.defaultClient());
    issuerApi.create(new V1beta1Issuer().metadata(new V1ObjectMeta().namespace("default").name("self-signed-issuer")).kind("Issuer").apiVersion("cert-manager.io/v1beta1").spec(new V1beta1IssuerSpec().selfSigned(new V1alpha2IssuerSpecSelfSigned())));
}
Also used : V1alpha2IssuerSpecSelfSigned(io.cert.manager.models.V1alpha2IssuerSpecSelfSigned) V1beta1Issuer(io.cert.manager.models.V1beta1Issuer) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) GenericKubernetesApi(io.kubernetes.client.util.generic.GenericKubernetesApi) V1beta1IssuerSpec(io.cert.manager.models.V1beta1IssuerSpec) V1beta1IssuerList(io.cert.manager.models.V1beta1IssuerList)

Example 70 with V1ObjectMeta

use of io.kubernetes.client.openapi.models.V1ObjectMeta in project java by kubernetes-client.

the class FluentExample method main.

public static void main(String[] args) throws IOException, ApiException {
    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    CoreV1Api api = new CoreV1Api();
    V1Pod pod = new V1PodBuilder().withNewMetadata().withName("apod").endMetadata().withNewSpec().addNewContainer().withName("www").withImage("nginx").endContainer().endSpec().build();
    api.createNamespacedPod("default", pod, null, null, null, null);
    V1Pod pod2 = new V1Pod().metadata(new V1ObjectMeta().name("anotherpod")).spec(new V1PodSpec().containers(Arrays.asList(new V1Container().name("www").image("nginx"))));
    api.createNamespacedPod("default", pod2, null, null, null, null);
    V1PodList list = api.listNamespacedPod("default", null, null, null, null, null, null, null, null, null, null);
    for (V1Pod item : list.getItems()) {
        System.out.println(item.getMetadata().getName());
    }
}
Also used : V1Container(io.kubernetes.client.openapi.models.V1Container) V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1PodBuilder(io.kubernetes.client.openapi.models.V1PodBuilder) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ApiClient(io.kubernetes.client.openapi.ApiClient) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) V1PodSpec(io.kubernetes.client.openapi.models.V1PodSpec)

Aggregations

V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)78 Test (org.junit.Test)49 V1Pod (io.kubernetes.client.openapi.models.V1Pod)37 HashMap (java.util.HashMap)14 ApiException (io.kubernetes.client.openapi.ApiException)11 V1PodList (io.kubernetes.client.openapi.models.V1PodList)11 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)10 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)8 V1Container (io.kubernetes.client.openapi.models.V1Container)7 ApiClient (io.kubernetes.client.openapi.ApiClient)6 JSON (io.kubernetes.client.openapi.JSON)6 V1Job (io.kubernetes.client.openapi.models.V1Job)6 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)6 V1PodTemplateSpec (io.kubernetes.client.openapi.models.V1PodTemplateSpec)6 V1Patch (io.kubernetes.client.custom.V1Patch)5 SharedInformerFactory (io.kubernetes.client.informer.SharedInformerFactory)5 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)5 V1Service (io.kubernetes.client.openapi.models.V1Service)5 V1ServiceSpec (io.kubernetes.client.openapi.models.V1ServiceSpec)5 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)5