diff --git a/operator/api/apps/v1/postgresservice_types.go b/operator/api/apps/v1/postgresservice_types.go index e6695222..c6f57a79 100644 --- a/operator/api/apps/v1/postgresservice_types.go +++ b/operator/api/apps/v1/postgresservice_types.go @@ -205,6 +205,7 @@ type IntegrationTests struct { DockerImage string `json:"image,omitempty"` RunTestScenarios string `json:"runTestScenarios,omitempty"` TestList []string `json:"testList,omitempty"` + Tags string `json:"tags,omitempty"` Replicas int `json:"replicas,omitempty"` PgNodeQty int `json:"pgNodeQty,omitempty"` PodLabels map[string]string `json:"podLabels,omitempty"` diff --git a/operator/api/common/v1/zz_generated.deepcopy.go b/operator/api/common/v1/zz_generated.deepcopy.go index a915d992..d6990f21 100644 --- a/operator/api/common/v1/zz_generated.deepcopy.go +++ b/operator/api/common/v1/zz_generated.deepcopy.go @@ -4,6 +4,8 @@ package v1 +import () + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Storage) DeepCopyInto(out *Storage) { *out = *in diff --git a/operator/api/patroni/v1/patronicore_types.go b/operator/api/patroni/v1/patronicore_types.go index 1c672f6a..689a365e 100644 --- a/operator/api/patroni/v1/patronicore_types.go +++ b/operator/api/patroni/v1/patronicore_types.go @@ -184,6 +184,7 @@ type IntegrationTests struct { DockerImage string `json:"image,omitempty"` RunTestScenarios string `json:"runTestScenarios,omitempty"` TestList []string `json:"testList,omitempty"` + Tags string `json:"tags,omitempty"` Replicas int `json:"replicas,omitempty"` PgNodeQty int `json:"pgNodeQty,omitempty"` PodLabels map[string]string `json:"podLabels,omitempty"` diff --git a/operator/charts/patroni-core/crds/netcracker.com_patronicores.yaml b/operator/charts/patroni-core/crds/netcracker.com_patronicores.yaml index 2d37f6ca..721e627b 100644 --- a/operator/charts/patroni-core/crds/netcracker.com_patronicores.yaml +++ b/operator/charts/patroni-core/crds/netcracker.com_patronicores.yaml @@ -1089,6 +1089,8 @@ spec: type: object runTestScenarios: type: string + tags: + type: string testList: items: type: string @@ -2636,9 +2638,10 @@ spec: operator: description: |- Operator represents a key's relationship to the value. - Valid operators are Exists and Equal. Defaults to Equal. + Valid operators are Exists, Equal, Lt, and Gt. Defaults to Equal. Exists is equivalent to wildcard for value, so that a pod can tolerate all taints of a particular category. + Lt and Gt perform numeric comparisons (requires feature gate TaintTolerationComparisonOperators). type: string tolerationSeconds: description: |- diff --git a/operator/charts/patroni-core/templates/cr.yaml b/operator/charts/patroni-core/templates/cr.yaml index 4643ab0c..a8c91c77 100644 --- a/operator/charts/patroni-core/templates/cr.yaml +++ b/operator/charts/patroni-core/templates/cr.yaml @@ -242,6 +242,9 @@ spec: - {{ . }} {{- end }} {{ end }} +{{- if .Values.tests.tags }} + tags: {{ .Values.tests.tags | quote }} +{{- end }} pgNodeQty: {{ ( include "postgres.replicasCount" . ) }} {{ end }} {{ if .Values.runTestsOnly }} diff --git a/operator/charts/patroni-core/templates/tests/tests-config.yaml b/operator/charts/patroni-core/templates/tests/tests-config.yaml index 20d08f8c..58809e25 100644 --- a/operator/charts/patroni-core/templates/tests/tests-config.yaml +++ b/operator/charts/patroni-core/templates/tests/tests-config.yaml @@ -6,9 +6,5 @@ metadata: labels: app: patroni-tests data: -{{- if include "patroni-tests.monitoredImages" . }} - dd_images: {{ include "patroni-tests.monitoredImages" . }} -{{ else }} - dd_images: "" -{{ end }} + dd_images: {{ (.Values.tests.ddImages | default (include "patroni-tests.monitoredImages" .) | default "") | quote }} {{- end }} diff --git a/operator/charts/patroni-core/values.yaml b/operator/charts/patroni-core/values.yaml index 1c15367d..271a4cca 100644 --- a/operator/charts/patroni-core/values.yaml +++ b/operator/charts/patroni-core/values.yaml @@ -276,6 +276,7 @@ tests: podLabels: {} # One of "full", "basic"or one from testScenarios runTestScenarios: "basic" + tags: "" testScenarios: patroniSimple: - check_patroni_rest diff --git a/operator/charts/patroni-services/crds/netcracker.com_patroniservices.yaml b/operator/charts/patroni-services/crds/netcracker.com_patroniservices.yaml index 436e2cc3..0fa10978 100644 --- a/operator/charts/patroni-services/crds/netcracker.com_patroniservices.yaml +++ b/operator/charts/patroni-services/crds/netcracker.com_patroniservices.yaml @@ -3625,6 +3625,8 @@ spec: type: object runTestScenarios: type: string + tags: + type: string testList: items: type: string @@ -6139,9 +6141,10 @@ spec: operator: description: |- Operator represents a key's relationship to the value. - Valid operators are Exists and Equal. Defaults to Equal. + Valid operators are Exists, Equal, Lt, and Gt. Defaults to Equal. Exists is equivalent to wildcard for value, so that a pod can tolerate all taints of a particular category. + Lt and Gt perform numeric comparisons (requires feature gate TaintTolerationComparisonOperators). type: string tolerationSeconds: description: |- diff --git a/operator/charts/patroni-services/templates/cr.yaml b/operator/charts/patroni-services/templates/cr.yaml index 33f5051b..fc09df5f 100644 --- a/operator/charts/patroni-services/templates/cr.yaml +++ b/operator/charts/patroni-services/templates/cr.yaml @@ -422,6 +422,9 @@ spec: - {{ . }} {{- end }} {{ end }} +{{- if .Values.tests.tags }} + tags: {{ .Values.tests.tags | quote }} +{{- 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/charts/patroni-services/values.yaml b/operator/charts/patroni-services/values.yaml index 0374f46b..6397da2d 100644 --- a/operator/charts/patroni-services/values.yaml +++ b/operator/charts/patroni-services/values.yaml @@ -433,6 +433,7 @@ tests: podLabels: {} # One of "full", "basic"or one from testScenarios runTestScenarios: "basic" + tags: "" testScenarios: patroniSimple: - check_patroni_rest diff --git a/operator/pkg/deployment/tests.go b/operator/pkg/deployment/tests.go index ecd2e663..de3237d4 100644 --- a/operator/pkg/deployment/tests.go +++ b/operator/pkg/deployment/tests.go @@ -16,7 +16,6 @@ package deployment import ( "fmt" - "regexp" "strconv" "strings" @@ -35,23 +34,21 @@ var ( func NewIntegrationTestsPod(cr *v1.PatroniServices, cluster *patroniv1.PatroniClusterSettings) *corev1.Pod { testsSpec := cr.Spec.IntegrationTests tastsTags := "" + opt := true pgHost := cluster.PostgresServiceName - if strings.ToLower(testsSpec.RunTestScenarios) == "full" { + + if testsSpec.Tags != "" { + tastsTags = strings.Join(strings.Fields(testsSpec.Tags), "") + } else if strings.ToLower(testsSpec.RunTestScenarios) == "full" { if cr.Spec.BackupDaemon != nil && cr.Spec.BackupDaemon.Resources != nil { tastsTags = "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 strings.ToLower(testsSpec.RunTestScenarios) == "basic" { + if cr.Spec.BackupDaemon != nil && cr.Spec.BackupDaemon.Resources != nil { + tastsTags = "backup_basic" } + } else if len(testsSpec.TestList) > 0 { + tastsTags = strings.Join(testsSpec.TestList, "OR") } dockerImage := testsSpec.DockerImage name := "integration-robot-tests" @@ -127,6 +124,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{}, }, @@ -150,25 +157,25 @@ func NewIntegrationTestsPod(cr *v1.PatroniServices, cluster *patroniv1.PatroniCl func NewCoreIntegrationTests(cr *patroniv1.PatroniCore, cluster *patroniv1.PatroniClusterSettings) *corev1.Pod { testsSpec := cr.Spec.IntegrationTests tastsTags := "" + opt := true pgHost := cluster.PostgresServiceName if cr.Spec.Patroni.StandbyCluster != nil { pgHost = fmt.Sprintf("pg-%s-external", cluster.ClusterName) } - if strings.ToLower(cr.Spec.Patroni.Dcs.Type) != "kubernetes" { + if testsSpec.Tags != "" { + tastsTags = strings.ReplaceAll(testsSpec.Tags, " ", "") + } else if strings.ToLower(cr.Spec.Patroni.Dcs.Type) != "kubernetes" { tastsTags = "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, "_") - } - } + } else if strings.ToLower(testsSpec.RunTestScenarios) == "full" { + tastsTags = "patroni*" + } else if strings.ToLower(testsSpec.RunTestScenarios) == "basic" { + tastsTags = "patroni_basic" + } else if len(testsSpec.TestList) > 0 { + cleaned := make([]string, 0, len(testsSpec.TestList)) + for _, t := range testsSpec.TestList { + cleaned = append(cleaned, strings.ReplaceAll(t, " ", "_")) } + tastsTags = strings.Join(cleaned, "OR") } dockerImage := testsSpec.DockerImage name := "patroni-robot-tests" @@ -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}