io.fabric8.kubernetes.api.model.Doneable Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.Doneable. 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: DefaultKubernetesClient.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>> customResources(CustomResourceDefinition crd, Class<T> resourceType, Class<L> listClass, Class<D> doneClass) {
  return new CustomResourceOperationsImpl<>(new CustomResourceOperationContext().withOkhttpClient(httpClient).withConfig(getConfiguration())
    .withCrd(crd)
    .withType(resourceType)
    .withListType(listClass)
    .withPropagationPolicy(DEFAULT_PROPAGATION_POLICY)
    .withDoneableType(doneClass));
}
 
Example #2
Source File: OpenShiftServiceImpl.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> Watch watchCR(CustomResourceDefinition crd, Class<T> resourceType, Class<L> resourceListType, Class<D> doneableResourceType, BiConsumer<Watcher.Action,T> watcher){
    return getCRDClient(crd, resourceType, resourceListType, doneableResourceType).inNamespace(config.getNamespace()).watch(new Watcher<T>() {
        @Override
        public void eventReceived(Action action, T t) {
            watcher.accept(action, t);
        }

        @Override
        public void onClose(KubernetesClientException e) {
            LOGGER.info("Closing watcher "+this+" on crd "+crd.getMetadata().getName(), e);
        }
    });
}
 
Example #3
Source File: OpenShiftServiceImpl.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked"})
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 getCRDClient(crd, resourceType, resourceListType, doneableResourceType).inNamespace(config.getNamespace()).withName(customResourceName)
        .cascading(cascading)
        .delete();
}
 
Example #4
Source File: DefaultKubernetesClient.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>> customResources(CustomResourceDefinitionContext crdContext, Class<T> resourceType, Class<L> listClass, Class<D> doneClass) {
  return new CustomResourceOperationsImpl<>(new CustomResourceOperationContext().withOkhttpClient(httpClient).withConfig(getConfiguration())
    .withCrdContext(crdContext)
    .withType(resourceType)
    .withListType(listClass)
    .withPropagationPolicy(DEFAULT_PROPAGATION_POLICY)
    .withDoneableType(doneClass));
}
 
Example #5
Source File: MockKube.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static <T extends HasMetadata, D extends Doneable<T>> T copyResource(T resource, Class<T> resourceClass, Class<D> doneableClass) {
    try {
        D doneableInstance = doneableClass.getDeclaredConstructor(resourceClass).newInstance(resource);
        T done = (T) Doneable.class.getMethod("done").invoke(doneableInstance);
        return done;
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
    }
}
 
Example #6
Source File: Crds.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
public static <T extends CustomResource, L extends CustomResourceList<T>, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>>
        operation(KubernetesClient client,
                  Class<T> cls,
                  Class<L> listCls,
                  Class<D> doneableCls) {
    return client.customResources(crd(cls), cls, listCls, doneableCls);
}
 
Example #7
Source File: MockKube.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
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 #8
Source File: MockBuilder.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected T copyResource(T resource) {
    if (resource == null) {
        return null;
    }
    try {
        D doneableInstance = doneableClass.getDeclaredConstructor(resourceTypeClass).newInstance(resource);
        return (T) Doneable.class.getMethod("done").invoke(doneableInstance);
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
    }
}
 
Example #9
Source File: ManagedKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>> customResources(CustomResourceDefinition crd, Class<T> resourceType, Class<L> listClass, Class<D> doneClass) {
  return delegate.customResources(crd, resourceType, listClass, doneClass);
}
 
Example #10
Source File: OpenShiftServiceImpl.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings({"unchecked"})
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 deleteCR(crd, resourceType, resourceListType, doneableResourceType, customResourceName, false);
}
 
Example #11
Source File: ManagedKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>> customResources(CustomResourceDefinitionContext crdContext, Class<T> resourceType, Class<L> listClass, Class<D> doneClass) {
  return delegate.customResources(crdContext, resourceType, listClass, doneClass);
}
 
Example #12
Source File: AbstractConnectOperator.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the Status field of the KafkaConnect or KafkaConnector CR. It diffs the desired status against the current status and calls
 * the update only when there is any difference in non-timestamp fields.
 *
 * @param resource The CR of KafkaConnect or KafkaConnector
 * @param reconciliation Reconciliation information
 * @param desiredStatus The KafkaConnectStatus or KafkaConnectorStatus which should be set
 *
 * @return
 */
protected <T extends CustomResource & HasStatus<S>, S extends Status, L extends CustomResourceList<T>, D extends Doneable<T>> Future<Void>
    maybeUpdateStatusCommon(CrdOperator<KubernetesClient, T, L, D> resourceOperator,
                            T resource,
                            Reconciliation reconciliation,
                            S desiredStatus,
                            BiFunction<T, S, T> copyWithStatus) {
    Promise<Void> updateStatusPromise = Promise.promise();

    resourceOperator.getAsync(resource.getMetadata().getNamespace(), resource.getMetadata().getName()).onComplete(getRes -> {
        if (getRes.succeeded()) {
            T fetchedResource = getRes.result();

            if (fetchedResource != null) {
                if ((!(fetchedResource instanceof KafkaConnector))
                        && (!(fetchedResource instanceof KafkaMirrorMaker2))
                        && StatusUtils.isResourceV1alpha1(fetchedResource)) {
                    log.warn("{}: {} {} needs to be upgraded from version {} to 'v1beta1' to use the status field",
                            reconciliation, fetchedResource.getKind(), fetchedResource.getMetadata().getName(), fetchedResource.getApiVersion());
                    updateStatusPromise.complete();
                } else {
                    S currentStatus = fetchedResource.getStatus();

                    StatusDiff ksDiff = new StatusDiff(currentStatus, desiredStatus);

                    if (!ksDiff.isEmpty()) {
                        T resourceWithNewStatus = copyWithStatus.apply(fetchedResource, desiredStatus);

                        resourceOperator.updateStatusAsync(resourceWithNewStatus).onComplete(updateRes -> {
                            if (updateRes.succeeded()) {
                                log.debug("{}: Completed status update", reconciliation);
                                updateStatusPromise.complete();
                            } else {
                                log.error("{}: Failed to update status", reconciliation, updateRes.cause());
                                updateStatusPromise.fail(updateRes.cause());
                            }
                        });
                    } else {
                        log.debug("{}: Status did not change", reconciliation);
                        updateStatusPromise.complete();
                    }
                }
            } else {
                log.error("{}: Current {} resource not found", reconciliation, resource.getKind());
                updateStatusPromise.fail("Current " + resource.getKind() + " resource not found");
            }
        } else {
            log.error("{}: Failed to get the current {} resource and its status", reconciliation, resource.getKind(), getRes.cause());
            updateStatusPromise.fail(getRes.cause());
        }
    });

    return updateStatusPromise.future();
}
 
Example #13
Source File: DefaultKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>> customResource(CustomResourceDefinition crd, Class<T> resourceType, Class<L> listClass, Class<D> doneClass) {
  return customResources(crd, resourceType, listClass, doneClass);
}
 
Example #14
Source File: MockKube.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
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) {
    return withCustomResourceDefinition(crd, instanceClass, instanceListClass, doneableInstanceClass, null, null);
}
 
Example #15
Source File: MockKube.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
private static <T extends HasMetadata, D extends Doneable<T>> Map<String, T> db(Collection<T> initialResources, Class<T> cls, Class<D> doneableClass) {
    return new ConcurrentHashMap<>(initialResources.stream().collect(Collectors.toMap(
        c -> c.getMetadata().getName(),
        c -> copyResource(c, cls, doneableClass))));
}
 
Example #16
Source File: KubeClient.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public <T extends HasMetadata, L extends KubernetesResourceList, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>> customResources(CustomResourceDefinition crd, Class<T> resourceType, Class<L> listClass, Class<D> doneClass) {
    return client.customResources(crd, resourceType, listClass, doneClass); //TODO namespace here
}
 
Example #17
Source File: ResourceManager.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static <T extends CustomResource, L extends CustomResourceList<T>, D extends Doneable<T>> void replaceCrdResource(Class<T> crdClass, Class<L> listClass, Class<D> doneableClass, String resourceName, Consumer<T> editor) {
    Resource<T, D> namedResource = Crds.operation(kubeClient().getClient(), crdClass, listClass, doneableClass).inNamespace(kubeClient().getNamespace()).withName(resourceName);
    T resource = namedResource.get();
    editor.accept(resource);
    namedResource.replace(resource);
}
 
Example #18
Source File: ManagedKubernetesClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>> customResource(CustomResourceDefinition crd, Class<T> resourceType, Class<L> listClass, Class<D> doneClass) {
  return customResources(crd, resourceType, listClass, doneClass);
}
 
Example #19
Source File: OpenShiftServiceNoOp.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@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 #20
Source File: OpenShiftServiceNoOp.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@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 #21
Source File: OpenShiftServiceNoOp.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> Watch watchCR(CustomResourceDefinition crd, Class<T> resourceType, Class<L> resourceListType, Class<D> doneableResourceType, BiConsumer<Watcher.Action, T> watcher) {
    return null;
}
 
Example #22
Source File: OpenShiftServiceNoOp.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@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 #23
Source File: OpenShiftServiceNoOp.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> T getCR(CustomResourceDefinition crd, Class<T> resourceType, Class<L> resourceListType, Class<D> doneableResourceType, String customResourceName) {
    // Empty no-op just for testing
    return null;
}
 
Example #24
Source File: OpenShiftServiceNoOp.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> T createOrReplaceCR(CustomResourceDefinition crd, Class<T> resourceType, Class<L> resourceListType, Class<D> doneableResourceType, T customResource) {
    // Empty no-op just for testing
    return null;
}
 
Example #25
Source File: OpenShiftServiceImpl.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@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 getCRDClient(crd, resourceType, resourceListType, doneableResourceType).inNamespace(config.getNamespace()).withLabels(labels).list().getItems();
}
 
Example #26
Source File: OpenShiftServiceImpl.java    From syndesis with Apache License 2.0 4 votes vote down vote up
private <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>> getCRDClient(CustomResourceDefinition crd, Class<T> resourceType, Class<L> resourceListType, Class<D> doneableResourceType) {
    return openShiftClient.customResources(crd, resourceType, resourceListType, doneableResourceType);
}
 
Example #27
Source File: OpenShiftServiceImpl.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> T getCR(CustomResourceDefinition crd, Class<T> resourceType, Class<L> resourceListType, Class<D> doneableResourceType, String customResourceName){
    return getCRDClient(crd, resourceType, resourceListType, doneableResourceType).inNamespace(config.getNamespace()).withName(customResourceName).get();
}
 
Example #28
Source File: OpenShiftServiceImpl.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings({"unchecked"})
public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> T createOrReplaceCR(CustomResourceDefinition crd, Class<T> resourceType, Class<L> resourceListType, Class<D> doneableResourceType, T customResource){
    return getCRDClient(crd, resourceType, resourceListType, doneableResourceType).inNamespace(config.getNamespace()).createOrReplace(customResource);
}
 
Example #29
Source File: KubernetesClient.java    From kubernetes-client with Apache License 2.0 2 votes vote down vote up
/**
 * Typed API for managing CustomResources. You would need to provide POJOs for
 * CustomResource into this and with it you would be able to instantiate a client
 * specific to CustomResource.
 *
 * @param crdContext CustomResourceDefinitionContext describes the core fields used to search for CustomResources
 * @param resourceType Class for CustomResource
 * @param listClass Class for list object for CustomResource
 * @param doneClass Class for Doneable CustomResource object
 * @param <T> T type represents CustomResource type
 * @param <L> L type represents CustomResourceList type
 * @param <D> D type represents DoneableCustomResource type
 * @return returns a MixedOperation object with which you can do basic CustomResource operations
 */
<T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>> customResources(CustomResourceDefinitionContext crdContext, Class<T> resourceType, Class<L> listClass, Class<D> doneClass);
 
Example #30
Source File: KubernetesClient.java    From kubernetes-client with Apache License 2.0 2 votes vote down vote up
/**
 * Typed API for managing CustomResources. You would need to provide POJOs for
 * CustomResource into this and with it you would be able to instantiate a client
 * specific to CustomResource.
 *
 * @deprecated use {@link #customResources(CustomResourceDefinitionContext, Class, Class, Class)}, which takes a {@link CustomResourceDefinitionContext}
 * instead of a full {@link CustomResourceDefinition}.
 *
 * @param crd CustomResourceDefinition object on basic of which this CustomResource was created
 * @param resourceType Class for CustomResource
 * @param listClass Class for list object for CustomResource
 * @param doneClass Class for Doneable CustomResource object
 * @param <T> T type represents CustomResource type
 * @param <L> L type represents CustomResourceList type
 * @param <D> D type represents DoneableCustomResource type
 * @return returns a MixedOperation object with which you can do basic CustomResource operations
 */
@Deprecated
<T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>> customResources(CustomResourceDefinition crd, Class<T> resourceType, Class<L> listClass, Class<D> doneClass);