From c8efd21920b31635bba772042c393417b350a59b Mon Sep 17 00:00:00 2001 From: walsd1 Date: Mon, 23 Oct 2023 09:53:00 -0400 Subject: [PATCH 1/3] support custom labels on HPA --- charts/pega/templates/_pega_hpa.tpl | 4 + .../pega/data/values_hpa_custom_label.yaml | 15 + terratest/src/test/pega/pega-tier-hpa_test.go | 261 +++++++++++------- 3 files changed, 180 insertions(+), 100 deletions(-) create mode 100644 terratest/src/test/pega/data/values_hpa_custom_label.yaml diff --git a/charts/pega/templates/_pega_hpa.tpl b/charts/pega/templates/_pega_hpa.tpl index 0857131db..7bf84bca6 100644 --- a/charts/pega/templates/_pega_hpa.tpl +++ b/charts/pega/templates/_pega_hpa.tpl @@ -10,6 +10,10 @@ kind: HorizontalPodAutoscaler metadata: name: {{ .name | quote}} namespace: {{ .root.Release.Namespace }} +{{- if .hpa.labels }} + labels: +{{ toYaml .hpa.labels | indent 4 }} +{{- end }} spec: scaleTargetRef: apiVersion: apps/v1 diff --git a/terratest/src/test/pega/data/values_hpa_custom_label.yaml b/terratest/src/test/pega/data/values_hpa_custom_label.yaml new file mode 100644 index 000000000..935407c7f --- /dev/null +++ b/terratest/src/test/pega/data/values_hpa_custom_label.yaml @@ -0,0 +1,15 @@ +--- +global: + tier: + - name: "web" + hpa: + enabled: true + labels: + web-label: "somevalue" + web-other-label: "someothervalue" + - name: "batch" + hpa: + enabled: true + labels: + batch-label: "batchlabel" + batch-other-label: "anothervalue" diff --git a/terratest/src/test/pega/pega-tier-hpa_test.go b/terratest/src/test/pega/pega-tier-hpa_test.go index 3b65e8d24..9e4facd75 100644 --- a/terratest/src/test/pega/pega-tier-hpa_test.go +++ b/terratest/src/test/pega/pega-tier-hpa_test.go @@ -8,15 +8,15 @@ import ( "github.com/gruntwork-io/terratest/modules/helm" "github.com/stretchr/testify/require" - "k8s.io/apimachinery/pkg/api/resource" autoscaling "k8s.io/api/autoscaling/v2beta2" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" ) func TestPegaTierHPA(t *testing.T) { - var supportedVendors = []string{"k8s", "openshift", "eks","gke","aks","pks"} - var supportedOperations = []string{"deploy","install-deploy","upgrade-deploy"} - var deploymentNames = []string{"pega","myapp-dev"} + var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"} + var supportedOperations = []string{"deploy", "install-deploy", "upgrade-deploy"} + var deploymentNames = []string{"pega", "myapp-dev"} helmChartPath, err := filepath.Abs(PegaHelmChartPath) require.NoError(t, err) @@ -25,48 +25,50 @@ func TestPegaTierHPA(t *testing.T) { for _, operation := range supportedOperations { - for _, depName := range deploymentNames { + for _, depName := range deploymentNames { - fmt.Println(vendor + "-" + operation) + fmt.Println(vendor + "-" + operation) - var options = &helm.Options{ - SetValues: map[string]string{ - "global.deployment.name": depName, - "global.provider": vendor, - "global.actions.execute": operation, + var options = &helm.Options{ + SetValues: map[string]string{ + "global.deployment.name": depName, + "global.provider": vendor, + "global.actions.execute": operation, "installer.upgrade.upgradeType": "zero-downtime", - }, - } - - yamlContent := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-hpa.yaml"}) - verifyPegaHPAs(t, yamlContent, options, []hpa{ - { - name: getObjName(options, "-web-hpa"), - targetRefName: getObjName(options, "-web"), - kind: "Deployment", - apiversion: "apps/v1", - cpu: true, - cpuValue: parseResourceValue(t, "2.55"), - }, - { - name: getObjName(options, "-batch-hpa"), - targetRefName: getObjName(options, "-batch"), - kind: "Deployment", - apiversion: "apps/v1", - cpu: true, - cpuValue: parseResourceValue(t, "2.55"), - }, - }) - } + }, + } + + yamlContent := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-hpa.yaml"}) + verifyPegaHPAs(t, yamlContent, options, []hpa{ + { + name: getObjName(options, "-web-hpa"), + targetRefName: getObjName(options, "-web"), + kind: "Deployment", + apiversion: "apps/v1", + cpu: true, + cpuValue: parseResourceValue(t, "2.55"), + }, + { + name: getObjName(options, "-batch-hpa"), + targetRefName: getObjName(options, "-batch"), + kind: "Deployment", + apiversion: "apps/v1", + cpu: true, + cpuValue: parseResourceValue(t, "2.55"), + }, + }) + } } } } +func TestPegaTierHPAWithCustomLabel(t *testing.T) { + var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"} + var supportedOperations = []string{"deploy", "install-deploy", "upgrade-deploy"} + var deploymentNames = []string{"pega", "myapp-dev"} -func TestPegaTierHPADisableTarget(t *testing.T) { - var supportedVendors = []string{"k8s", "openshift", "eks","gke","aks","pks"} - var supportedOperations = []string{"deploy","install-deploy","upgrade-deploy"} - var deploymentNames = []string{"pega","myapp-dev"} + expectedWebLabels := map[string]string{"web-label": "somevalue", "web-other-label": "someothervalue"} + expectedBatchLabels := map[string]string{"batch-label": "batchlabel", "batch-other-label": "anothervalue"} helmChartPath, err := filepath.Abs(PegaHelmChartPath) require.NoError(t, err) @@ -78,48 +80,100 @@ func TestPegaTierHPADisableTarget(t *testing.T) { for _, operation := range supportedOperations { - for _, depName := range deploymentNames { - fmt.Println(vendor + "-" + operation) + for _, depName := range deploymentNames { - var options = &helm.Options{ - SetValues: map[string]string{ - "global.deployment.name": depName, - "global.provider": vendor, - "global.actions.execute": operation, + fmt.Println(vendor + "-" + operation) + + var options = &helm.Options{ + SetValues: map[string]string{ + "global.deployment.name": depName, + "global.provider": vendor, + "global.actions.execute": operation, "installer.upgrade.upgradeType": "zero-downtime", - }, - } - - - yamlContent := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-hpa.yaml"}, "--values", testsPath+"/data/values_hpa_disabletarget.yaml") - verifyPegaHPAs(t, yamlContent, options, []hpa{ - { - name: getObjName(options, "-web-hpa"), - targetRefName: getObjName(options, "-web"), - kind: "Deployment", - apiversion: "apps/v1", - mem: true, - memPercent: 85, - }, - { - name: getObjName(options, "-batch-hpa"), - targetRefName: getObjName(options, "-batch"), - kind: "Deployment", - apiversion: "apps/v1", - cpu: true, - cpuValue: parseResourceValue(t, "2.55"), - }, - }) - } + }, + } + + yamlContent := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-hpa.yaml"}, "--values", testsPath+"/data/values_hpa_custom_label.yaml") + verifyPegaHPAs(t, yamlContent, options, []hpa{ + { + name: getObjName(options, "-web-hpa"), + targetRefName: getObjName(options, "-web"), + kind: "Deployment", + apiversion: "apps/v1", + labels: expectedWebLabels, + cpu: true, + cpuValue: parseResourceValue(t, "2.55"), + }, + { + name: getObjName(options, "-batch-hpa"), + targetRefName: getObjName(options, "-batch"), + kind: "Deployment", + apiversion: "apps/v1", + labels: expectedBatchLabels, + cpu: true, + cpuValue: parseResourceValue(t, "2.55"), + }, + }) + } } } } +func TestPegaTierHPADisableTarget(t *testing.T) { + var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"} + var supportedOperations = []string{"deploy", "install-deploy", "upgrade-deploy"} + var deploymentNames = []string{"pega", "myapp-dev"} + + helmChartPath, err := filepath.Abs(PegaHelmChartPath) + require.NoError(t, err) + + testsPath, err := filepath.Abs(PegaHelmChartTestsPath) + require.NoError(t, err) + + for _, vendor := range supportedVendors { + + for _, operation := range supportedOperations { + + for _, depName := range deploymentNames { + fmt.Println(vendor + "-" + operation) + + var options = &helm.Options{ + SetValues: map[string]string{ + "global.deployment.name": depName, + "global.provider": vendor, + "global.actions.execute": operation, + "installer.upgrade.upgradeType": "zero-downtime", + }, + } + + yamlContent := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-hpa.yaml"}, "--values", testsPath+"/data/values_hpa_disabletarget.yaml") + verifyPegaHPAs(t, yamlContent, options, []hpa{ + { + name: getObjName(options, "-web-hpa"), + targetRefName: getObjName(options, "-web"), + kind: "Deployment", + apiversion: "apps/v1", + mem: true, + memPercent: 85, + }, + { + name: getObjName(options, "-batch-hpa"), + targetRefName: getObjName(options, "-batch"), + kind: "Deployment", + apiversion: "apps/v1", + cpu: true, + cpuValue: parseResourceValue(t, "2.55"), + }, + }) + } + } + } +} func TestPegaTierOverrideValues(t *testing.T) { var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"} var supportedOperations = []string{"deploy", "install-deploy", "upgrade-deploy"} - var deploymentNames = []string{"pega","myapp-dev"} + var deploymentNames = []string{"pega", "myapp-dev"} helmChartPath, err := filepath.Abs(PegaHelmChartPath) require.NoError(t, err) @@ -131,38 +185,38 @@ func TestPegaTierOverrideValues(t *testing.T) { for _, operation := range supportedOperations { - for _, depName := range deploymentNames { - fmt.Println(vendor + "-" + operation + "-" + depName) + for _, depName := range deploymentNames { + fmt.Println(vendor + "-" + operation + "-" + depName) - var options = &helm.Options{ - SetValues: map[string]string{ - "global.provider": vendor, - "global.actions.execute": operation, + var options = &helm.Options{ + SetValues: map[string]string{ + "global.provider": vendor, + "global.actions.execute": operation, "installer.upgrade.upgradeType": "zero-downtime", - }, - } - - yamlContent := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-hpa.yaml"}, "--values", testsPath+"/data/values_hpa_overridevalues.yaml") - verifyPegaHPAs(t, yamlContent, options, []hpa{ - { - name: getObjName(options, "-web-hpa"), - targetRefName: getObjName(options, "-web"), - kind: "Deployment", - apiversion: "apps/v1", - cpu: true, - cpuValue: parseResourceValue(t, "4.13"), - mem: true, - memPercent: 42, - }, - { - name: getObjName(options, "-batch-hpa"), - targetRefName: getObjName(options, "-batch"), - kind: "Deployment", - apiversion: "apps/v1", - cpu: true, - cpuPercent: 24, - }, - }) + }, + } + + yamlContent := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-hpa.yaml"}, "--values", testsPath+"/data/values_hpa_overridevalues.yaml") + verifyPegaHPAs(t, yamlContent, options, []hpa{ + { + name: getObjName(options, "-web-hpa"), + targetRefName: getObjName(options, "-web"), + kind: "Deployment", + apiversion: "apps/v1", + cpu: true, + cpuValue: parseResourceValue(t, "4.13"), + mem: true, + memPercent: 42, + }, + { + name: getObjName(options, "-batch-hpa"), + targetRefName: getObjName(options, "-batch"), + kind: "Deployment", + apiversion: "apps/v1", + cpu: true, + cpuPercent: 24, + }, + }) } } } @@ -210,6 +264,12 @@ func verifyPegaHpa(t *testing.T, hpaObj *autoscaling.HorizontalPodAutoscaler, ex currentMetricIndex++ } + for key, expectedValue := range expectedHpa.labels { + actual := hpaObj.Labels[key] + require.NotNil(t, actual) + require.Equal(t, expectedValue, actual) + } + require.Equal(t, int32(5), hpaObj.Spec.MaxReplicas) } @@ -218,6 +278,7 @@ type hpa struct { targetRefName string kind string apiversion string + labels map[string]string cpu bool cpuValue resource.Quantity cpuPercent int32 From 6a2b0b0131f67941d81e9a471879444de30a7719 Mon Sep 17 00:00:00 2001 From: walsd1 Date: Mon, 23 Oct 2023 16:08:18 -0400 Subject: [PATCH 2/3] support custom labels on PDB --- charts/pega/templates/_pega-pdb.tpl | 4 + .../pega/data/values_pdb_custom_labels.yaml | 295 ++++++++++++++++++ terratest/src/test/pega/pega-tier-pdb_test.go | 65 ++++ 3 files changed, 364 insertions(+) create mode 100644 terratest/src/test/pega/data/values_pdb_custom_labels.yaml diff --git a/charts/pega/templates/_pega-pdb.tpl b/charts/pega/templates/_pega-pdb.tpl index f76eaccd9..d9423b6ae 100644 --- a/charts/pega/templates/_pega-pdb.tpl +++ b/charts/pega/templates/_pega-pdb.tpl @@ -10,6 +10,10 @@ kind: PodDisruptionBudget metadata: name: {{ .name }}-pdb namespace: {{ .root.Release.Namespace }} +{{- if .pdb.labels }} + labels: +{{ toYaml .pdb.labels | indent 4 }} +{{- end }} spec: {{- if .pdb.minAvailable }} minAvailable: {{ .pdb.minAvailable }} diff --git a/terratest/src/test/pega/data/values_pdb_custom_labels.yaml b/terratest/src/test/pega/data/values_pdb_custom_labels.yaml new file mode 100644 index 000000000..f3e487905 --- /dev/null +++ b/terratest/src/test/pega/data/values_pdb_custom_labels.yaml @@ -0,0 +1,295 @@ +--- +global: + # This values.yaml file is an example. For more information about + # each configuration option, see the project readme. + + # Enter your Kubernetes provider. + provider: "YOUR_KUBERNETES_PROVIDER" + + deployment: + # The name specified will be used to prefix all of the Pega pods (replacing "pega" with something like "app1-dev"). + name: "pega" + + # Deploy Pega nodes + actions: + execute: "deploy" + + # Provide JDBC connection information to the Pega relational database + # If you are installing or upgrading on IBM DB2, update the udb.conf file in the /charts/pega/charts/installer/config/udb directory with any additional connection properties. + jdbc: + # url Valid values are: + # + # Oracle jdbc:oracle:thin:@//localhost:1521/dbName + # IBM DB/2 z / OS jdbc:db2://localhost:50000/dbName + # IBM DB/2 jdbc:db2://localhost:50000/dbName:fullyMaterializeLobData=true;fullyMaterializeInputStreams=true; + # progressiveStreaming=2;useJDBC4ColumnNameAndLabelSemantics=2; + # SQL Server jdbc:sqlserver://localhost:1433;databaseName=dbName;selectMethod=cursor;sendStringParametersAsUnicode=false + # PostgreSQL jdbc:postgresql://localhost:5432/dbName + url: "YOUR_JDBC_URL" + # driverClass -- jdbc class. Valid values are: + # + # Oracle oracle.jdbc.OracleDriver + # IBM DB/2 com.ibm.db2.jcc.DB2Driver + # SQL Server com.microsoft.sqlserver.jdbc.SQLServerDriver + # PostgreSQL org.postgresql.Driver + driverClass: "YOUR_JDBC_DRIVER_CLASS" + # pega.database.type Valid values are: mssql, oracledate, udb, db2zos, postgres + dbType: "YOUR_DATABASE_TYPE" + # For databases that use multiple JDBC driver files (such as DB2), specify comma separated values for 'driverUri' + driverUri: "YOUR_JDBC_DRIVER_URI" + username: "YOUR_JDBC_USERNAME" + password: "YOUR_JDBC_PASSWORD" + # CUSTOM CONNECTION PROPERTIES + # Add a list of ; delimited connections properties. The list must end with ; + # For example: connectionProperties=user=usr;password=pwd; + connectionProperties: "" + rulesSchema: "YOUR_RULES_SCHEMA" + dataSchema: "YOUR_DATA_SCHEMA" + customerDataSchema: "" + + # If using a custom Docker registry, supply the credentials here to pull Docker images. + docker: + registry: + url: "YOUR_DOCKER_REGISTRY" + username: "YOUR_DOCKER_REGISTRY_USERNAME" + password: "YOUR_DOCKER_REGISTRY_PASSWORD" + # Docker image information for the Pega docker image, containing the application server. + pega: + image: "pegasystems/pega" + + # Upgrade specific properties + upgrade: + # Configure only for aks/pks + # Run "kubectl cluster-info" command to get the service host and https service port of kubernetes api server. + # Example - Kubernetes master is running at https://: + kube-apiserver: + serviceHost: "API_SERVICE_ADDRESS" + httpsServicePort: "SERVICE_PORT_HTTPS" + + # Specify the Pega tiers to deploy + tier: + - name: "web" + # Create a an interactive tier for web users. This tier uses + # the WebUser node type and will be exposed via a service to + # the load balancer. + nodeType: "WebUser" + + # Pega requestor specific properties + requestor: + # Inactivity time after which requestor is passivated + passivationTimeSec: 900 + + service: + # For help configuring the service block, see the Helm chart documentation + # https://github.com/pegasystems/pega-helm-charts/blob/master/charts/pega/README.md#service + port: 80 + targetPort: 8080 + + ingress: + # For help configuring the ingress block including TLS, see the Helm chart documentation + # https://github.com/pegasystems/pega-helm-charts/blob/master/charts/pega/README.md#ingress + + # Enter the domain name to access web nodes via a load balancer. + # e.g. web.mypega.example.com + domain: "YOUR_WEB_NODE_DOMAIN" + tls: + # Enable TLS encryption + enabled: true + # secretName: + # useManagedCertificate: false + # ssl_annotation: + + replicas: 1 + javaOpts: "" + pegaDiagnosticUser: "" + pegaDiagnosticPassword: "" + + deploymentStrategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 0 + type: RollingUpdate + + livenessProbe: + port: 8081 + + # Optionally overridde default resource specifications + # cpuRequest: 2 + # memRequest: "12Gi" + # cpuLimit: 4 + # memLimit: "12Gi" + # initialHeap: "4096m" + # maxHeap: "8192m" + + # To configure an alternative user for custom image, set value for runAsUser. + # See, https://github.com/pegasystems/pega-helm-charts/blob/master/charts/pega/README.md#security-context + # securityContext: + # runAsUser: 9001 + + hpa: + enabled: true + + # Set enabled to true to include a Pod Disruption Budget for this tier + pdb: + enabled: true + minAvailable: 1 + labels: + weblabel: "somevalue" + anotherlabel: "anothervalue" + # maxUnavailable: "50%" + + - name: "batch" + # Create a background tier for batch processing. This tier uses + # a collection of background node types and will not be exposed to + # the load balancer. + nodeType: "BackgroundProcessing,Search,Batch,RealTime,Custom1,Custom2,Custom3,Custom4,Custom5,BIX" + + replicas: 1 + javaOpts: "" + + pegaDiagnosticUser: "" + pegaDiagnosticPassword: "" + + deploymentStrategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 0 + type: RollingUpdate + + livenessProbe: + port: 8081 + + # To configure an alternative user for your custom image, set value for runAsUser + # See, https://github.com/pegasystems/pega-helm-charts/blob/master/charts/pega/README.md#security-context + # securityContext: + # runAsUser: 9001 + + hpa: + enabled: true + + # Set enabled to true to include a Pod Disruption Budget for this tier + pdb: + enabled: true + minAvailable: 1 + labels: + batchlabel: "batchvalue" + anotherbatchlabel: "batchvalue2" + # maxUnavailable: "50%" + + - name: "stream" + # Create a stream tier for queue processing. This tier deploys + # as a stateful set to ensure durability of queued data. It may + # be optionally exposed to the load balancer. + nodeType: "Stream" + + # Pega requestor specific properties + requestor: + # Inactivity time after which requestor is passivated + passivationTimeSec: 900 + + service: + port: 7003 + targetPort: 7003 + + # If a nodeSelector is required for this or any tier, it may be specified here: + # nodeSelector: + # disktype: ssd + + ingress: + # Enter the domain name to access web nodes via a load balancer. + # e.g. web.mypega.example.com + domain: "YOUR_STREAM_NODE_DOMAIN" + tls: + # Enable TLS encryption + enabled: true + # secretName: + # useManagedCertificate: false + # ssl_annotation: + + livenessProbe: + port: 8081 + + # To configure an alternative user for your custom image, set value for runAsUser + # See, https://github.com/pegasystems/pega-helm-charts/blob/master/charts/pega/README.md#security-context + # securityContext: + # runAsUser: 9001 + + replicas: 2 + + volumeClaimTemplate: + resources: + requests: + storage: 5Gi + + # Set enabled to true to include a Pod Disruption Budget for this tier + pdb: + enabled: true + minAvailable: 1 + # maxUnavailable: "50%" + +# External services + +# Cassandra automatic deployment settings. +cassandra: + enabled: true + persistence: + enabled: true + resources: + requests: + memory: "4Gi" + cpu: 2 + limits: + memory: "8Gi" + cpu: 4 + +# DDS (external Cassandra) connection settings. +# These settings should only be modified if you are using a custom Cassandra deployment. +dds: + externalNodes: "" + port: "9042" + username: "dnode_ext" + password: "dnode_ext" + clientEncryption: false + trustStore: "" + trustStorePassword: "" + keyStore: "" + keyStorePassword: "" + +# Elasticsearch deployment settings. +# Note: This Elasticsearch deployment is used for Pega search, and is not the same Elasticsearch deployment used by the EFK stack. +# These search nodes will be deployed regardless of the Elasticsearch configuration above. +# Refer to README document to configure `Search and Reporting Service` as a search functionality provider under this section. +pegasearch: + image: "pegasystems/search" + memLimit: "3Gi" + replicas: 1 + +# Pega Installer settings. +installer: + image: "YOUR_INSTALLER_IMAGE:TAG" + # Set the initial administrator@pega.com password for your installation. This will need to be changed at first login. + # The adminPassword value cannot start with "@". + adminPassword: "ADMIN_PASSWORD" + # Upgrade specific properties + upgrade: + # Type of upgrade + # Valid upgradeType values are 'in-place' , 'zero-downtime' , 'custom' , 'out-of-place-rules' , 'out-of-place-data' . + upgradeType: "in-place" + # Specify a name for a target rules schema that the upgrade process creates for patches and upgrades. + targetRulesSchema: "" + # Specify a name for a target data schema that the upgrade process creates for patches and upgrades. + # For postgres databases that you are upgrading from Pega Infinity version 8.4.0 and later + # And for Oracle databases that you are upgrading from Pega Infinity version 8.4.3 and later. + targetDataSchema: "" + +# Hazelcast settings (applicable from Pega 8.6) +hazelcast: + image: "YOUR_HAZELCAST_IMAGE:TAG" + # Setting below to true will deploy the infinity in client-server Hazelcast model + enabled: false + # No. of initial members to join + replicas: 3 + # UserName to be used in client-server Hazelcast model for authentication + username: "" + # Password to be used in client-server Hazelcast model for authentication + password: "" diff --git a/terratest/src/test/pega/pega-tier-pdb_test.go b/terratest/src/test/pega/pega-tier-pdb_test.go index b8ddb1a4f..0997267ce 100644 --- a/terratest/src/test/pega/pega-tier-pdb_test.go +++ b/terratest/src/test/pega/pega-tier-pdb_test.go @@ -65,6 +65,64 @@ func TestPegaTierPDBEnabled(t *testing.T) { } } +func TestPegaTierPDBWithCustomLabels(t *testing.T) { + var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"} + var supportedOperations = []string{"deploy", "install-deploy"} + var deploymentNames = []string{"pega", "myapp-dev"} + + webPDBLabels := map[string]string{"weblabel": "somevalue", "anotherlabel": "anothervalue"} + batchPDBLabels := map[string]string{"batchlabel": "batchvalue", "anotherbatchlabel": "batchvalue2"} + + helmChartPath, err := filepath.Abs(PegaHelmChartPath) + require.NoError(t, err) + + testsPath, err := filepath.Abs(PegaHelmChartTestsPath) + require.NoError(t, err) + + for _, vendor := range supportedVendors { + + for _, operation := range supportedOperations { + + for _, depName := range deploymentNames { + + fmt.Println(vendor + "-" + operation) + + var options = &helm.Options{ + SetValues: map[string]string{ + "global.deployment.name": depName, + "global.provider": vendor, + "global.actions.execute": operation, + }, + } + + yamlContent := RenderTemplate(t, options, helmChartPath, []string{"templates/pega-tier-pdb.yaml"}, "--values", testsPath+"/data/values_pdb_custom_labels.yaml") + verifyPegaPDBs(t, yamlContent, options, []pdb{ + { + name: getObjName(options, "-web-pdb"), + kind: "PodDisruptionBudget", + apiversion: "policy/v1beta1", + labels: webPDBLabels, + minAvailable: 1, + }, + { + name: getObjName(options, "-batch-pdb"), + kind: "PodDisruptionBudget", + apiversion: "policy/v1beta1", + labels: batchPDBLabels, + minAvailable: 1, + }, + { + name: getObjName(options, "-stream-pdb"), + kind: "PodDisruptionBudget", + apiversion: "policy/v1beta1", + minAvailable: 1, + }, + }) + } + } + } +} + // TestPegaTierPDBDisabled - verify that a PodDisruptionBudget is not created when global.tier.pdb.enabled=false func TestPegaTierPDBDisabled(t *testing.T) { var supportedVendors = []string{"k8s", "openshift", "eks", "gke", "aks", "pks"} @@ -121,11 +179,18 @@ func verifyPegaPdb(t *testing.T, pegaPdbObj *v1beta1.PodDisruptionBudget, expect //kubernetes 1.21 or higher, and we should adjust this test to use the policy/v1 API version require.Equal(t, pegaPdbObj.TypeMeta.APIVersion, expectedPdb.apiversion) require.Equal(t, expectedPdb.minAvailable, pegaPdbObj.Spec.MinAvailable.IntVal) + + for key, expectedValue := range expectedPdb.labels { + actual := pegaPdbObj.Labels[key] + require.NotNil(t, actual) + require.Equal(t, expectedValue, actual) + } } type pdb struct { name string kind string apiversion string + labels map[string]string minAvailable int32 } From 32274764b5458031408c274ab674aa58163a251a Mon Sep 17 00:00:00 2001 From: walsd1 Date: Tue, 24 Oct 2023 11:50:15 -0400 Subject: [PATCH 3/3] fix lint issue in pdb test values --- terratest/src/test/pega/data/values_pdb_custom_labels.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/terratest/src/test/pega/data/values_pdb_custom_labels.yaml b/terratest/src/test/pega/data/values_pdb_custom_labels.yaml index f3e487905..e06275c8c 100644 --- a/terratest/src/test/pega/data/values_pdb_custom_labels.yaml +++ b/terratest/src/test/pega/data/values_pdb_custom_labels.yaml @@ -136,7 +136,6 @@ global: labels: weblabel: "somevalue" anotherlabel: "anothervalue" - # maxUnavailable: "50%" - name: "batch" # Create a background tier for batch processing. This tier uses @@ -174,7 +173,6 @@ global: labels: batchlabel: "batchvalue" anotherbatchlabel: "batchvalue2" - # maxUnavailable: "50%" - name: "stream" # Create a stream tier for queue processing. This tier deploys