Skip to content

Commit

Permalink
Fix suggested comments
Browse files Browse the repository at this point in the history
  • Loading branch information
toVersus committed Sep 10, 2019
1 parent e3a6395 commit 5c7b441
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
11 changes: 5 additions & 6 deletions pkg/kn/commands/service/configuration_edit_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,14 @@ func (p *ConfigurationEditFlags) Apply(
if err != nil {
return errors.Wrap(err, "Invalid --env")
}
envKeyToRemove := []string{}
envToRemove := []string{}
for key := range envMap {
if !strings.HasSuffix(key, "-") {
continue
if strings.HasSuffix(key, "-") {
envToRemove = append(envToRemove, key[:len(key)-1])
delete(envMap, key)
}
envKeyToRemove = append(envKeyToRemove, key[:len(key)-1])
delete(envMap, key)
}
err = servinglib.UpdateEnvVars(template, envMap, envKeyToRemove)
err = servinglib.UpdateEnvVars(template, envMap, envToRemove)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/serving/config_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ func UpdateEnvVars(template *servingv1alpha1.RevisionTemplateSpec, toUpdate map[
if err != nil {
return err
}
updated := updateEnvVars(container.Env, toUpdate)
removed := removeEnvVars(updated, toRemove)
updated := updateEnvVarsFromMap(container.Env, toUpdate)
updated = removeEnvVars(updated, toRemove)
// Sort by env key name
sort.SliceStable(removed, func(i, j int) bool {
return removed[i].Name < removed[j].Name
sort.SliceStable(updated, func(i, j int) bool {
return updated[i].Name < updated[j].Name
})
container.Env = removed
container.Env = updated

return nil
}
Expand Down Expand Up @@ -242,7 +242,7 @@ func UpdateLabels(service *servingv1alpha1.Service, template *servingv1alpha1.Re

// =======================================================================================

func updateEnvVars(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)
for i := range env {
envVar := &env[i]
Expand Down

0 comments on commit 5c7b441

Please sign in to comment.