- * If specified CRD is of Namespaced scope, this method would delete all Custom Resources in namespace which is
- * specified as parameter.
- * If specified CRD is of Cluster scope, this method would delete a Custom Resource matching the name which is
- * specified as parameter
- *
- *
- * @param namespaceOrName desired namespace(if CRD is Namespaced) or name(If CRD is Cluster)
- * @return deleted objects as HashMap
- * @deprecated Use {@link #inNamespace(String)}.{@link #delete()} or {@link #withName(String)}.{@link #delete()} instead.
- */
- @Deprecated
- public boolean delete(String namespaceOrName) {
- if (delegate.isResourceNamespaced()) {
- return delegate.inNamespace(namespaceOrName).delete();
- }
- return delegate.withName(namespaceOrName).delete();
- }
-
- /**
- * Delete all Namespaced Scoped Custom Resources in a specified namespace
- *
- * If specified CRD is of Namespaced scope, this method would delete all Custom Resources in namespace which is
- * specified as parameter.
- * If specified CRD is of Cluster scope, this method would delete a Custom Resource matching the name which is
- * specified as parameter
- *
- *
- * @param namespaceOrName desired namespace(If CRD is Namespaced) or name(If CRD is Cluster)
- * @param cascading whether dependent object need to be orphaned or not. If true/false, the "orphan"
- * finalizer will be added to/removed from the object's finalizers list.
- * @return a boolean value whether item was deleted or item didn't exist in server
- * @throws IOException in case of any network/parsing exception
- */
- public boolean delete(String namespaceOrName, boolean cascading) throws IOException {
- if (delegate.isResourceNamespaced()) {
- return delegate.inNamespace(namespaceOrName).delete();
- }
- return delegate.withName(namespaceOrName).cascading(cascading).delete();
- }
-
- /**
- * Delete all Namespaced Scoped Custom Resources in a specified namespace
- *
- * If specified CRD is of Namespaced scope, this method would delete all Custom Resources in namespace which is
- * specified as parameter.
- * If specified CRD is of Cluster scope, this method would delete a Custom Resource matching the name which is
- * specified as parameter
- *
- *
- * @param namespaceOrName desired namespace(If CRD is Namespaced) or name(If CRD is Cluster)
- * @param deleteOptions object provided by Kubernetes API for more fine grained control over deletion.
- * For more information please see https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#deleteoptions-v1-meta
- * @return a boolean value whether item was deleted or item didn't exist in server
- * @throws IOException in case of any network/object parse problems
- */
- public boolean delete(String namespaceOrName, DeleteOptions deleteOptions) throws IOException {
- if (delegate.isResourceNamespaced()) {
- return withDeleteOptions(deleteOptions).inNamespace(namespaceOrName).delete();
- }
- return withDeleteOptions(deleteOptions).withName(namespaceOrName).delete();
- }
-
- /**
- * Delete a custom resource in a specific namespace
- *
- * @param namespace desired namespace
- * @param name custom resource's name
- * @return a boolean value whether item was deleted or item didn't exist in server
- * @throws IOException in case of any network/object parse problems
- * @deprecated Use {@link #inNamespace(String)}.{@link #withName(String)}.{@link #delete()} instead.
- */
- @Deprecated
- public boolean delete(String namespace, String name) throws IOException {
- return delegate.inNamespace(namespace).withName(name).delete();
- }
-
- /**
- * Delete a custom resource in a specific namespace
- *
- * @param namespace required namespace
- * @param name required name of custom resource
- * @param cascading whether dependent object need to be orphaned or not. If true/false, the "orphan"
- * finalizer will be added to/removed from the object's finalizers list.
- * @return a boolean value whether item was deleted or item didn't exist in server
- * @throws IOException exception related to network/object parsing
- */
- public boolean delete(String namespace, String name, boolean cascading) throws IOException {
- return delegate.inNamespace(namespace).withName(name).cascading(cascading).delete();
- }
-
- /**
- * Delete a custom resource in a specific namespace
- *
- * @param namespace required namespace
- * @param name required name of custom resource
- * @param propagationPolicy Whether and how garbage collection will be performed. Either this field or OrphanDependents
- * may be set, but not both. The default policy is decided by the existing finalizer set in
- * the metadata.finalizers and the resource-specific default policy.
- * Acceptable values are:
- * 'Orphan' - orphan the dependents;
- * 'Background' - allow the garbage collector to delete the dependents in the background;
- * 'Foreground' - a cascading policy that deletes all dependents in the foreground.
- * @return a boolean value whether item was deleted or item didn't exist in server
- * @throws IOException in case of network/object parse exception
- */
- public boolean delete(String namespace, String name, String propagationPolicy) throws IOException {
- return delegate.inNamespace(namespace).withName(name)
- .withPropagationPolicy(resolveDeletionPropagation(propagationPolicy)).delete();
- }
-
- /**
- * Delete a custom resource in a specific namespace
- *
- * @param namespace required namespace
- * @param name name of custom resource
- * @param deleteOptions object provided by Kubernetes API for more fine grained control over deletion.
- * For more information please see https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#deleteoptions-v1-meta
- * @return a boolean value whether item was deleted or item didn't exist in server
- * @throws IOException in case of any network/object parse exception
- */
- public boolean delete(String namespace, String name, DeleteOptions deleteOptions) throws IOException {
- return withDeleteOptions(deleteOptions).inNamespace(namespace).withName(name).delete();
- }
-
- @Override
- public Boolean delete() {
- return delegate.delete();
- }
-
-
- /**
- * Watch custom resources across all namespaces. Here watcher is provided
- * for string type only. User has to deserialize object itself.
- *
- * @param watcher watcher object which reports events
- * @return watch object for watching resource
- * @throws IOException in case of network error
- */
- public Watch watch(Watcher watcher) throws IOException {
- return delegate.watch(new DelegateWatcher(watcher));
- }
-
- /**
- * Watch custom resources in the parameters specified.
- *
- * Most of the parameters except watcher are optional, they would be
- * skipped if passed null. Here watcher is provided for string type
- * only. User has to deserialize the object itself.
- *
- * @param namespace namespace to watch (optional
- * @param name name of custom resource (optional)
- * @param labels HashMap containing labels (optional)
- * @param options {@link ListOptions} list options for watch
- * @param watcher watcher object which reports events
- * @return watch object for watching resource
- * @throws IOException in case of network error
- */
- public Watch watch(String namespace, String name, Map labels, ListOptions options, Watcher watcher) throws IOException {
- GenericKubernetesResourceOperationsImpl ops = delegate;
- if (Utils.isNotNullOrEmpty(namespace)) {
- ops = (GenericKubernetesResourceOperationsImpl) ops.inNamespace(namespace);
- }
- if (Utils.isNotNullOrEmpty(name)) {
- ops = (GenericKubernetesResourceOperationsImpl) ops.withName(name);
- }
- return ops.watch(
- listOptionsBuilder(options).withLabelSelector(getLabelsQueryParam(labels)).build(),
- new DelegateWatcher(watcher));
- }
-
- /**
- * Watch custom resources in the parameters specified.
- *
- * Most of the parameters except watcher are optional, they would be
- * skipped if passed null. Here watcher is provided for string type
- * only. User has to deserialize the object itself.
- *
- * @param namespace namespace to watch (optional
- * @param name name of custom resource (optional)
- * @param labels HashMap containing labels (optional)
- * @param resourceVersion resource version to start watch from
- * @param watcher watcher object which reports events
- * @return watch object for watching resource
- * @throws IOException in case of network error
- */
- public Watch watch(String namespace, String name, Map labels, String resourceVersion, Watcher watcher) throws IOException {
- return watch(namespace, name, labels, new ListOptionsBuilder().withResourceVersion(resourceVersion).build(), watcher);
- }
-
- /**
- * Watch custom resources in a specific namespace. Here Watcher is provided
- * for string type only. User has to deserialize object itself.
- *
- * @param namespace namespace to watch
- * @param watcher watcher object which reports updates with object
- * @return watch object for watching resource
- * @throws IOException in case of network error
- */
- public Watch watch(String namespace, Watcher watcher) throws IOException {
- return watch(namespace, null, null, (ListOptions) null, watcher);
- }
-
- /**
- * Watch a custom resource in a specific namespace with some resourceVersion. Here
- * watcher is provided from string type only. User has to deserialize object itself.
- *
- * @param namespace namespace to watch
- * @param resourceVersion resource version since when to watch
- * @param watcher watcher object which reports updates
- * @return watch object for watching resource
- * @throws IOException in case of network error
- */
- public Watch watch(String namespace, String resourceVersion, Watcher watcher) throws IOException {
- return watch(namespace, null, null, resourceVersion, watcher);
- }
-
- /**
- * Watch a custom resource in a specific namespace with some resourceVersion. Here
- * watcher is provided from string type only. User has to deserialize object itself.
- *
- * @param namespace namespace to watch
- * @param options {@link ListOptions} list options for watching
- * @param watcher watcher object which reports updates
- * @return watch object for watching resource
- * @throws IOException in case of network error
- */
- public Watch watch(String namespace, ListOptions options, Watcher watcher) throws IOException {
- return watch(namespace, null, null, options, watcher);
- }
-
- /**
- * Watch custom resources in the parameters specified.
- *
- * Most of the parameters except watcher are optional, they would be
- * skipped if passed null. Here watcher is provided for string type
- * only. User has to deserialize the object itself.
- *
- * @param labels HashMap containing labels (optional)
- * @param options {@link ListOptions} list options for watch
- * @param watcher watcher object which reports events
- * @return watch object for watching resource
- * @throws IOException in case of network error
- */
- public Watch watch(Map labels, ListOptions options, Watcher watcher) throws IOException {
- return delegate.watch(
- listOptionsBuilder(options).withLabelSelector(getLabelsQueryParam(labels)).build(),
- new DelegateWatcher(watcher));
- }
-
- private String getLabelsQueryParam(Map labels) {
- if (labels == null) {
- return null;
- }
- StringBuilder labelQueryBuilder = new StringBuilder();
- for (Map.Entry entry : labels.entrySet()) {
- if (labelQueryBuilder.length() > 0) {
- labelQueryBuilder.append(",");
- }
- labelQueryBuilder.append(entry.getKey()).append("=").append(entry.getValue());
- }
- return labelQueryBuilder.toString();
- }
-
- private static DeletionPropagation resolveDeletionPropagation(String propagationPolicy) {
- return Stream.of(DeletionPropagation.values())
- .filter(dp -> dp.name().toUpperCase(Locale.ENGLISH).equals(propagationPolicy.toUpperCase(Locale.ENGLISH)))
- .findFirst()
- .orElse(DEFAULT_PROPAGATION_POLICY);
- }
-
- private long resolveGracePeriod(Long gracePeriodInSeconds) {
- return gracePeriodInSeconds != null ? gracePeriodInSeconds : delegate.getGracePeriodSeconds();
- }
-
- private DeletionPropagation resolvePropagationPolicy(String deletionPropagation) {
- return deletionPropagation != null ? resolveDeletionPropagation(deletionPropagation) : delegate.getPropagationPolicy();
- }
-
- private static ListOptionsBuilder listOptionsBuilder(ListOptions options) {
- return options == null ? new ListOptionsBuilder() : new ListOptionsBuilder(options);
- }
-
- private static Map toMap(GenericKubernetesResource gkr) {
- return Serialization.jsonMapper().convertValue(gkr, new TypeReference