diff --git a/docs-v2/content/en/schemas/v4beta12.json b/docs-v2/content/en/schemas/v4beta12.json index 5d635ad8377..b8bad3b0334 100755 --- a/docs-v2/content/en/schemas/v4beta12.json +++ b/docs-v2/content/en/schemas/v4beta12.json @@ -1228,6 +1228,15 @@ "description": "describes how to mount the local Docker configuration into a pod.", "x-intellij-html-description": "describes how to mount the local Docker configuration into a pod." }, + "labels": { + "additionalProperties": { + "type": "string" + }, + "type": "object", + "description": "describes the Kubernetes labels for the pod.", + "x-intellij-html-description": "describes the Kubernetes labels for the pod.", + "default": "{}" + }, "namespace": { "type": "string", "description": "Kubernetes namespace. Defaults to current namespace in Kubernetes configuration.", @@ -1318,6 +1327,7 @@ "tolerations", "nodeSelector", "annotations", + "labels", "runAsUser", "resources", "concurrency", diff --git a/pkg/skaffold/build/cluster/pod.go b/pkg/skaffold/build/cluster/pod.go index e3eaf911097..1932d7e890c 100644 --- a/pkg/skaffold/build/cluster/pod.go +++ b/pkg/skaffold/build/cluster/pod.go @@ -49,11 +49,16 @@ func (b *Builder) kanikoPodSpec(artifact *latest.KanikoArtifact, tag string, pla MountPath: kaniko.DefaultEmptyDirMountPath, } + labels := map[string]string{"skaffold-kaniko": "skaffold-kaniko"} + for k, v := range b.ClusterDetails.Labels { + labels[k] = v + } + pod := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Annotations: b.ClusterDetails.Annotations, GenerateName: "kaniko-", - Labels: map[string]string{"skaffold-kaniko": "skaffold-kaniko"}, + Labels: labels, Namespace: b.ClusterDetails.Namespace, }, Spec: v1.PodSpec{ diff --git a/pkg/skaffold/build/cluster/pod_test.go b/pkg/skaffold/build/cluster/pod_test.go index eec3d80b7c3..70d16d410f0 100644 --- a/pkg/skaffold/build/cluster/pod_test.go +++ b/pkg/skaffold/build/cluster/pod_test.go @@ -220,6 +220,8 @@ func TestKanikoPodSpec(t *testing.T) { HTTPProxy: "http://proxy", HTTPSProxy: "https://proxy", ServiceAccountName: "aVerySpecialSA", + Annotations: map[string]string{"test": "test"}, + Labels: map[string]string{"test-key": "test-value"}, RunAsUser: &runAsUser, Resources: &latest.ResourceRequirements{ Requests: &latest.ResourceRequirement{ @@ -268,7 +270,7 @@ func TestKanikoPodSpec(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{"test": "test"}, GenerateName: "kaniko-", - Labels: map[string]string{"skaffold-kaniko": "skaffold-kaniko"}, + Labels: map[string]string{"skaffold-kaniko": "skaffold-kaniko", "test-key": "test-value"}, Namespace: "ns", }, Spec: v1.PodSpec{ @@ -405,6 +407,7 @@ func TestKanikoPodSpec(t *testing.T) { testutil.CheckDeepEqual(t, expectedPod.Spec.Containers[0].Env, pod.Spec.Containers[0].Env) testutil.CheckDeepEqual(t, expectedPod.Spec.Containers[0].Args, pod.Spec.Containers[0].Args) + testutil.CheckDeepEqual(t, expectedPod.ObjectMeta, pod.ObjectMeta) } func TestResourceRequirements(t *testing.T) { diff --git a/pkg/skaffold/schema/latest/config.go b/pkg/skaffold/schema/latest/config.go index 80ab110169c..78354fbcda9 100644 --- a/pkg/skaffold/schema/latest/config.go +++ b/pkg/skaffold/schema/latest/config.go @@ -544,6 +544,9 @@ type ClusterDetails struct { // Annotations describes the Kubernetes annotations for the pod. Annotations map[string]string `yaml:"annotations,omitempty"` + // Labels describes the Kubernetes labels for the pod. + Labels map[string]string `yaml:"labels,omitempty"` + // RunAsUser defines the UID to request for running the container. // If omitted, no SecurityContext will be specified for the pod and will therefore be inherited // from the service account.