Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions controller/api/models.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions controller/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,13 @@ components:
infra:
x-fern-ignore: true
$ref: "#/components/schemas/InfraClusterProvider"
enableCPNodeRecycling:
type: boolean
default: false
description: |
When true, control-plane upgrades and configuration changes replace nodes
automatically. When false, the default, nodes needing replacement are reported as
pending and wait for an operator.
NodeAgentConfig:
description: Desired control-plane node-agent configuration.
type: object
Expand Down
685 changes: 343 additions & 342 deletions controller/api/server.gen.go

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions controller/internal/server/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -1497,17 +1497,22 @@ func DBClusterFromAPI(req *api.CreateClusterRequest) (db.Cluster, error) {
if req.CniVersion != nil {
cniVersion = strings.TrimSpace(*req.CniVersion)
}
var enableCPNodeRecycling bool
if req.EnableCPNodeRecycling != nil {
enableCPNodeRecycling = *req.EnableCPNodeRecycling
}
cniPlugin := db.EffectiveCNIPlugin(db.CniPlugin(req.CniPlugin))
controlPlaneVIP := strings.TrimSpace(req.ControlPlaneVIP)

cluster := db.Cluster{
Name: req.Name,
CniPlugin: cniPlugin,
CniVersion: db.EffectiveCNIVersion(cniPlugin, cniVersion),
EtcdEncrypted: req.EtcdEncrypted,
KubernetesVersion: req.ControlPlaneKubernetesVersion,
ControlPlaneVIP: controlPlaneVIP,
TeleportEnabled: teleportEnabled,
Name: req.Name,
CniPlugin: cniPlugin,
CniVersion: db.EffectiveCNIVersion(cniPlugin, cniVersion),
EtcdEncrypted: req.EtcdEncrypted,
KubernetesVersion: req.ControlPlaneKubernetesVersion,
ControlPlaneVIP: controlPlaneVIP,
TeleportEnabled: teleportEnabled,
EnableCPNodeRecycling: enableCPNodeRecycling,

Conditions: db.ClusterConditions{
Provisioning: db.NewCondition(true, "Starting provisioning"),
Expand Down
27 changes: 27 additions & 0 deletions controller/internal/server/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2367,6 +2367,33 @@ func TestDbClusterFromAPI_NestedProvidersReachTheStoredCluster(t *testing.T) {
})
}

func TestDbClusterFromAPI_EnableCPNodeRecycling(t *testing.T) {
boolPtr := func(b bool) *bool { return &b }
cases := []struct {
name string
input *bool
want bool
}{
{name: "unset defaults to false", input: nil, want: false},
{name: "explicit false is stored as false", input: boolPtr(false), want: false},
{name: "explicit true is stored as true", input: boolPtr(true), want: true},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
req := &api.CreateClusterRequest{
Name: "recycle",
ControlPlaneKubernetesVersion: "1.31.0",
CniPlugin: "cilium",
EnableCPNodeRecycling: tc.input,
}

cluster, err := server.DBClusterFromAPI(req)
require.NoError(t, err)
assert.Equal(t, tc.want, cluster.EnableCPNodeRecycling)
})
}
}

func TestApiClusterFromDB_OmitsMissingProviderPayload(t *testing.T) {
// The nico mapper reads the JSONB payload, so a row whose payload has not
// been stamped yet emits nico:null rather than inventing one.
Expand Down
16 changes: 16 additions & 0 deletions controller/test/e2e/internal/nvke/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ type ClusterSpec struct {
ControlPlane ControlPlane
Workers []NodePoolSpec
Network *ClusterNetworkSpec
// EnableCPNodeRecycling sets enableCPNodeRecycling true on the create request.
// False leaves the field out, so the controller default applies.
EnableCPNodeRecycling bool

// Infrastructure-specific cluster fields. Nico containers use SiteID and
// VpcID inside their CAPI manifests; NICo VMs use all three as API fields.
Expand Down Expand Up @@ -209,6 +212,19 @@ func shellQuote(value string) string {
// creates it through the CLI. Sharing the builder is what keeps the CLI-driven
// table entry differing from its REST counterpart in transport alone.
func BuildCreateRequest(spec ClusterSpec) (api.CreateClusterRequest, error) {
req, err := buildBackendCreateRequest(spec)
if err != nil {
return req, err
}
if spec.EnableCPNodeRecycling {
enable := true
req.EnableCPNodeRecycling = &enable
}
return req, nil
}

// buildBackendCreateRequest builds the backend-specific part of the create request.
func buildBackendCreateRequest(spec ClusterSpec) (api.CreateClusterRequest, error) {
switch spec.Backend {
case BackendCAPD:
return buildCAPDRequest(spec)
Expand Down
30 changes: 27 additions & 3 deletions controller/test/e2e/nvkectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/dsx-ai-factory/nvke/controller/api"
"github.com/dsx-ai-factory/nvke/controller/test/e2e/internal/config"
"github.com/dsx-ai-factory/nvke/controller/test/e2e/internal/nvke"
"github.com/dsx-ai-factory/nvke/controller/test/e2e/internal/nvkectl"
)
Expand Down Expand Up @@ -89,6 +90,11 @@ func (t *tenantTest) closeNvkectl() {
// cluster. initCluster already drove the create, list and provisioning wait
// through nvkectl; these are the commands left over.
func validateNvkectlPostCreate(test *tenantTest) {
// test.cfg is only assigned inside "creates the cluster", which runs after the
// tree is built. The reuse setting is read from the config file here instead.
cfg, err := config.Load(cfgPath)
Expect(err).NotTo(HaveOccurred(), "load e2e configuration")

Describe("nvkectl against the provisioned cluster", Label("nvkectl"), func() {
BeforeEach(func() {
// Assert rather than Skip: a missing runner here is a bug in this
Expand Down Expand Up @@ -127,20 +133,38 @@ func validateNvkectlPostCreate(test *tenantTest) {
Expect(nodes.Items).NotTo(BeEmpty(), "the tenant cluster should report at least one node")
}, SpecTimeout(5*time.Minute))

// initCluster created this cluster with enableCPNodeRecycling set, through
// `nvkectl create cluster`. Checking the stored value proves the create-time
// flag reaches the controller. This spec must run before the patch below.
//
// A reused cluster was not created by this run, so its create-time flag is
// unknown. The spec is left out of the tree rather than skipped at run time:
// a runtime skip from this file would trip e2e_assert_no_new_skips.
if cfg.Lifecycle.ReuseCluster == "" {
It("stores enableCPNodeRecycling set at create", func(ctx context.Context) {
cluster, err := test.lifecycle.GetByName(ctx, test.cluster.Name)
Expect(err).NotTo(HaveOccurred(), "should read the created cluster")

Expect(cluster.EnableCPNodeRecycling).NotTo(BeNil(), "the create-time field should be reported")
Expect(*cluster.EnableCPNodeRecycling).To(BeTrue(), "the create-time flag should be stored")
}, SpecTimeout(5*time.Minute))
}

// The CLI's unit tests cover the flag surface; what is left to e2e is a
// patch reaching the controller and sticking to a cluster that provisioned.
//
// enableCPNodeRecycling only changes what a later upgrade would do, so it
// starts nothing that could collide with the delete below. The one-way
// fields each hold the update lock for a workflow, and a version bump
// recycles nodes.
// recycles nodes. The create-time flag is already true, so this patch sets
// it to false; that makes the stored-value check meaningful.
It("applies a patch to the provisioned cluster", func(ctx context.Context) {
patched, err := test.nvkectlRunner.PatchCluster(ctx, test.cluster.Name,
[]byte("enableCPNodeRecycling: true\n"))
[]byte("enableCPNodeRecycling: false\n"))
Expect(err).NotTo(HaveOccurred(), "should patch the cluster")

Expect(patched.EnableCPNodeRecycling).NotTo(BeNil(), "the patched field should be reported")
Expect(*patched.EnableCPNodeRecycling).To(BeTrue(), "the patch should have been applied")
Expect(*patched.EnableCPNodeRecycling).To(BeFalse(), "the patch should have been applied")
}, SpecTimeout(5*time.Minute))

// The smoke asserts this too, but against a controller holding no clusters. A
Expand Down
3 changes: 3 additions & 0 deletions controller/test/e2e/tenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,9 @@ func setupTenantTest(ctx context.Context, mgmt managementCluster, timeouts nvke.
func (t *tenantTest) initCluster(ctx context.Context, b testSpec) {
GinkgoHelper()
t.spec = b.buildSpec(t.cfg, clusterNamePrefix, b.shape)
// The CLI-driven entry sets enableCPNodeRecycling at create, so the create-time
// flag goes through `nvkectl create cluster`. validateNvkectlPostCreate checks it.
t.spec.EnableCPNodeRecycling = b.createVia == clientNvkectl
Expect(validateCAPDFailureDomainReuse(t.spec, b.validate.controlPlaneController, t.cfg.Lifecycle.ReuseCluster)).To(Succeed())
if b.validate.controlPlaneController && t.spec.Backend == nvke.BackendCAPD {
Expect(t.spec.CAPDFailureDomains).NotTo(BeEmpty(), "CAPD control-plane-controller rows must advertise failure domains")
Expand Down
Loading