Skip to content

Commit

Permalink
bundle: set ROLEARN env variable in noobaa subscription
Browse files Browse the repository at this point in the history
If ROLEARN env variable is set, then pass on that env variable
to noobaa subscription.

Signed-off-by: Nikhil-Ladha <nikhilladha1999@gmail.com>
  • Loading branch information
Nikhil-Ladha committed Dec 6, 2023
1 parent 47e5643 commit 9bc9e07
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 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,30 @@ func CheckExistingSubscriptions(cli client.Client, desiredSubscription *operator
return desiredSubscription, nil
}

// getMergedEnvVars updates the env variables in the existing subscription with the desired subscription
func getMergedEnvVars(existingSub, desiredSub []corev1.EnvVar) []corev1.EnvVar {
envMap := make(map[string]string)

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

for _, env := range desiredSub {
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 +272,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 9bc9e07

Please sign in to comment.