From 9a0262605bf8f68d9f57f56b0ca555544bd6d835 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Fri, 1 Nov 2024 08:13:08 +0100 Subject: [PATCH 1/7] Add e2e test concurrency w/ signal This will help make sure the big refactoring does not break the main features. Signed-off-by: Jean-Philippe Evrard --- .github/workflows/on-pr.yaml | 3 +- Makefile | 6 ++-- tests/kind/main_test.go | 58 +++++++++++++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/.github/workflows/on-pr.yaml b/.github/workflows/on-pr.yaml index 86973d425..e505be769 100644 --- a/.github/workflows/on-pr.yaml +++ b/.github/workflows/on-pr.yaml @@ -88,6 +88,7 @@ jobs: - "TestE2EWithCommand" - "TestE2EWithSignal" - "TestE2EConcurrentWithCommand" + - "TestE2EConcurrentWithSignal" kubernetes_version: - "previous" - "current" @@ -148,4 +149,4 @@ jobs: install_only: true version: v0.22.0 - name: Run specific e2e tests - run: make e2e-test ARGS="-run ^${{ matrix.testname }}" \ No newline at end of file + run: make e2e-test ARGS="-run ^${{ matrix.testname }}" diff --git a/Makefile b/Makefile index 39cd5d5fe..591cab08b 100644 --- a/Makefile +++ b/Makefile @@ -47,8 +47,10 @@ dev-manifest: sed -e "s#image: ghcr.io/.*kured.*#image: kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' kured-ds.yaml > tests/kind/testfiles/kured-ds.yaml # signal e2e scenario sed -e "s#image: ghcr.io/.*kured.*#image: kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' kured-ds-signal.yaml > tests/kind/testfiles/kured-ds-signal.yaml - # concurrency e2e scenario - sed -e "s#image: ghcr.io/.*kured.*#image: kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' -e 's/#\(.*\)--concurrency=1/\1--concurrency=2/g' kured-ds.yaml > tests/kind/testfiles/kured-ds-concurrent.yaml + # concurrency e2e command scenario + sed -e "s#image: ghcr.io/.*kured.*#image: kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' -e 's/#\(.*\)--concurrency=1/\1--concurrency=2/g' kured-ds.yaml > tests/kind/testfiles/kured-ds-concurrent-command.yaml + # concurrency e2e signal scenario + sed -e "s#image: ghcr.io/.*kured.*#image: kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' -e 's/#\(.*\)--concurrency=1/\1--concurrency=2/g' kured-ds-signal.yaml > tests/kind/testfiles/kured-ds-concurrent-signal.yaml e2e-test: dev-manifest dev-image diff --git a/tests/kind/main_test.go b/tests/kind/main_test.go index 0a13c00f9..eea0faf3a 100644 --- a/tests/kind/main_test.go +++ b/tests/kind/main_test.go @@ -257,7 +257,57 @@ func TestE2EConcurrentWithCommand(t *testing.T) { kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-%v.yaml", version) kindContext := fmt.Sprintf("kind-%v", kindClusterName) - k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy("testfiles/kured-ds-concurrent.yaml")) + k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy("testfiles/kured-ds-concurrent-command.yaml")) + defer k.FlushLog() + + err := k.Create() + if err != nil { + t.Fatalf("Error creating cluster %v", err) + } + defer func(k *KindTest) { + err := k.Destroy() + if err != nil { + t.Fatalf("Error destroying cluster %v", err) + } + }(k) + + k.Write([]byte("Now running e2e tests")) + + if err := k.RunCmd("bash", "testfiles/create-reboot-sentinels.sh", kindContext); err != nil { + t.Fatalf("failed to create sentinels: %v", err) + } + + if err := k.RunCmd("bash", "testfiles/follow-coordinated-reboot.sh", kindContext); err != nil { + t.Fatalf("failed to follow reboot: %v", err) + } + }) + } +} + +func TestE2EConcurrentWithSignal(t *testing.T) { + t.Parallel() + if testing.Short() { + t.Skip("skipping test in short mode.") + } + + var kindClusterConfigs = []string{ + "previous", + "current", + "next", + } + // Iterate over each Kubernetes version + for _, version := range kindClusterConfigs { + version := version + // Define a subtest for each combination + t.Run(version, func(t *testing.T) { + t.Parallel() // Allow tests to run in parallel + + randomInt := fmt.Sprintf(strconv.Itoa(rand.Intn(100))) + kindClusterName := fmt.Sprintf("kured-e2e-concurrentsignal-%v-%v", version, randomInt) + kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-%v.yaml", version) + kindContext := fmt.Sprintf("kind-%v", kindClusterName) + + k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy("testfiles/kured-ds-concurrent-signal.yaml")) defer k.FlushLog() err := k.Create() @@ -307,10 +357,10 @@ func TestCordonningIsKept(t *testing.T) { kindContext := fmt.Sprintf("kind-%v", kindClusterName) var manifest string - if version == "concurrency1" { - manifest = fmt.Sprintf("testfiles/kured-ds.yaml") + if variant == "concurrency1" { + manifest = fmt.Sprintf("testfiles/kured-ds-signal.yaml") } else { - manifest = fmt.Sprintf("testfiles/kured-ds-concurrent.yaml") + manifest = fmt.Sprintf("testfiles/kured-ds-concurrent-signal.yaml") } k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy(manifest)) defer k.FlushLog() From 27c9c5d36b6043df89870883e1754d890c9078cd Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Fri, 1 Nov 2024 08:32:34 +0100 Subject: [PATCH 2/7] Add podblocker test Extends test coverage to ensure nothing breaks Signed-off-by: Jean-Philippe Evrard --- .github/workflows/on-pr.yaml | 5 +++ Makefile | 3 +- tests/kind/main_test.go | 43 ++++++++++++++++++++++++ tests/kind/testfiles/podblocker.sh | 54 ++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100755 tests/kind/testfiles/podblocker.sh diff --git a/.github/workflows/on-pr.yaml b/.github/workflows/on-pr.yaml index e505be769..74ebe8a5f 100644 --- a/.github/workflows/on-pr.yaml +++ b/.github/workflows/on-pr.yaml @@ -127,6 +127,7 @@ jobs: testname: - "TestCordonningIsKept/concurrency1" - "TestCordonningIsKept/concurrency2" + - "TestE2EBlocker/podblocker" steps: - uses: actions/checkout@v4 - name: Ensure go version @@ -148,5 +149,9 @@ jobs: with: install_only: true version: v0.22.0 + # Keep this until v1.31 (or superior) becomes the default kubectl version for the kind-action. + # It is used in podblocker shell script test to use --all-pods. + # If the podblocker e2e test relies on another way, this can also be removed. + kubectl_version: v1.31.0 - name: Run specific e2e tests run: make e2e-test ARGS="-run ^${{ matrix.testname }}" diff --git a/Makefile b/Makefile index 591cab08b..a7dabc9a9 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,8 @@ dev-manifest: sed -e "s#image: ghcr.io/.*kured.*#image: kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' -e 's/#\(.*\)--concurrency=1/\1--concurrency=2/g' kured-ds.yaml > tests/kind/testfiles/kured-ds-concurrent-command.yaml # concurrency e2e signal scenario sed -e "s#image: ghcr.io/.*kured.*#image: kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' -e 's/#\(.*\)--concurrency=1/\1--concurrency=2/g' kured-ds-signal.yaml > tests/kind/testfiles/kured-ds-concurrent-signal.yaml - + # pod blocker e2e signal scenario + sed -e "s#image: ghcr.io/.*kured.*#image: kured:dev#g" -e 's/#\(.*\)--period=1h/\1--period=20s/g' -e 's/#\(.*\)--blocking-pod-selector=name=temperamental/\1--blocking-pod-selector=app=blocker/g' kured-ds-signal.yaml > tests/kind/testfiles/kured-ds-podblocker.yaml e2e-test: dev-manifest dev-image echo "Running ALL go tests" diff --git a/tests/kind/main_test.go b/tests/kind/main_test.go index eea0faf3a..4f5f510d0 100644 --- a/tests/kind/main_test.go +++ b/tests/kind/main_test.go @@ -384,3 +384,46 @@ func TestCordonningIsKept(t *testing.T) { }) } } +func TestE2EBlocker(t *testing.T) { + t.Parallel() + if testing.Short() { + t.Skip("skipping test in short mode.") + } + + var kindClusterConfigs = []string{ + "podblocker", + } + // Iterate over each Kubernetes version + for _, version := range kindClusterConfigs { + version := version + // Define a subtest for each combination + t.Run(version, func(t *testing.T) { + t.Parallel() // Allow tests to run in parallel + + randomInt := fmt.Sprintf(strconv.Itoa(rand.Intn(100))) + kindClusterName := fmt.Sprintf("kured-e2e-cordon-%v-%v", version, randomInt) + kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-next.yaml") + kindContext := fmt.Sprintf("kind-%v", kindClusterName) + + k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy(fmt.Sprintf("testfiles/kured-ds-%v.yaml", version))) + defer k.FlushLog() + + err := k.Create() + if err != nil { + t.Fatalf("Error creating cluster %v", err) + } + defer func(k *KindTest) { + err := k.Destroy() + if err != nil { + t.Fatalf("Error destroying cluster %v", err) + } + }(k) + + k.Write([]byte("Now running e2e tests")) + + if err := k.RunCmd("bash", fmt.Sprintf("testfiles/%v.sh",version), kindContext); err != nil { + t.Fatalf("node blocker test did not succeed: %v", err) + } + }) + } +} diff --git a/tests/kind/testfiles/podblocker.sh b/tests/kind/testfiles/podblocker.sh new file mode 100755 index 000000000..66bf6d543 --- /dev/null +++ b/tests/kind/testfiles/podblocker.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +kubectl_flags=( ) +[[ "$1" != "" ]] && kubectl_flags=("${kubectl_flags[@]}" --context "$1") + +function gather_logs_and_cleanup { + for id in $(docker ps -q); do + echo "############################################################" + echo "docker logs for container $id:" + docker logs "$id" + done + ${KUBECTL_CMD:-kubectl} "${kubectl_flags[@]}" logs ds/kured --all-pods -n kube-system +} +trap gather_logs_and_cleanup EXIT + +set +o errexit +worker=$(${KUBECTL_CMD:-kubectl} "${kubectl_flags[@]}" get nodes -o custom-columns=name:metadata.name --no-headers | grep worker | head -n 1) + +${KUBECTL_CMD:-kubectl} "${kubectl_flags[@]}" label nodes "$worker" blocked-host=yes + +${KUBECTL_CMD:-kubectl} "${kubectl_flags[@]}" apply -f - << EOF +apiVersion: v1 +kind: Pod +metadata: + name: nginx + labels: + app: blocker +spec: + containers: + - name: nginx + image: nginx + imagePullPolicy: IfNotPresent + nodeSelector: + blocked-host: "yes" +EOF + +docker exec "$worker" touch "${SENTINEL_FILE:-/var/run/reboot-required}" + +set -o errexit +max_attempts="100" +attempt_num=1 +sleep_time=5 + +until ${KUBECTL_CMD:-kubectl} "${kubectl_flags[@]}" logs ds/kured --all-pods -n kube-system | grep -i -e "Reboot.*blocked" +do + if (( attempt_num == max_attempts )); then + echo "Attempt $attempt_num failed and there are no more attempts left!" + exit 1 + else + echo "Did not find 'reboot blocked' in the log, retrying in $sleep_time seconds (Attempt #$attempt_num)" + sleep "$sleep_time" + fi + (( attempt_num++ )) +done From 0a1750dc6dc37f703ac811520ce15055a5b98764 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Fri, 1 Nov 2024 08:34:42 +0100 Subject: [PATCH 3/7] Rename "version" with "variant" in tests For tests not running in different kubernetes versions, but have different tests subcases/variants, rephrase the wording "versions" as it is confusing. Signed-off-by: Jean-Philippe Evrard --- tests/kind/main_test.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/kind/main_test.go b/tests/kind/main_test.go index 4f5f510d0..c09c71e16 100644 --- a/tests/kind/main_test.go +++ b/tests/kind/main_test.go @@ -344,15 +344,15 @@ func TestCordonningIsKept(t *testing.T) { "concurrency1", "concurrency2", } - // Iterate over each Kubernetes version - for _, version := range kindClusterConfigs { - version := version + // Iterate over each test variant + for _, variant := range kindClusterConfigs { + variant := variant // Define a subtest for each combination - t.Run(version, func(t *testing.T) { + t.Run(variant, func(t *testing.T) { t.Parallel() // Allow tests to run in parallel randomInt := fmt.Sprintf(strconv.Itoa(rand.Intn(100))) - kindClusterName := fmt.Sprintf("kured-e2e-cordon-%v-%v", version, randomInt) + kindClusterName := fmt.Sprintf("kured-e2e-cordon-%v-%v", variant, randomInt) kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-next.yaml") kindContext := fmt.Sprintf("kind-%v", kindClusterName) @@ -393,19 +393,19 @@ func TestE2EBlocker(t *testing.T) { var kindClusterConfigs = []string{ "podblocker", } - // Iterate over each Kubernetes version - for _, version := range kindClusterConfigs { - version := version + // Iterate over each variant of the test + for _, variant := range kindClusterConfigs { + variant := variant // Define a subtest for each combination - t.Run(version, func(t *testing.T) { + t.Run(variant, func(t *testing.T) { t.Parallel() // Allow tests to run in parallel randomInt := fmt.Sprintf(strconv.Itoa(rand.Intn(100))) - kindClusterName := fmt.Sprintf("kured-e2e-cordon-%v-%v", version, randomInt) + kindClusterName := fmt.Sprintf("kured-e2e-cordon-%v-%v", variant, randomInt) kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-next.yaml") kindContext := fmt.Sprintf("kind-%v", kindClusterName) - k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy(fmt.Sprintf("testfiles/kured-ds-%v.yaml", version))) + k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy(fmt.Sprintf("testfiles/kured-ds-%v.yaml", variant))) defer k.FlushLog() err := k.Create() @@ -421,7 +421,7 @@ func TestE2EBlocker(t *testing.T) { k.Write([]byte("Now running e2e tests")) - if err := k.RunCmd("bash", fmt.Sprintf("testfiles/%v.sh",version), kindContext); err != nil { + if err := k.RunCmd("bash", fmt.Sprintf("testfiles/%v.sh",variant), kindContext); err != nil { t.Fatalf("node blocker test did not succeed: %v", err) } }) From 6170770484057c7b5df646c4e1e1113b135da10f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Thu, 7 Nov 2024 19:34:03 +0100 Subject: [PATCH 4/7] Fix Staticcheck's SA1024 (subset with dupe chars) This will replace trim, taking a cutset, with Replace. This clarifies the intent to remove a substring. Signed-off-by: Jean-Philippe Evrard --- cmd/kured/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/kured/main.go b/cmd/kured/main.go index b3412932a..a6b1c0e82 100644 --- a/cmd/kured/main.go +++ b/cmd/kured/main.go @@ -320,11 +320,11 @@ func validateNotificationURL(notifyURL string, slackHookURL string) string { log.Errorf("slack-hook-url is not properly formatted... no notification will be sent: %v\n", err) return "" } - if len(strings.Split(strings.Trim(parsedURL.Path, "/services/"), "/")) != 3 { + if len(strings.Split(strings.Replace(parsedURL.Path, "/services/", "", -1), "/")) != 3 { log.Errorf("slack-hook-url is not properly formatted... no notification will be sent: unexpected number of / in URL\n") return "" } - return fmt.Sprintf("slack://%s", strings.Trim(parsedURL.Path, "/services/")) + return fmt.Sprintf("slack://%s", strings.Replace(parsedURL.Path, "/services/", "", -1)) } return "" } From ca73c4a0731cb210a45c49ee6566578b08f8cc7a Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Thu, 7 Nov 2024 19:38:38 +0100 Subject: [PATCH 5/7] Fix Staticcheck's ST1005 According to staticcheck, Error strings should not be capitalized (ST1005). This changes the cases for our errors. Signed-off-by: Jean-Philippe Evrard --- pkg/daemonsetlock/daemonsetlock.go | 4 ++-- pkg/timewindow/days.go | 4 ++-- pkg/timewindow/timewindow.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/daemonsetlock/daemonsetlock.go b/pkg/daemonsetlock/daemonsetlock.go index c0da3a59c..ba300f9de 100644 --- a/pkg/daemonsetlock/daemonsetlock.go +++ b/pkg/daemonsetlock/daemonsetlock.go @@ -214,10 +214,10 @@ func (dsl *DaemonSetSingleLock) Release() error { } if value.NodeID != dsl.nodeID { - return fmt.Errorf("Not lock holder: %v", value.NodeID) + return fmt.Errorf("not lock holder: %v", value.NodeID) } } else { - return fmt.Errorf("Lock not held") + return fmt.Errorf("lock not held") } delete(ds.ObjectMeta.Annotations, dsl.annotation) diff --git a/pkg/timewindow/days.go b/pkg/timewindow/days.go index 9d0e8b956..8a46e054d 100644 --- a/pkg/timewindow/days.go +++ b/pkg/timewindow/days.go @@ -81,11 +81,11 @@ func parseWeekday(day string) (time.Weekday, error) { if n >= 0 && n < 7 { return time.Weekday(n), nil } - return time.Sunday, fmt.Errorf("Invalid weekday, number out of range: %s", day) + return time.Sunday, fmt.Errorf("invalid weekday, number out of range: %s", day) } if weekday, ok := dayStrings[strings.ToLower(day)]; ok { return weekday, nil } - return time.Sunday, fmt.Errorf("Invalid weekday: %s", day) + return time.Sunday, fmt.Errorf("invalid weekday: %s", day) } diff --git a/pkg/timewindow/timewindow.go b/pkg/timewindow/timewindow.go index 13e24d8dd..973980ead 100644 --- a/pkg/timewindow/timewindow.go +++ b/pkg/timewindow/timewindow.go @@ -77,5 +77,5 @@ func parseTime(s string, loc *time.Location) (time.Time, error) { } } - return time.Now(), fmt.Errorf("Invalid time format: %s", s) + return time.Now(), fmt.Errorf("invalid time format: %s", s) } From 3cb82a0da18adb93c6626fdef9d1c5ad2202eda6 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Thu, 7 Nov 2024 19:46:38 +0100 Subject: [PATCH 6/7] Fix incorrect string prints A few strings have evolved to eventually remove all the templating part of their strings, yet kept the formatting features. This is incorrect, and will not pass staticcheck SA1006 and S1039. Signed-off-by: Jean-Philippe Evrard --- tests/kind/main_test.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/kind/main_test.go b/tests/kind/main_test.go index c09c71e16..fec78a917 100644 --- a/tests/kind/main_test.go +++ b/tests/kind/main_test.go @@ -152,7 +152,7 @@ func TestE2EWithCommand(t *testing.T) { t.Run(version, func(t *testing.T) { t.Parallel() // Allow tests to run in parallel - randomInt := fmt.Sprintf(strconv.Itoa(rand.Intn(100))) + randomInt := strconv.Itoa(rand.Intn(100)) kindClusterName := fmt.Sprintf("kured-e2e-command-%v-%v", version, randomInt) kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-%v.yaml", version) kindContext := fmt.Sprintf("kind-%v", kindClusterName) @@ -202,7 +202,7 @@ func TestE2EWithSignal(t *testing.T) { t.Run(version, func(t *testing.T) { t.Parallel() // Allow tests to run in parallel - randomInt := fmt.Sprintf(strconv.Itoa(rand.Intn(100))) + randomInt := strconv.Itoa(rand.Intn(100)) kindClusterName := fmt.Sprintf("kured-e2e-signal-%v-%v", version, randomInt) kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-%v.yaml", version) kindContext := fmt.Sprintf("kind-%v", kindClusterName) @@ -252,7 +252,7 @@ func TestE2EConcurrentWithCommand(t *testing.T) { t.Run(version, func(t *testing.T) { t.Parallel() // Allow tests to run in parallel - randomInt := fmt.Sprintf(strconv.Itoa(rand.Intn(100))) + randomInt := strconv.Itoa(rand.Intn(100)) kindClusterName := fmt.Sprintf("kured-e2e-concurrentcommand-%v-%v", version, randomInt) kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-%v.yaml", version) kindContext := fmt.Sprintf("kind-%v", kindClusterName) @@ -302,7 +302,7 @@ func TestE2EConcurrentWithSignal(t *testing.T) { t.Run(version, func(t *testing.T) { t.Parallel() // Allow tests to run in parallel - randomInt := fmt.Sprintf(strconv.Itoa(rand.Intn(100))) + randomInt := strconv.Itoa(rand.Intn(100)) kindClusterName := fmt.Sprintf("kured-e2e-concurrentsignal-%v-%v", version, randomInt) kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-%v.yaml", version) kindContext := fmt.Sprintf("kind-%v", kindClusterName) @@ -351,16 +351,16 @@ func TestCordonningIsKept(t *testing.T) { t.Run(variant, func(t *testing.T) { t.Parallel() // Allow tests to run in parallel - randomInt := fmt.Sprintf(strconv.Itoa(rand.Intn(100))) + randomInt := strconv.Itoa(rand.Intn(100)) kindClusterName := fmt.Sprintf("kured-e2e-cordon-%v-%v", variant, randomInt) - kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-next.yaml") + kindClusterConfigFile := "../../.github/kind-cluster-next.yaml" kindContext := fmt.Sprintf("kind-%v", kindClusterName) var manifest string if variant == "concurrency1" { - manifest = fmt.Sprintf("testfiles/kured-ds-signal.yaml") + manifest = "testfiles/kured-ds-signal.yaml" } else { - manifest = fmt.Sprintf("testfiles/kured-ds-concurrent-signal.yaml") + manifest = "testfiles/kured-ds-concurrent-signal.yaml" } k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy(manifest)) defer k.FlushLog() @@ -400,9 +400,9 @@ func TestE2EBlocker(t *testing.T) { t.Run(variant, func(t *testing.T) { t.Parallel() // Allow tests to run in parallel - randomInt := fmt.Sprintf(strconv.Itoa(rand.Intn(100))) + randomInt := strconv.Itoa(rand.Intn(100)) kindClusterName := fmt.Sprintf("kured-e2e-cordon-%v-%v", variant, randomInt) - kindClusterConfigFile := fmt.Sprintf("../../.github/kind-cluster-next.yaml") + kindClusterConfigFile := "../../.github/kind-cluster-next.yaml" kindContext := fmt.Sprintf("kind-%v", kindClusterName) k := NewKindTester(kindClusterName, kindClusterConfigFile, t, LocalImage(kuredDevImage), Deploy("../../kured-rbac.yaml"), Deploy(fmt.Sprintf("testfiles/kured-ds-%v.yaml", variant))) @@ -421,7 +421,7 @@ func TestE2EBlocker(t *testing.T) { k.Write([]byte("Now running e2e tests")) - if err := k.RunCmd("bash", fmt.Sprintf("testfiles/%v.sh",variant), kindContext); err != nil { + if err := k.RunCmd("bash", fmt.Sprintf("testfiles/%v.sh", variant), kindContext); err != nil { t.Fatalf("node blocker test did not succeed: %v", err) } }) From 76765f5dd130910e9d5b643888e8fcc3d37329ef Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Thu, 7 Nov 2024 19:50:15 +0100 Subject: [PATCH 7/7] Add staticcheck in make tests Without this, people like myself will forget to run staticcheck. This fixes it by making it part of make tests, which will run with all the fast tests in CI. Signed-off-by: Jean-Philippe Evrard --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a7dabc9a9..c81b1d31a 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ bootstrap-tools: $(HACKDIR) command -v $(HACKDIR)/cosign || curl -sSfL https://github.com/sigstore/cosign/releases/download/v2.2.3/cosign-linux-amd64 -o $(HACKDIR)/cosign command -v $(HACKDIR)/shellcheck || (curl -sSfL https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz | tar -J -v -x shellcheck-stable/shellcheck && mv shellcheck-stable/shellcheck $(HACKDIR)/shellcheck && rmdir shellcheck-stable) chmod +x $(HACKDIR)/goreleaser $(HACKDIR)/cosign $(HACKDIR)/syft $(HACKDIR)/shellcheck - # go install honnef.co/go/tools/cmd/staticcheck@latest + command -v staticcheck || go install honnef.co/go/tools/cmd/staticcheck@latest clean: rm -rf ./dist @@ -71,4 +71,4 @@ test: bootstrap-tools go test -test.short -json ./... > test.json echo "Running shellcheck" find . -name '*.sh' | xargs -n1 $(HACKDIR)/shellcheck - # Need to add staticcheck to replace golint as golint is deprecated, and staticcheck is the recommendation + staticcheck ./...