Skip to content

Commit

Permalink
feat(cluster): Add labels to cluster config (#9553)
Browse files Browse the repository at this point in the history
* feat(cluster): Add labels to cluster config

Signed-off-by: Suleiman Dibirov <[email protected]>

* Updated schema v4beta12.json

Signed-off-by: Suleiman Dibirov <[email protected]>

* fix code style

Signed-off-by: Suleiman Dibirov <[email protected]>

---------

Signed-off-by: Suleiman Dibirov <[email protected]>
  • Loading branch information
idsulik authored Nov 18, 2024
1 parent 1385a7d commit e55f954
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
10 changes: 10 additions & 0 deletions docs-v2/content/en/schemas/v4beta12.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -1318,6 +1327,7 @@
"tolerations",
"nodeSelector",
"annotations",
"labels",
"runAsUser",
"resources",
"concurrency",
Expand Down
7 changes: 6 additions & 1 deletion pkg/skaffold/build/cluster/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
5 changes: 4 additions & 1 deletion pkg/skaffold/build/cluster/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e55f954

Please sign in to comment.