/// <summary>
        ///     Ensure that a PersistentVolumeClaim for data exists for the specified database server.
        /// </summary>
        /// <returns>
        ///     The PersistentVolumeClaim resource, as a <see cref="PersistentVolumeClaimV1"/>.
        /// </returns>
        public async Task <PersistentVolumeClaimV1> EnsureDataVolumeClaimPresent()
        {
            RequireCurrentState();

            PersistentVolumeClaimV1 existingPersistentVolumeClaim = await FindDataVolumeClaim();

            if (existingPersistentVolumeClaim != null)
            {
                Log.LogInformation("Found existing data-volume claim {PersistentVolumeClaimName} for server {ServerId}.",
                                   existingPersistentVolumeClaim.Metadata.Name,
                                   State.Id
                                   );

                return(existingPersistentVolumeClaim);
            }

            Log.LogInformation("Creating data-volume claim for server {ServerId}...",
                               State.Id
                               );

            PersistentVolumeClaimV1 createdPersistentVolumeClaim = await KubeClient.PersistentVolumeClaimsV1().Create(
                KubeResources.DataVolumeClaim(State,
                                              kubeNamespace: KubeOptions.KubeNamespace
                                              )
                );

            Log.LogInformation("Successfully created data-volume claim {PersistentVolumeClaimName} for server {ServerId}.",
                               createdPersistentVolumeClaim.Metadata.Name,
                               State.Id
                               );

            return(createdPersistentVolumeClaim);
        }
        /// <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);
        }
        /// <summary>
        ///     Find the server's associated PersistentVolumeClaim for data (if it exists).
        /// </summary>
        /// <returns>
        ///     The PersistentVolumeClaim, or <c>null</c> if it was not found.
        /// </returns>
        public async Task <PersistentVolumeClaimV1> FindDataVolumeClaim()
        {
            RequireCurrentState();

            List <PersistentVolumeClaimV1> matchingPersistentVolumeClaims = await KubeClient.PersistentVolumeClaimsV1().List(
                labelSelector: $"cloud.dimensiondata.daas.server-id = {State.Id}, cloud.dimensiondata.daas.volume-type = data",
                kubeNamespace: KubeOptions.KubeNamespace
                );

            if (matchingPersistentVolumeClaims.Count == 0)
            {
                return(null);
            }

            return(matchingPersistentVolumeClaims[matchingPersistentVolumeClaims.Count - 1]);
        }