Skip to content

Commit

Permalink
Use sets utility for saving updated env vars (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
toVersus authored and knative-prow-robot committed Sep 17, 2019
1 parent b1f5e7d commit 94bb1cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
21 changes: 8 additions & 13 deletions pkg/serving/config_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 94bb1cf

Please sign in to comment.