/// <summary> /// Asynchronously deletes a namespaced object, and waits for the delete operation /// to complete. /// </summary> /// <typeparam name="T"> /// The type of the Kubernetes object to delete. /// </typeparam> /// <param name="value"> /// The object to delete. /// </param> /// <param name="deleteAction"> /// A delegate to a method which schedules the deletion. /// </param> /// <param name="watchAction"> /// A delegate to a method which creates a watcher for the object. /// Used to monitor the progress of the delete operation. /// </param> /// <param name="timeout"> /// The amount of time to wait for the object to be deleted. /// </param> /// <param name="cancellationToken"> /// A <see cref="CancellationToken"/> which can be used to cancel the /// asynchronous operation. /// </param> /// <returns> /// A <see cref="Task"/> representing the asynchronous operation. /// </returns> public Task DeleteNamespacedObjectAsync <T>( T value, DeleteNamespacedObjectAsyncDelegate <T> deleteAction, WatchObjectAsyncDelegate <T> watchAction, TimeSpan timeout, CancellationToken cancellationToken) where T : IKubernetesObject <V1ObjectMeta> { return(this.DeleteNamespacedObjectAsync( value, options: null, deleteAction, watchAction, timeout, cancellationToken)); }
/// <summary> /// Asynchronously deletes a namespaced object, and waits for the delete operation /// to complete. /// </summary> /// <typeparam name="T"> /// The type of the Kubernetes object to delete. /// </typeparam> /// <param name="value"> /// The object to delete. /// </param> /// <param name="options"> /// Additional options which specify how the delete operation should be processed. /// </param> /// <param name="deleteAction"> /// A delegate to a method which schedules the deletion. /// </param> /// <param name="watchAction"> /// A delegate to a method which creates a watcher for the object. /// Used to monitor the progress of the delete operation. /// </param> /// <param name="timeout"> /// The amount of time to wait for the object to be deleted. /// </param> /// <param name="cancellationToken"> /// A <see cref="CancellationToken"/> which can be used to cancel the /// asynchronous operation. /// </param> /// <returns> /// A <see cref="Task"/> representing the asynchronous operation. /// </returns> public virtual async Task DeleteNamespacedObjectAsync <T>( T value, V1DeleteOptions?options, DeleteNamespacedObjectAsyncDelegate <T> deleteAction, WatchObjectAsyncDelegate <T> watchAction, TimeSpan timeout, CancellationToken cancellationToken) where T : IKubernetesObject <V1ObjectMeta> { if (value == null) { throw new ArgumentNullException(nameof(value)); } if (value.Metadata == null) { throw new ValidationException(ValidationRules.CannotBeNull, "value.Metadata"); } if (value.Metadata.Name == null) { throw new ValidationException(ValidationRules.CannotBeNull, "value.Metadata.Name"); } if (value.Metadata.NamespaceProperty == null) { throw new ValidationException(ValidationRules.CannotBeNull, "value.Metadata.NamespaceProperty"); } CancellationTokenSource cts = new CancellationTokenSource(); cancellationToken.Register(cts.Cancel); var watchTask = watchAction( value, onEvent: (type, updatedValue) => { value = updatedValue; if (type == WatchEventType.Deleted) { return(Task.FromResult(WatchResult.Stop)); } return(Task.FromResult(WatchResult.Continue)); }, cts.Token); await deleteAction( value.Metadata.Name, value.Metadata.NamespaceProperty, body : options, cancellationToken : cancellationToken).ConfigureAwait(false); if (await Task.WhenAny(watchTask, Task.Delay(timeout)).ConfigureAwait(false) != watchTask) { cts.Cancel(); throw new KubernetesException($"The {value.Kind} '{value.Metadata.Name}' was not deleted within a timeout of {timeout.TotalSeconds} seconds."); } var result = await watchTask.ConfigureAwait(false); if (result != WatchExitReason.ClientDisconnected) { throw new KubernetesException($"The API server unexpectedly closed the connection while watching {value.Kind} '{value.Metadata.Name}'."); } }