Skip to content

Commit

Permalink
Fix long label made of profile names
Browse files Browse the repository at this point in the history
Fix GoogleContainerTools#3277

Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Nov 21, 2019
1 parent debaab9 commit 4830837
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/skaffold/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ func (opts *SkaffoldOptions) Labels() map[string]string {
labels["skaffold.dev/namespace"] = opts.Namespace
}
if len(opts.Profiles) > 0 {
labels["skaffold.dev/profiles"] = strings.Join(opts.Profiles, "__")
profiles := strings.Join(opts.Profiles, "__")
if len(profiles) > 63 {
// k8s labels can't be more than 63 characters
// and must end with an alphanumeric character.
profiles = profiles[0:62] + "z"
}

labels["skaffold.dev/profiles"] = profiles
}
for _, cl := range opts.CustomLabels {
l := strings.SplitN(cl, "=", 2)
Expand All @@ -92,6 +99,7 @@ func (opts *SkaffoldOptions) Labels() map[string]string {
}
labels[l[0]] = l[1]
}

return labels
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/skaffold/config/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ func TestLabels(t *testing.T) {
"skaffold.dev/profiles": "profile1__profile2",
},
},
{
description: "lots of profiles",
options: SkaffoldOptions{Profiles: []string{
"long_profile_name_1",
"long_profile_name_2",
"long_profile_name_3",
"long_profile_name_4",
"long_profile_name_5",
}},
expectedLabels: map[string]string{
"skaffold.dev/profiles": "long_profile_name_1__long_profile_name_2__long_profile_name_3_z",
},
},
{
description: "tail",
options: SkaffoldOptions{Tail: true},
Expand Down

0 comments on commit 4830837

Please sign in to comment.