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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ nr cluster register \

`--org-id` is required (or set `NR_ORGANIZATION_ID`). It only sends `X-Organization-ID`. A missing or unauthorized token still fails; a token from another organization cannot register into this one.

The CLI uses the organization hypervisor driver (`proxmox`, `virtfusion`, or `solusvm`). Pass `--hypervisor-driver` only to confirm it; a mismatch is rejected.
The CLI uses the organization hypervisor driver (`proxmox`, `virtfusion`, or `solusvm`). Pass `--hypervisor-driver` only to confirm it; a mismatch is rejected. `pterodactyl` is not a hypervisor driver. After the agent is registered, `nr cluster install-pterodactyl` installs the game server operator beside it.

`--agent-ip` must be an address assigned to a local interface on the VM (`ip -4 addr`). k3s uses it as `--node-ip`; a placeholder such as `1.1.1.1` fails preflight.

Expand Down
4 changes: 4 additions & 0 deletions docs/CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ TLS verification is off. No flag or env var is required.

TLS verification is off. No flag or env var is required.

### Pterodactyl (`nr cluster install-pterodactyl`)

This is not a `--hypervisor-driver` value. Register the hypervisor agent first, then install the game server operator. The command asks for the panel URL, both keys, and the panel user id, and shows the keys as you type. Export `PTERODACTYL_APPLICATION_KEY` and `PTERODACTYL_CLIENT_KEY` to the keys themselves to skip those prompts. The keys are stored in a Secret on the agent and are not sent to NodeRings.

## State

Registration checkpoints live under `~/.nr/`. Do not copy these directories between machines.
Expand Down
1 change: 1 addition & 0 deletions internal/cli/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ func runAgentCreate(cmd *cobra.Command, args []string) error {
hypervisorDriverRaw,
cmd.Flags().Changed("hypervisor-driver"),
orgDriver,
!cmd.Flags().Changed("hypervisor-driver"),
)
if err != nil {
return err
Expand Down
48 changes: 41 additions & 7 deletions internal/cli/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ func init() {
clusterRegisterCmd.Flags().Bool("reinstall-operator", false, "Re-run hypervisor operator Helm install even if that phase already succeeded (use with --resume). Reuses cluster Secrets unless hypervisor credentials are provided.")
clusterRegisterCmd.Flags().String("operator-chart", "", "Local path or OCI ref for the hypervisor operator chart (default: Harbor OCI or sibling checkout)")
clusterRegisterCmd.Flags().String("operator-chart-version", "", "Helm chart version when using OCI (default: "+config.DefaultProxmoxOperatorChartVersion+")")
clusterRegisterCmd.Flags().String("hypervisor-driver", "", "Required until the first agent in this organization is registered. After that, omit it or pass the same driver (proxmox, virtfusion, or solusvm).")
clusterRegisterCmd.Flags().String("hypervisor-driver", "", "Hypervisor for this agent: proxmox, virtfusion, or solusvm. Omit it with --pterodactyl to install game servers only. One hypervisor per organization.")
clusterRegisterCmd.Flags().Bool("pterodactyl", false, "Install the game server operator. Does not set a hypervisor. Combine with --hypervisor-driver to install both. Panel URL, keys, and user id are prompted unless set with flags or PTERODACTYL_* env.")
clusterRegisterCmd.Flags().String("panel-url", "", "Panel origin with no /admin, used with --pterodactyl (prompted, or PTERODACTYL_PANEL_URL)")
clusterRegisterCmd.Flags().String("application-key-file", "", "File containing the ptla_ application key (prompted, or PTERODACTYL_APPLICATION_KEY / PTERODACTYL_APPLICATION_KEY_FILE)")
clusterRegisterCmd.Flags().String("client-key-file", "", "File containing the ptlc_ client key (prompted, or PTERODACTYL_CLIENT_KEY / PTERODACTYL_CLIENT_KEY_FILE)")
clusterRegisterCmd.Flags().String("panel-user-id", "", "Panel user id that owns NodeRings servers (prompted, or PTERODACTYL_PANEL_USER_ID)")
clusterRegisterCmd.Flags().String("pterodactyl-chart", "", "Local chart path or OCI reference for the Pterodactyl operator")
clusterRegisterCmd.Flags().String("proxmox-instances-file", "", "YAML file with proxmox.instances list (or PROXMOX_INSTANCES_FILE)")
clusterRegisterCmd.Flags().String("virtfusion-instances-file", "", "YAML file with virtfusion.instances list (or VIRTFUSION_INSTANCES_FILE)")
clusterRegisterCmd.Flags().String("solusvm-instances-file", "", "YAML file with solusvm.instances list (or SOLUSVM_INSTANCES_FILE)")
Expand Down Expand Up @@ -148,10 +154,12 @@ func runClusterRegister(cmd *cobra.Command, args []string) error {
}

orgDriver := fetchOrganizationHypervisorDriver(ctx, apiClient)
installPterodactyl, _ := cmd.Flags().GetBool("pterodactyl")
hypervisorDriver, err := resolveHypervisorDriver(
hypervisorDriverRaw,
cmd.Flags().Changed("hypervisor-driver"),
orgDriver,
installPterodactyl && !cmd.Flags().Changed("hypervisor-driver"),
)
if err != nil {
return err
Expand All @@ -169,6 +177,8 @@ func runClusterRegister(cmd *cobra.Command, args []string) error {
operatorChartPath: operatorChartPath,
operatorChartVersion: operatorChartVersion,
hypervisorDriver: hypervisorDriver,
installPterodactyl: installPterodactyl,
command: cmd,
proxmoxInstancesFile: proxmoxInstancesFile,
virtfusionInstancesFile: virtfusionInstancesFile,
solusvmInstancesFile: solusvmInstancesFile,
Expand All @@ -189,6 +199,15 @@ func runClusterRegister(cmd *cobra.Command, args []string) error {
if err := validateRegisterHypervisorOpts(registerOpts); err != nil {
return err
}
if installPterodactyl {
if yes {
if _, err := loadPterodactylInstall(cmd, "pterodactyl-chart", true); err != nil {
return err
}
} else if err := preflightPterodactylInstall(cmd); err != nil {
return err
}
}

if err := applyDevRegisterProfile(cfg, devMode); err != nil {
return err
Expand Down Expand Up @@ -273,7 +292,7 @@ func runClusterRegister(cmd *cobra.Command, args []string) error {

// Handle resume
if resume {
return handleResume(ctx, stateManager, apiClient, log, configDir, skipPrechecks, dryRun, offline, cfg, registerOpts)
return handleResume(cmd, ctx, stateManager, apiClient, log, configDir, skipPrechecks, dryRun, offline, cfg, registerOpts)
}

// Handle dry-run
Expand All @@ -284,11 +303,14 @@ func runClusterRegister(cmd *cobra.Command, args []string) error {
if namespaces := collectOffloadNamespaces(registerOpts); len(namespaces) > 0 {
log.Infof("Would offload namespaces: %v", namespaces)
}
if registerOpts.skipOperatorInstall {
log.Infof("Would skip %s install", operatorHelmName(registerOpts.hypervisorDriver))
if registerOpts.hypervisorDriver == "" || registerOpts.skipOperatorInstall {
log.Info("Would skip the hypervisor operator")
} else {
log.Infof("Would install %s / vnc-gateway", operatorHelmName(registerOpts.hypervisorDriver))
}
if registerOpts.installPterodactyl {
log.Info("Would install the Pterodactyl operator")
}
log.Info("Would verify provider health (subsections scoped to register flags)")
return nil
}
Expand Down Expand Up @@ -530,10 +552,13 @@ func runClusterRegister(cmd *cobra.Command, args []string) error {
return err
}

// Step 9: Install hypervisor operator + vnc-gateway
// Step 9: Install hypervisor operator + vnc-gateway, then the game server operator when requested.
if err := runOperatorInstallPhase(ctx, apiClient, log, stateManager, agentID, registerOpts); err != nil {
return err
}
if err := ensurePterodactylRelease(cmd, registerOpts, agentID); err != nil {
return err
}

// Step 10: Verify provider cluster health (subsections honor register flags)
if err := runPostRegisterVerify(ctx, apiClient, log, agentID, registerOpts); err != nil {
Expand Down Expand Up @@ -769,7 +794,7 @@ func createAgent(ctx context.Context, apiClient *api.Client, name, agentIP, gate
func persistAgentHypervisorDriver(ctx context.Context, apiClient *api.Client, agentID, hypervisorDriver string) error {
apiDriver := hypervisorDriverToAPI(hypervisorDriver)
if apiDriver == nil {
return fmt.Errorf("hypervisor driver is required to register an agent")
return nil
}
genClient := apiClient.GetGeneratedClient()
resp, err := apiClient.DoWithAutoRefresh(ctx, 3, func() (*http.Response, error) {
Expand Down Expand Up @@ -836,7 +861,7 @@ func preparePlatformVersions(
}

// handleResume resumes a failed installation
func handleResume(ctx context.Context, stateManager *state.Manager, apiClient *api.Client, log *logger.Logger, configDir string, skipPrechecks, dryRun, offline bool, cfg *config.Config, registerOpts clusterRegisterOpts) error {
func handleResume(cmd *cobra.Command, ctx context.Context, stateManager *state.Manager, apiClient *api.Client, log *logger.Logger, configDir string, skipPrechecks, dryRun, offline bool, cfg *config.Config, registerOpts clusterRegisterOpts) error {
installState := stateManager.GetState()

if installState.AgentID == "" {
Expand Down Expand Up @@ -888,6 +913,9 @@ func handleResume(ctx context.Context, stateManager *state.Manager, apiClient *a

if installState.Phase == state.PhaseComplete && !operatorInstallPending {
log.Info("Installation already complete; verifying provider health...")
if err := ensurePterodactylRelease(cmd, registerOpts, installState.AgentID); err != nil {
return err
}
if err := runPostRegisterVerify(ctx, apiClient, log, installState.AgentID, registerOpts); err != nil {
return err
}
Expand Down Expand Up @@ -933,6 +961,9 @@ func handleResume(ctx context.Context, stateManager *state.Manager, apiClient *a
return resumeFromOperatorInstall(ctx, stateManager, apiClient, log, registerOpts)
case state.PhaseOperatorInstall:
log.Info("Operator install already completed; verifying before marking complete...")
if err := ensurePterodactylRelease(cmd, registerOpts, installState.AgentID); err != nil {
return err
}
if err := runPostRegisterVerify(ctx, apiClient, log, installState.AgentID, registerOpts); err != nil {
return err
}
Expand Down Expand Up @@ -1223,6 +1254,9 @@ func resumeFromOperatorInstall(ctx context.Context, stateManager *state.Manager,
if err := runOperatorInstallPhase(ctx, apiClient, log, stateManager, stateManager.GetAgentID(), registerOpts); err != nil {
return err
}
if err := ensurePterodactylRelease(registerOpts.command, registerOpts, stateManager.GetAgentID()); err != nil {
return err
}
if err := runPostRegisterVerify(ctx, apiClient, log, stateManager.GetAgentID(), registerOpts); err != nil {
return err
}
Expand Down
151 changes: 151 additions & 0 deletions internal/cli/cluster_hypervisor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package cli

import (
"context"
"fmt"
"os"
"os/exec"
"strings"

"github.com/spf13/cobra"

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

func init() {
cmd := &cobra.Command{
Use: "install-hypervisor",
Short: "Install one hypervisor operator",
Long: `Install proxmox, virtfusion, or solusvm on the current cluster.

Run it on a new agent, or after game servers are already installed.
An agent has one hypervisor. A second choice is rejected.
Pass --agent-id to store that driver on an agent registered with --pterodactyl only.`,
RunE: runInstallHypervisor,
}
cmd.Flags().String("hypervisor-driver", "", "proxmox, virtfusion, or solusvm (required)")
cmd.Flags().String("agent-id", "", "Agent UUID. Stores the driver when this agent had no hypervisor yet.")
cmd.Flags().BoolP("yes", "y", false, "Non-interactive: read hypervisor credentials from the environment or an instances file")
cmd.Flags().String("operator-chart", "", "Local path or OCI ref for the hypervisor operator chart")
cmd.Flags().String("operator-chart-version", "", "Helm chart version when using OCI")
cmd.Flags().String("proxmox-instances-file", "", "YAML file with proxmox.instances list (or PROXMOX_INSTANCES_FILE)")
cmd.Flags().String("virtfusion-instances-file", "", "YAML file with virtfusion.instances list (or VIRTFUSION_INSTANCES_FILE)")
cmd.Flags().String("solusvm-instances-file", "", "YAML file with solusvm.instances list (or SOLUSVM_INSTANCES_FILE)")
cmd.Flags().String("vnc-gateway-namespace", "", "VNC gateway namespace (default: vnc-gateway)")
clusterCmd.AddCommand(cmd)
}

func runInstallHypervisor(cmd *cobra.Command, _ []string) error {
if !cmd.Flags().Changed("hypervisor-driver") {
return UsageErrorf("--hypervisor-driver is required (proxmox, virtfusion, or solusvm)")
}
raw, _ := cmd.Flags().GetString("hypervisor-driver")
driver, err := parseHypervisorDriver(raw)
if err != nil {
return err
}
if strings.TrimSpace(raw) == "" {
return UsageErrorf("--hypervisor-driver is required (proxmox, virtfusion, or solusvm)")
}

present, err := installedHypervisorNamespaces()
if err != nil {
return err
}
if err := conflictingHypervisorNamespace(present, driver); err != nil {
return err
}

agentID, _ := cmd.Flags().GetString("agent-id")
agentID = strings.TrimSpace(agentID)
yes, _ := cmd.Flags().GetBool("yes")
chart, _ := cmd.Flags().GetString("operator-chart")
chartVersion, _ := cmd.Flags().GetString("operator-chart-version")
pveFile, _ := cmd.Flags().GetString("proxmox-instances-file")
vfFile, _ := cmd.Flags().GetString("virtfusion-instances-file")
svmFile, _ := cmd.Flags().GetString("solusvm-instances-file")
vncNS, _ := cmd.Flags().GetString("vnc-gateway-namespace")

opts := clusterRegisterOpts{
yes: yes,
hypervisorDriver: driver,
operatorChartPath: chart,
operatorChartVersion: chartVersion,
proxmoxInstancesFile: pveFile,
virtfusionInstancesFile: vfFile,
solusvmInstancesFile: svmFile,
vncGatewayNamespace: vncNS,
}
if err := validateRegisterHypervisorOpts(opts); err != nil {
return err
}

ctx := context.Background()
log, err := logger.NewLogger("info", "")
if err != nil {
return err
}
if agentID != "" || strings.TrimSpace(os.Getenv("MIMIR_BEARER_TOKEN")) == "" {
apiClient, apiErr := getAuthenticatedAPIClient(cmd)
if apiErr != nil {
return fmt.Errorf("log in, or set MIMIR_BEARER_TOKEN, before installing the hypervisor operator: %w", apiErr)
}
if agentID != "" {
orgDriver := fetchOrganizationHypervisorDriver(ctx, apiClient)
bound, bindErr := resolveHypervisorDriver(driver, true, orgDriver, false)
if bindErr != nil {
return bindErr
}
if err := persistAgentHypervisorDriver(ctx, apiClient, agentID, bound); err != nil {
return err
}
log.Infof("Stored hypervisor driver %s on agent %s", bound, agentID)
}
stateManager := state.NewManager(config.GetConfigDir(), agentID)
return runOperatorInstallPhase(ctx, apiClient, log, stateManager, agentID, opts)
}

stateManager := state.NewManager(config.GetConfigDir(), "install-hypervisor")
return runOperatorInstallPhase(ctx, nil, log, stateManager, "", opts)
}

func hypervisorNamespace(driver string) string {
switch driver {
case config.HypervisorDriverVirtFusion:
return config.DefaultVirtFusionOperatorHelmNamespace
case config.HypervisorDriverSolusVM:
return config.DefaultSolusVMOperatorHelmNamespace
default:
return config.DefaultProxmoxOperatorHelmNamespace
}
}

func conflictingHypervisorNamespace(present []string, requested string) error {
want := hypervisorNamespace(requested)
for _, ns := range present {
ns = strings.TrimSpace(ns)
if ns == "" || ns == want {
continue
}
return UsageErrorf("this cluster already has the %s hypervisor. An agent has one of proxmox, virtfusion, or solusvm", ns)
}
return nil
}

func installedHypervisorNamespaces() ([]string, error) {
known := []string{
config.DefaultProxmoxOperatorHelmNamespace,
config.DefaultVirtFusionOperatorHelmNamespace,
config.DefaultSolusVMOperatorHelmNamespace,
}
var found []string
for _, ns := range known {
check := exec.Command("kubectl", "get", "ns", ns)
if err := check.Run(); err == nil {
found = append(found, ns)
}
}
return found, nil
}
9 changes: 9 additions & 0 deletions internal/cli/cluster_inbound_peering.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ func runInboundPeeringPhase(
log.Warnf("Failed to save state: %v", err)
}

// The mothership virtual-kubelet starts as soon as this kubeconfig is uploaded.
// CRDs and Liqo roles have to exist on this cluster before that.
log.Info("Ensuring game catalog reflection on this cluster...")
if err := liqoManager.PrepareGameCatalogReflection(ctx); err != nil {
stateManager.SetError(state.PhaseInboundPeering, err.Error(), true)
_ = stateManager.Save()
return fmt.Errorf("prepare game catalog reflection: %w", err)
}

detectedRemoteClusterID, detectErr := liqoManager.GetPeeredClusterID(ctx)
neoClusterID, err := resolveRemoteClusterID(log, opts, detectedRemoteClusterID, detectErr)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions internal/cli/cluster_operator_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ func runOperatorInstallPhase(
agentID string,
opts clusterRegisterOpts,
) error {
if strings.TrimSpace(opts.hypervisorDriver) == "" {
log.Info("No hypervisor selected; skipping the hypervisor operator")
stateManager.AddCheckpoint(state.PhaseOperatorInstall, state.CheckpointStatusSuccess, "no hypervisor")
if err := stateManager.Save(); err != nil {
log.Warnf("Failed to save state: %v", err)
}
return nil
}
if opts.skipOperatorInstall {
log.Infof("Skipping %s install (--skip-operator-install)", operatorHelmName(opts.hypervisorDriver))
return nil
Expand Down
Loading
Loading