From a518ce7b0551abef7ae1510dacd92e276a96305b Mon Sep 17 00:00:00 2001 From: Gaurav <39389231+gsquared94@users.noreply.github.com> Date: Wed, 23 Dec 2020 11:05:08 -0800 Subject: [PATCH] Profile with multiple activations should be processed only once. (#5182) --- pkg/skaffold/schema/profiles.go | 3 ++- pkg/skaffold/schema/profiles_test.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/skaffold/schema/profiles.go b/pkg/skaffold/schema/profiles.go index feaec4eea19..9fd467b4dec 100644 --- a/pkg/skaffold/schema/profiles.go +++ b/pkg/skaffold/schema/profiles.go @@ -105,6 +105,7 @@ func activatedProfiles(profiles []latest.Profile, opts cfg.SkaffoldOptions) ([]s contextSpecificProfiles = append(contextSpecificProfiles, profile.Name) } activated = append(activated, profile.Name) + break } } } @@ -113,7 +114,7 @@ func activatedProfiles(profiles []latest.Profile, opts cfg.SkaffoldOptions) ([]s for _, profile := range opts.Profiles { if strings.HasPrefix(profile, "-") { activated = removeValue(activated, strings.TrimPrefix(profile, "-")) - } else { + } else if !skutil.StrSliceContains(activated, profile) { activated = append(activated, profile) } } diff --git a/pkg/skaffold/schema/profiles_test.go b/pkg/skaffold/schema/profiles_test.go index 19d30b819b0..2b0b4c7d3f2 100644 --- a/pkg/skaffold/schema/profiles_test.go +++ b/pkg/skaffold/schema/profiles_test.go @@ -557,6 +557,20 @@ func TestActivatedProfiles(t *testing.T) { {Name: "regex-activated-substring-match", Activation: []latest.Activation{{Env: "KEY=^VAL"}}}, }, expected: []string{"activated", "also-activated", "regex-activated", "regex-activated-two", "regex-activated-substring-match"}, + }, { + description: "Profile with multiple valid activations", + envs: map[string]string{"KEY": "VALUE"}, + opts: cfg.SkaffoldOptions{ + ProfileAutoActivation: true, + Command: "dev", + Profiles: []string{"activated", "also-activated"}, + }, + profiles: []latest.Profile{ + {Name: "activated", Activation: []latest.Activation{{Env: "KEY=VALUE"}, {Command: "dev"}}}, + {Name: "not-activated", Activation: []latest.Activation{{Env: "KEY=OTHER"}}}, + {Name: "also-activated", Activation: []latest.Activation{{Env: "KEY=!OTHER"}}}, + }, + expected: []string{"activated", "also-activated"}, }, { description: "Invalid env variable", envs: map[string]string{"KEY": "VALUE"},