Skip to content

Commit

Permalink
THREESCALE-9315 set backend-listener to async mode also
Browse files Browse the repository at this point in the history
THREESCALE-9315 only add CONFIG_REDIS_ASYNC if it is missing, dont reconcile other envvars

THREESCALE-9315 always set CONFIG_REDIS_ASYNC to 1
  • Loading branch information
austincunningham committed Sep 27, 2023
1 parent 6a9f5c7 commit bd898a9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/3scale/amp/component/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ func (backend *Backend) buildBackendListenerEnv() []v1.EnvVar {
result := []v1.EnvVar{}
result = append(result, backend.buildBackendCommonEnv()...)
result = append(result,
helper.EnvVarFromValue("CONFIG_REDIS_ASYNC", "1"),
helper.EnvVarFromValue("PUMA_WORKERS", "16"),
helper.EnvVarFromSecret("CONFIG_INTERNAL_API_USER", BackendSecretInternalApiSecretName, BackendSecretInternalApiUsernameFieldName),
helper.EnvVarFromSecret("CONFIG_INTERNAL_API_PASSWORD", BackendSecretInternalApiSecretName, BackendSecretInternalApiPasswordFieldName),
Expand Down
2 changes: 2 additions & 0 deletions pkg/3scale/amp/operator/backend_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (r *BackendReconciler) Reconcile() (reconcile.Result, error) {

// Listener DC
listenerConfigMutator := reconcilers.GenericBackendMutators()
listenerConfigMutator = append(listenerConfigMutator, reconcilers.DeploymentConfigEnvMutator)
if r.apiManager.Spec.Backend.ListenerSpec.Replicas != nil {
listenerConfigMutator = append(listenerConfigMutator, reconcilers.DeploymentConfigReplicasMutator)
}
Expand All @@ -62,6 +63,7 @@ func (r *BackendReconciler) Reconcile() (reconcile.Result, error) {

// Worker DC
workerConfigMutator := reconcilers.GenericBackendMutators()
workerConfigMutator = append(workerConfigMutator, reconcilers.DeploymentConfigEnvMutator)
if r.apiManager.Spec.Backend.WorkerSpec.Replicas != nil {
workerConfigMutator = append(workerConfigMutator, reconcilers.DeploymentConfigReplicasMutator)
}
Expand Down
27 changes: 27 additions & 0 deletions pkg/reconcilers/deploymentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,33 @@ func GenericBackendMutators() []DCMutateFn {
}
}

func DeploymentConfigEnvMutator(desired, existing *appsv1.DeploymentConfig) (bool, error) {
update := false
if !reflect.DeepEqual(existing.Spec.Template.Spec.Containers[0].Env, desired.Spec.Template.Spec.Containers[0].Env) {
diff := cmp.Diff(existing.Spec.Template.Spec.Containers[0].Env, desired.Spec.Template.Spec.Containers[0].Env)
log.Info(fmt.Sprintf("%s spec.template.spec.containers[0].Env has changed: %s", common.ObjectInfo(desired), diff))
// Always set env var CONFIG_REDIS_ASYNC to 1
for envId, envVar := range existing.Spec.Template.Spec.Containers[0].Env {
if envVar.Name == "CONFIG_REDIS_ASYNC" {
if envVar.Value != "1" {
existing.Spec.Template.Spec.Containers[0].Env[envId].Value = "1"
update = true
return update, nil
}
return update, nil
}
}
// Always set env var create CONFIG_REDIS_ASYNC if not present
for envId, envVar := range desired.Spec.Template.Spec.Containers[0].Env {
if envVar.Name == "CONFIG_REDIS_ASYNC" {
existing.Spec.Template.Spec.Containers[0].Env = append(existing.Spec.Template.Spec.Containers[0].Env, desired.Spec.Template.Spec.Containers[0].Env[envId])
update = true
}
}
}
return update, nil
}

func DeploymentConfigReplicasMutator(desired, existing *appsv1.DeploymentConfig) (bool, error) {
update := false

Expand Down

0 comments on commit bd898a9

Please sign in to comment.