public DatabaseServerResource Rehydrate(DatabaseServerResource server)
        {
            if (string.IsNullOrEmpty(server?.Spec.ServiceUrl) && server?.Spec.ServiceSelector != null)
            {
                var services   = service.GetService(server.Metadata.NamespaceProperty, server.Spec.ServiceSelector);
                var sqlService = services?.Items?.FirstOrDefault();

                if (sqlService != null)
                {
                    server.Spec.ServiceUrl = $"{sqlService.Metadata.Name}.{sqlService.Metadata.NamespaceProperty}.svc,{sqlService.Spec.Ports.FirstOrDefault()?.Port}";
                }
            }

            if (string.IsNullOrEmpty(server?.Spec.AdminPasswordSecret.Value) && server?.Spec.AdminPasswordSecret.SecretKeyRef != null)
            {
                server.Spec.AdminPasswordSecret = secretRehydrator.Rehydrate(server.Metadata.NamespaceProperty, server.Spec.AdminPasswordSecret);
            }

            return(server);
        }
        public override bool HandleDequeuedItem(WatchEventType eventType, CredentialsResource item, int previousExecutionCount)
        {
            try
            {
                if (eventType != WatchEventType.Deleted)
                {
                    int executionCount = 0;
                    secretSourceRehydrator.Rehydrate(item.Metadata.NamespaceProperty, item.Spec.Secret);

                    var databases = k8sService.GetDatabases(item.Metadata.NamespaceProperty, item.Spec.DatabaseSelector);
                    foreach (var database in databases.Items)
                    {
                        if (database.Status.Reason == "Available")
                        {
                            var servers = k8sService.GetDatabaseServer(item.Metadata.NamespaceProperty, database.Spec.DatabaseServerSelector);
                            foreach (var server in servers.Items)
                            {
                                rehydrator.Rehydrate(server);
                                if (sqlService.DoesCredentialExist(server.Spec, item.Spec.CredentialName))
                                {
                                    sqlService.UpdateCredential(server.Spec, item.Spec);
                                }
                                else
                                {
                                    sqlService.CreateCredential(server.Spec, item.Spec);
                                }

                                executionCount++;
                            }
                        }
                    }

                    if (executionCount > 0)
                    {
                        RecordStatus(item, "Executed", "Successfully executed");
                        return(true);
                    }

                    return(false);
                }
                else
                {
                    var databases = k8sService.GetDatabases(item.Metadata.NamespaceProperty, item.Spec.DatabaseSelector);
                    foreach (var database in databases.Items)
                    {
                        if (database.Status.Reason == "Available")
                        {
                            var servers = k8sService.GetDatabaseServer(item.Metadata.NamespaceProperty, database.Spec.DatabaseServerSelector);
                            foreach (var server in servers.Items)
                            {
                                rehydrator.Rehydrate(server);
                                sqlService.DeleteCredential(server.Spec, item.Spec);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "An error occurred during message processing");

                try
                {
                    RecordStatus(item, "Failed", ex.GetType().Name);
                    eventRecorder.Record("ExecuteDeploymentScript",
                                         "Failed",
                                         ex.Message,
                                         new V1ObjectReference(
                                             item.ApiVersion,
                                             kind: item.Kind,
                                             name: item.Metadata.Name,
                                             namespaceProperty: item.Metadata.NamespaceProperty)
                                         );
                }
                catch (HttpOperationException httpEx)
                {
                    Logger.LogError(httpEx, "An error occurred logging this info to Kubernetes");
                    Logger.LogDebug(httpEx.Response.Content);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return(true);
        }