Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ go_library(
"//src/compute-plane-services/nvca/cmd/internal",
"//src/compute-plane-services/nvca/internal/clustervalidator",
"//src/compute-plane-services/nvca/vendor/github.com/NVIDIA/nvcf/src/libraries/go/lib/pkg/core",
"//src/compute-plane-services/nvca/vendor/k8s.io/client-go/dynamic",
],
)

Expand Down Expand Up @@ -42,4 +43,7 @@ go_test(
name = "cluster-validator_test",
srcs = ["main_test.go"],
embed = [":cluster-validator_lib"],
deps = [
"//src/compute-plane-services/nvca/internal/clustervalidator",
],
)
25 changes: 24 additions & 1 deletion src/compute-plane-services/nvca/cmd/cluster-validator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,34 @@ func main() {
clustervalidator.SummaryConfigMapNamespaceEnv)
}

if err := clustervalidator.Run(ctx, client, configNS, configName, summaryNS, emitMetrics); err != nil {
// VALIDATOR_ROLE selects which check set runs: "control-plane" enables
// gateway and StorageClass checks and skips GPU/SMB; anything else (including
// unset) runs the compute-plane check set (backward-compatible default).
roleEnv := os.Getenv("VALIDATOR_ROLE")
role := parseRole(roleEnv)
if roleEnv != "" && role == "" {
log.Warnf("VALIDATOR_ROLE=%q is not recognized; defaulting to compute-plane", roleEnv)
}

if err := clustervalidator.Run(ctx, client, configNS, configName, summaryNS, emitMetrics, role); err != nil {
log.WithError(err).Fatal("Cluster validation failed")
}
}

// parseRole normalizes the VALIDATOR_ROLE env value. Returns the matching
// clustervalidator constant for "control-plane" or "compute-plane"; returns ""
// (compute-plane default) for any other value so unknown inputs are safe.
func parseRole(v string) string {
switch strings.ToLower(strings.TrimSpace(v)) {
case clustervalidator.RoleControlPlane:
return clustervalidator.RoleControlPlane
case clustervalidator.RoleComputePlane:
return clustervalidator.RoleComputePlane
default:
return ""
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

// preflightMode reports whether this is a one-shot preflight run (e.g. nvcf-cli,
// before NVCA is installed), which skips the summary write. Read from an env
// (not a flag) so an unknown value is ignored rather than crashing arg parsing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,35 @@ limitations under the License.

package main

import "testing"
import (
"testing"

"github.com/NVIDIA/nvcf/src/compute-plane-services/nvca/internal/clustervalidator"
)

func TestParseRole(t *testing.T) {
tests := []struct {
in string
want string
}{
// Known roles are normalized.
{"control-plane", clustervalidator.RoleControlPlane},
{"CONTROL-PLANE", clustervalidator.RoleControlPlane},
{" control-plane ", clustervalidator.RoleControlPlane},
{"compute-plane", clustervalidator.RoleComputePlane},
{"COMPUTE-PLANE", clustervalidator.RoleComputePlane},
// Unknown values (including unset) fall back to "" = compute-plane default.
{"", ""},
{"gpu", ""},
{"both", ""},
{"control_plane", ""}, // underscore, not hyphen
}
for _, tt := range tests {
if got := parseRole(tt.in); got != tt.want {
t.Errorf("parseRole(%q) = %q, want %q", tt.in, got, tt.want)
}
}
}

func TestPreflightMode(t *testing.T) {
tests := []struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ go_library(
deps = [
"//src/compute-plane-services/nvca/vendor/github.com/NVIDIA/nvcf/src/libraries/go/lib/pkg/core",
"//src/compute-plane-services/nvca/vendor/github.com/sirupsen/logrus",
"//src/compute-plane-services/nvca/vendor/k8s.io/api/apps/v1:apps",
"//src/compute-plane-services/nvca/vendor/k8s.io/api/core/v1:core",
"//src/compute-plane-services/nvca/vendor/k8s.io/api/networking/v1:networking",
"//src/compute-plane-services/nvca/vendor/k8s.io/apimachinery/pkg/api/errors",
"//src/compute-plane-services/nvca/vendor/k8s.io/apimachinery/pkg/api/resource",
"//src/compute-plane-services/nvca/vendor/k8s.io/apimachinery/pkg/apis/meta/v1:meta",
"//src/compute-plane-services/nvca/vendor/k8s.io/apimachinery/pkg/util/rand",
"//src/compute-plane-services/nvca/vendor/k8s.io/apimachinery/pkg/util/intstr",
"//src/compute-plane-services/nvca/vendor/k8s.io/client-go/discovery",
"//src/compute-plane-services/nvca/vendor/k8s.io/client-go/kubernetes",
Expand All @@ -41,6 +43,7 @@ alias(
go_test(
name = "clustervalidator_test",
srcs = [
"checks_controlplane_test.go",
"checks_test.go",
"config_test.go",
"enforcement_test.go",
Expand Down
Loading
Loading