From e714130eb42e2234c37702d17a49994d7db4361a Mon Sep 17 00:00:00 2001 From: yerkennz Date: Thu, 9 Apr 2026 19:11:58 +0500 Subject: [PATCH] fix[CPCAP-3400]: test tags and hardcode images test --- .../charts/patroni-core/templates/cr.yaml | 23 ++++-- .../charts/patroni-services/templates/cr.yaml | 23 ++++-- .../templates/tests/tests-config.yaml | 6 +- operator/pkg/deployment/tests.go | 79 +++++++++++-------- tests/robot/image_tests/image_tests.robot | 8 +- 5 files changed, 85 insertions(+), 54 deletions(-) diff --git a/operator/charts/patroni-core/templates/cr.yaml b/operator/charts/patroni-core/templates/cr.yaml index 4643ab0c..3a273e45 100644 --- a/operator/charts/patroni-core/templates/cr.yaml +++ b/operator/charts/patroni-core/templates/cr.yaml @@ -233,15 +233,24 @@ spec: cpu: 150m memory: 256Mi {{ end }} -{{- $runTestScenarios := .Values.tests.runTestScenarios }} -{{- if or (eq (lower $runTestScenarios) "full") (eq (lower $runTestScenarios) "basic") }} - runTestScenarios: {{.Values.tests.runTestScenarios}} -{{- else if index .Values.tests.testScenarios (printf "%s" $runTestScenarios) }} +{{- $runTestScenarios := lower .Values.tests.runTestScenarios }} +{{- if or (eq $runTestScenarios "full") (eq $runTestScenarios "basic") }} + runTestScenarios: {{ $runTestScenarios }} +{{- else if eq $runTestScenarios "custom" }} + runTestScenarios: custom + {{- if .Values.tests.testList }} testList: - {{- range (index .Values.tests.testScenarios (printf "%s" $runTestScenarios)) }} + {{- range .Values.tests.testList }} - {{ . }} - {{- end }} -{{ end }} + {{- end }} + {{- end }} +{{- else if hasKey .Values.tests.testScenarios .Values.tests.runTestScenarios }} + runTestScenarios: custom + testList: + {{- range (index .Values.tests.testScenarios .Values.tests.runTestScenarios) }} + - {{ . }} + {{- end }} +{{- end }} pgNodeQty: {{ ( include "postgres.replicasCount" . ) }} {{ end }} {{ if .Values.runTestsOnly }} diff --git a/operator/charts/patroni-services/templates/cr.yaml b/operator/charts/patroni-services/templates/cr.yaml index d397a2b5..a80611cb 100644 --- a/operator/charts/patroni-services/templates/cr.yaml +++ b/operator/charts/patroni-services/templates/cr.yaml @@ -413,15 +413,24 @@ spec: cpu: 150m memory: 256Mi {{ end }} -{{- $runTestScenarios := .Values.tests.runTestScenarios }} -{{- if or (eq (lower $runTestScenarios) "full") (eq (lower $runTestScenarios) "basic") }} - runTestScenarios: {{.Values.tests.runTestScenarios}} -{{- else if index .Values.tests.testScenarios (printf "%s" $runTestScenarios) }} +{{- $runTestScenarios := lower .Values.tests.runTestScenarios }} +{{- if or (eq $runTestScenarios "full") (eq $runTestScenarios "basic") }} + runTestScenarios: {{ $runTestScenarios }} +{{- else if eq $runTestScenarios "custom" }} + runTestScenarios: custom + {{- if .Values.tests.testList }} testList: - {{- range (index .Values.tests.testScenarios (printf "%s" $runTestScenarios)) }} + {{- range .Values.tests.testList }} - {{ . }} - {{- end }} -{{ end }} + {{- end }} + {{- end }} +{{- else if hasKey .Values.tests.testScenarios .Values.tests.runTestScenarios }} + runTestScenarios: custom + testList: + {{- range (index .Values.tests.testScenarios .Values.tests.runTestScenarios) }} + - {{ . }} + {{- end }} +{{- end }} pgNodeQty: {{ default "1" .Values.patroni.replicas }} {{ end }} {{ if .Values.runTestsOnly }} diff --git a/operator/charts/patroni-services/templates/tests/tests-config.yaml b/operator/charts/patroni-services/templates/tests/tests-config.yaml index cd0c087c..62afb167 100644 --- a/operator/charts/patroni-services/templates/tests/tests-config.yaml +++ b/operator/charts/patroni-services/templates/tests/tests-config.yaml @@ -6,9 +6,5 @@ metadata: labels: app: patroni-tests data: - {{- if include "supplementary-tests.monitoredImages" . }} - dd_images: {{ include "supplementary-tests.monitoredImages" . }} - {{ else }} - dd_images: "" - {{ end }} + dd_images: {{ (.Values.tests.ddImages | default (include "supplementary-tests.monitoredImages" .) | default "") | quote }} {{- end }} diff --git a/operator/pkg/deployment/tests.go b/operator/pkg/deployment/tests.go index ecd2e663..0c93ffd8 100644 --- a/operator/pkg/deployment/tests.go +++ b/operator/pkg/deployment/tests.go @@ -34,24 +34,22 @@ var ( func NewIntegrationTestsPod(cr *v1.PatroniServices, cluster *patroniv1.PatroniClusterSettings) *corev1.Pod { testsSpec := cr.Spec.IntegrationTests - tastsTags := "" + var testsTags string + opt := true pgHost := cluster.PostgresServiceName - if strings.ToLower(testsSpec.RunTestScenarios) == "full" { + scenario := strings.ToLower(testsSpec.RunTestScenarios) + if scenario == "full" { if cr.Spec.BackupDaemon != nil && cr.Spec.BackupDaemon.Resources != nil { - tastsTags = "backup*ORdbaas*" + testsTags = "backup*ORdbaas*" } - } else { - if strings.ToLower(testsSpec.RunTestScenarios) == "basic" { - if cr.Spec.BackupDaemon != nil && cr.Spec.BackupDaemon.Resources != nil { - tastsTags = "backup_basic" - } - } else { - if testsSpec.TestList != nil { - tastsTags = strings.Join(testsSpec.TestList, "OR") - r := regexp.MustCompile(`\s+`) - tastsTags = r.ReplaceAllString(tastsTags, "_") - } + } else if scenario == "basic" { + if cr.Spec.BackupDaemon != nil && cr.Spec.BackupDaemon.Resources != nil { + testsTags = "backup_basic" } + } else if scenario == "custom" && testsSpec.TestList != nil { + testsTags = strings.Join(testsSpec.TestList, "OR") + r := regexp.MustCompile(`\s+`) + testsTags = r.ReplaceAllString(testsTags, "_") } dockerImage := testsSpec.DockerImage name := "integration-robot-tests" @@ -75,7 +73,7 @@ func NewIntegrationTestsPod(cr *v1.PatroniServices, cluster *patroniv1.PatroniCl Image: dockerImage, ImagePullPolicy: cr.Spec.ImagePullPolicy, SecurityContext: util.GetDefaultSecurityContext(), - Args: []string{"robot", "-i", tastsTags, "/test_runs/"}, + Args: []string{"robot", "-i", testsTags, "/test_runs/"}, Env: []corev1.EnvVar{ { Name: "POSTGRES_USER", @@ -105,7 +103,7 @@ func NewIntegrationTestsPod(cr *v1.PatroniServices, cluster *patroniv1.PatroniCl }, { Name: "TESTS_TAGS", - Value: tastsTags, + Value: testsTags, }, { Name: "PG_HOST", @@ -127,6 +125,16 @@ func NewIntegrationTestsPod(cr *v1.PatroniServices, cluster *patroniv1.PatroniCl }, }, }, + { + Name: "DD_IMAGES", + ValueFrom: &corev1.EnvVarSource{ + ConfigMapKeyRef: &corev1.ConfigMapKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{Name: "supplementary-tests-config"}, + Key: "dd_images", + Optional: &opt, + }, + }, + }, }, VolumeMounts: []corev1.VolumeMount{}, }, @@ -149,25 +157,24 @@ func NewIntegrationTestsPod(cr *v1.PatroniServices, cluster *patroniv1.PatroniCl func NewCoreIntegrationTests(cr *patroniv1.PatroniCore, cluster *patroniv1.PatroniClusterSettings) *corev1.Pod { testsSpec := cr.Spec.IntegrationTests - tastsTags := "" + var testsTags string + opt := true pgHost := cluster.PostgresServiceName + scenario := strings.ToLower(testsSpec.RunTestScenarios) if cr.Spec.Patroni.StandbyCluster != nil { pgHost = fmt.Sprintf("pg-%s-external", cluster.ClusterName) } if strings.ToLower(cr.Spec.Patroni.Dcs.Type) != "kubernetes" { - tastsTags = "patroni_simple" + testsTags = "patroni_simple" } else { - if strings.ToLower(testsSpec.RunTestScenarios) == "full" { - tastsTags = "patroni*" - } else { - if strings.ToLower(testsSpec.RunTestScenarios) == "basic" { - tastsTags = "patroni_basic" - } else { - if testsSpec.TestList != nil { - r := regexp.MustCompile(`\s+`) - tastsTags = r.ReplaceAllString(tastsTags, "_") - } - } + if scenario == "full" { + testsTags = "patroni*" + } else if scenario == "basic" { + testsTags = "patroni_basic" + } else if scenario == "custom" && len(testsSpec.TestList) > 0 { + testsTags = strings.Join(testsSpec.TestList, "OR") + r := regexp.MustCompile(`\s+`) + testsTags = r.ReplaceAllString(testsTags, "_") } } dockerImage := testsSpec.DockerImage @@ -192,7 +199,7 @@ func NewCoreIntegrationTests(cr *patroniv1.PatroniCore, cluster *patroniv1.Patro Image: dockerImage, ImagePullPolicy: cr.Spec.ImagePullPolicy, SecurityContext: util.GetDefaultSecurityContext(), - Args: []string{"robot", "-i", tastsTags, "/test_runs/"}, + Args: []string{"robot", "-i", testsTags, "/test_runs/"}, Env: []corev1.EnvVar{ { Name: "POSTGRES_USER", @@ -226,7 +233,7 @@ func NewCoreIntegrationTests(cr *patroniv1.PatroniCore, cluster *patroniv1.Patro }, { Name: "TESTS_TAGS", - Value: tastsTags, + Value: testsTags, }, { Name: "PG_HOST", @@ -248,6 +255,16 @@ func NewCoreIntegrationTests(cr *patroniv1.PatroniCore, cluster *patroniv1.Patro }, }, }, + { + Name: "DD_IMAGES", + ValueFrom: &corev1.EnvVarSource{ + ConfigMapKeyRef: &corev1.ConfigMapKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{Name: "patroni-tests-config"}, + Key: "dd_images", + Optional: &opt, + }, + }, + }, }, VolumeMounts: []corev1.VolumeMount{}, }, diff --git a/tests/robot/image_tests/image_tests.robot b/tests/robot/image_tests/image_tests.robot index 74d03332..7e890d33 100644 --- a/tests/robot/image_tests/image_tests.robot +++ b/tests/robot/image_tests/image_tests.robot @@ -17,12 +17,12 @@ Compare Images From Resources With Dd *** Test Cases *** Test Hardcoded Images For Core Services [Tags] patroni basic check_pg_images - ${dd_images}= Get Dd Images From Config Map patroni-tests-config - Skip If '${dd_images}' == '${None}' There is no dd, not possible to check case! + ${dd_images}= Get Environment Variable DD_IMAGES + Skip If '${dd_images}' == '${None}' or '${dd_images}' == '' There is no dd, not possible to check case! Compare Images From Resources With Dd ${dd_images} Test Hardcoded Images For Supplementary Services [Tags] backup basic check_pg_images - ${dd_images}= Get Dd Images From Config Map supplementary-tests-config - Skip If '${dd_images}' == '${None}' There is no dd, not possible to check case! + ${dd_images}= Get Environment Variable DD_IMAGES + Skip If '${dd_images}' == '${None}' or '${dd_images}' == '' There is no dd, not possible to check case! Compare Images From Resources With Dd ${dd_images}