Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set ROLEARN env variable in noobaa subscription #349

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading