diff --git a/controllers/drupalsite_controller_test.go b/controllers/drupalsite_controller_test.go index 851c5b7326828934ed378092413e9bf3477c2370..6a62ffe0a4409233ec9bfb59ce5eb7957a411154 100644 --- a/controllers/drupalsite_controller_test.go +++ b/controllers/drupalsite_controller_test.go @@ -1564,30 +1564,6 @@ var _ = Describe("DrupalSite controller", func() { oidcReturnUri := authz.OidcReturnURI{} schedule := velerov1.Schedule{} cronjob := batchbeta1.CronJob{} - redis_deploy := appsv1.Deployment{} - redis_secret := corev1.Secret{} - redis_service := corev1.Service{} - - // Check Redis deployment resource creation - By("Expecting Redis deployment created") - Eventually(func() []metav1.OwnerReference { - k8sClient.Get(ctx, types.NamespacedName{Name: "redis-" + key.Name, Namespace: key.Namespace}, &redis_deploy) - return redis_deploy.ObjectMeta.OwnerReferences - }, timeout, interval).Should(ContainElement(expectedOwnerReference)) - - // Check Redis service resource creation - By("Expecting Redis service created") - Eventually(func() []metav1.OwnerReference { - k8sClient.Get(ctx, types.NamespacedName{Name: "redis-" + key.Name, Namespace: key.Namespace}, &redis_service) - return redis_service.ObjectMeta.OwnerReferences - }, timeout, interval).Should(ContainElement(expectedOwnerReference)) - - // Check Redis secret resource creation - By("Expecting Redis secret created") - Eventually(func() []metav1.OwnerReference { - k8sClient.Get(ctx, types.NamespacedName{Name: "redis-" + key.Name, Namespace: key.Namespace}, &redis_secret) - return redis_secret.ObjectMeta.OwnerReferences - }, timeout, interval).Should(ContainElement(expectedOwnerReference)) // Check DBOD resource creation By("Expecting Database resource created") @@ -1717,7 +1693,7 @@ var _ = Describe("DrupalSite controller", func() { Describe("Updating the critical QoS drupalSite object", func() { Context("With standard QoS", func() { - It("All dependent resources should be created and redis resources should be removed", func() { + It("All dependent resources should be created", func() { key = types.NamespacedName{ Name: Name + "-critical", Namespace: "critical", @@ -1756,27 +1732,6 @@ var _ = Describe("DrupalSite controller", func() { oidcReturnUri := authz.OidcReturnURI{} schedule := velerov1.Schedule{} cronjob := batchbeta1.CronJob{} - redis_deploy := appsv1.Deployment{} - redis_secret := corev1.Secret{} - redis_service := corev1.Service{} - - // Check Redis deployment resource deleted - By("Expecting Redis deployment deleted") - Eventually(func() error { - return k8sClient.Get(ctx, types.NamespacedName{Name: "redis-" + key.Name, Namespace: key.Namespace}, &redis_deploy) - }, timeout, interval).Should(Not(Succeed())) - - // Check Redis service resource deleted - By("Expecting Redis service deleted") - Eventually(func() error { - return k8sClient.Get(ctx, types.NamespacedName{Name: "redis-" + key.Name, Namespace: key.Namespace}, &redis_service) - }, timeout, interval).Should(Not(Succeed())) - - // Check Redis secret resource creation - By("Expecting Redis secret created") - Eventually(func() error { - return k8sClient.Get(ctx, types.NamespacedName{Name: "redis-" + key.Name, Namespace: key.Namespace}, &redis_secret) - }, timeout, interval).Should(Not(Succeed())) // Check DBOD resource creation By("Expecting Database resource created") diff --git a/controllers/drupalsite_resources.go b/controllers/drupalsite_resources.go index 5d58b3830854e8d34368a6977d61c75b6f3fc443..18e8052e0e5eadbb96a7e95911f4d8e3beeba41b 100644 --- a/controllers/drupalsite_resources.go +++ b/controllers/drupalsite_resources.go @@ -27,7 +27,6 @@ import ( "net/url" "path" "reflect" - "sort" "strconv" "time" @@ -301,30 +300,6 @@ func (r *DrupalSiteReconciler) ensureResources(drp *webservicesv1a1.DrupalSite, if transientErr := r.ensureResourceX(ctx, drp, "tekton_extra_perm_rbac", log); transientErr != nil { transientErrs = append(transientErrs, transientErr.Wrap("%v: for Tekton Extra Permissions ClusterRoleBinding")) } - - // 6. Redis cache for critical QoS Class sites - - if drp.Spec.QoSClass == webservicesv1a1.QoSCritical { - if transientErr := r.ensureRedisDeployment(ctx, drp, deploymentConfig, log); transientErr != nil { - transientErrs = append(transientErrs, transientErr.Wrap("%v: for Redis deployment")) - } - if transientErr := r.ensureResourceX(ctx, drp, "svc_redis", log); transientErr != nil { - transientErrs = append(transientErrs, transientErr.Wrap("%v: for Redis service")) - } - if transientErr := r.ensureResourceX(ctx, drp, "secret_redis", log); transientErr != nil { - transientErrs = append(transientErrs, transientErr.Wrap("%v: for Redis secret")) - } - } else { - if transientErr := r.ensureNoRedisDeployment(ctx, drp, log); transientErr != nil { - transientErrs = append(transientErrs, transientErr.Wrap("%v: while deleting the redis deployment")) - } - if transientErr := r.ensureNoRedisService(ctx, drp, log); transientErr != nil { - transientErrs = append(transientErrs, transientErr.Wrap("%v: while deleting the redis service")) - } - if transientErr := r.ensureNoRedisSecret(ctx, drp, log); transientErr != nil { - transientErrs = append(transientErrs, transientErr.Wrap("%v: while deleting the redis secret")) - } - } return transientErrs } @@ -349,8 +324,6 @@ ensureResourceX ensure the requested resource is created, with the following val - backup_schedule: Velero Schedule for scheduled backups of the drupalSite - tekton_extra_perm_rbac: ClusterRoleBinding for tekton tasks - cronjob: Creates cronjob to trigger Cron tasks on Drupalsites, see: https://gitlab.cern.ch/webservices/webframeworks-planning/-/issues/437 - - svc_redis: Redis Service for a critical QoS site - - gitlab_trigger_secret: Secret for Gitlab trigger config in buildconfig */ func (r *DrupalSiteReconciler) ensureResourceX(ctx context.Context, d *webservicesv1a1.DrupalSite, resType string, log logr.Logger) (transientErr reconcileError) { switch resType { @@ -549,37 +522,6 @@ func (r *DrupalSiteReconciler) ensureResourceX(ctx context.Context, d *webservic return newApplicationError(err, ErrClientK8s) } return nil - case "svc_redis": - service := &corev1.Service{ObjectMeta: metav1.ObjectMeta{Name: "redis-" + d.Name, Namespace: d.Namespace}} - _, err := controllerruntime.CreateOrUpdate(ctx, r.Client, service, func() error { - return serviceForRedis(service, d) - }) - if err != nil { - log.Error(err, "Failed to ensure Resource", "Kind", service.TypeMeta.Kind, "Resource.Namespace", service.Namespace, "Resource.Name", service.Name) - return newApplicationError(err, ErrClientK8s) - } - return nil - case "secret_redis": - secret := &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "redis-" + d.Name, Namespace: d.Namespace}} - _, err := controllerruntime.CreateOrUpdate(ctx, r.Client, secret, func() error { - return secretForRedis(secret, d) - }) - if err != nil { - log.Error(err, "Failed to ensure Resource", "Kind", secret.TypeMeta.Kind, "Resource.Namespace", secret.Namespace, "Resource.Name", secret.Name) - return newApplicationError(err, ErrClientK8s) - } - return nil - case "gitlab_trigger_secret": - gitlab_trigger_secret := &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "gitlab-trigger-secret-" + d.Name, Namespace: d.Namespace}} - _, err := controllerruntime.CreateOrUpdate(ctx, r.Client, gitlab_trigger_secret, func() error { - log.V(3).Info("Ensuring Resource", "Kind", gitlab_trigger_secret.TypeMeta.Kind, "Resource.Namespace", gitlab_trigger_secret.Namespace, "Resource.Name", gitlab_trigger_secret.Name) - return secretForS2iGitlabTrigger(gitlab_trigger_secret, d) - }) - if err != nil { - log.Error(err, "Failed to ensure Resource", "Kind", gitlab_trigger_secret.TypeMeta.Kind, "Resource.Namespace", gitlab_trigger_secret.Namespace, "Resource.Name", gitlab_trigger_secret.Name) - return newApplicationError(err, ErrClientK8s) - } - return nil default: return newApplicationError(nil, ErrFunctionDomain) } @@ -611,28 +553,9 @@ func (r *DrupalSiteReconciler) ensureDrupalDeployment(ctx context.Context, d *we return nil } -/* -ensureRedisDeployment is similar to ensureResourceX, but for the Redis deployment, which requires extra information. -*/ -func (r *DrupalSiteReconciler) ensureRedisDeployment(ctx context.Context, d *webservicesv1a1.DrupalSite, config DeploymentConfig, log logr.Logger) (transientErr reconcileError) { - deployment := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "redis-" + d.Name, Namespace: d.Namespace}} - _, err := controllerruntime.CreateOrUpdate(ctx, r.Client, deployment, func() error { - return deploymentForRedis(deployment, d, config) - }) - if err != nil { - log.Error(err, "Failed to ensure Resource", "Kind", deployment.TypeMeta.Kind, "Resource.Namespace", deployment.Namespace, "Resource.Name", deployment.Name) - return newApplicationError(err, ErrClientK8s) - } - return nil -} - func cronjobForDrupalSite(currentobject *batchbeta1.CronJob, databaseSecret string, drupalsite *webservicesv1a1.DrupalSite) error { var jobsHistoryLimit int32 = 1 var jobBackoffLimit int32 = 1 - var isCriticalSite string = "false" - if drupalsite.Spec.QoSClass == webservicesv1a1.QoSCritical { - isCriticalSite = "true" - } if currentobject.Labels == nil { currentobject.Labels = map[string]string{} } @@ -674,12 +597,6 @@ func cronjobForDrupalSite(currentobject *batchbeta1.CronJob, databaseSecret stri corev1.ResourceMemory: resource.MustParse(jobMemoryRequest), }, }, - Env: []corev1.EnvVar{ - { - Name: "ENABLE_REDIS", - Value: isCriticalSite, - }, - }, EnvFrom: []corev1.EnvFromSource{ { SecretRef: &corev1.SecretEnvSource{ @@ -751,9 +668,6 @@ func cronjobForDrupalSite(currentobject *batchbeta1.CronJob, databaseSecret stri }, }} } - for i := range currentobject.Spec.JobTemplate.Spec.Template.Spec.Containers { - addOrRemoveRedisEnvironment(¤tobject.Spec.JobTemplate.Spec.Template.Spec.Containers[i], drupalsite) - } for i, container := range currentobject.Spec.JobTemplate.Spec.Template.Spec.Containers { switch container.Name { @@ -919,44 +833,10 @@ func (r *DrupalSiteReconciler) ensureNoSchedule(ctx context.Context, d *webservi return nil } -// ensureNoRedisDeployment ensures there is no redis deployment object for the drupalsite -func (r *DrupalSiteReconciler) ensureNoRedisDeployment(ctx context.Context, d *webservicesv1a1.DrupalSite, log logr.Logger) (transientErr reconcileError) { - deployment := &appsv1.Deployment{} - if err := r.Get(ctx, types.NamespacedName{Name: "redis-" + d.Name, Namespace: d.Namespace}, deployment); err != nil { - switch { - case k8sapierrors.IsNotFound(err): - return nil - default: - return newApplicationError(err, ErrClientK8s) - } - } - if err := r.Delete(ctx, deployment); err != nil { - return newApplicationError(err, ErrClientK8s) - } - return nil -} - -// ensureNoRedisService ensures there is no redis service object for the drupalsite -func (r *DrupalSiteReconciler) ensureNoRedisService(ctx context.Context, d *webservicesv1a1.DrupalSite, log logr.Logger) (transientErr reconcileError) { - service := &corev1.Service{} - if err := r.Get(ctx, types.NamespacedName{Name: "redis-" + d.Name, Namespace: d.Namespace}, service); err != nil { - switch { - case k8sapierrors.IsNotFound(err): - return nil - default: - return newApplicationError(err, ErrClientK8s) - } - } - if err := r.Delete(ctx, service); err != nil { - return newApplicationError(err, ErrClientK8s) - } - return nil -} - -// ensureNoRedisSecret ensures there is no redis secret object for the drupalsite -func (r *DrupalSiteReconciler) ensureNoRedisSecret(ctx context.Context, d *webservicesv1a1.DrupalSite, log logr.Logger) (transientErr reconcileError) { - secret := &corev1.Secret{} - if err := r.Get(ctx, types.NamespacedName{Name: "redis-" + d.Name, Namespace: d.Namespace}, secret); err != nil { +// ensureNoBackupSchedule ensures there is no velero backup schedule object for the drupalsite +func (r *DrupalSiteReconciler) ensureNoBackupSchedule(ctx context.Context, d *webservicesv1a1.DrupalSite, log logr.Logger) (transientErr reconcileError) { + schedule := &velerov1.Schedule{} + if err := r.Get(ctx, types.NamespacedName{Name: d.Namespace + "-" + d.Name, Namespace: VeleroNamespace}, schedule); err != nil { switch { case k8sapierrors.IsNotFound(err): return nil @@ -964,7 +844,7 @@ func (r *DrupalSiteReconciler) ensureNoRedisSecret(ctx context.Context, d *webse return newApplicationError(err, ErrClientK8s) } } - if err := r.Delete(ctx, secret); err != nil { + if err := r.Delete(ctx, schedule); err != nil { return newApplicationError(err, ErrClientK8s) } return nil @@ -1135,10 +1015,6 @@ func deploymentForDrupalSite(currentobject *appsv1.Deployment, databaseSecret st currentobject.Labels[k] = v } - var isCriticalSite string = "false" - if d.Spec.QoSClass == webservicesv1a1.QoSCritical { - isCriticalSite = "true" - } addOwnerRefToObject(currentobject, asOwner(d)) if currentobject.Annotations == nil { currentobject.Annotations = map[string]string{} @@ -1149,7 +1025,7 @@ func deploymentForDrupalSite(currentobject *appsv1.Deployment, databaseSecret st if currentobject.CreationTimestamp.IsZero() { currentobject.Spec.Template.ObjectMeta.Annotations = map[string]string{} if d.Spec.QoSClass == webservicesv1a1.QoSCritical { - // TODO: move this to the `DeploymentConfig` + // TODO: move this to the `DeploymentConfig` // openshift-user-critical is part of the default OKD4 Priority classes // https://github.com/openshift/cluster-config-operator/blob/168704868381c88551627239d132a3900eedc14f/manifests/0000_50_config-operator_09_user-priority-class.yaml currentobject.Spec.Template.Spec.PriorityClassName = "openshift-user-critical" @@ -1301,10 +1177,6 @@ func deploymentForDrupalSite(currentobject *appsv1.Deployment, databaseSecret st Name: "SMTPHOST", Value: SMTPHost, }, - { - Name: "ENABLE_REDIS", - Value: isCriticalSite, - }, } currentobject.Spec.Template.Spec.Containers[i].EnvFrom = []corev1.EnvFromSource{ { @@ -1438,11 +1310,6 @@ func deploymentForDrupalSite(currentobject *appsv1.Deployment, databaseSecret st case "php-fpm": currentobject.Spec.Template.Spec.Containers[i].Command = []string{"php-fpm"} currentobject.Spec.Template.Spec.Containers[i].Resources = config.phpResources - for j, item := range currentobject.Spec.Template.Spec.Containers[i].Env { - if item.Name == "ENABLE_REDIS" { - currentobject.Spec.Template.Spec.Containers[i].Env[j].Value = isCriticalSite - } - } case "php-fpm-exporter": currentobject.Spec.Template.Spec.Containers[i].Resources = config.phpExporterResources case "webdav": @@ -1460,13 +1327,6 @@ func deploymentForDrupalSite(currentobject *appsv1.Deployment, databaseSecret st currentobject.Spec.Template.ObjectMeta.Annotations["pre.hook.backup.velero.io/timeout"] = "90m" currentobject.Spec.Template.ObjectMeta.Annotations["backup.velero.io/backup-volumes"] = "drupal-directory-" + d.Name - for i, container := range currentobject.Spec.Template.Spec.Containers { - switch container.Name { - case "php-fpm": - addOrRemoveRedisEnvironment(¤tobject.Spec.Template.Spec.Containers[i], d) - } - } - // Ensure availability zones for critical sites if enabled if d.Spec.QoSClass == webservicesv1a1.QoSCritical && EnableTopologySpread { currentobject.Annotations["critical-site"] = "true" @@ -1635,10 +1495,6 @@ func newOidcReturnURI(currentobject *authz.OidcReturnURI, d *webservicesv1a1.Dru // jobForDrupalSiteInstallation returns a job object thats runs drush func jobForDrupalSiteInstallation(currentobject *batchv1.Job, databaseSecret string, d *webservicesv1a1.DrupalSite) error { ls := labelsForDrupalSite(d.Name) - var isCriticalSite string = "false" - if d.Spec.QoSClass == webservicesv1a1.QoSCritical { - isCriticalSite = "true" - } if currentobject.CreationTimestamp.IsZero() { addOwnerRefToObject(currentobject, asOwner(d)) currentobject.Labels = map[string]string{} @@ -1684,10 +1540,6 @@ func jobForDrupalSiteInstallation(currentobject *batchv1.Job, databaseSecret str Name: "SMTPHOST", Value: SMTPHost, }, - { - Name: "ENABLE_REDIS", - Value: isCriticalSite, - }, }, EnvFrom: []corev1.EnvFromSource{ { @@ -1755,9 +1607,6 @@ func jobForDrupalSiteInstallation(currentobject *batchv1.Job, databaseSecret str }, }, } - for i := range currentobject.Spec.Template.Spec.Containers { - addOrRemoveRedisEnvironment(¤tobject.Spec.Template.Spec.Containers[i], d) - } ls["app"] = "drush" for k, v := range ls { currentobject.Labels[k] = v @@ -1769,10 +1618,6 @@ func jobForDrupalSiteInstallation(currentobject *batchv1.Job, databaseSecret str // jobForDrupalSiteClone returns a job object thats clones a drupalsite func jobForDrupalSiteClone(currentobject *batchv1.Job, databaseSecret string, d *webservicesv1a1.DrupalSite) error { ls := labelsForDrupalSite(d.Name) - var isCriticalSite string = "false" - if d.Spec.QoSClass == webservicesv1a1.QoSCritical { - isCriticalSite = "true" - } if currentobject.CreationTimestamp.IsZero() { addOwnerRefToObject(currentobject, asOwner(d)) currentobject.Labels = map[string]string{} @@ -1823,11 +1668,6 @@ func jobForDrupalSiteClone(currentobject *batchv1.Job, databaseSecret string, d Name: "DRUPAL_SHARED_VOLUME", Value: "/drupal-data-source", }, - { - // Needed for https://gitlab.cern.ch/drupal/paas/cern-drupal-distribution/-/merge_requests/41#note_4919578 - Name: "ENABLE_REDIS", - Value: isCriticalSite, - }, }, EnvFrom: []corev1.EnvFromSource{ { @@ -1907,9 +1747,6 @@ func jobForDrupalSiteClone(currentobject *batchv1.Job, databaseSecret string, d }, }, } - for i := range currentobject.Spec.Template.Spec.Containers { - addOrRemoveRedisEnvironment(¤tobject.Spec.Template.Spec.Containers[i], d) - } ls["app"] = "clone" for k, v := range ls { currentobject.Labels[k] = v @@ -2136,137 +1973,6 @@ func updateConfigMapForPHPCLI(ctx context.Context, currentobject *corev1.ConfigM return nil } -// deploymentForRedis defines the redis deployment needed for a DrupalSite with critical QoS -func deploymentForRedis(currentobject *appsv1.Deployment, d *webservicesv1a1.DrupalSite, config DeploymentConfig) error { - ls := labelsForDrupalSite(d.Name) - if currentobject.Labels == nil { - currentobject.Labels = map[string]string{} - } - ls["app"] = "redis" - for k, v := range ls { - currentobject.Labels[k] = v - } - - if currentobject.CreationTimestamp.IsZero() { - addOwnerRefToObject(currentobject, asOwner(d)) - currentobject.Annotations = map[string]string{} - currentobject.Spec.Template.ObjectMeta.Annotations = map[string]string{} - - } - currentobject.Spec.Selector = &metav1.LabelSelector{ - MatchLabels: ls, - } - currentobject.Spec.Replicas = pointer.Int32Ptr(1) - currentobject.Spec.Template.ObjectMeta.Labels = ls - - currentobject.Spec.Template.Spec.Volumes = []corev1.Volume{ - { - Name: "empty-dir", - VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}}, - }, - } - currentobject.Spec.Template.Spec.Containers = []corev1.Container{{ - Name: "redis", - ImagePullPolicy: "IfNotPresent", - Image: "redis:6.2.5", - Command: []string{ - "/bin/sh", - "-c", - "redis-server --requirepass ${REDIS_PASSWORD}", - }, - EnvFrom: []corev1.EnvFromSource{ - { - SecretRef: &corev1.SecretEnvSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "redis-" + d.Name, - }, - }, - }, - }, - Ports: []corev1.ContainerPort{{ - ContainerPort: 6379, - Name: "redis", - Protocol: "TCP", - }}, - Resources: config.redisResources, - ReadinessProbe: &v1.Probe{ - Handler: v1.Handler{ - Exec: &v1.ExecAction{ - Command: []string{ - "/bin/sh", - "-c", - "redis-cli -a $REDIS_PASSWORD ping", - }, - }, - }, - InitialDelaySeconds: 30, - TimeoutSeconds: 15, - }, - LivenessProbe: &v1.Probe{ - Handler: v1.Handler{ - TCPSocket: &v1.TCPSocketAction{ - Port: intstr.FromInt(6379), - }, - }, - InitialDelaySeconds: 30, - TimeoutSeconds: 5, - }, - VolumeMounts: []corev1.VolumeMount{ - { - Name: "empty-dir", - MountPath: "/data", - }, - }, - }} - return nil -} - -// serviceForRedis returns a service object for Redis deployment -func serviceForRedis(currentobject *corev1.Service, d *webservicesv1a1.DrupalSite) error { - if currentobject.Labels == nil { - currentobject.Labels = map[string]string{} - } - ls := labelsForDrupalSite(d.Name) - ls["app"] = "redis" - for k, v := range ls { - currentobject.Labels[k] = v - } - - if currentobject.CreationTimestamp.IsZero() { - addOwnerRefToObject(currentobject, asOwner(d)) - currentobject.Spec.Selector = ls - currentobject.Spec.Ports = []corev1.ServicePort{ - { - TargetPort: intstr.FromInt(6379), - Name: "redis", - Port: 6379, - Protocol: "TCP", - }, - } - } - return nil -} - -// secretForRedis returns a Secret object for Redis deployment -func secretForRedis(currentobject *corev1.Secret, d *webservicesv1a1.DrupalSite) error { - addOwnerRefToObject(currentobject, asOwner(d)) - currentobject.Type = "kubernetes.io/opaque" - if currentobject.CreationTimestamp.IsZero() { - currentobject.StringData = map[string]string{ - "REDIS_PASSWORD": generateRandomPassword(), - } - } - if currentobject.Labels == nil { - currentobject.Labels = map[string]string{} - } - ls := labelsForDrupalSite(d.Name) - ls["app"] = "redis" - for k, v := range ls { - currentobject.Labels[k] = v - } - return nil -} - // addOwnerRefToObject appends the desired OwnerReference to the object func addOwnerRefToObject(obj metav1.Object, ownerRef metav1.OwnerReference) { // If Owner already in object, we ignore @@ -2354,11 +2060,6 @@ func syncDrupalFilesToEmptydir() []string { return []string{"/operations/sync-drupal-emptydir.sh"} } -// enableOrDisableRedis outputs the command to enable/ disable redis module for the site -func enableOrDisableRedis() []string { - return []string{"/operations/enable-or-disable-redis.sh"} -} - // backupListUpdateNeeded tells whether two arrays of velero Backups elements are the same or not. // A nil argument is equivalent to an empty slice. func backupListUpdateNeeded(veleroBackupsList []velerov1.Backup, statusBackupsList []webservicesv1a1.Backup) bool { @@ -2447,10 +2148,6 @@ func (r *DrupalSiteReconciler) getDeploymentConfiguration(ctx context.Context, d if err != nil { reconcileErr = newApplicationError(err, ErrFunctionDomain) } - redisResources, err := reqLimDict("redis", drupalSite.Spec.QoSClass) - if err != nil { - reconcileErr = newApplicationError(err, ErrFunctionDomain) - } if reconcileErr != nil { return } @@ -2477,7 +2174,7 @@ func (r *DrupalSiteReconciler) getDeploymentConfiguration(ctx context.Context, d } config = DeploymentConfig{replicas: replicas, - phpResources: phpResources, nginxResources: nginxResources, phpExporterResources: phpExporterResources, webDAVResources: webDAVResources, redisResources: redisResources, + phpResources: phpResources, nginxResources: nginxResources, phpExporterResources: phpExporterResources, webDAVResources: webDAVResources, } return } @@ -2488,7 +2185,6 @@ type DeploymentConfig struct { nginxResources corev1.ResourceRequirements phpExporterResources corev1.ResourceRequirements webDAVResources corev1.ResourceRequirements - redisResources corev1.ResourceRequirements } func (r *DrupalSiteReconciler) getConfigOverride(ctx context.Context, drp *webservicesv1a1.DrupalSite) (*webservicesv1a1.DrupalSiteConfigOverrideSpec, reconcileError) { @@ -2502,56 +2198,3 @@ func (r *DrupalSiteReconciler) getConfigOverride(ctx context.Context, drp *webse } return &configOverride.Spec, nil } - -// addOrRemoveRedisEnvironment adds or removes the redis environment variables like REDIS_SERVICE_HOST, REDIS_SERVICE_PORT and redis secret -// depending on the QoSClass -func addOrRemoveRedisEnvironment(container *v1.Container, drupalSite *webservicesv1a1.DrupalSite) error { - if drupalSite.Spec.QoSClass == webservicesv1a1.QoSCritical { - if !checkIfEnvVarExists(container.Env, "REDIS_SERVICE_HOST") { - container.Env = append(container.Env, corev1.EnvVar{ - Name: "REDIS_SERVICE_HOST", - Value: "redis-" + drupalSite.Name, - }) - } - if !checkIfEnvVarExists(container.Env, "REDIS_SERVICE_PORT") { - container.Env = append(container.Env, corev1.EnvVar{ - Name: "REDIS_SERVICE_PORT", - Value: "6379", - }) - } - if !checkIfEnvFromSourceExists(container.EnvFrom, "redis-"+drupalSite.Name) { - container.EnvFrom = append(container.EnvFrom, corev1.EnvFromSource{ - SecretRef: &corev1.SecretEnvSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "redis-" + drupalSite.Name, - }, - }, - }) - } - // Sort the container's env var array - // If we create an unsorted array, Kubernetes sorts it and there's a new reconciliation and new rollout of the deployment - // Better to avoid that - sort.Slice(container.Env, func(i, j int) bool { - return container.Env[i].Name < container.Env[j].Name - }) - sort.Slice(container.EnvFrom, func(i, j int) bool { - return container.EnvFrom[i].SecretRef.Name < container.EnvFrom[j].SecretRef.Name - }) - } else { - for index := 0; index < len(container.Env); index++ { - // index, value := range container.Env { - value := container.Env[index] - if value.Name == "REDIS_SERVICE_HOST" || value.Name == "REDIS_SERVICE_PORT" { - container.Env = append(container.Env[:index], container.Env[index+1:]...) - } - } - for index := 0; index < len(container.EnvFrom); index++ { - // for index, value := range container.EnvFrom { - value := container.EnvFrom[index] - if value.SecretRef.Name == "redis-"+drupalSite.Name { - container.EnvFrom = append(container.EnvFrom[:index], container.EnvFrom[index+1:]...) - } - } - } - return nil -} diff --git a/controllers/reconciler_utils.go b/controllers/reconciler_utils.go index f3b564c8328e08dcfd0efc4a8da4388695b93735..55a64bdd84e75476563896dbdd5d95906f0cea38 100644 --- a/controllers/reconciler_utils.go +++ b/controllers/reconciler_utils.go @@ -249,8 +249,6 @@ func reqLimDict(container string, qosClass webservicesv1a1.QoSClass) (corev1.Res } // WebDAV workloads are very bursty and they need a lot of CPU to process, therefore giving very high spread return ResourceRequestLimit("10Mi", "20m", "100Mi", "500m") - case "redis": - return ResourceRequestLimit("256Mi", "50m", "500Mi", "500m") } return corev1.ResourceRequirements{ Requests: corev1.ResourceList{},