Skip to content

Commit de0cd3d

Browse files
author
priyawadhwa
authored
Merge pull request #1098 from priyawadhwa/label
Add --label flag to specify custom labels for deployments
2 parents 3e2d5c1 + b862d80 commit de0cd3d

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

cmd/skaffold/app/cmd/cmd.go

+2
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,12 @@ func AddDevFlags(cmd *cobra.Command) {
136136
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.")
137137
cmd.Flags().IntVarP(&opts.WatchPollInterval, "watch-poll-interval", "i", 1000, "Interval (in ms) between two checks for file changes.")
138138
cmd.Flags().BoolVar(&opts.PortForward, "port-forward", true, "Port-forward exposed container ports within pods")
139+
cmd.Flags().StringArrayVarP(&opts.CustomLabels, "label", "l", nil, "Add custom labels to deployed objects. Set multiple times for multiple labels.")
139140
}
140141

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

145147
func AddRunDevFlags(cmd *cobra.Command) {

pkg/skaffold/config/options.go

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type SkaffoldOptions struct {
3434
Namespace string
3535
Watch []string
3636
Trigger string
37+
CustomLabels []string
3738
WatchPollInterval int
3839
}
3940

@@ -54,5 +55,13 @@ func (opts *SkaffoldOptions) Labels() map[string]string {
5455
if len(opts.Profiles) > 0 {
5556
labels["profiles"] = strings.Join(opts.Profiles, ",")
5657
}
58+
for _, cl := range opts.CustomLabels {
59+
l := strings.SplitN(cl, "=", 2)
60+
if len(l) == 1 {
61+
labels[l[0]] = ""
62+
continue
63+
}
64+
labels[l[0]] = l[1]
65+
}
5766
return labels
5867
}

pkg/skaffold/config/options_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ func TestLabels(t *testing.T) {
6565
"profiles": "p1,p2",
6666
},
6767
},
68+
{
69+
description: "custom labels",
70+
options: SkaffoldOptions{
71+
Cleanup: true,
72+
CustomLabels: []string{
73+
"one=first",
74+
"two=second",
75+
"three=",
76+
"four",
77+
},
78+
},
79+
expectedLabels: map[string]string{
80+
"cleanup": "true",
81+
"one": "first",
82+
"two": "second",
83+
"three": "",
84+
"four": "",
85+
},
86+
},
6887
}
6988

7089
for _, test := range tests {

0 commit comments

Comments
 (0)