From 0fcc4b8256039145050d008f8d071ad39bf82c64 Mon Sep 17 00:00:00 2001 From: Kanishka Nambiar Date: Fri, 12 Apr 2024 23:51:17 +0530 Subject: [PATCH] Changed it to use imagetest_harness_k3s --- images/node-feature-discovery/tests/main.tf | 114 +++++++----------- .../tests/test-pod-logs-gc.sh | 48 -------- .../tests/test-pod-logs-master.sh | 49 -------- .../tests/test-pod-logs-worker.sh | 48 -------- 4 files changed, 44 insertions(+), 215 deletions(-) delete mode 100755 images/node-feature-discovery/tests/test-pod-logs-gc.sh delete mode 100755 images/node-feature-discovery/tests/test-pod-logs-master.sh delete mode 100755 images/node-feature-discovery/tests/test-pod-logs-worker.sh diff --git a/images/node-feature-discovery/tests/main.tf b/images/node-feature-discovery/tests/main.tf index 6f28c1c17e..9bbb3f7fe1 100644 --- a/images/node-feature-discovery/tests/main.tf +++ b/images/node-feature-discovery/tests/main.tf @@ -1,6 +1,8 @@ terraform { required_providers { - oci = { source = "chainguard-dev/oci" } + oci = { source = "chainguard-dev/oci" } + helm = { source = "hashicorp/helm" } + imagetest = { source = "chainguard-dev/imagetest" } } } @@ -12,84 +14,56 @@ data "oci_string" "ref" { input = var.digest } -resource "random_pet" "suffix" {} +data "imagetest_inventory" "this" {} -resource "helm_release" "test_helm_deploy" { - name = "node-feature-discovery-${random_pet.suffix.id}" - repository = "https://kubernetes-sigs.github.io/node-feature-discovery/charts" - chart = "node-feature-discovery" - namespace = "node-feature-discovery-${random_pet.suffix.id}" - create_namespace = true +resource "imagetest_harness_k3s" "this" { + name = "node-feature-discovery" + inventory = data.imagetest_inventory.this - values = [jsonencode({ + sandbox = { + mounts = [ + { + source = path.module + destination = "/tests" + } + ] + } +} + +module "helm_node-feature-discovery" { + source = "../../../tflib/imagetest/helm" + chart = "node-feature-discovery" + repo = "https://kubernetes-sigs.github.io/node-feature-discovery/charts" + name = "node-feature-discovery" + values = { image = { repository = data.oci_string.ref.registry_repo tag = data.oci_string.ref.pseudo_tag + pullPolicy = "Always" } - })] -} - -data "oci_exec_test" "test_validate_logs_gc" { - depends_on = [helm_release.test_helm_deploy] - digest = var.digest - working_dir = path.module - script = "./test-pod-logs-gc.sh" - - env { - name = "K8S_NAME" - value = "${helm_release.test_helm_deploy.id}-gc" } - env { - name = "K8S_NAMESPACE" - value = helm_release.test_helm_deploy.namespace - } - } -data "oci_exec_test" "test_validate_logs_master" { - depends_on = [helm_release.test_helm_deploy] - digest = var.digest - working_dir = path.module - script = "./test-pod-logs-master.sh" - - env { - name = "K8S_NAME" - value = "${helm_release.test_helm_deploy.id}-master" - } - env { - name = "K8S_NAMESPACE" - value = helm_release.test_helm_deploy.namespace - } - -} - -data "oci_exec_test" "test_validate_logs_worker" { - depends_on = [helm_release.test_helm_deploy] - digest = var.digest - working_dir = path.module - script = "./test-pod-logs-worker.sh" +resource "imagetest_feature" "test_labels" { + harness = imagetest_harness_k3s.this + name = "Test Labels" + description = "Basic functionality of the node-feature-discovery helm chart." + + steps = [ + { + name = "Helm install node-feature-discovery" + cmd = module.helm_node-feature-discovery.install_cmd + }, + { + name = "Ensure it has the necessary labels For CPU, Kernel and Storage" + cmd = <&1) - local logs_found=true - - # Search the container logs for our expected log lines. - for log in "${expected_logs[@]}"; do - if ! echo "$logs" | grep -Fq "$log"; then - logs_found=false - fi - done - - if $logs_found; then - return 0 - elif [[ $i -lt ${RETRIES} ]]; then - echo "Some expected logs were missing. Retrying in ${RETRY_DELAY_SECONDS} seconds..." - sleep ${RETRY_DELAY_SECONDS} - fi - done - - # After all retries, record the missing logs - for log in "${expected_logs[@]}"; do - if ! echo "${logs}" | grep -Fq "$log"; then - missing_logs+=("${log}") - fi - done - - echo "FAILED: The following log lines where not found:" - printf '%s\n' "${missing_logs[@]}" - exit 1 -} - -TEST_validate_container_logs \ No newline at end of file diff --git a/images/node-feature-discovery/tests/test-pod-logs-master.sh b/images/node-feature-discovery/tests/test-pod-logs-master.sh deleted file mode 100755 index 9730babfd6..0000000000 --- a/images/node-feature-discovery/tests/test-pod-logs-master.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -o nounset -o errtrace -o pipefail -x - -# Looks for these log statements in the pod logs -expected_logs=( - "starting the nfd api controller" - "starting the NFD master node updater pool" - "will process all nodes in the cluster" -) - -missing_logs=() - -RETRIES=5 -RETRY_DELAY_SECONDS=15 - -TEST_validate_container_logs() { - for ((i=1; i<=${RETRIES}; i++)); do - local logs=$(kubectl logs "deploy/${K8S_NAME}" -n "${K8S_NAMESPACE}" 2>&1) - local logs_found=true - - # Search the container logs for our expected log lines. - for log in "${expected_logs[@]}"; do - if ! echo "$logs" | grep -Fq "$log"; then - logs_found=false - fi - done - - if $logs_found; then - return 0 - elif [[ $i -lt ${RETRIES} ]]; then - echo "Some expected logs were missing. Retrying in ${RETRY_DELAY_SECONDS} seconds..." - sleep ${RETRY_DELAY_SECONDS} - fi - done - - # After all retries, record the missing logs - for log in "${expected_logs[@]}"; do - if ! echo "${logs}" | grep -Fq "$log"; then - missing_logs+=("${log}") - fi - done - - echo "FAILED: The following log lines where not found:" - printf '%s\n' "${missing_logs[@]}" - exit 1 -} - -TEST_validate_container_logs \ No newline at end of file diff --git a/images/node-feature-discovery/tests/test-pod-logs-worker.sh b/images/node-feature-discovery/tests/test-pod-logs-worker.sh deleted file mode 100755 index 19fd36da14..0000000000 --- a/images/node-feature-discovery/tests/test-pod-logs-worker.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -o nounset -o errtrace -o pipefail -x - -# Looks for these log statements in the pod logs -expected_logs=( - "starting feature discovery..." - "feature discovery completed" -) - -missing_logs=() - -RETRIES=5 -RETRY_DELAY_SECONDS=15 - -TEST_validate_container_logs() { - for ((i=1; i<=${RETRIES}; i++)); do - local logs=$(kubectl logs "ds/${K8S_NAME}" -n "${K8S_NAMESPACE}" 2>&1) - local logs_found=true - - # Search the container logs for our expected log lines. - for log in "${expected_logs[@]}"; do - if ! echo "$logs" | grep -Fq "$log"; then - logs_found=false - fi - done - - if $logs_found; then - return 0 - elif [[ $i -lt ${RETRIES} ]]; then - echo "Some expected logs were missing. Retrying in ${RETRY_DELAY_SECONDS} seconds..." - sleep ${RETRY_DELAY_SECONDS} - fi - done - - # After all retries, record the missing logs - for log in "${expected_logs[@]}"; do - if ! echo "${logs}" | grep -Fq "$log"; then - missing_logs+=("${log}") - fi - done - - echo "FAILED: The following log lines where not found:" - printf '%s\n' "${missing_logs[@]}" - exit 1 -} - -TEST_validate_container_logs \ No newline at end of file