From 205c450a5fe63b7687dbc6bf007b21f96f596200 Mon Sep 17 00:00:00 2001 From: "aleksej.paschenko" Date: Tue, 11 Jan 2022 12:34:50 +0300 Subject: [PATCH] Use MetadataItems to set labels/annotations for pods --- config/crd/bases/theketch.io_apps.yaml | 4 +- internal/api/v1beta1/app_types.go | 10 +- internal/chart/application_chart_test.go | 35 ++- internal/chart/process.go | 60 +++-- internal/chart/process_test.go | 230 +++++++++++++----- .../dashboard-istio-cluster-issuer.yaml | 3 + .../testdata/charts/dashboard-istio.yaml | 3 + .../dashboard-nginx-cluster-issuer.yaml | 3 + .../testdata/charts/dashboard-nginx.yaml | 3 + ...ashboard-traefik-cluster-issuer-shipa.yaml | 3 + .../dashboard-traefik-cluster-issuer.yaml | 3 + .../testdata/charts/dashboard-traefik.yaml | 3 + .../templates/common/yamls/deployment.yaml | 39 +-- internal/templates/common/yamls/service.yaml | 6 +- 14 files changed, 279 insertions(+), 126 deletions(-) diff --git a/config/crd/bases/theketch.io_apps.yaml b/config/crd/bases/theketch.io_apps.yaml index 3d5ad1b7..cb873596 100644 --- a/config/crd/bases/theketch.io_apps.yaml +++ b/config/crd/bases/theketch.io_apps.yaml @@ -45,7 +45,7 @@ spec: properties: annotations: description: Annotations is a list of annotations that will be applied - to Services/Deployments/Gateways. + to Services/Deployments/Pods/Gateways/Ingresses/IngressRoutes. items: description: MetadataItem represent a request to add label/annotations to processes @@ -2356,7 +2356,7 @@ spec: - generateDefaultCname type: object labels: - description: Labels is a list of labels that will be applied to Services/Deployments. + description: Labels is a list of labels that will be applied to Services/Deployments/Pods. items: description: MetadataItem represent a request to add label/annotations to processes diff --git a/internal/api/v1beta1/app_types.go b/internal/api/v1beta1/app_types.go index a7c81c11..d66e2218 100644 --- a/internal/api/v1beta1/app_types.go +++ b/internal/api/v1beta1/app_types.go @@ -96,7 +96,6 @@ type ProcessSpec struct { Volumes []v1.Volume `json:"volumes,omitempty"` VolumeMounts []v1.VolumeMount `json:"volumeMounts,omitempty"` - // Security options the process should run with. SecurityContext *v1.SecurityContext `json:"securityContext,omitempty"` } @@ -225,10 +224,10 @@ type AppSpec struct { // BuildPacks is a list of build packs to use when building from source. BuildPacks []string `json:"buildPacks,omitempty"` - // Labels is a list of labels that will be applied to Services/Deployments. + // Labels is a list of labels that will be applied to Services/Deployments/Pods. Labels []MetadataItem `json:"labels,omitempty"` - // Annotations is a list of annotations that will be applied to Services/Deployments/Gateways. + // Annotations is a list of annotations that will be applied to Services/Deployments/Pods/Gateways/Ingresses/IngressRoutes. Annotations []MetadataItem `json:"annotations,omitempty"` // ServiceAccountName specifies a service account name to be used for this application. @@ -664,6 +663,11 @@ func (t Target) IsService() bool { return t.Kind == "Service" && t.APIVersion == "v1" } +// IsPod returns true if the target is a Pod. +func (t Target) IsPod() bool { + return t.Kind == "Pod" && t.APIVersion == "v1" +} + const ( CanaryNotActiveEvent = "CanaryNotActive" CanaryNotActiveEventDesc = "error - canary triggered, but not active" diff --git a/internal/chart/application_chart_test.go b/internal/chart/application_chart_test.go index 7ac66ecd..133dcc89 100644 --- a/internal/chart/application_chart_test.go +++ b/internal/chart/application_chart_test.go @@ -140,22 +140,31 @@ func TestNewApplicationChart(t *testing.T) { {Name: "darkweb.theketch.io", Secure: true, SecretName: "darkweb-ssl"}, }, }, - Labels: []ketchv1.MetadataItem{{ - Apply: map[string]string{"theketch.io/test-label": "test-label-value"}, - DeploymentVersion: 3, - ProcessName: "web", - Target: ketchv1.Target{ - APIVersion: "apps/v1", - Kind: "Deployment", + Labels: []ketchv1.MetadataItem{ + { + Apply: map[string]string{"pod.io/label": "pod-label"}, + DeploymentVersion: 3, + ProcessName: "web", + Target: ketchv1.Target{APIVersion: "v1", Kind: "Pod"}, + }, + { + Apply: map[string]string{"theketch.io/test-label": "test-label-value"}, + DeploymentVersion: 3, + ProcessName: "web", + Target: ketchv1.Target{APIVersion: "apps/v1", Kind: "Deployment"}, }, - }, { - Apply: map[string]string{"theketch.io/test-label-all": "test-label-value-all"}, - Target: ketchv1.Target{ - APIVersion: "apps/v1", - Kind: "Deployment", + { + Apply: map[string]string{"theketch.io/test-label-all": "test-label-value-all"}, + Target: ketchv1.Target{APIVersion: "apps/v1", Kind: "Deployment"}, }, - }}, + }, Annotations: []ketchv1.MetadataItem{ + { + Apply: map[string]string{"pod.io/annotation": "pod-annotation"}, + DeploymentVersion: 3, + ProcessName: "web", + Target: ketchv1.Target{APIVersion: "v1", Kind: "Pod"}, + }, { Apply: map[string]string{"theketch.io/test-annotation": "test-annotation-value"}, DeploymentVersion: 4, diff --git a/internal/chart/process.go b/internal/chart/process.go index ef15ae72..5acff1d7 100644 --- a/internal/chart/process.go +++ b/internal/chart/process.go @@ -24,10 +24,6 @@ type process struct { PublicServicePort int32 `json:"publicServicePort,omitempty"` Env []ketchv1.Env `json:"env"` - PodExtra podExtra `json:"extra"` -} - -type podExtra struct { SecurityContext *v1.SecurityContext `json:"securityContext,omitempty"` ResourceRequirements *v1.ResourceRequirements `json:"resourceRequirements,omitempty"` NodeSelectorTerms []v1.NodeSelectorTerm `json:"nodeSelectorTerms,omitempty"` @@ -36,8 +32,12 @@ type podExtra struct { ReadinessProbe *v1.Probe `json:"readinessProbe,omitempty"` LivenessProbe *v1.Probe `json:"livenessProbe,omitempty"` Lifecycle *v1.Lifecycle `json:"lifecycle,omitempty"` - ServiceMetadata extraMetadata `json:"serviceMetadata,omitempty"` - DeploymentMetadata extraMetadata `json:"deploymentMetadata,omitempty"` + // ServiceMetadata contains Labels and Annotations to be added to a k8s Service of this process. + ServiceMetadata extraMetadata `json:"serviceMetadata,omitempty"` + // DeploymentMetadata contains Labels and Annotations to be added to a k8s Deployment of this process. + DeploymentMetadata extraMetadata `json:"deploymentMetadata,omitempty"` + // PodMetadata contains Labels and Annotations to be added to a k8s Pod of this process. + PodMetadata extraMetadata `json:"podMetadata,omitempty"` } type extraMetadata struct { @@ -91,43 +91,43 @@ func withPortsAndProbes(c portConfigurator) processOption { return err } p.PublicServicePort = p.ServicePorts[0].Port - p.PodExtra.LivenessProbe = probes.Liveness - p.PodExtra.ReadinessProbe = probes.Readiness + p.LivenessProbe = probes.Liveness + p.ReadinessProbe = probes.Readiness return nil } } func withSecurityContext(securityContext *v1.SecurityContext) processOption { return func(p *process) error { - p.PodExtra.SecurityContext = securityContext + p.SecurityContext = securityContext return nil } } func withLifecycle(lc *v1.Lifecycle) processOption { return func(p *process) error { - p.PodExtra.Lifecycle = lc + p.Lifecycle = lc return nil } } func withResourceRequirements(rr *v1.ResourceRequirements) processOption { return func(p *process) error { - p.PodExtra.ResourceRequirements = rr + p.ResourceRequirements = rr return nil } } func withVolumes(volumes []v1.Volume) processOption { return func(p *process) error { - p.PodExtra.Volumes = volumes + p.Volumes = volumes return nil } } func withVolumeMounts(vm []v1.VolumeMount) processOption { return func(p *process) error { - p.PodExtra.VolumeMounts = vm + p.VolumeMounts = vm return nil } } @@ -144,15 +144,20 @@ func withLabels(labels []ketchv1.MetadataItem, deploymentVersion ketchv1.Deploym } for k, v := range label.Apply { if label.Target.IsDeployment() { - if p.PodExtra.DeploymentMetadata.Labels == nil { - p.PodExtra.DeploymentMetadata.Labels = make(map[string]string) + if p.DeploymentMetadata.Labels == nil { + p.DeploymentMetadata.Labels = make(map[string]string) } - p.PodExtra.DeploymentMetadata.Labels[k] = v + p.DeploymentMetadata.Labels[k] = v } else if label.Target.IsService() { - if p.PodExtra.ServiceMetadata.Labels == nil { - p.PodExtra.ServiceMetadata.Labels = make(map[string]string) + if p.ServiceMetadata.Labels == nil { + p.ServiceMetadata.Labels = make(map[string]string) } - p.PodExtra.ServiceMetadata.Labels[k] = v + p.ServiceMetadata.Labels[k] = v + } else if label.Target.IsPod() { + if p.PodMetadata.Labels == nil { + p.PodMetadata.Labels = make(map[string]string) + } + p.PodMetadata.Labels[k] = v } } } @@ -172,15 +177,20 @@ func withAnnotations(annotations []ketchv1.MetadataItem, deploymentVersion ketch } for k, v := range annotation.Apply { if annotation.Target.IsDeployment() { - if p.PodExtra.DeploymentMetadata.Annotations == nil { - p.PodExtra.DeploymentMetadata.Annotations = make(map[string]string) + if p.DeploymentMetadata.Annotations == nil { + p.DeploymentMetadata.Annotations = make(map[string]string) } - p.PodExtra.DeploymentMetadata.Annotations[k] = v + p.DeploymentMetadata.Annotations[k] = v } else if annotation.Target.IsService() { - if p.PodExtra.ServiceMetadata.Annotations == nil { - p.PodExtra.ServiceMetadata.Annotations = make(map[string]string) + if p.ServiceMetadata.Annotations == nil { + p.ServiceMetadata.Annotations = make(map[string]string) + } + p.ServiceMetadata.Annotations[k] = v + } else if annotation.Target.IsPod() { + if p.PodMetadata.Annotations == nil { + p.PodMetadata.Annotations = make(map[string]string) } - p.PodExtra.ServiceMetadata.Annotations[k] = v + p.PodMetadata.Annotations[k] = v } } } diff --git a/internal/chart/process_test.go b/internal/chart/process_test.go index 4c8eb3fc..472cd429 100644 --- a/internal/chart/process_test.go +++ b/internal/chart/process_test.go @@ -118,15 +118,13 @@ func TestNewProcess(t *testing.T) { {Name: "PORT", Value: "9999"}, {Name: "PORT_web", Value: "9999"}, }, - PodExtra: podExtra{ - Lifecycle: &v1.Lifecycle{}, - SecurityContext: &v1.SecurityContext{ - Privileged: boolRef(true), - }, - ResourceRequirements: &rr, - Volumes: volumes, - VolumeMounts: volumeMounts, + Lifecycle: &v1.Lifecycle{}, + SecurityContext: &v1.SecurityContext{ + Privileged: boolRef(true), }, + ResourceRequirements: &rr, + Volumes: volumes, + VolumeMounts: volumeMounts, }, }, { @@ -228,57 +226,159 @@ func TestNewProcess(t *testing.T) { } } -func TestWithAnnotationsAndLabels(t *testing.T) { - newProcess := func() *process { - return &process{ - Name: "web", - PodExtra: podExtra{ - ServiceMetadata: extraMetadata{ - Labels: make(map[string]string), - Annotations: make(map[string]string), - }, - DeploymentMetadata: extraMetadata{ - Labels: make(map[string]string), - Annotations: make(map[string]string), - }, - }, - } - } +func Test_withAnnotations(t *testing.T) { tests := []struct { description string annotations []ketchv1.MetadataItem - labels []ketchv1.MetadataItem deploymentVersion ketchv1.DeploymentVersion expected *process expectedError error }{ { - description: "ok - specify deploymentVersion and processName", + description: "ok - specify exact deploymentVersion and processName", annotations: []ketchv1.MetadataItem{ { Target: ketchv1.Target{Kind: "Deployment", APIVersion: "apps/v1"}, DeploymentVersion: 1, ProcessName: "web", - Apply: map[string]string{"theketch.io/test": "value"}, + Apply: map[string]string{"deployment.io/test": "value"}, }, { Target: ketchv1.Target{Kind: "Service", APIVersion: "v1"}, DeploymentVersion: 1, ProcessName: "web", - Apply: map[string]string{"theketch.io/test": "value"}, + Apply: map[string]string{"service.io/test": "value"}, + }, + { + Target: ketchv1.Target{Kind: "Pod", APIVersion: "v1"}, + DeploymentVersion: 1, + ProcessName: "web", + Apply: map[string]string{"pod.io/test": "value"}, + }, + }, + deploymentVersion: 1, + expected: &process{ + Name: "web", + ServiceMetadata: extraMetadata{ + Annotations: map[string]string{"service.io/test": "value"}, + }, + DeploymentMetadata: extraMetadata{ + Annotations: map[string]string{"deployment.io/test": "value"}, }, + PodMetadata: extraMetadata{ + Annotations: map[string]string{"pod.io/test": "value"}, + }, + }, + }, + { + description: "ok - any deploymentVersion and processName", + annotations: []ketchv1.MetadataItem{ { Target: ketchv1.Target{Kind: "Service", APIVersion: "v1"}, DeploymentVersion: 1, - Apply: map[string]string{"theketch.io/any-deployment-1": "any-deployment-1-value"}, + Apply: map[string]string{"service.io/any-deployment-1": "any-deployment-1-value"}, }, { Target: ketchv1.Target{Kind: "Service", APIVersion: "v1"}, ProcessName: "web", - Apply: map[string]string{"theketch.io/any-process-web": "any-process-web-value"}, + Apply: map[string]string{"service.io/any-process-web": "any-process-web-value"}, + }, + { + Target: ketchv1.Target{Kind: "Pod", APIVersion: "v1"}, + DeploymentVersion: 1, + Apply: map[string]string{"pod.io/any-deployment-1": "any-deployment-1-value"}, + }, + { + Target: ketchv1.Target{Kind: "Pod", APIVersion: "v1"}, + ProcessName: "web", + Apply: map[string]string{"pod.io/any-process-web": "any-process-web-value"}, + }, + { + Target: ketchv1.Target{Kind: "Deployment", APIVersion: "apps/v1"}, + DeploymentVersion: 1, + Apply: map[string]string{"deployment.io/any-deployment-1": "any-deployment-1-value"}, + }, + { + Target: ketchv1.Target{Kind: "Deployment", APIVersion: "apps/v1"}, + ProcessName: "web", + Apply: map[string]string{"deployment.io/any-process-web": "any-process-web-value"}, + }, + }, + deploymentVersion: 1, + expected: &process{ + Name: "web", + ServiceMetadata: extraMetadata{ + Annotations: map[string]string{ + "service.io/any-deployment-1": "any-deployment-1-value", + "service.io/any-process-web": "any-process-web-value", + }, + }, + DeploymentMetadata: extraMetadata{ + Annotations: map[string]string{ + "deployment.io/any-deployment-1": "any-deployment-1-value", + "deployment.io/any-process-web": "any-process-web-value", + }, + }, + PodMetadata: extraMetadata{ + Annotations: map[string]string{ + "pod.io/any-deployment-1": "any-deployment-1-value", + "pod.io/any-process-web": "any-process-web-value", + }, + }, + }, + }, + { + description: "error - malformed annotations", + annotations: []ketchv1.MetadataItem{ + { + Target: ketchv1.Target{Kind: "Deployment", APIVersion: "apps/v1"}, + DeploymentVersion: 1, + ProcessName: "web", + Apply: map[string]string{"_theketch.io/test": "CANT_START_KEY_WITH_UNDERSCORE"}, + }, + }, + deploymentVersion: 1, + expectedError: errors.New("malformed metadata key"), + }, + } + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + p := &process{Name: "web"} + fn := withAnnotations(tt.annotations, tt.deploymentVersion) + err := fn(p) + if tt.expectedError != nil { + require.EqualError(t, err, tt.expectedError.Error()) + } else { + require.Equal(t, tt.expected, p) + } + }) + } +} + +func Test_withLabels(t *testing.T) { + tests := []struct { + name string + labels []ketchv1.MetadataItem + deploymentVersion ketchv1.DeploymentVersion + expected *process + wantErr string + }{ + { + name: "error - malformed label", + labels: []ketchv1.MetadataItem{ + { + Target: ketchv1.Target{Kind: "Deployment", APIVersion: "apps/v1"}, + DeploymentVersion: 1, + ProcessName: "web", + Apply: map[string]string{"_theketch.io/test": "CANT_START_KEY_WITH_UNDERSCORE"}, }, }, + deploymentVersion: 1, + wantErr: "malformed metadata key", + }, + { + name: "all good", labels: []ketchv1.MetadataItem{ { Target: ketchv1.Target{Kind: "Deployment", APIVersion: "apps/v1"}, @@ -296,7 +396,7 @@ func TestWithAnnotationsAndLabels(t *testing.T) { Target: ketchv1.Target{Kind: "Deployment", APIVersion: "apps/v1"}, DeploymentVersion: 2, ProcessName: "web", - Apply: map[string]string{"theketch.io/NON-MATCHING-DEPLOYEMT-VERSION": "value"}, + Apply: map[string]string{"theketch.io/NON-MATCHING-DEPLOYMENT-VERSION": "value"}, }, { Target: ketchv1.Target{Kind: "Deployment", APIVersion: "apps/v1"}, @@ -316,52 +416,52 @@ func TestWithAnnotationsAndLabels(t *testing.T) { ProcessName: "web", Apply: map[string]string{"theketch.io/NON-EXISTENT-KIND": "value"}, }, + { + Target: ketchv1.Target{Kind: "Pod", APIVersion: "v1"}, + DeploymentVersion: 1, + ProcessName: "web", + Apply: map[string]string{"pod.label.io": "pod-label"}, + }, + { + Target: ketchv1.Target{Kind: "Pod", APIVersion: "v1"}, + DeploymentVersion: 2, + ProcessName: "web", + Apply: map[string]string{"theketch.io/NON-MATCHING-DEPLOYMENT-VERSION": "value"}, + }, + { + Target: ketchv1.Target{Kind: "Pod", APIVersion: "v1"}, + DeploymentVersion: 1, + ProcessName: "SOMETHING_ELSE", + Apply: map[string]string{"theketch.io/NON-MATCHING-PROCESS": "value"}, + }, }, deploymentVersion: 1, expected: &process{ Name: "web", - PodExtra: podExtra{ - ServiceMetadata: extraMetadata{ - Labels: map[string]string{"theketch.io/test": "value"}, - Annotations: map[string]string{ - "theketch.io/test": "value", - "theketch.io/any-deployment-1": "any-deployment-1-value", - "theketch.io/any-process-web": "any-process-web-value", - }, - }, - DeploymentMetadata: extraMetadata{ - Labels: map[string]string{"theketch.io/test": "value"}, - Annotations: map[string]string{"theketch.io/test": "value"}, - }, + ServiceMetadata: extraMetadata{ + Labels: map[string]string{"theketch.io/test": "value"}, }, - }, - }, - { - description: "error - malformed label", - labels: []ketchv1.MetadataItem{ - { - Target: ketchv1.Target{Kind: "Deployment", APIVersion: "apps/v1"}, - DeploymentVersion: 1, - ProcessName: "web", - Apply: map[string]string{"_theketch.io/test": "CANT_START_KEY_WITH_UNDERSCORE"}, + DeploymentMetadata: extraMetadata{ + Labels: map[string]string{"theketch.io/test": "value"}, + }, + PodMetadata: extraMetadata{ + Labels: map[string]string{"pod.label.io": "pod-label"}, }, }, - deploymentVersion: 1, - expectedError: errors.New("malformed metadata key"), }, } for _, tt := range tests { - t.Run(tt.description, func(t *testing.T) { - p := newProcess() - fn := withAnnotations(tt.annotations, tt.deploymentVersion) - fn(p) - fn = withLabels(tt.labels, tt.deploymentVersion) + t.Run(tt.name, func(t *testing.T) { + fn := withLabels(tt.labels, tt.deploymentVersion) + p := &process{Name: "web"} err := fn(p) - if tt.expectedError != nil { - require.EqualError(t, err, tt.expectedError.Error()) - } else { - require.Equal(t, tt.expected, p) + if len(tt.wantErr) > 0 { + require.NotNil(t, err) + require.Equal(t, tt.wantErr, err.Error()) + return } + require.Nil(t, err) + require.Equal(t, tt.expected, p) }) } } diff --git a/internal/chart/testdata/charts/dashboard-istio-cluster-issuer.yaml b/internal/chart/testdata/charts/dashboard-istio-cluster-issuer.yaml index ca03d970..5eadfe19 100755 --- a/internal/chart/testdata/charts/dashboard-istio-cluster-issuer.yaml +++ b/internal/chart/testdata/charts/dashboard-istio-cluster-issuer.yaml @@ -146,6 +146,9 @@ spec: theketch.io/app-process: "web" theketch.io/app-deployment-version: "3" theketch.io/is-isolated-run: "false" + pod.io/label: "pod-label" + annotations: + pod.io/annotation: "pod-annotation" spec: containers: - name: dashboard-web-3 diff --git a/internal/chart/testdata/charts/dashboard-istio.yaml b/internal/chart/testdata/charts/dashboard-istio.yaml index ffe6d33c..86f56cb7 100755 --- a/internal/chart/testdata/charts/dashboard-istio.yaml +++ b/internal/chart/testdata/charts/dashboard-istio.yaml @@ -146,6 +146,9 @@ spec: theketch.io/app-process: "web" theketch.io/app-deployment-version: "3" theketch.io/is-isolated-run: "false" + pod.io/label: "pod-label" + annotations: + pod.io/annotation: "pod-annotation" spec: containers: - name: dashboard-web-3 diff --git a/internal/chart/testdata/charts/dashboard-nginx-cluster-issuer.yaml b/internal/chart/testdata/charts/dashboard-nginx-cluster-issuer.yaml index b1571d14..0b514410 100755 --- a/internal/chart/testdata/charts/dashboard-nginx-cluster-issuer.yaml +++ b/internal/chart/testdata/charts/dashboard-nginx-cluster-issuer.yaml @@ -146,6 +146,9 @@ spec: theketch.io/app-process: "web" theketch.io/app-deployment-version: "3" theketch.io/is-isolated-run: "false" + pod.io/label: "pod-label" + annotations: + pod.io/annotation: "pod-annotation" spec: containers: - name: dashboard-web-3 diff --git a/internal/chart/testdata/charts/dashboard-nginx.yaml b/internal/chart/testdata/charts/dashboard-nginx.yaml index d97bfc59..19a60a6e 100755 --- a/internal/chart/testdata/charts/dashboard-nginx.yaml +++ b/internal/chart/testdata/charts/dashboard-nginx.yaml @@ -146,6 +146,9 @@ spec: theketch.io/app-process: "web" theketch.io/app-deployment-version: "3" theketch.io/is-isolated-run: "false" + pod.io/label: "pod-label" + annotations: + pod.io/annotation: "pod-annotation" spec: serviceAccountName: custom-service-account containers: diff --git a/internal/chart/testdata/charts/dashboard-traefik-cluster-issuer-shipa.yaml b/internal/chart/testdata/charts/dashboard-traefik-cluster-issuer-shipa.yaml index 4e5cd33f..847dc099 100755 --- a/internal/chart/testdata/charts/dashboard-traefik-cluster-issuer-shipa.yaml +++ b/internal/chart/testdata/charts/dashboard-traefik-cluster-issuer-shipa.yaml @@ -146,6 +146,9 @@ spec: shipa.io/app-process: "web" shipa.io/app-deployment-version: "3" shipa.io/is-isolated-run: "false" + pod.io/label: "pod-label" + annotations: + pod.io/annotation: "pod-annotation" spec: containers: - name: dashboard-web-3 diff --git a/internal/chart/testdata/charts/dashboard-traefik-cluster-issuer.yaml b/internal/chart/testdata/charts/dashboard-traefik-cluster-issuer.yaml index 977f244c..00136e68 100755 --- a/internal/chart/testdata/charts/dashboard-traefik-cluster-issuer.yaml +++ b/internal/chart/testdata/charts/dashboard-traefik-cluster-issuer.yaml @@ -146,6 +146,9 @@ spec: theketch.io/app-process: "web" theketch.io/app-deployment-version: "3" theketch.io/is-isolated-run: "false" + pod.io/label: "pod-label" + annotations: + pod.io/annotation: "pod-annotation" spec: containers: - name: dashboard-web-3 diff --git a/internal/chart/testdata/charts/dashboard-traefik.yaml b/internal/chart/testdata/charts/dashboard-traefik.yaml index 5471d40a..655c4142 100755 --- a/internal/chart/testdata/charts/dashboard-traefik.yaml +++ b/internal/chart/testdata/charts/dashboard-traefik.yaml @@ -146,6 +146,9 @@ spec: theketch.io/app-process: "web" theketch.io/app-deployment-version: "3" theketch.io/is-isolated-run: "false" + pod.io/label: "pod-label" + annotations: + pod.io/annotation: "pod-annotation" spec: containers: - name: dashboard-web-3 diff --git a/internal/templates/common/yamls/deployment.yaml b/internal/templates/common/yamls/deployment.yaml index 19612eef..7937ef81 100644 --- a/internal/templates/common/yamls/deployment.yaml +++ b/internal/templates/common/yamls/deployment.yaml @@ -9,12 +9,12 @@ metadata: {{ $.Values.app.group }}/app-process-replicas: {{ $process.units | quote }} {{ $.Values.app.group }}/app-deployment-version: {{ $deployment.version | quote }} {{ $.Values.app.group }}/is-isolated-run: "false" - {{- range $k, $v := $process.extra.deploymentMetadata.labels }} + {{- range $k, $v := $process.deploymentMetadata.labels }} {{ $k }}: {{ $v | quote }} {{- end}} - {{- if $process.extra.deploymentMetadata.annotations }} + {{- if $process.deploymentMetadata.annotations }} annotations: - {{- range $k, $v := $process.extra.deploymentMetadata.annotations }} + {{- range $k, $v := $process.deploymentMetadata.annotations }} {{ $k }}: {{ $v | quote }} {{- end }} {{- end }} @@ -38,6 +38,15 @@ spec: {{ $.Values.app.group }}/app-process: {{ $process.name | quote }} {{ $.Values.app.group }}/app-deployment-version: {{ $deployment.version | quote }} {{ $.Values.app.group }}/is-isolated-run: "false" + {{- range $k, $v := $process.podMetadata.labels }} + {{ $k }}: {{ $v | quote }} + {{- end }} + {{- if $process.podMetadata.annotations }} + annotations: + {{- range $k, $v := $process.podMetadata.annotations }} + {{ $k }}: {{ $v | quote }} + {{- end }} + {{- end }} spec: {{- if $.Values.app.serviceAccountName }} serviceAccountName: {{ $.Values.app.serviceAccountName }} @@ -59,36 +68,36 @@ spec: ports: {{ $process.containerPorts | toYaml | indent 10 }} {{- end }} - {{- if $process.extra.volumeMounts }} + {{- if $process.volumeMounts }} volumeMounts: -{{ $process.extra.volumeMounts | toYaml | indent 12 }} +{{ $process.volumeMounts | toYaml | indent 12 }} {{- end }} - {{- if $process.extra.resourceRequirements }} + {{- if $process.resourceRequirements }} resources: -{{ $process.extra.resourceRequirements | toYaml | indent 12 }} +{{ $process.resourceRequirements | toYaml | indent 12 }} {{- end }} - {{- if $process.extra.lifecycle }} + {{- if $process.lifecycle }} lifecycle: -{{ $process.extra.lifecycle | toYaml | indent 12 }} +{{ $process.lifecycle | toYaml | indent 12 }} {{- end }} - {{- if $process.extra.securityContext }} + {{- if $process.securityContext }} securityContext: -{{ $process.extra.securityContext | toYaml | indent 12 }} +{{ $process.securityContext | toYaml | indent 12 }} {{- end }} {{- if $deployment.imagePullSecrets }} imagePullSecrets: {{ $deployment.imagePullSecrets | toYaml | indent 12}} {{- end }} - {{- if $process.extra.volumes }} + {{- if $process.volumes }} volumes: -{{ $process.extra.volumes | toYaml | indent 12 }} +{{ $process.volumes | toYaml | indent 12 }} {{- end }} - {{- if $process.extra.nodeSelectorTerms }} + {{- if $process.nodeSelectorTerms }} affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: -{{ $process.extra.nodeSelectorTerms | toYaml | indent 14 }} +{{ $process.nodeSelectorTerms | toYaml | indent 14 }} {{- end }} --- {{ end }} diff --git a/internal/templates/common/yamls/service.yaml b/internal/templates/common/yamls/service.yaml index 3a2d033d..ae11182f 100644 --- a/internal/templates/common/yamls/service.yaml +++ b/internal/templates/common/yamls/service.yaml @@ -12,12 +12,12 @@ metadata: {{- range $i, $label := $deployment.labels }} {{ $label.name }}: {{ $label.value | quote }} {{- end }} - {{- range $k, $v := $process.extra.serviceMetadata.labels }} + {{- range $k, $v := $process.serviceMetadata.labels }} {{ $k }}: {{ $v | quote }} {{- end}} - {{- if $process.extra.serviceMetadata.annotations }} + {{- if $process.serviceMetadata.annotations }} annotations: - {{- range $k, $v := $process.extra.serviceMetadata.annotations }} + {{- range $k, $v := $process.serviceMetadata.annotations }} {{ $k }}: {{ $v | quote }} {{- end }} {{- end }}