io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinitionList Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinitionList.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ListCustomResourceDefinitions.java From kubernetes-client with Apache License 2.0 | 6 votes |
public static void main(String[] args) { try { KubernetesClient client = new DefaultKubernetesClient(); if (!client.supportsApiPath("/apis/apiextensions.k8s.io/v1beta1") && !client.supportsApiPath("/apis/apiextensions.k8s.io/v1")) { System.out.println("WARNING this cluster does not support the API Group apiextensions.k8s.io"); return; } CustomResourceDefinitionList list = client.customResourceDefinitions().list(); if (list == null) { System.out.println("ERROR no list returned!"); return; } List<CustomResourceDefinition> items = list.getItems(); for (CustomResourceDefinition item : items) { System.out.println("CustomResourceDefinition " + item.getMetadata().getName() + " has version: " + item.getApiVersion()); } } catch (KubernetesClientException e) { System.out.println("Failed: " + e); e.printStackTrace(); } }
Example #2
Source File: CRDLoadExample.java From kubernetes-client with Apache License 2.0 | 6 votes |
public static void main(String args[]) throws IOException { try (final KubernetesClient client = new DefaultKubernetesClient()) { // List all Custom resources. log("Listing all current Custom Resource Definitions :"); CustomResourceDefinitionList crdList = client.customResourceDefinitions().list(); crdList.getItems().forEach(crd -> log(crd.getMetadata().getName())); // Creating a custom resource from yaml CustomResourceDefinition aCustomResourceDefinition = client.customResourceDefinitions().load(CRDLoadExample.class.getResourceAsStream("/crd.yml")).get(); log("Creating CRD..."); client.customResourceDefinitions().create(aCustomResourceDefinition); log("Updated Custom Resource Definitions: "); client.customResourceDefinitions().list().getItems().forEach(crd -> log(crd.getMetadata().getName())); } }
Example #3
Source File: CustomResourceTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test public void testListWithFields() { final CustomResourceDefinitionList customResourceDefinitionList = new CustomResourceDefinitionListBuilder() .addNewItem().and() .addNewItem().and() .build(); server.expect().get().withPath("/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions?fieldSelector=" + Utils .toUrlEncoded("key1=value1,key2=value2,key3!=value3,key3!=value4")).andReturn(HttpURLConnection.HTTP_CREATED, customResourceDefinitionList).once(); KubernetesClient client = server.getClient(); CustomResourceDefinitionList list = client.customResourceDefinitions() .withField("key1", "value1") .withField("key2","value2") .withoutField("key3","value3") .withoutField("key3", "value4") .list(); List<CustomResourceDefinition> items = list.getItems(); assertNotNull(items); assertEquals(2, items.size()); }
Example #4
Source File: IstioExecutor.java From istio-apim with Apache License 2.0 | 6 votes |
/** * Setting up custom resources */ public void setupCRDs() { CustomResourceDefinitionList crds = client.customResourceDefinitions().list(); List<CustomResourceDefinition> crdsItems = crds.getItems(); for (CustomResourceDefinition crd : crdsItems) { ObjectMeta metadata = crd.getMetadata(); if (metadata != null) { String name = metadata.getName(); if (RULE_CRD_NAME.equals(name)) { ruleCRD = crd; } else if (HTTPAPISpec_CRD_NAME.equals(name)) { httpAPISpecCRD = crd; } else if (HTTPAPISpecBinding_CRD_NAME.equals(name)) { httpAPISpecBindingCRD = crd; } } } }
Example #5
Source File: CustomResourceDefinitionIT.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test public void testCrdOperations() { // Load CustomResourceDefinition aCustomResourceDefinition = client.customResourceDefinitions().load(getClass().getResourceAsStream("/test-crd.yml")).get(); assertThat(aCustomResourceDefinition).isNotNull(); // Get crd1 = client.customResourceDefinitions().withName(crd1.getMetadata().getName()).get(); assertThat(crd1).isNotNull(); // List CustomResourceDefinitionList crdList = client.customResourceDefinitions().list(); assertThat(crdList).isNotNull(); assertThat(crdList.getItems().size()).isGreaterThan(0); // Update CustomResourceDefinition updatedCrd = client.customResourceDefinitions().withName(crd1.getMetadata().getName()).edit().editSpec().editOrNewNames().addNewShortName("its").endNames().endSpec().done(); assertThat(updatedCrd.getSpec().getNames().getShortNames().size()).isEqualTo(2); // Delete boolean bDeleted = client.customResourceDefinitions().withName(crd1.getMetadata().getName()).delete(); assertThat(bDeleted).isTrue(); }
Example #6
Source File: CustomResourceDefinitionTest.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Test void testList() { server.expect().get().withPath("/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions").andReturn(200, new KubernetesListBuilder().withItems(customResourceDefinition).build()).once(); KubernetesClient client = server.getClient(); CustomResourceDefinitionList crdList = client.customResourceDefinitions().list(); assertNotNull(crdList); assertEquals(1, crdList.getItems().size()); assertEquals("sparkclusters.radanalytics.io", crdList.getItems().get(0).getMetadata().getName()); }
Example #7
Source File: CustomResourceDefinitionOperationsImpl.java From kubernetes-client with Apache License 2.0 | 5 votes |
public CustomResourceDefinitionOperationsImpl(OperationContext context) { super(context.withApiGroupName("apiextensions.k8s.io") .withApiGroupVersion("v1beta1") .withPlural("customresourcedefinitions")); this.type = CustomResourceDefinition.class; this.listType = CustomResourceDefinitionList.class; this.doneableType = DoneableCustomResourceDefinition.class; }
Example #8
Source File: DefaultKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public NonNamespaceOperation<CustomResourceDefinition, CustomResourceDefinitionList, DoneableCustomResourceDefinition, Resource<CustomResourceDefinition, DoneableCustomResourceDefinition>> customResourceDefinitions() { return new CustomResourceDefinitionOperationsImpl(httpClient, getConfiguration()); }
Example #9
Source File: K8sManager.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * Deploys the API Custom resource kind in kubernetes * * @param client , Openshift client * @param configmapNames , Name of the configmap * @param replicas , number of replicas * @param apiIdentifier , APIIdentifier * @param override , Checks whether the API CR needs to be overrode or not */ private void applyAPICustomResourceDefinition(OpenShiftClient client, String[] configmapNames, int replicas, APIIdentifier apiIdentifier, Boolean override) { CustomResourceDefinitionList customResourceDefinitionList = client.customResourceDefinitions().list(); List<CustomResourceDefinition> customResourceDefinitionItems = customResourceDefinitionList.getItems(); CustomResourceDefinition apiCustomResourceDefinition = null; for (CustomResourceDefinition crd : customResourceDefinitionItems) { ObjectMeta metadata = crd.getMetadata(); if (metadata != null && metadata.getName().equals(API_CRD_NAME)) { apiCustomResourceDefinition = crd; } } if (apiCustomResourceDefinition != null) { log.info("Found [CRD] " + apiCustomResourceDefinition.getMetadata().getSelfLink()); } else { log.error("Custom resource definition apis.wso2.com was not found in the specified cluster"); return; } NonNamespaceOperation<APICustomResourceDefinition, APICustomResourceDefinitionList, DoneableAPICustomResourceDefinition, Resource<APICustomResourceDefinition, DoneableAPICustomResourceDefinition>> apiCrdClient = getCRDClient(client, apiCustomResourceDefinition); // assigning values and creating API cr Definition definition = new Definition(); Interceptors interceptors = new Interceptors(); interceptors.setBallerina(new String[]{}); interceptors.setJava(new String[]{}); definition.setType(SWAGGER); definition.setSwaggerConfigmapNames(configmapNames); definition.setInterceptors(interceptors); APICustomResourceDefinitionSpec apiCustomResourceDefinitionSpec = new APICustomResourceDefinitionSpec(); apiCustomResourceDefinitionSpec.setDefinition(definition); apiCustomResourceDefinitionSpec.setMode(MODE); apiCustomResourceDefinitionSpec.setReplicas(replicas); apiCustomResourceDefinitionSpec.setOverride(override); apiCustomResourceDefinitionSpec.setUpdateTimeStamp(""); Status status = new Status(); APICustomResourceDefinition apiCustomResourceDef = new APICustomResourceDefinition(); apiCustomResourceDef.setSpec(apiCustomResourceDefinitionSpec); apiCustomResourceDef.setStatus(status); apiCustomResourceDef.setApiVersion(API_VERSION); apiCustomResourceDef.setKind(CRD_KIND); ObjectMeta meta = new ObjectMeta(); meta.setName(apiIdentifier.getApiName().toLowerCase()); meta.setNamespace(client.getNamespace()); apiCustomResourceDef.setMetadata(meta); apiCrdClient.createOrReplace(apiCustomResourceDef); log.info("Created [API-CR] apis.wso2.com/" + apiCustomResourceDef.getMetadata().getName() + " for the " + "[API] " + apiIdentifier.getApiName()); }
Example #10
Source File: DefaultOpenShiftClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public NonNamespaceOperation<CustomResourceDefinition, CustomResourceDefinitionList, DoneableCustomResourceDefinition, Resource<CustomResourceDefinition, DoneableCustomResourceDefinition>> customResourceDefinitions() { return new CustomResourceDefinitionOperationsImpl(httpClient, getConfiguration()); }
Example #11
Source File: ManagedOpenShiftClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public NonNamespaceOperation<CustomResourceDefinition, CustomResourceDefinitionList, DoneableCustomResourceDefinition, Resource<CustomResourceDefinition, DoneableCustomResourceDefinition>> customResourceDefinitions() { return delegate.customResourceDefinitions(); }
Example #12
Source File: ManagedKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public NonNamespaceOperation<CustomResourceDefinition, CustomResourceDefinitionList, DoneableCustomResourceDefinition, Resource<CustomResourceDefinition, DoneableCustomResourceDefinition>> customResourceDefinitions() { return delegate.customResourceDefinitions(); }
Example #13
Source File: ClusterOperatorTest.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
/** * Asserts that Cluster Operator starts and then stops a verticle in every namespace using the namespace wildcard (*) * @param context test context passed in for assertions * @param namespaces namespaces the operator should be watching and operating on */ private void startStopAllNamespaces(VertxTestContext context, String namespaces, boolean openShift) throws InterruptedException { AtomicInteger numWatchers = new AtomicInteger(0); KubernetesClient client; if (openShift) { client = mock(OpenShiftClient.class); when(client.isAdaptable(eq(OpenShiftClient.class))).thenReturn(true); when(client.adapt(eq(OpenShiftClient.class))).thenReturn((OpenShiftClient) client); } else { client = mock(KubernetesClient.class); when(client.isAdaptable(eq(OpenShiftClient.class))).thenReturn(false); } when(client.isAdaptable(eq(OkHttpClient.class))).thenReturn(true); try { when(client.getMasterUrl()).thenReturn(new URL("http://localhost")); } catch (MalformedURLException e) { throw new RuntimeException(e); } MixedOperation mockCms = mock(MixedOperation.class); NonNamespaceOperation<CustomResourceDefinition, CustomResourceDefinitionList, DoneableCustomResourceDefinition, Resource<CustomResourceDefinition, DoneableCustomResourceDefinition>> mockCrds = mock(NonNamespaceOperation.class); Resource<CustomResourceDefinition, DoneableCustomResourceDefinition> mockResource = mock(Resource.class); if (openShift) { when(mockResource.get()).thenReturn(Crds.kafkaConnectS2I()); } else { when(mockResource.get()).thenReturn(null); } when(mockCrds.withName(KafkaConnectS2I.CRD_NAME)).thenReturn(mockResource); when(client.customResourceDefinitions()).thenReturn(mockCrds); when(client.customResources(any(), any(), any(), any())).thenReturn(mockCms); FilterWatchListMultiDeletable mockFilteredCms = mock(FilterWatchListMultiDeletable.class); when(mockFilteredCms.withLabels(any())).thenReturn(mockFilteredCms); when(mockFilteredCms.watch(any())).thenAnswer(invo -> { numWatchers.incrementAndGet(); Watch mockWatch = mock(Watch.class); doAnswer(invo2 -> { ((Watcher) invo.getArgument(0)).onClose(null); return null; }).when(mockWatch).close(); return mockWatch; }); when(mockCms.inAnyNamespace()).thenReturn(mockFilteredCms); Map<String, String> env = buildEnv(namespaces); CountDownLatch latch = new CountDownLatch(2); Main.run(vertx, client, new PlatformFeaturesAvailability(openShift, KubernetesVersion.V1_9), ClusterOperatorConfig.fromMap(env, KafkaVersionTestUtils.getKafkaVersionLookup())) .onComplete(context.succeeding(v -> context.verify(() -> { assertThat("A verticle per namespace", vertx.deploymentIDs(), hasSize(1)); for (String deploymentId: vertx.deploymentIDs()) { vertx.undeploy(deploymentId, asyncResult -> { if (asyncResult.failed()) { log.error("Failed to undeploy {}", deploymentId); context.failNow(asyncResult.cause()); } latch.countDown(); }); } int maximumExpectedNumberOfWatchers = openShift ? 9 : 7; // we do not have connectS2I on k8s assertThat("Looks like there were more watchers than namespaces", numWatchers.get(), lessThanOrEqualTo(maximumExpectedNumberOfWatchers)); latch.countDown(); }))); latch.await(10, TimeUnit.SECONDS); context.completeNow(); }
Example #14
Source File: ClusterOperatorTest.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
/** * Asserts that Cluster Operator starts and then stops a verticle in each namespace * @param context test context passed in for assertions * @param namespaces namespaces the operator should be watching and operating on */ private void startStop(VertxTestContext context, String namespaces, boolean openShift) throws InterruptedException { AtomicInteger numWatchers = new AtomicInteger(0); KubernetesClient client; if (openShift) { client = mock(OpenShiftClient.class); when(client.isAdaptable(eq(OpenShiftClient.class))).thenReturn(true); when(client.adapt(eq(OpenShiftClient.class))).thenReturn((OpenShiftClient) client); } else { client = mock(KubernetesClient.class); when(client.isAdaptable(eq(OpenShiftClient.class))).thenReturn(false); } when(client.isAdaptable(eq(OkHttpClient.class))).thenReturn(true); try { when(client.getMasterUrl()).thenReturn(new URL("http://localhost")); } catch (MalformedURLException e) { throw new RuntimeException(e); } MixedOperation mockCms = mock(MixedOperation.class); NonNamespaceOperation<CustomResourceDefinition, CustomResourceDefinitionList, DoneableCustomResourceDefinition, Resource<CustomResourceDefinition, DoneableCustomResourceDefinition>> mockCrds = mock(NonNamespaceOperation.class); Resource<CustomResourceDefinition, DoneableCustomResourceDefinition> mockResource = mock(Resource.class); if (openShift) { when(mockResource.get()).thenReturn(Crds.kafkaConnectS2I()); } else { when(mockResource.get()).thenReturn(null); } when(mockCrds.withName(KafkaConnectS2I.CRD_NAME)).thenReturn(mockResource); when(client.customResourceDefinitions()).thenReturn(mockCrds); when(client.customResources(any(), any(), any(), any())).thenReturn(mockCms); List<String> namespaceList = asList(namespaces.split(" *,+ *")); for (String namespace: namespaceList) { MixedOperation mockNamespacedCms = mock(MixedOperation.class); when(mockNamespacedCms.watch(any())).thenAnswer(invo -> { numWatchers.incrementAndGet(); Watch mockWatch = mock(Watch.class); doAnswer(invo2 -> { ((Watcher) invo.getArgument(0)).onClose(null); return null; }).when(mockWatch).close(); return mockWatch; }); when(mockNamespacedCms.withLabels(any())).thenReturn(mockNamespacedCms); when(mockCms.inNamespace(namespace)).thenReturn(mockNamespacedCms); } Map<String, String> env = buildEnv(namespaces); CountDownLatch latch = new CountDownLatch(namespaceList.size() + 1); Main.run(vertx, client, new PlatformFeaturesAvailability(openShift, KubernetesVersion.V1_9), ClusterOperatorConfig.fromMap(env, KafkaVersionTestUtils.getKafkaVersionLookup())) .onComplete(context.succeeding(v -> context.verify(() -> { assertThat("A verticle per namespace", vertx.deploymentIDs(), hasSize(namespaceList.size())); for (String deploymentId: vertx.deploymentIDs()) { vertx.undeploy(deploymentId, asyncResult -> { if (asyncResult.failed()) { log.error("Failed to undeploy {}", deploymentId); context.failNow(asyncResult.cause()); } latch.countDown(); }); } int maximumExpectedNumberOfWatchers = (openShift ? 9 : 7) * namespaceList.size(); // we do not have connectS2I on k8s assertThat("Looks like there were more watchers than namespaces", numWatchers.get(), lessThanOrEqualTo(maximumExpectedNumberOfWatchers)); latch.countDown(); }))); latch.await(10, TimeUnit.SECONDS); context.completeNow(); }
Example #15
Source File: KafkaMetaDataRetrievalTest.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void shouldFetchPropertiesFromKafkaCustomResources() { final KubernetesClient client = mock(KubernetesClient.class); final KafkaMetaDataRetrieval metaDataRetrieval = new KafkaMetaDataRetrieval() { @Override KubernetesClient createKubernetesClient() { return client; } }; @SuppressWarnings("unchecked") final NonNamespaceOperation<CustomResourceDefinition, CustomResourceDefinitionList, DoneableCustomResourceDefinition, Resource<CustomResourceDefinition, DoneableCustomResourceDefinition>> definitions = mock( NonNamespaceOperation.class); when(client.customResourceDefinitions()).thenReturn(definitions); final CustomResourceDefinitionList values = new CustomResourceDefinitionList(); values.setItems(Collections.singletonList(STRIMZI_KAFKA_CRD)); when(definitions.list()).thenReturn(values); @SuppressWarnings("unchecked") final MixedOperation<Kafka, KafkaResourceList, KafkaResourceDoneable, Resource<Kafka, KafkaResourceDoneable>> operation = mock( MixedOperation.class); when(client.customResources(STRIMZI_KAFKA_CRD, Kafka.class, KafkaResourceList.class, KafkaResourceDoneable.class)).thenReturn(operation); when(operation.inAnyNamespace()).thenReturn(operation); when(operation.list()).thenReturn(KAFKAS); final SyndesisMetadataProperties properties = metaDataRetrieval.fetchProperties(null, null, null); final Map<String, List<PropertyPair>> expected = new HashMap<>(); expected.put("brokers", Arrays.asList( new PropertyPair("my-cluster-kafka-bootstrap.zregvart.svc:9092", "zregvart::my-cluster (plain)"), new PropertyPair("my-cluster-kafka-bootstrap.zregvart.svc:9093", "zregvart::my-cluster (tls)"), new PropertyPair("zorans-cluster-kafka-bootstrap.zregvart.svc:9092", "zregvart::zorans-cluster (plain)"), new PropertyPair("zorans-cluster-kafka-bootstrap.zregvart.svc:9093", "zregvart::zorans-cluster (tls)") )); assertThat(properties.getProperties()).containsExactlyEntriesOf(expected); }
Example #16
Source File: K8SCoreRuntime.java From jhipster-operator with Apache License 2.0 | 4 votes |
public CustomResourceDefinitionList getCustomResourceDefinitionList() { return kubernetesClient.customResourceDefinitions().list(); }
Example #17
Source File: AppsOperator.java From jhipster-operator with Apache License 2.0 | 4 votes |
private boolean areRequiredCRDsPresent() { try { appService.registerCustomResourcesForRuntime(); CustomResourceDefinitionList crds = k8SCoreRuntime.getCustomResourceDefinitionList(); for (CustomResourceDefinition crd : crds.getItems()) { ObjectMeta metadata = crd.getMetadata(); if (metadata != null) { String name = metadata.getName(); if (AppCRDs.MICROSERVICE_CRD_NAME.equals(name)) { microServiceCRD = crd; } if (AppCRDs.GATEWAY_CRD_NAME.equals(name)) { gatewayCRD = crd; } if (AppCRDs.REGISTRY_CRD_NAME.equals(name)) { registryCRD = crd; } if (AppCRDs.APP_CRD_NAME.equals(name)) { applicationCRD = crd; } } } if (allCRDsFound()) { logger.info("\t > App CRD: " + applicationCRD.getMetadata().getName()); logger.info("\t > MicroService CRD: " + microServiceCRD.getMetadata().getName()); logger.info("\t > Registry CRD: " + registryCRD.getMetadata().getName()); logger.info("\t > Gateway CRD: " + gatewayCRD.getMetadata().getName()); return true; } else { logger.error("> Custom CRDs required to work not found please check your installation!"); logger.error("\t > App CRD: " + ((applicationCRD == null) ? " NOT FOUND " : applicationCRD.getMetadata().getName())); logger.error("\t > MicroService CRD: " + ((microServiceCRD == null) ? " NOT FOUND " : microServiceCRD.getMetadata().getName())); logger.error("\t > Registry CRD: " + ((registryCRD == null) ? " NOT FOUND " : registryCRD.getMetadata().getName())); logger.error("\t > Gateway CRD: " + ((gatewayCRD == null) ? " NOT FOUND " : gatewayCRD.getMetadata().getName())); return false; } } catch (Exception e) { e.printStackTrace(); logger.error("> Init sequence not done"); } return false; }
Example #18
Source File: KubernetesClient.java From kubernetes-client with Apache License 2.0 | 2 votes |
/** * API entrypoint for CustomResourcedefinition(CRDs). This offers basic operations like * load, get, create, update, delete and watch for APIGroup apiextensions/v1beta1 * * @return NonNamespaceOperation object for CustomResourceDefinition */ NonNamespaceOperation<CustomResourceDefinition, CustomResourceDefinitionList, DoneableCustomResourceDefinition, Resource<CustomResourceDefinition, DoneableCustomResourceDefinition>> customResourceDefinitions();