Skip to content
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
20 changes: 20 additions & 0 deletions pkg/operator/v1helpers/helpers.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would return empty list maybe so we can append?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

append works with nil too.

}

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
}