Skip to content

Add --label flag to specify custom labels for deployments #1098

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

Merged
merged 1 commit into from
Oct 4, 2018
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
2 changes: 2 additions & 0 deletions cmd/skaffold/app/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,12 @@ func AddDevFlags(cmd *cobra.Command) {
cmd.Flags().StringArrayVarP(&opts.Watch, "watch-image", "w", nil, "Choose which artifacts to watch. Artifacts with image names that contain the expression will be watched only. Default is to watch sources for all artifacts.")
cmd.Flags().IntVarP(&opts.WatchPollInterval, "watch-poll-interval", "i", 1000, "Interval (in ms) between two checks for file changes.")
cmd.Flags().BoolVar(&opts.PortForward, "port-forward", true, "Port-forward exposed container ports within pods")
cmd.Flags().StringArrayVarP(&opts.CustomLabels, "label", "l", nil, "Add custom labels to deployed objects. Set multiple times for multiple labels.")
}

func AddRunDeployFlags(cmd *cobra.Command) {
cmd.Flags().BoolVar(&opts.Tail, "tail", false, "Stream logs from deployed objects")
cmd.Flags().StringArrayVarP(&opts.CustomLabels, "label", "l", nil, "Add custom labels to deployed objects. Set multiple times for multiple labels.")
}

func AddRunDevFlags(cmd *cobra.Command) {
Expand Down
9 changes: 9 additions & 0 deletions pkg/skaffold/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type SkaffoldOptions struct {
Namespace string
Watch []string
Trigger string
CustomLabels []string
WatchPollInterval int
}

Expand All @@ -54,5 +55,13 @@ func (opts *SkaffoldOptions) Labels() map[string]string {
if len(opts.Profiles) > 0 {
labels["profiles"] = strings.Join(opts.Profiles, ",")
}
for _, cl := range opts.CustomLabels {
l := strings.SplitN(cl, "=", 2)
if len(l) == 1 {
labels[l[0]] = ""
continue
}
labels[l[0]] = l[1]
}
return labels
}
19 changes: 19 additions & 0 deletions pkg/skaffold/config/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ func TestLabels(t *testing.T) {
"profiles": "p1,p2",
},
},
{
description: "custom labels",
options: SkaffoldOptions{
Cleanup: true,
CustomLabels: []string{
"one=first",
"two=second",
"three=",
"four",
},
},
expectedLabels: map[string]string{
"cleanup": "true",
"one": "first",
"two": "second",
"three": "",
"four": "",
},
},
}

for _, test := range tests {
Expand Down