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());
}
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);
}
}
}
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);
}
}
}
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())));
}
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());
}
}
Aggregations