diff --git a/pkg/operator/v1helpers/helpers.go b/pkg/operator/v1helpers/helpers.go index 0c0d62da0a..65fb3e9309 100644 --- a/pkg/operator/v1helpers/helpers.go +++ b/pkg/operator/v1helpers/helpers.go @@ -1,9 +1,11 @@ package v1helpers import ( + "sort" "strings" "time" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -259,3 +261,21 @@ func (agg aggregate) Error() string { func (agg aggregate) Errors() []error { return []error(agg) } + +// MapToEnvVars converts a string-string map to a slice of corev1.EnvVar-s +func MapToEnvVars(mapEnvVars map[string]string) []corev1.EnvVar { + if mapEnvVars == nil { + return nil + } + + envVars := make([]corev1.EnvVar, len(mapEnvVars)) + i := 0 + for k, v := range mapEnvVars { + envVars[i] = corev1.EnvVar{Name: k, Value: v} + i++ + } + + // need to sort the slice so that kube-controller-manager-pod configmap does not change all the time + sort.Slice(envVars, func(i, j int) bool { return envVars[i].Name < envVars[j].Name }) + return envVars +}