io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition.
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: 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 #2
Source File: AbstractWatcher.java From abstract-operator with Apache License 2.0 | 6 votes |
protected AbstractWatcher(boolean isCrd, String namespace, String entityName, KubernetesClient client, CustomResourceDefinition crd, Map<String, String> selector, BiConsumer<T, String> onAdd, BiConsumer<T, String> onDelete, BiConsumer<T, String> onModify, Predicate<ConfigMap> isSupported, Function<ConfigMap, T> convert, Function<InfoClass, T> convertCr) { this.isCrd = isCrd; this.namespace = namespace; this.entityName = entityName; this.client = client; this.crd = crd; this.selector = selector; this.onAdd = onAdd; this.onDelete = onDelete; this.onModify = onModify; this.isSupported = isSupported; this.convert = convert; this.convertCr = convertCr; }
Example #3
Source File: KubernetesConnection.java From vault-crd with Apache License 2.0 | 6 votes |
@Bean public MixedOperation<Vault, VaultList, DoneableVault, Resource<Vault, DoneableVault>> customResource( KubernetesClient client, @Value("${kubernetes.crd.name}") String crdName) { Resource<CustomResourceDefinition, DoneableCustomResourceDefinition> crdResource = client.customResourceDefinitions().withName(crdName); // Hack for bug in Kubernetes-Client for CRDs https://github.com/fabric8io/kubernetes-client/issues/1099 String kind = StringUtils.substringAfter(crdName, ".") + "/v1#Vault"; KubernetesDeserializer.registerCustomKind(kind, Vault.class); CustomResourceDefinition customResourceDefinition = crdResource.get(); if (customResourceDefinition == null) { log.error("Please first apply custom resource definition and then restart vault-crd"); System.exit(1); } return client.customResources(customResourceDefinition, Vault.class, VaultList.class, DoneableVault.class); }
Example #4
Source File: MockKube.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public void mockCrs(KubernetesClient mockClient) { when(mockClient.customResources(any(CustomResourceDefinition.class), any(Class.class), any(Class.class), any(Class.class))).thenAnswer(invocation -> { CustomResourceDefinition crdArg = invocation.getArgument(0); String key = crdKey(crdArg); CreateOrReplaceable createOrReplaceable = crdMixedOps.get(key); if (createOrReplaceable == null) { throw new RuntimeException("Unknown CRD " + invocation.getArgument(0)); } return createOrReplaceable; }); }
Example #5
Source File: ApplyService.java From jkube with Eclipse Public License 2.0 | 5 votes |
public void applyCustomResourceDefinition(CustomResourceDefinition entity, String sourceName) { String namespace = getNamespace(); String id = getName(entity); Objects.requireNonNull(id, "No name for " + entity + " " + sourceName); if (isServicesOnlyMode()) { log.debug("Only processing Services right now so ignoring Custom Resource Definition: " + namespace + ":" + id); return; } CustomResourceDefinition old = kubernetesClient.customResourceDefinitions().withName(id).get(); if (isRunning(old)) { if (UserConfigurationCompare.configEqual(entity, old)) { log.info("Custom Resource Definition has not changed so not doing anything"); } else { if (isRecreateMode()) { log.info("Deleting Custom Resource Definition: " + id); kubernetesClient.customResourceDefinitions().withName(id).delete(); doCreateCustomResourceDefinition(entity, sourceName); } else { log.info("Updating a Custom Resource Definition from " + sourceName + " name " + getName(entity)); try { HasMetadata answer = patchService.compareAndPatchEntity(namespace, entity, old); log.info("Updated Custom Resource Definition result: " + getName(answer)); } catch (Exception e) { onApplyError("Failed to update Custom Resource Definition from " + sourceName + ". " + e + ". " + entity, e); } } } } else { if (!isAllowCreate()) { log.warn("Creation disabled so not creating a Custom Resource Definition from " + sourceName + " name " + getName(entity)); } else { doCreateCustomResourceDefinition(entity, sourceName); } } }
Example #6
Source File: ApplyService.java From jkube with Eclipse Public License 2.0 | 5 votes |
private void doCreateCustomResourceDefinition(CustomResourceDefinition entity, String sourceName) { log.info("Creating a Custom Resource Definition from " + sourceName + " name " + getName(entity)); try { Object answer = kubernetesClient.customResourceDefinitions().create(entity); log.info("Created Custom Resource Definition result: " + ((CustomResourceDefinition) answer).getMetadata().getName()); } catch (Exception e) { onApplyError("Failed to create Custom Resource Definition from " + sourceName + ". " + e + ". " + entity, e); } }
Example #7
Source File: K8sImplTest.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Test public void testList(VertxTestContext context) { Checkpoint async = context.checkpoint(); List<KafkaTopic> mockKafkaTopicsList = Collections.singletonList(new KafkaTopicBuilder() .withMetadata(new ObjectMetaBuilder() .withName("unrelated") .withLabels(Collections.singletonMap("foo", "bar")).build()) .build()); KubernetesClient mockClient = mock(KubernetesClient.class); MixedOperation<KafkaTopic, KafkaTopicList, TopicOperator.DeleteKafkaTopic, Resource<KafkaTopic, TopicOperator.DeleteKafkaTopic>> mockResources = mock(MixedOperation.class); when(mockClient.customResources(any(CustomResourceDefinition.class), any(Class.class), any(Class.class), any(Class.class))).thenReturn(mockResources); when(mockResources.withLabels(any())).thenReturn(mockResources); when(mockResources.inNamespace(any())).thenReturn(mockResources); when(mockResources.list()).thenAnswer(invocation -> { KafkaTopicList ktl = new KafkaTopicList(); ktl.setItems(mockKafkaTopicsList); return ktl; }); K8sImpl k8s = new K8sImpl(vertx, mockClient, new Labels("foo", "bar"), "default"); k8s.listResources().onComplete(context.succeeding(kafkaTopics -> context.verify(() -> { assertThat(kafkaTopics, is(mockKafkaTopicsList)); async.flag(); }))); }
Example #8
Source File: MockKube.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
public <T extends CustomResource, L extends KubernetesResourceList<T>, D extends Doneable<T>, S> MockedCrd<T, L, D, S> withCustomResourceDefinition(CustomResourceDefinition crd, Class<T> instanceClass, Class<L> instanceListClass, Class<D> doneableInstanceClass, Function<T, S> getStatus, BiConsumer<T, S> setStatus) { MockedCrd<T, L, D, S> mockedCrd = new MockedCrd<>(crd, instanceClass, instanceListClass, doneableInstanceClass, getStatus, setStatus); this.mockedCrds.add(mockedCrd); return mockedCrd; }
Example #9
Source File: Operator.java From java-operator-sdk with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") private <R extends CustomResource> void registerController(ResourceController<R> controller, boolean watchAllNamespaces, Retry retry, String... targetNamespaces) throws OperatorException { Class<R> resClass = getCustomResourceClass(controller); CustomResourceDefinition crd = getCustomResourceDefinitionForController(controller); KubernetesDeserializer.registerCustomKind(getApiVersion(crd), getKind(crd), resClass); MixedOperation client = k8sClient.customResources(crd, resClass, CustomResourceList.class, getCustomResourceDoneableClass(controller)); EventDispatcher eventDispatcher = new EventDispatcher(controller, getDefaultFinalizer(controller), new EventDispatcher.CustomResourceReplaceFacade(client)); EventScheduler eventScheduler = new EventScheduler(eventDispatcher, retry, ControllerUtils.getGenerationEventProcessing(controller)); registerWatches(controller, client, resClass, watchAllNamespaces, targetNamespaces, eventScheduler); }
Example #10
Source File: KnativeMetaDataSupport.java From syndesis with Apache License 2.0 | 5 votes |
private static List<String> listResources(CustomResourceDefinition crd) { try (OpenShiftClient client = new DefaultOpenShiftClient()) { return client.customResources(crd, KnativeResource.class, KnativeResourceList.class, KnativeResourceDoneable.class) .inNamespace(getTargetNamespace()) .list() .getItems() .stream() .map(KnativeResource::getMetadata) .map(ObjectMeta::getName) .collect(Collectors.toList()); } }
Example #11
Source File: Operator.java From java-operator-sdk with Apache License 2.0 | 5 votes |
private CustomResourceDefinition getCustomResourceDefinitionForController(ResourceController controller) { String crdName = getCrdName(controller); CustomResourceDefinition customResourceDefinition = k8sClient.customResourceDefinitions().withName(crdName).get(); if (customResourceDefinition == null) { throw new OperatorException("Cannot find Custom Resource Definition with name: " + crdName); } return customResourceDefinition; }
Example #12
Source File: KafkaMetaDataRetrieval.java From syndesis with Apache License 2.0 | 5 votes |
/** * Used to filter brokers. Right now, based on GROUP and PLURAL. */ static boolean isKafkaCustomResourceDefinition(final CustomResourceDefinition crd) { final CustomResourceDefinitionSpec spec = crd.getSpec(); final String group = spec.getGroup(); final CustomResourceDefinitionNames names = spec.getNames(); final String plural = names.getPlural(); return GROUP.equalsIgnoreCase(group) && PLURAL.equalsIgnoreCase(plural); }
Example #13
Source File: MockKube.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
private MockedCrd(CustomResourceDefinition crd, Class<T> crClass, Class<L> crListClass, Class<D> crDoneableClass, Function<T, S> getStatus, BiConsumer<T, S> setStatus) { this.crd = crd; this.crClass = crClass; this.crListClass = crListClass; this.crDoneableClass = crDoneableClass; this.getStatus = getStatus; this.setStatus = setStatus; instances = db(emptySet(), crClass, crDoneableClass); }
Example #14
Source File: NetworkPartitionResourceController.java From rabbitmq-operator with Apache License 2.0 | 5 votes |
@Override protected MixedOperation<RabbitMQNetworkPartitionCustomResource, RabbitMQNetworkPartitionCustomResourceList, DoneableRabbitMQNetworkPartitionCustomResource, Resource<RabbitMQNetworkPartitionCustomResource, DoneableRabbitMQNetworkPartitionCustomResource>> operation() { final CustomResourceDefinition networkPartitionCrd = getClient().customResourceDefinitions().withName(RABBITMQ_NETWORK_PARTITION_CRD_NAME).get(); if (networkPartitionCrd == null) { throw new RuntimeException(String.format("CustomResourceDefinition %s has not been defined", RABBITMQ_NETWORK_PARTITION_CRD_NAME)); } return getClient().customResources(networkPartitionCrd, RabbitMQNetworkPartitionCustomResource.class, RabbitMQNetworkPartitionCustomResourceList.class, DoneableRabbitMQNetworkPartitionCustomResource.class); }
Example #15
Source File: CamelKSupport.java From syndesis with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static List<io.syndesis.server.controller.integration.camelk.crd.Integration> getIntegrationCRbyLabels( OpenShiftService openShiftService, CustomResourceDefinition integrationCRD, Map<String,String> labels) { return openShiftService.getCRBylabel( integrationCRD, io.syndesis.server.controller.integration.camelk.crd.Integration.class, IntegrationList.class, DoneableIntegration.class, labels ); }
Example #16
Source File: KafkaCrdOperatorIT.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
@Override protected CustomResourceDefinition getCrd() { return Crds.kafka(); }
Example #17
Source File: AdminCrd.java From enmasse with Apache License 2.0 | 4 votes |
public static CustomResourceDefinition addressSpacePlans() { return ADDRESS_SPACE_PLAN_CRD; }
Example #18
Source File: CoreCrd.java From enmasse with Apache License 2.0 | 4 votes |
public static CustomResourceDefinition addresses() { return ADDRESS_CRD; }
Example #19
Source File: Crds.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
public static CustomResourceDefinition kafkaConnector() { return crd(KafkaConnector.class); }
Example #20
Source File: BaseCamelKHandler.java From syndesis with Apache License 2.0 | 4 votes |
protected CustomResourceDefinition getCustomResourceDefinition() { return CamelKSupport.CAMEL_K_INTEGRATION_CRD; }
Example #21
Source File: Crds.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
public static CustomResourceDefinition kafkaConnectS2I() { return crd(KafkaConnectS2I.class); }
Example #22
Source File: MockKube.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
CustomResourceDefinition getCrd() { return crd; }
Example #23
Source File: Crds.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
public static CustomResourceDefinition kafkaMirrorMaker2() { return crd(KafkaMirrorMaker2.class); }
Example #24
Source File: OpenShiftServiceNoOp.java From syndesis with Apache License 2.0 | 4 votes |
@Override public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> boolean deleteCR(CustomResourceDefinition crd, Class<T> resourceType, Class<L> resourceListType, Class<D> doneableResourceType, String customResourceName) { return false; }
Example #25
Source File: OpenShiftServiceNoOp.java From syndesis with Apache License 2.0 | 4 votes |
@Override public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> boolean deleteCR(CustomResourceDefinition crd, Class<T> resourceType, Class<L> resourceListType, Class<D> doneableResourceType, String customResourceName, boolean cascading) { return false; }
Example #26
Source File: Crds.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
public static CustomResourceDefinition kafkaUser() { return crd(KafkaUser.class); }
Example #27
Source File: OpenShiftServiceNoOp.java From syndesis with Apache License 2.0 | 4 votes |
@Override public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> List<T> getCRBylabel(CustomResourceDefinition crd, Class<T> resourceType, Class<L> resourceListType, Class<D> doneableResourceType, Map<String, String> labels) { return null; }
Example #28
Source File: MockKube.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
public String crdKey(CustomResourceDefinition crd) { return crd.getSpec().getGroup() + "##" + crd.getSpec().getVersion() + "##" + crd.getSpec().getNames().getKind(); }
Example #29
Source File: CoreCrd.java From enmasse with Apache License 2.0 | 4 votes |
public static CustomResourceDefinition messagingAddresses() { return MESSAGING_ADDRESS_CRD; }
Example #30
Source File: Crds.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
public static CustomResourceDefinition kafkaTopic() { return crd(KafkaTopic.class); }