Skip to content

Commit

Permalink
Merge pull request #349 from Nikhil-Ladha/rolearn-env-var
Browse files Browse the repository at this point in the history
set ROLEARN env variable in noobaa subscription
  • Loading branch information
openshift-merge-bot[bot] authored Dec 7, 2023
2 parents 47e5643 + f53ed2f commit 509016e
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions controllers/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controllers
import (
"context"
"fmt"
"os"

"go.uber.org/multierr"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -61,6 +62,10 @@ func CheckExistingSubscriptions(cli client.Client, desiredSubscription *operator
// If the config is not set, only then set it to the desired value => allow user to override
if actualSub.Spec.Config == nil {
actualSub.Spec.Config = desiredSubscription.Spec.Config
} else if actualSub.Spec.Config != nil && desiredSubscription.Spec.Config != nil {
// Combines the environment variables from both subscriptions.
// If actualSub already contains an environment variable, its value will be updated with the value from desiredSubscription.
actualSub.Spec.Config.Env = getMergedEnvVars(actualSub.Spec.Config.Env, desiredSubscription.Spec.Config.Env)
}

desiredSubscription = actualSub
Expand All @@ -70,6 +75,31 @@ func CheckExistingSubscriptions(cli client.Client, desiredSubscription *operator
return desiredSubscription, nil
}

// getMergedEnvVars updates the value of env variables in the envList1 with that of envList2 and
// returns the updated list of env variables.
func getMergedEnvVars(envList1, envList2 []corev1.EnvVar) []corev1.EnvVar {
envMap := make(map[string]string)

for _, env := range envList1 {
envMap[env.Name] = env.Value
}

for _, env := range envList2 {
envMap[env.Name] = env.Value
}

// Convert the map back to a slice
var updatedEnvVars []corev1.EnvVar
for key, value := range envMap {
updatedEnvVars = append(updatedEnvVars, corev1.EnvVar{
Name: key,
Value: value,
})
}

return updatedEnvVars
}

func EnsureDesiredSubscription(cli client.Client, desiredSubscription *operatorv1alpha1.Subscription) error {

var err error
Expand Down Expand Up @@ -243,6 +273,18 @@ func GetStorageClusterSubscriptions() []*operatorv1alpha1.Subscription {
},
}

roleARN := os.Getenv("ROLEARN")
if roleARN != "" {
noobaaSubscription.Spec.Config = &operatorv1alpha1.SubscriptionConfig{
Env: []corev1.EnvVar{
{
Name: "ROLEARN",
Value: roleARN,
},
},
}
}

ocsSubscription := &operatorv1alpha1.Subscription{
ObjectMeta: metav1.ObjectMeta{
Name: OcsSubscriptionName,
Expand Down

0 comments on commit 509016e

Please sign in to comment.