From cd2aed2d7b05499c7bb57395cdd24d4e897aea97 Mon Sep 17 00:00:00 2001 From: Mitali Salvi <44349099+mitali-salvi@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:34:46 -0400 Subject: [PATCH] Running helm integration tests on PR build (#21) --- ...h-observability-helm-integration-test.yaml | 7 +++- .../terraform/helm/main.tf | 4 ++ .../validator/validateResources_test.go | 40 ++++++++++++++----- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/.github/workflows/amazon-cloudwatch-observability-helm-integration-test.yaml b/.github/workflows/amazon-cloudwatch-observability-helm-integration-test.yaml index f108c8b..0d2a1a2 100644 --- a/.github/workflows/amazon-cloudwatch-observability-helm-integration-test.yaml +++ b/.github/workflows/amazon-cloudwatch-observability-helm-integration-test.yaml @@ -5,9 +5,12 @@ name: Run Integration Test for Amazon CloudWatch Observability Helm Chart on: push: branches: - - helm-tests* + - main + pull_request: + types: [ opened, reopened, synchronize, ready_for_review ] + branches: + - main workflow_dispatch: - concurrency: group: ${{ github.workflow }}-${{ github.ref_name }} cancel-in-progress: true diff --git a/integration-tests/amazon-cloudwatch-observability/terraform/helm/main.tf b/integration-tests/amazon-cloudwatch-observability/terraform/helm/main.tf index 3cfc632..3180338 100644 --- a/integration-tests/amazon-cloudwatch-observability/terraform/helm/main.tf +++ b/integration-tests/amazon-cloudwatch-observability/terraform/helm/main.tf @@ -120,6 +120,10 @@ resource "helm_release" "this" { name = "region" value = "${var.region}" } + set { + name = "clusterName" + value = "${aws_eks_cluster.this.name}" + } } resource "null_resource" "validator" { diff --git a/integration-tests/amazon-cloudwatch-observability/validator/validateResources_test.go b/integration-tests/amazon-cloudwatch-observability/validator/validateResources_test.go index 08860b7..f414142 100644 --- a/integration-tests/amazon-cloudwatch-observability/validator/validateResources_test.go +++ b/integration-tests/amazon-cloudwatch-observability/validator/validateResources_test.go @@ -23,14 +23,17 @@ import ( ) const ( - nameSpace = "amazon-cloudwatch" - addOnName = "amazon-cloudwatch-observability" - agentName = "cloudwatch-agent" - operatorName = addOnName + "-controller-manager" - fluentBitName = "fluent-bit" - dcgmExporterName = "dcgm-exporter" - podNameRegex = "(" + agentName + "|" + operatorName + "|" + fluentBitName + ")-*" - serviceNameRegex = agentName + "(-headless|-monitoring)?|" + addOnName + "-webhook-service|" + dcgmExporterName + "-service" + nameSpace = "amazon-cloudwatch" + addOnName = "amazon-cloudwatch-observability" + agentName = "cloudwatch-agent" + agentNameWindows = "cloudwatch-agent-windows" + operatorName = addOnName + "-controller-manager" + fluentBitName = "fluent-bit" + fluentBitNameWindows = "fluent-bit-windows" + dcgmExporterName = "dcgm-exporter" + neuronMonitor = "neuron-monitor" + podNameRegex = "(" + agentName + "|" + agentNameWindows + "|" + operatorName + "|" + fluentBitName + "|" + fluentBitNameWindows + ")-*" + serviceNameRegex = agentName + "(-headless|-monitoring)?|" + agentNameWindows + "(-headless|-monitoring)?|" + addOnName + "-webhook-service|" + dcgmExporterName + "-service|" + neuronMonitor + "-service" ) func TestOperatorOnEKs(t *testing.T) { @@ -66,8 +69,10 @@ func TestOperatorOnEKs(t *testing.T) { assert.Contains(t, []v1.PodPhase{v1.PodRunning, v1.PodPending}, pod.Status.Phase) // matches // - cloudwatch-agent-* + // - cloudwatch-agent-windows-* // - amazon-cloudwatch-observability-controller-manager-* // - fluent-bit-* + // - fluent-bit-windows-* if match, _ := regexp.MatchString(podNameRegex, pod.Name); !match { assert.Fail(t, "Cluster Pods are not created correctly") } @@ -76,7 +81,7 @@ func TestOperatorOnEKs(t *testing.T) { //Validating the services services, err := ListServices(nameSpace, clientSet) assert.NoError(t, err) - assert.Len(t, services.Items, 5) + assert.Len(t, services.Items, 9) for _, service := range services.Items { fmt.Println("service name: " + service.Name + " namespace:" + service.Namespace) // matches @@ -84,7 +89,11 @@ func TestOperatorOnEKs(t *testing.T) { // - cloudwatch-agent // - cloudwatch-agent-headless // - cloudwatch-agent-monitoring + // - cloudwatch-agent-windows + // - cloudwatch-agent-windows-headless + // - cloudwatch-agent-windows-monitoring // - dcgm-exporter-service + // - neuron-monitor-service if match, _ := regexp.MatchString(serviceNameRegex, service.Name); !match { assert.Fail(t, "Cluster Service is not created correctly") } @@ -108,14 +117,17 @@ func TestOperatorOnEKs(t *testing.T) { //Validating the Daemon Sets daemonSets, err := ListDaemonSets(nameSpace, clientSet) assert.NoError(t, err) - assert.Len(t, daemonSets.Items, 3) + assert.Len(t, daemonSets.Items, 6) for _, daemonSet := range daemonSets.Items { fmt.Println("daemonSet name: " + daemonSet.Name + " namespace:" + daemonSet.Namespace) // matches // - cloudwatch-agent + // - cloudwatch-agent-windows // - fluent-bit + // - fluent-bit-windows // - dcgm-exporter (this can be removed in the future) - if match, _ := regexp.MatchString(agentName+"|fluent-bit|dcgm-exporter", daemonSet.Name); !match { + // - neuron-monitor + if match, _ := regexp.MatchString(agentName+"|fluent-bit|dcgm-exporter|neuron-monitor", daemonSet.Name); !match { assert.Fail(t, "DaemonSet is not created correctly") } } @@ -130,9 +142,11 @@ func TestOperatorOnEKs(t *testing.T) { // - amazon-cloudwatch-observability-controller-manager // - cloudwatch-agent // - dcgm-exporter-service-acct + // - neuron-monitor-service-acct assert.True(t, validateServiceAccount(serviceAccounts, addOnName+"-controller-manager")) assert.True(t, validateServiceAccount(serviceAccounts, agentName)) assert.True(t, validateServiceAccount(serviceAccounts, dcgmExporterName+"-service-acct")) + assert.True(t, validateServiceAccount(serviceAccounts, neuronMonitor+"-service-acct")) //Validating ClusterRoles clusterRoles, err := ListClusterRoles(clientSet) @@ -148,7 +162,9 @@ func TestOperatorOnEKs(t *testing.T) { assert.NoError(t, err) // searches // - dcgm-exporter-role + // - neuron-monitor-role assert.True(t, validateRoles(roles, dcgmExporterName+"-role")) + assert.True(t, validateRoles(roles, neuronMonitor+"-role")) //Validating ClusterRoleBinding clusterRoleBindings, err := ListClusterRoleBindings(clientSet) @@ -164,7 +180,9 @@ func TestOperatorOnEKs(t *testing.T) { assert.NoError(t, err) // searches // - dcgm-exporter-role-binding + // - neuron-monitor-role-binding assert.True(t, validateRoleBindings(roleBindings, dcgmExporterName+"-role-binding")) + assert.True(t, validateRoleBindings(roleBindings, neuronMonitor+"-role-binding")) //Validating MutatingWebhookConfiguration mutatingWebhookConfigurations, err := ListMutatingWebhookConfigurations(clientSet)