Use sets utility for saving updated env vars (#409)

This commit is contained in:
Tsubasa Nagasawa 2019-09-17 23:53:46 +09:00 committed by Knative Prow Robot
parent b1f5e7d6fe
commit 94bb1cf8db
2 changed files with 9 additions and 14 deletions

View File

@ -23,6 +23,7 @@ import (
"strings"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
"knative.dev/serving/pkg/apis/autoscaling"
servingv1alpha1 "knative.dev/serving/pkg/apis/serving/v1alpha1"
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 {
set := make(map[string]bool)
set := sets.NewString()
for i := range env {
envVar := &env[i]
value, present := toUpdate[envVar.Name]
if present {
envVar.Value = value
set[envVar.Name] = true
if val, ok := toUpdate[envVar.Name]; ok {
envVar.Value = val
set.Insert(envVar.Name)
}
}
for name, value := range toUpdate {
if !set[name] {
env = append(
env,
corev1.EnvVar{
Name: name,
Value: value,
})
for name, val := range toUpdate {
if !set.Has(name) {
env = append(env, corev1.EnvVar{Name: name, Value: val})
}
}
return env

2
vendor/modules.txt vendored
View File

@ -189,9 +189,9 @@ k8s.io/apimachinery/pkg/api/resource
k8s.io/apimachinery/pkg/api/meta
k8s.io/apimachinery/pkg/util/runtime
k8s.io/apimachinery/pkg/runtime/schema
k8s.io/apimachinery/pkg/util/sets
k8s.io/apimachinery/pkg/fields
k8s.io/apimachinery/pkg/labels
k8s.io/apimachinery/pkg/util/sets
k8s.io/apimachinery/pkg/watch
k8s.io/apimachinery/pkg/util/validation/field
k8s.io/apimachinery/pkg/conversion