Files
nvke/controller/test/e2e/open_vswitch_test.go
Davanum SrinivasandClaude Fable 5.1 6029bf16ab chore: say NVKE in the comments and display text that still said NKE (#1470)
* chore: say NVKE in the comments that still said NKE

The word NKE in comments becomes NVKE: Go comments through the token
scanner, so no string literal moves; proto doc comments, with the
generated *.pb.go files regenerated by `make -C agent protos`; and the
comment lines of YAML, shell, Make, Tilt, systemd, Packer, Nix and
template files. The provisioned provider's CRD description comes from a
doc comment, so `make -C cluster-api-provider-provisioned manifests` and
`make -C cli provider-manifest` regenerated the CRD and the CLI's
embedded copy of it.

Kept on purpose: the comment quoting the "NKE Agent Version:" line the
updater parses, and the comments about the NGC organisation that is
named NKE.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

* chore: say NVKE in the display text that still said NKE

User-facing text that carried the word NKE now says NVKE: nvkectl help
text; log, error and condition messages; Ginkgo suite and spec names;
deb and OCI package metadata; systemd unit descriptions; workflow step
names and input descriptions; Helm render failures; and the nine
Markdown lines the prose sweep (#1462) missed. The tests that assert
these strings move with them.

Kept on purpose, because something parses or persists them: the
"NKE Agent Version:" and "NKE Agent Updater Version:" lines the updater
reads; the "update NKE RBAC:" errors of the UpdateNKERBAC rpc; the 2025
migration text; the OIDC upstream CA's CN and OU, since re-issuing that
CA would break tenant trust; the nico-sim tenant "Forge-Tenant-NKE"; the
Keycloak lab realm; and the NGC organisation that is named NKE.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>

---------

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-10 18:28:35 -04:00

124 lines
4.6 KiB
Go

// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package e2e
import (
"context"
"fmt"
"net/http"
"strconv"
"strings"
"testing"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/dsx-ai-factory/nvke/controller/test/e2e/internal/controller"
"github.com/dsx-ai-factory/nvke/controller/test/e2e/internal/kube"
)
const openVSwitchMetricName = "nvke_controller_open_vswitch_reconciliation_total"
func validateOpenVSwitchPostCreate(test *tenantTest) {
It("configures Open vSwitch through the typed node-agent RPC", func(ctx context.Context) {
restConfig, err := kube.RESTConfig(test.mgmt.Kubeconfig, test.mgmt.Context)
Expect(err).NotTo(HaveOccurred(), "read management-cluster kubeconfig")
metrics, err := kube.SharedServiceForwarder(restConfig, controller.Namespace(), controller.Service(), nvkeControllerMetricsPort)
Expect(err).NotTo(HaveOccurred(), "build a port-forward to NVKE controller metrics")
expectedNodes := clusterNodeCount(test.spec)
// Node readiness above is the behavioral assertion: OVN cannot converge
// without the host bridge. This metric assertion identifies which of the
// two implementations produced that behavior during a mixed-agent rollout.
Eventually(func(ctx context.Context) error {
statusCode, body, getErr := metrics.Get(ctx, metricsPath)
if getErr != nil {
return getErr
}
if statusCode != http.StatusOK {
return fmt.Errorf("GET %s returned %d: %s", metricsPath, statusCode, body)
}
rpcSuccess, fallback, parseErr := openVSwitchPathCounts(string(body), test.cluster.Name)
if parseErr != nil {
return parseErr
}
if fallback != 0 {
return fmt.Errorf("legacy Open vSwitch fallback ran %d times", fallback)
}
if rpcSuccess < expectedNodes {
return fmt.Errorf("typed Open vSwitch RPC has %d successful node reconciliations, want at least %d", rpcSuccess, expectedNodes)
}
return nil
}).WithContext(ctx).WithTimeout(30 * time.Second).WithPolling(2 * time.Second).Should(Succeed())
}, Label("openvswitch"), SpecTimeout(2*time.Minute))
}
func openVSwitchPathCounts(exposition, clusterName string) (int, int, error) {
clusterLabel := `tenant_cluster="` + clusterName + `"`
rpcNodes := map[string]struct{}{}
fallback := 0
for _, line := range strings.Split(exposition, "\n") {
openIdx := strings.Index(line, "{")
closeIdx := strings.LastIndex(line, "}")
if openIdx < 0 || closeIdx < openIdx || line[:openIdx] != openVSwitchMetricName {
continue
}
labels := line[openIdx+1 : closeIdx]
if !strings.Contains(labels, clusterLabel) {
continue
}
fields := strings.Fields(line[closeIdx+1:])
if len(fields) == 0 {
return 0, 0, fmt.Errorf("malformed exposition line %q", line)
}
value, parseErr := strconv.ParseFloat(fields[0], 64)
if parseErr != nil {
return 0, 0, fmt.Errorf("parse value from %q: %w", line, parseErr)
}
switch {
case strings.Contains(labels, `path="rpc"`) && strings.Contains(labels, `result="success"`):
nodeName, found := openVSwitchMetricLabel(labels, "node_name")
if !found {
return 0, 0, fmt.Errorf("Open vSwitch RPC metric has no node_name label: %q", line)
}
rpcNodes[nodeName] = struct{}{}
case strings.Contains(labels, `path="legacy_runbook"`):
fallback += int(value)
}
}
return len(rpcNodes), fallback, nil
}
func openVSwitchMetricLabel(labels, name string) (string, bool) {
prefix := name + `="`
start := strings.Index(labels, prefix)
if start < 0 {
return "", false
}
value := labels[start+len(prefix):]
end := strings.Index(value, `"`)
if end < 0 {
return "", false
}
return value[:end], true
}
func TestOpenVSwitchPathCounts(t *testing.T) {
exposition := `# TYPE nvke_controller_open_vswitch_reconciliation_total counter
nvke_controller_open_vswitch_reconciliation_total{node_name="cp-0",path="rpc",result="success",tenant_cluster="e2e-nico-vms"} 2
nvke_controller_open_vswitch_reconciliation_total{node_name="cp-1",path="rpc",result="success",tenant_cluster="e2e-nico-vms"} 1
nvke_controller_open_vswitch_reconciliation_total{node_name="other",path="legacy_runbook",result="success",tenant_cluster="another-cluster"} 7
nvke_controller_open_vswitch_reconciliation_total{node_name="cp-2",path="legacy_runbook",result="failure",tenant_cluster="e2e-nico-vms"} 1
`
rpcSuccess, fallback, err := openVSwitchPathCounts(exposition, "e2e-nico-vms")
if err != nil {
t.Fatalf("openVSwitchPathCounts: %v", err)
}
if rpcSuccess != 2 || fallback != 1 {
t.Fatalf("openVSwitchPathCounts = (%d, %d), want (2, 1)", rpcSuccess, fallback)
}
}