mirror of https://github.com/knative/client.git
Use sets utility for saving updated env vars (#409)
This commit is contained in:
parent
b1f5e7d6fe
commit
94bb1cf8db
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"knative.dev/serving/pkg/apis/autoscaling"
|
"knative.dev/serving/pkg/apis/autoscaling"
|
||||||
servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1"
|
servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1"
|
||||||
servingv1beta1 "knative.dev/serving/pkg/apis/serving/v1beta1"
|
servingv1beta1 "knative.dev/serving/pkg/apis/serving/v1beta1"
|
||||||
|
|
@ -243,23 +244,17 @@ func UpdateLabels(service *servingv1alpha1.Service, template *servingv1alpha1.Re
|
||||||
// =======================================================================================
|
// =======================================================================================
|
||||||
|
|
||||||
func updateEnvVarsFromMap(env []corev1.EnvVar, toUpdate map[string]string) []corev1.EnvVar {
|
func updateEnvVarsFromMap(env []corev1.EnvVar, toUpdate map[string]string) []corev1.EnvVar {
|
||||||
set := make(map[string]bool)
|
set := sets.NewString()
|
||||||
for i := range env {
|
for i := range env {
|
||||||
envVar := &env[i]
|
envVar := &env[i]
|
||||||
value, present := toUpdate[envVar.Name]
|
if val, ok := toUpdate[envVar.Name]; ok {
|
||||||
if present {
|
envVar.Value = val
|
||||||
envVar.Value = value
|
set.Insert(envVar.Name)
|
||||||
set[envVar.Name] = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for name, value := range toUpdate {
|
for name, val := range toUpdate {
|
||||||
if !set[name] {
|
if !set.Has(name) {
|
||||||
env = append(
|
env = append(env, corev1.EnvVar{Name: name, Value: val})
|
||||||
env,
|
|
||||||
corev1.EnvVar{
|
|
||||||
Name: name,
|
|
||||||
Value: value,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return env
|
return env
|
||||||
|
|
|
||||||
|
|
@ -189,9 +189,9 @@ k8s.io/apimachinery/pkg/api/resource
|
||||||
k8s.io/apimachinery/pkg/api/meta
|
k8s.io/apimachinery/pkg/api/meta
|
||||||
k8s.io/apimachinery/pkg/util/runtime
|
k8s.io/apimachinery/pkg/util/runtime
|
||||||
k8s.io/apimachinery/pkg/runtime/schema
|
k8s.io/apimachinery/pkg/runtime/schema
|
||||||
|
k8s.io/apimachinery/pkg/util/sets
|
||||||
k8s.io/apimachinery/pkg/fields
|
k8s.io/apimachinery/pkg/fields
|
||||||
k8s.io/apimachinery/pkg/labels
|
k8s.io/apimachinery/pkg/labels
|
||||||
k8s.io/apimachinery/pkg/util/sets
|
|
||||||
k8s.io/apimachinery/pkg/watch
|
k8s.io/apimachinery/pkg/watch
|
||||||
k8s.io/apimachinery/pkg/util/validation/field
|
k8s.io/apimachinery/pkg/util/validation/field
|
||||||
k8s.io/apimachinery/pkg/conversion
|
k8s.io/apimachinery/pkg/conversion
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue