Interface NonDeletingOperation<T>

    • Method Detail

      • createOr

        T createOr​(Function<NonDeletingOperation<T>,​T> conflictAction)
        Alternative to CreateOrReplaceable.createOrReplace().

        Will attempt a create, and if that fails will perform the conflictAction.

        Most commonly the conflictAction will be NonDeletingOperation::update or NonDeletingOperation::patch, but you are free to provide whatever Function suits your needs.

        Parameters:
        conflictAction - to be performed it the create fails with a conflict
        Returns:
      • unlock

        NonDeletingOperation<T> unlock()
        Removes the resource version from the current item. If the operation context was created by name, and without an item, this will fetch the item from the api server first.
        Returns:
        NonDeletingOperation that may act on the unlocked item
      • editStatus

        T editStatus​(UnaryOperator<T> function)
        Edit the status subresource
        Parameters:
        function - to produce a modified status
        Returns:
        updated object
      • patchStatus

        T patchStatus()
        Does a PATCH request to the /status subresource ignoring changes to anything except the status stanza.

        This method has the same patching behavior as EditReplacePatchable.patch(PatchContext), with PatchType.JSON_MERGE but against the status subresource.

        Set the resourceVersion to null to prevent optimistic locking.

        Returns:
        updated object
      • subresource

        EditReplacePatchable<T> subresource​(String subresource)
        Provides edit, patch, and replace methods for the given subresource.

        This method allows you to perform operations on any subresource of a Kubernetes resource, similar to kubectl's --subresource flag. Subresources are specialized endpoints that provide additional operations beyond standard CRUD operations.

        Common Kubernetes Subresources:

        • status - Updates the status stanza independently (use status() convenience method)
        • scale - Manages replica counts for scalable resources (Deployment, ReplicaSet, StatefulSet, etc.)
        • ephemeralcontainers - Manages ephemeral containers for debugging Pods
        • binding - Binds Pods to Nodes (typically handled by the Kubernetes scheduler)
        • approval - Approves CertificateSigningRequests
        • token - Requests bound service account tokens (use ServiceAccountResource#tokenRequest())
        • Custom subresources - Defined by CustomResourceDefinitions (CRDs)

        Example usage:

         
         // 1. Update ephemeral containers subresource (for debugging)
         client.pods().withName("my-pod")
           .subresource("ephemeralcontainers")
           .edit(pod -> new PodBuilder(pod)
             .editSpec()
               .addNewEphemeralContainer()
                 .withName("debugger")
                 .withImage("busybox:latest")
                 .withCommand("sh")
               .endEphemeralContainer()
             .endSpec()
             .build());
        
         // 2. Patch scale subresource to change replica count
         //    (alternative to using the Scalable interface)
         client.apps().deployments()
           .inNamespace("default")
           .withName("my-deployment")
           .subresource("scale")
           .patch(PatchContext.of(PatchType.JSON_MERGE),
             "{\"spec\":{\"replicas\":5}}");
        
         // 3. Update status subresource (prefer using status() method)
         client.pods().resource(myPod)
           .subresource("status")
           .patch();
        
         // 4. Work with custom subresources on CRDs
         client.resources(MyCustomResource.class)
           .inNamespace("default")
           .withName("my-resource")
           .subresource("my-custom-subresource")
           .patch();
         
         

        Note: For common operations, consider using specialized methods or interfaces:

        Parameters:
        subresource - the name of the subresource (e.g., "status", "scale", "ephemeralcontainers", "binding", "approval")
        Returns:
        an operation context for the specified subresource that supports edit, patch, and replace operations
        See Also:
        status(), Scalable, Kubernetes API Concepts - Subresources
      • status

        default EditReplacePatchable<T> status()
        Provides edit, patch, and replace methods for the status subresource.

        This is a convenience method equivalent to subresource("status"). The status subresource is used to update the status stanza of a Kubernetes resource without modifying the spec or metadata.

        Example usage:

         
         // Update custom resource status
         client.resources(MyCustomResource.class)
           .withName("my-resource")
           .status()
           .edit(resource -> {
             resource.setStatus(new MyCustomResourceStatus());
             return resource;
           });
        
         // Patch status directly
         myResource.getStatus().setPhase("Ready");
         client.resource(myResource)
           .status()
           .patch();
         
         
        Returns:
        an operation context for the status subresource
        See Also:
        subresource(String), editStatus(UnaryOperator), patchStatus()