/// <summary> /// Ensure that a PersistentVolumeClaim for data does not exist for the specified database server. /// </summary> /// <returns> /// <c>true</c>, if the controller is now absent; otherwise, <c>false</c>. /// </returns> public async Task <bool> EnsureDataVolumeClaimAbsent() { RequireCurrentState(); PersistentVolumeClaimV1 dataVolumeClaim = await FindDataVolumeClaim(); if (dataVolumeClaim == null) { return(true); } Log.LogInformation("Deleting data-volume claim {PersistentVolumeClaimName} for server {ServerId}...", dataVolumeClaim.Metadata.Name, State.Id ); try { await KubeClient.PersistentVolumeClaimsV1().Delete( name: dataVolumeClaim.Metadata.Name, kubeNamespace: KubeOptions.KubeNamespace, propagationPolicy: DeletePropagationPolicy.Background ); string dataVolumeName = dataVolumeClaim.Spec.VolumeName; if (!String.IsNullOrWhiteSpace(dataVolumeClaim.Spec.VolumeName)) { Log.LogInformation("Deleting data volume {PersistentVolumeName} for server {ServerId}...", dataVolumeName, State.Id ); await KubeClient.PersistentVolumesV1().Delete( name: dataVolumeName, kubeNamespace: KubeOptions.KubeNamespace ); } } catch (HttpRequestException <StatusV1> deleteFailed) { Log.LogError("Failed to delete data-volume claim {PersistentVolumeClaimName} for server {ServerId} (Message:{FailureMessage}, Reason:{FailureReason}).", dataVolumeClaim.Metadata.Name, State.Id, deleteFailed.Response.Message, deleteFailed.Response.Reason ); return(false); } Log.LogInformation("Deleted data-volume claim {PersistentVolumeClaimName} for server {ServerId}.", dataVolumeClaim.Metadata.Name, State.Id ); return(true); }