Files
Terry Howe e34e07e355 feat(chart)!: default the controller chart names and SPIFFE service path segment to nvke (#1769)
* test(chart): assert default, legacy-pinned and greenfield renders separately

chart-identity-assertions.py asserted the legacy names against the default render, so moving a default and keeping an existing install on its names could not be told apart. It now renders three scenarios, each with its own expectations: the chart's defaults, hack/testdata/chart-legacy-pinned-values.yaml, and a renamed greenfield install.

A default that moves now changes DEFAULT only. A pin that stops holding the old name fails the legacy-pinned render. The management namespace check is folded into the scenarios, and every check runs so a failure shows which render it was.

Signed-off-by: Terry Howe <thowe@nvidia.com>

* feat(chart)!: default nameOverride and the controller config ConfigMap to nvke-controller

A new install now gets nvke-controller for the Deployment, Service and every object named from the fullname, and nvke-controller-config for the settings ConfigMap. The ServiceAccount, the ServiceMonitor and the nke-rbac objects keep their names; they move separately.

BREAKING CHANGE: an install that predates this must set nameOverride to cloud-workflow-engine and controllerConfig.name to nke-controller-config before it takes this chart. The Deployment's spec.selector is immutable, so an upgrade that moves nameOverride fails, and the ConfigMap rename orphans the live object. hack/testdata/chart-legacy-pinned-values.yaml lists the pins.

The default scenario of chart-identity-assertions.py moves to the new names and the legacy-pinned scenario does not. The chart scripts, the chart test and the e2e helpers that select the ConfigMap by name follow the default; nvke-auth-demo.sh takes it from NKE_CONTROLLER_CONFIGMAP.

Signed-off-by: Terry Howe <thowe@nvidia.com>

* style: gofmt map literal alignment in oidc site_test

Signed-off-by: Terry Howe <thowe@nvidia.com>

* feat(chart)!: default the SPIFFE service path segment to nvke-service

A new install issues the controller the ID spiffe://<trust domain>/nvke-service/<service account>: the chart's default RBAC subjects, the ClusterSPIFFEID and the SPIRE admin ID now agree on nvke-service. The CLI bootstrap, the deploy path, the e2e stacks, Tilt and the e2e helpers that name the controller's ID follow.

BREAKING CHANGE: an install that predates this must set spiffe.servicePathSegment to nke-service and keep its ClusterSPIFFEID and SPIRE admin ID on /nke-service/. Node agents from before the nvke rename admit only that path, and the controller dials every node with one SVID, so moving it on such a site breaks controller-to-node mTLS.

chart-identity-assertions.py checks each scenario's SPIFFE subjects against its segment: nvke-service by default, nke-service in the legacy-pinned render.

Signed-off-by: Terry Howe <thowe@nvidia.com>

* fix: address review feedback

Name the auth demo's controller ConfigMap setting NVKE_CONTROLLER_CONFIGMAP, the prefix AGENTS.md requires for settings that name the controller. Show the default SPIFFE subjects in the chart README under spiffe.servicePathSegment instead of a fixed /nke-service/.

Signed-off-by: Terry Howe <thowe@nvidia.com>

---------

Signed-off-by: Terry Howe <thowe@nvidia.com>
2026-10-19 11:34:48 -06:00

181 lines
6.4 KiB
Go

// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package controllerdeploy
import (
"context"
"io/fs"
"os"
"strings"
"testing"
"gopkg.in/yaml.v3"
)
// The controller's name is written in cweNamespace and in three embedded
// manifests. A copy left at the legacy name installs cleanly and then fails as
// a Service with no endpoints or a controller with no SPIFFE identity, so this
// checks every place the bootstrap names it.
const legacyControllerName = "cloud-workflow-engine"
func TestBootstrapNamesNoLegacyController(t *testing.T) {
for _, file := range []string{spireValuesFile, cweValuesFile, cweNodePortFile} {
body, err := fs.ReadFile(manifestsFS, file)
if err != nil {
t.Fatal(err)
}
for _, line := range strings.Split(string(body), "\n") {
if !strings.HasPrefix(strings.TrimSpace(line), "#") && strings.Contains(line, legacyControllerName) {
t.Errorf("%s names the legacy controller: %q", file, line)
}
}
}
runner := &fakeRunner{}
if err := New(runner, nil).Deploy(context.Background(), "/tmp/kubeconfig", testConfig(t)); err != nil {
t.Fatalf("Deploy returned error: %v", err)
}
for _, call := range runner.calls {
if args := joinArgs(call.args); strings.Contains(args, legacyControllerName) {
t.Errorf("%s call names the legacy controller: %s", call.name, args)
}
}
for _, manifest := range runner.applied {
if strings.Contains(manifest, legacyControllerName) {
t.Errorf("applied manifest names the legacy controller:\n%s", manifest)
}
}
}
// TestControllerValuesNameEveryObject pins the chart values that have to carry
// the name besides the fullname: nameOverride is the pod label the external
// Service selects on, and the chart pins serviceAccount.name instead of
// deriving it, which the SPIRE admin ID and the controller's SPIFFE ID name.
func TestControllerValuesNameEveryObject(t *testing.T) {
body, err := fs.ReadFile(manifestsFS, cweValuesFile)
if err != nil {
t.Fatal(err)
}
for _, want := range []string{
"fullnameOverride: " + cweNamespace + "\n",
"nameOverride: " + cweNamespace + "\n",
"namespaceOverride: " + cweNamespace + "\n",
"serviceAccount:\n name: " + cweNamespace + "\n",
} {
if !strings.Contains(string(body), want) {
t.Errorf("%s does not set %q", cweValuesFile, strings.TrimSpace(want))
}
}
}
// TestNodePortAndSPIRENameTheController pins the two other manifests that carry
// the name. The external Service has to select the controller's pods, and the
// SPIRE namespace selectors have to keep the controller's namespace out of the
// default identity and issue it the nvke-service one; a typo in any of them
// installs cleanly and fails later.
func TestNodePortAndSPIRENameTheController(t *testing.T) {
path, cleanup, err := writeEmbeddedTemplate(cweNodePortFile, struct{ Port int32 }{DefaultCWEPort})
if err != nil {
t.Fatal(err)
}
defer cleanup()
body, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
var service struct {
Metadata struct {
Name string `yaml:"name"`
} `yaml:"metadata"`
Spec struct {
Selector map[string]string `yaml:"selector"`
} `yaml:"spec"`
}
if err := yaml.Unmarshal(body, &service); err != nil {
t.Fatalf("%s: %v", cweNodePortFile, err)
}
if want := cweNamespace + "-external"; service.Metadata.Name != want {
t.Errorf("%s metadata.name = %q, want %q", cweNodePortFile, service.Metadata.Name, want)
}
for _, key := range []string{"app.kubernetes.io/name", "app.kubernetes.io/instance"} {
if got := service.Spec.Selector[key]; got != cweNamespace {
t.Errorf("%s selector %s = %q, want %q", cweNodePortFile, key, got, cweNamespace)
}
}
body, err = fs.ReadFile(manifestsFS, spireValuesFile)
if err != nil {
t.Fatal(err)
}
type selector struct {
NamespaceSelector struct {
MatchExpressions []struct {
Key string `yaml:"key"`
Operator string `yaml:"operator"`
Values []string `yaml:"values"`
} `yaml:"matchExpressions"`
} `yaml:"namespaceSelector"`
}
var values struct {
SPIREServer struct {
ControllerManager struct {
Identities struct {
ClusterSPIFFEIDs map[string]selector `yaml:"clusterSPIFFEIDs"`
} `yaml:"identities"`
} `yaml:"controllerManager"`
} `yaml:"spire-server"`
}
if err := yaml.Unmarshal(body, &values); err != nil {
t.Fatalf("%s: %v", spireValuesFile, err)
}
ids := values.SPIREServer.ControllerManager.Identities.ClusterSPIFFEIDs
for id, operator := range map[string]string{"default": "NotIn", "nvke-service": "In"} {
exprs := ids[id].NamespaceSelector.MatchExpressions
if len(exprs) != 1 || exprs[0].Key != "kubernetes.io/metadata.name" || exprs[0].Operator != operator ||
len(exprs[0].Values) != 1 || exprs[0].Values[0] != cweNamespace {
t.Errorf("%s clusterSPIFFEIDs.%s.namespaceSelector = %+v, want kubernetes.io/metadata.name %s [%s]",
spireValuesFile, id, exprs, operator, cweNamespace)
}
}
}
// TestPostgresCreatesTheDatabaseTheControllerUses pins the two settings that
// have to agree. The controller's database name is appDb.dbName in the
// controller values; the database is created by the Postgres script that
// postgres-values.yaml replaces. A name on one side only installs cleanly and
// leaves the controller unready, because it connects to a database nobody
// created. The Temporal script is not replaced, so the chart still creates the
// Temporal databases.
func TestPostgresCreatesTheDatabaseTheControllerUses(t *testing.T) {
var controller struct {
AppDB struct {
DBName string `yaml:"dbName"`
} `yaml:"appDb"`
}
var postgres struct {
InitDB struct {
Scripts map[string]string `yaml:"scripts"`
} `yaml:"initdb"`
}
for file, into := range map[string]any{cweValuesFile: &controller, postgresValuesFile: &postgres} {
body, err := fs.ReadFile(manifestsFS, file)
if err != nil {
t.Fatal(err)
}
if err := yaml.Unmarshal(body, into); err != nil {
t.Fatalf("%s: %v", file, err)
}
}
if controller.AppDB.DBName != cweNamespace {
t.Errorf("%s appDb.dbName = %q, want %q", cweValuesFile, controller.AppDB.DBName, cweNamespace)
}
if got, want := postgres.InitDB.Scripts["init-cwe.sql"], `CREATE DATABASE "`+controller.AppDB.DBName+`";`; strings.TrimSpace(got) != want {
t.Errorf("%s init-cwe.sql = %q, want %q", postgresValuesFile, got, want)
}
if len(postgres.InitDB.Scripts) != 1 {
t.Errorf("%s sets scripts %v, want only init-cwe.sql: the Temporal script stays as the chart ships it", postgresValuesFile, postgres.InitDB.Scripts)
}
}