Skip to content

Commit e55f954

Browse files
authored
feat(cluster): Add labels to cluster config (#9553)
* feat(cluster): Add labels to cluster config Signed-off-by: Suleiman Dibirov <idsulik@gmail.com> * Updated schema v4beta12.json Signed-off-by: Suleiman Dibirov <idsulik@gmail.com> * fix code style Signed-off-by: Suleiman Dibirov <idsulik@gmail.com> --------- Signed-off-by: Suleiman Dibirov <idsulik@gmail.com>
1 parent 1385a7d commit e55f954

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

docs-v2/content/en/schemas/v4beta12.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,15 @@
12281228
"description": "describes how to mount the local Docker configuration into a pod.",
12291229
"x-intellij-html-description": "describes how to mount the local Docker configuration into a pod."
12301230
},
1231+
"labels": {
1232+
"additionalProperties": {
1233+
"type": "string"
1234+
},
1235+
"type": "object",
1236+
"description": "describes the Kubernetes labels for the pod.",
1237+
"x-intellij-html-description": "describes the Kubernetes labels for the pod.",
1238+
"default": "{}"
1239+
},
12311240
"namespace": {
12321241
"type": "string",
12331242
"description": "Kubernetes namespace. Defaults to current namespace in Kubernetes configuration.",
@@ -1318,6 +1327,7 @@
13181327
"tolerations",
13191328
"nodeSelector",
13201329
"annotations",
1330+
"labels",
13211331
"runAsUser",
13221332
"resources",
13231333
"concurrency",

pkg/skaffold/build/cluster/pod.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,16 @@ func (b *Builder) kanikoPodSpec(artifact *latest.KanikoArtifact, tag string, pla
4949
MountPath: kaniko.DefaultEmptyDirMountPath,
5050
}
5151

52+
labels := map[string]string{"skaffold-kaniko": "skaffold-kaniko"}
53+
for k, v := range b.ClusterDetails.Labels {
54+
labels[k] = v
55+
}
56+
5257
pod := &v1.Pod{
5358
ObjectMeta: metav1.ObjectMeta{
5459
Annotations: b.ClusterDetails.Annotations,
5560
GenerateName: "kaniko-",
56-
Labels: map[string]string{"skaffold-kaniko": "skaffold-kaniko"},
61+
Labels: labels,
5762
Namespace: b.ClusterDetails.Namespace,
5863
},
5964
Spec: v1.PodSpec{

pkg/skaffold/build/cluster/pod_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ func TestKanikoPodSpec(t *testing.T) {
220220
HTTPProxy: "http://proxy",
221221
HTTPSProxy: "https://proxy",
222222
ServiceAccountName: "aVerySpecialSA",
223+
Annotations: map[string]string{"test": "test"},
224+
Labels: map[string]string{"test-key": "test-value"},
223225
RunAsUser: &runAsUser,
224226
Resources: &latest.ResourceRequirements{
225227
Requests: &latest.ResourceRequirement{
@@ -268,7 +270,7 @@ func TestKanikoPodSpec(t *testing.T) {
268270
ObjectMeta: metav1.ObjectMeta{
269271
Annotations: map[string]string{"test": "test"},
270272
GenerateName: "kaniko-",
271-
Labels: map[string]string{"skaffold-kaniko": "skaffold-kaniko"},
273+
Labels: map[string]string{"skaffold-kaniko": "skaffold-kaniko", "test-key": "test-value"},
272274
Namespace: "ns",
273275
},
274276
Spec: v1.PodSpec{
@@ -405,6 +407,7 @@ func TestKanikoPodSpec(t *testing.T) {
405407

406408
testutil.CheckDeepEqual(t, expectedPod.Spec.Containers[0].Env, pod.Spec.Containers[0].Env)
407409
testutil.CheckDeepEqual(t, expectedPod.Spec.Containers[0].Args, pod.Spec.Containers[0].Args)
410+
testutil.CheckDeepEqual(t, expectedPod.ObjectMeta, pod.ObjectMeta)
408411
}
409412

410413
func TestResourceRequirements(t *testing.T) {

pkg/skaffold/schema/latest/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,9 @@ type ClusterDetails struct {
544544
// Annotations describes the Kubernetes annotations for the pod.
545545
Annotations map[string]string `yaml:"annotations,omitempty"`
546546

547+
// Labels describes the Kubernetes labels for the pod.
548+
Labels map[string]string `yaml:"labels,omitempty"`
549+
547550
// RunAsUser defines the UID to request for running the container.
548551
// If omitted, no SecurityContext will be specified for the pod and will therefore be inherited
549552
// from the service account.

0 commit comments

Comments
 (0)