Search code examples
kuberneteskubectlfabric8

How to delete a custom resource using fabric8io?


Is it possible to delete custom resource using fabric8io?
If not, is it possible using kubectl java client ?


Solution

  • Both is possible.

    Fabric8 example:

    public static Map<String, Object> doDeleteCustomResource(
        KubernetesClient kubernetesClient, CustomResourceDefinitionContext crdContext, String namespace, String name)
        throws IOException{
    
        if ("Namespaced".equals(crdContext.getScope())) {
            return kubernetesClient.customResource(crdContext).delete(namespace, name);
        } else {
            return kubernetesClient.customResource(crdContext).delete(name);
        }
    }
    

    Taken from here.

    Or similarly using the Java Operator SDK which is also using the Fabric8 client:

    client.customResource(context).delete(name);
    

    You can also check out the tests in the fabric8 client code here for more examples.