Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- `nr cluster liqo upgrade` upgrades an existing Liqo release to the pinned Harbor chart. It applies the chart CRDs, then runs Helm with `--reset-then-reuse-values` so the cluster id and provider values stay. It does not ask for a hypervisor token. Run it on the agent together with `nr cluster operator upgrade`.

## [1.0.20] - 2026-11-29

### Changed
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ If registration is interrupted:
nr cluster register --resume --name edge-ams-01 --org-id <org-uuid>
```

Upgrade the operator later without re-entering hypervisor tokens:
Upgrade an existing agent without re-entering hypervisor tokens:

```bash
nr cluster liqo upgrade
nr cluster operator upgrade
```

`nr cluster liqo upgrade` moves Liqo to the pinned chart and image and keeps the cluster id. The gateway restarts, so the peer can blip. `nr cluster operator upgrade` moves the hypervisor operator chart and image.

`nr cluster register --resume --reinstall-operator` also reuses existing Secrets unless you pass credentials (that path is for rotating tokens).

## Common commands
Expand All @@ -87,6 +90,7 @@ nr auth status
nr cluster status --name edge-ams-01
nr cluster verify --name edge-ams-01
nr cluster health --name edge-ams-01
nr cluster liqo upgrade
nr cluster operator upgrade
nr cluster deregister --name edge-ams-01
```
Expand Down
2 changes: 1 addition & 1 deletion docs/CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ This is not a `--hypervisor-driver` value. Register the hypervisor agent first,

Registration checkpoints live under `~/.nr/`. Do not copy these directories between machines.

Never commit tokens, kubeconfigs, or instances files to version control. If a hypervisor token leaked, rotate it and re-run `nr cluster register --resume --reinstall-operator` with the new credentials (env or instances file). Chart-only upgrades use `nr cluster operator upgrade` and do not rewrite Secrets.
Never commit tokens, kubeconfigs, or instances files to version control. If a hypervisor token leaked, rotate it and re-run `nr cluster register --resume --reinstall-operator` with the new credentials (env or instances file). Chart-only upgrades use `nr cluster liqo upgrade` and `nr cluster operator upgrade`. Neither rewrites Secrets.
9 changes: 9 additions & 0 deletions docs/TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ nr cluster register --resume --name <same-name> --org-id <org-uuid>

Checkpoints live under `~/.nr/`. Use `nr cluster status` and `nr cluster debug` for details.

**Upgrade Liqo and the operator (no hypervisor tokens)**

```bash
nr cluster liqo upgrade
nr cluster operator upgrade
```

`nr cluster liqo upgrade` reuses the Liqo cluster id and Helm values, applies the chart CRDs, and sets the image tag. It does not need `NR_API_TOKEN` or `--org-id`. The gateway restarts and the peer can show Error until it returns to Connected.

**Upgrade operator charts (no hypervisor tokens)**

```bash
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ func handleResume(cmd *cobra.Command, ctx context.Context, stateManager *state.M
if err := runPostRegisterVerify(ctx, apiClient, log, installState.AgentID, registerOpts); err != nil {
return err
}
log.Info("Tip: upgrade charts with 'nr cluster operator upgrade', or --resume --reinstall-operator")
log.Info("Tip: upgrade with 'nr cluster liqo upgrade' and 'nr cluster operator upgrade', or --resume --reinstall-operator")
return nil
}

Expand Down
99 changes: 99 additions & 0 deletions internal/cli/cluster_liqo_upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package cli

import (
"context"
"fmt"

"github.com/spf13/cobra"

"github.com/noderings/cli/internal/config"
"github.com/noderings/cli/internal/install"
"github.com/noderings/cli/internal/logger"
)

const (
flagLiqoChart = "liqo-chart"
flagLiqoChartVersion = "liqo-chart-version"
flagLiqoTimeout = "timeout"
)

var clusterLiqoCmd = &cobra.Command{
Use: "liqo",
Short: "Manage the Liqo Helm release on this agent",
}

var clusterLiqoUpgradeCmd = &cobra.Command{
Use: "upgrade",
Short: "Upgrade the Liqo chart and images without re-peering",
Long: `Upgrade the existing Liqo Helm release on this agent to the CLI-pinned build.

Reuses the cluster id, network CIDRs, and custom-resource list already stored
on the release. Applies the chart CRDs first, then runs helm upgrade with
--reset-then-reuse-values so new chart keys render. Does not uninstall Liqo,
change the cluster id, or ask for a hypervisor token.

Does not require NR_API_TOKEN or --org-id. Run on the agent VM.

The WireGuard gateway restarts. The peer can show Error for a short time and
then return to Connected. ` + fmt.Sprintf("This CLI pins chart %s and image %s.", config.DefaultLiqoChartVersion, config.DefaultLiqoVersion),
Args: cobra.NoArgs,
RunE: runClusterLiqoUpgrade,
}

func init() {
clusterCmd.AddCommand(clusterLiqoCmd)
clusterLiqoCmd.AddCommand(clusterLiqoUpgradeCmd)
clusterLiqoUpgradeCmd.Flags().String(flagLiqoChart, "", "Local path or OCI ref for the Liqo chart (default: Harbor OCI pin)")
clusterLiqoUpgradeCmd.Flags().String(flagLiqoChartVersion, "", "Helm chart version (image tag is the same value with a leading v)")
clusterLiqoUpgradeCmd.Flags().String(flagLiqoTimeout, "", "Helm --wait timeout (default 10m)")
clusterLiqoUpgradeCmd.Flags().Bool(flagDryRun, false, "Print the Helm upgrade and exit")
}

func runClusterLiqoUpgrade(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
if ctx == nil {
ctx = context.Background()
}

cfgLoader := config.NewLoader()
cfg, err := cfgLoader.Load()
if err != nil {
return fmt.Errorf("load config: %w", err)
}
log, err := logger.NewLogger(cfg.Logging.Level, cfg.Logging.File)
if err != nil {
return err
}

chart, err := cmd.Flags().GetString(flagLiqoChart)
if err != nil {
return err
}
chartVersion, err := cmd.Flags().GetString(flagLiqoChartVersion)
if err != nil {
return err
}
timeout, err := cmd.Flags().GetString(flagLiqoTimeout)
if err != nil {
return err
}
dryRun, err := cmd.Flags().GetBool(flagDryRun)
if err != nil {
return err
}

if _, err := install.EnsureCLIBinDir(); err != nil {
log.Warnf("Could not add ~/.nr/bin to PATH: %v", err)
}
kubeconfig := install.EnsureReadableKubeconfig(ctx, "", log)
u, err := install.NewLiqoUpgrade(chart, chartVersion, kubeconfig, timeout)
if err != nil {
return err
}
if dryRun {
_, err := fmt.Fprint(cmd.OutOrStdout(), install.LiqoUpgradeDryRun(u))
return err
}
log.Infof("Liqo upgrade target chart %s tag %s", u.ChartVersion, u.ImageTag)
return install.UpgradeLiqoRelease(ctx, u, log)
}
221 changes: 221 additions & 0 deletions internal/install/liqo_upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
package install

import (
"context"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/noderings/cli/internal/config"
)

const (
liqoHelmRelease = "liqo"
liqoHelmValueTag = "tag"
liqoCRDRelDir = "charts/liqo-crds/crds"
liqoPulledChartPlaceholder = "<pulled-chart>"
defaultLiqoHelmTimeout = "10m"
helmFlagWait = "--wait"
helmFlagTimeout = "--timeout"
)

// LiqoUpgrade is an in-place Helm upgrade of an existing provider Liqo release.
// It reuses the cluster id, CIDRs, and custom-resource list already stored on the
// release. It does not install Liqo, rotate peering, or ask for a hypervisor token.
type LiqoUpgrade struct {
Chart string
ChartVersion string
ImageTag string
Release string
Namespace string
Kubeconfig string
Timeout string
}

// NewLiqoUpgrade builds an upgrade from the CLI pin. An empty chart uses the Harbor
// OCI chart. chartVersion is the Helm chart version (leading v is stripped). The
// image tag always keeps the v prefix.
func NewLiqoUpgrade(chart, chartVersion, kubeconfig, timeout string) (LiqoUpgrade, error) {
chart = strings.TrimSpace(chart)
if chart == "" {
chart = config.DefaultLiqoChartOCI
}
if strings.TrimSpace(timeout) == "" {
timeout = defaultLiqoHelmTimeout
}
u := LiqoUpgrade{
Chart: chart,
ChartVersion: liqoChartVersion(chartVersion),
ImageTag: liqoImageTag(chartVersion),
Release: liqoHelmRelease,
Namespace: config.DefaultLiqoNamespace,
Kubeconfig: strings.TrimSpace(kubeconfig),
Timeout: strings.TrimSpace(timeout),
}
return u, u.Validate()
}

func (u LiqoUpgrade) Validate() error {
if strings.TrimSpace(u.Chart) == "" {
return fmt.Errorf("liqo chart is required")
}
if strings.TrimSpace(u.ImageTag) == "" {
return fmt.Errorf("liqo image tag is required")
}
if strings.TrimSpace(u.Release) == "" || strings.TrimSpace(u.Namespace) == "" {
return fmt.Errorf("liqo release and namespace are required")
}
if strings.TrimSpace(u.Timeout) == "" {
return fmt.Errorf("liqo upgrade timeout is required")
}
if isOCIRef(u.Chart) && strings.TrimSpace(u.ChartVersion) == "" {
return fmt.Errorf("liqo chart version is required for an OCI chart")
}
// Helm splits one --set-string value on commas, so a comma in the tag can
// inject another key=value pair. Reject the separators before argv is built.
if err := rejectHelmSetSeparators("liqo chart version", u.ChartVersion); err != nil {
return err
}
if err := rejectHelmSetSeparators("liqo image tag", u.ImageTag); err != nil {
return err
}
return nil
}

func rejectHelmSetSeparators(field, value string) error {
if strings.ContainsAny(value, ",=") {
return fmt.Errorf("%s %q must not contain ',' or '='", field, value)
}
return nil
}

// LiqoUpgradeArgs is the helm argv for the in-place upgrade.
// --reset-then-reuse-values keeps the cluster id and provider values while
// picking up chart keys added since the previous release. --reuse-values alone
// leaves those keys nil and the new chart fails to render.
// This is helm upgrade without --install: a missing release must fail closed.
func LiqoUpgradeArgs(u LiqoUpgrade) []string {
args := []string{
helmCmdUpgrade, u.Release, u.Chart,
helmFlagNamespace, u.Namespace,
helmFlagResetThenReuseValues,
helmFlagSetString, liqoHelmValueTag + "=" + u.ImageTag,
helmFlagWait,
helmFlagTimeout, u.Timeout,
}
args = appendOCIChartVersion(args, u.Chart, u.ChartVersion)
return withKubeconfig(u.Kubeconfig, args)
}

// LiqoCRDDir is the chart directory of Liqo CRD manifests. Helm does not upgrade
// CRDs from a subchart on upgrade, and the new chart writes statusSync.
func LiqoCRDDir(chartPath string) (string, error) {
dir := filepath.Join(chartPath, liqoCRDRelDir)
st, err := os.Stat(dir)
if err != nil {
return "", fmt.Errorf("liqo chart %s CRD directory %s: %w", chartPath, dir, err)
}
if !st.IsDir() {
return "", fmt.Errorf("liqo chart %s CRD path %s is not a directory", chartPath, dir)
}
return dir, nil
}

// LiqoUpgradeDryRun is the command sequence UpgradeLiqoRelease runs.
// An OCI chart is pulled first. Helm then upgrades that extracted chart, so the
// upgrade argv has no --version.
func LiqoUpgradeDryRun(u LiqoUpgrade) string {
chartPath := u.Chart
var b strings.Builder
if isOCIRef(u.Chart) {
fmt.Fprintf(&b, "helm pull %s --version %s\n", u.Chart, u.ChartVersion)
chartPath = liqoPulledChartPlaceholder
}
fmt.Fprintf(&b, "kubectl apply --server-side --force-conflicts -f %s/%s\n", chartPath, liqoCRDRelDir)
fmt.Fprintf(&b, "helm %s\n", strings.Join(liqoExecutedUpgradeArgs(u, chartPath), " "))
return b.String()
}

func liqoExecutedUpgradeArgs(u LiqoUpgrade, chartPath string) []string {
run := u
run.Chart = chartPath
return LiqoUpgradeArgs(run)
}

// UpgradeLiqoRelease applies the chart CRDs, then upgrades the existing release.
func UpgradeLiqoRelease(ctx context.Context, u LiqoUpgrade, logger Logger) error {
if logger == nil {
logger = noopLogger{}
}
if err := u.Validate(); err != nil {
return err
}
ok, err := helmReleaseExists(ctx, u.Kubeconfig, u.Release, u.Namespace)
if err != nil {
return err
}
if !ok {
return fmt.Errorf("no Liqo Helm release %s in namespace %s. Install with nr cluster register", u.Release, u.Namespace)
}

chartPath, cleanup, err := resolveLiqoChart(ctx, u, logger)
if err != nil {
return err
}
if cleanup != nil {
defer cleanup()
}
crdDir, err := LiqoCRDDir(chartPath)
if err != nil {
return err
}
logger.Infof("Applying Liqo CRDs from %s", crdDir)
if err := runCmd(ctx, binKubectl, withKubeconfig(u.Kubeconfig, []string{
kubectlCmdApply, kubectlFlagServerSide, kubectlFlagForceConflicts,
kubectlFlagFilename, crdDir,
})...); err != nil {
return fmt.Errorf("apply liqo CRDs: %w", err)
}

args := liqoExecutedUpgradeArgs(u, chartPath)
logger.Infof("Upgrading Liqo chart %s tag=%s (reusing the existing cluster id)...", u.ChartVersion, u.ImageTag)
if err := runCmd(ctx, binHelm, args...); err != nil {
return fmt.Errorf("helm upgrade: %w", err)
}
logger.Infof("✓ Liqo chart %s / image %s", u.ChartVersion, u.ImageTag)
return nil
}

func resolveLiqoChart(ctx context.Context, u LiqoUpgrade, logger Logger) (string, func(), error) {
if !isOCIRef(u.Chart) {
if _, err := os.Stat(filepath.Join(u.Chart, helmChartFile)); err != nil {
return "", nil, fmt.Errorf("liqo chart %s: %w", u.Chart, err)
}
return u.Chart, nil, nil
}
mgr := NewLiqoManager(nil, nil, &LiqoConfig{
ChartOCI: u.Chart,
ChartVersion: u.ChartVersion,
}, logger)
return mgr.prepareLocalChart(ctx)
}

func liqoChartVersion(version string) string {
version = strings.TrimSpace(version)
if version == "" {
return config.DefaultLiqoChartVersion
}
return strings.TrimPrefix(version, "v")
}

func liqoImageTag(version string) string {
version = strings.TrimSpace(version)
if version == "" {
return config.DefaultLiqoVersion
}
if strings.HasPrefix(version, "v") {
return version
}
return "v" + version
}
Loading
Loading