From ea244dc3c8deed5d0fbd0b981ee13cffb6a31d53 Mon Sep 17 00:00:00 2001 From: Joshua Hoblitt Date: Fri, 5 Jun 2026 15:38:50 -0700 Subject: [PATCH] test: remove unused label verification helpers VerifyPodLabels had no callers anywhere in the repo, and it was the only caller of VerifyAppLabels, which in turn was the only caller of the checkLabel and combineErrors helpers. Remove the whole dead cluster (and the now-unused strings, github.com/pkg/errors, and ceph/controller imports). AssertLabelsContainCephRequirements in the same file remains and is unaffected. Verified with grep, deadcode, and staticcheck. Signed-off-by: Joshua Hoblitt (cherry picked from commit ac75488621ead519a7cdb5cac7d63c7f8f3a2462) --- pkg/operator/ceph/test/spec.go | 45 ---------------------------------- 1 file changed, 45 deletions(-) diff --git a/pkg/operator/ceph/test/spec.go b/pkg/operator/ceph/test/spec.go index 0c69dbf59..0d45ada8e 100644 --- a/pkg/operator/ceph/test/spec.go +++ b/pkg/operator/ceph/test/spec.go @@ -19,57 +19,12 @@ package test import ( "fmt" "os" - "strings" "testing" - e "github.com/pkg/errors" - "github.com/rook/rook/pkg/operator/ceph/controller" optest "github.com/rook/rook/pkg/operator/test" "github.com/stretchr/testify/assert" ) -func checkLabel(key, value string, labels map[string]string) error { - v, ok := labels[key] - if !ok { - return e.Errorf("label not present: expected={%s: %s}", key, value) - } - if v != value { - return e.Errorf("label mismatch: expected={%s: %s} present={%s: %s}", key, value, key, v) - } - return nil -} - -func combineErrors(errors ...error) error { - errText := "" - failure := false - for _, e := range errors { - if e != nil { - failure = true - errText = fmt.Sprintf("%v: %s", e, errText) // Will result in string ending in ": " - } - } - if failure { - errText = strings.TrimRight(errText, ": ") // Remove ": " from end - return e.Errorf("%s", errText) - } - return nil -} - -// VerifyAppLabels returns a descriptive error if app labels are not present or not as expected. -func VerifyAppLabels(appName, namespace string, labels map[string]string) error { - errA := checkLabel("app", appName, labels) - errB := checkLabel("rook_cluster", namespace, labels) - return combineErrors(errA, errB) -} - -// VerifyPodLabels returns a descriptive error if pod labels are not present or not as expected. -func VerifyPodLabels(appName, namespace, daemonType, daemonID string, labels map[string]string) error { - errA := VerifyAppLabels(appName, namespace, labels) - errB := checkLabel(controller.DaemonIDLabel, daemonID, labels) - errC := checkLabel(daemonType, daemonID, labels) - return combineErrors(errA, errB, errC) -} - // AssertLabelsContainCephRequirements asserts that the labels under test contain the labels // which all Ceph pods should have. This can be used with labels for Kubernetes Deployments, // DaemonSets, etc.