Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore (service): Use sets utility for holding updated env vars #409

Merged
merged 1 commit into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
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
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