Files
nvke/cli/internal/nvkectl/patch.go
Jonathan MeierandClaude Opus 5 9b96cb09fc refactor(cli): move the nvkectl command tree into an importable package (#1407)
The command tree lives in package main, where it can be executed but never
imported. A second program therefore has no way to reach it, which is what a
generated CLI reference needs: the reference has to be built from the same
tree the binary runs, or the two drift.

Move the tree to internal/nvkectl and leave cmd/nvkectl as a shim. The split
follows what kubectl, clusterctl, gh and argocd each do for the same reason.

The build-time version strings stay in package main. The linker matches -X on
the package NAME, and for a command that name is "main", so a symbol moved
into internal/nvkectl would be silently left at its default -- no error, no
warning, just a binary reporting "dev". `make -C cli build` runs the binary and
fails on that, and it still passes.

Terminating the process stays in cmd/nvkectl. The internal package exposes
Run, which returns the status to exit with rather than calling os.Exit itself:
an os.Exit inside an importable package takes down whatever imported it,
skipping every deferred close, flush and cleanup still outstanding. Run also
hands the signals back and releases its watcher goroutine before returning, so
it leaves a caller's signal handling as it found it. Two tests cover this, and
both fail loudly if it regresses -- an os.Exit would take the test binary with
it.

contract_test.go stays in cmd/nvkectl too. It builds the binary from its own
directory and runs it as a process, referencing no symbol from the package, so
it keeps testing the same boundary from the same place.

The CI path filters move with the files. Three workflows selected the old
location:

  - capd-e2e.yml and the cwe_facing regex in e2e-pr-path-filter.yml both
    matched cli/cmd/**. controller/hack/ci/nvkectl-smoke.sh drives config
    set-site, config view, create cluster and delete nodepool against a live
    controller, and all four now sit in internal/nvkectl, so without this a
    later change to any of them would skip that lane.
  - kind-stack-from-release.yml named cli/cmd/nvkectl/validate.go and
    cli/cmd/nvkectl/render.go by exact path; both are repointed.

cmd/ stays in the first two lists: it still holds main and the contract test.

No behaviour change: the help output of all 46 commands is byte-identical to a
binary built from main.

Signed-off-by: Jonathan Meier <jomeier@nvidia.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-10-15 14:12:26 -04:00

22 lines
556 B
Go

// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package nvkectl
import (
"github.com/spf13/cobra"
"github.com/dsx-ai-factory/nvke/cli/internal/controller/clusters"
"github.com/dsx-ai-factory/nvke/cli/internal/controller/nodepools"
)
func newPatchCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "patch",
Short: "Patch a resource",
}
cmd.AddCommand(clusters.NewPatchCmd(loadClient))
cmd.AddCommand(nodepools.NewPatchCmd(loadClient))
return cmd
}