Skip to content

Commit e5f1f81

Browse files
authored
Merge pull request #2 from noderings/feat/agent-hypervisor-driver
Persist hypervisor driver on the agent at register
2 parents 07f550e + 8cb5699 commit e5f1f81

9 files changed

Lines changed: 79 additions & 18 deletions

File tree

‎internal/api/generated/openapi3.yaml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8735,6 +8735,11 @@ components:
87358735
type: string
87368736
description:
87378737
type: string
8738+
hypervisorDriver:
8739+
$ref: "#/components/schemas/v1PlatformDriver"
8740+
description: >-
8741+
Set when registering an existing (console-created) agent via CLI.
8742+
Must match the organization driver after the first registered agent.
87388743
AgentServiceUploadInboundPeeringConfigBody:
87398744
type: object
87408745
properties:
@@ -9623,6 +9628,9 @@ components:
96239628
type: string
96249629
serviceStatus:
96259630
$ref: "#/components/schemas/v1ServiceStatus"
9631+
hypervisorDriver:
9632+
$ref: "#/components/schemas/v1PlatformDriver"
9633+
description: Set when this agent is registered via CLI. Empty/UNSPECIFIED until then.
96269634
v1AgentGatewayRegion:
96279635
type: string
96289636
enum:

‎internal/api/generated/types.gen.go‎

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎internal/cli/agent.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func init() {
7373
agentCreateCmd.Flags().String("agent-ip", "", "Agent public IP address (required, must be valid public IP)")
7474
agentCreateCmd.Flags().String("gateway-region", "", "Gateway region (required)")
7575
agentCreateCmd.Flags().String("description", "", "Optional description for the agent")
76-
agentCreateCmd.Flags().String("hypervisor-driver", "", "Optional. Uses the organization hypervisor driver when omitted. Must match the organization if set.")
76+
agentCreateCmd.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).")
7777
agentCreateCmd.Flags().String("output", config.OutputFormatText, "Output format: text|json")
7878

7979
// agent list flags

‎internal/cli/cluster.go‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func init() {
6969
clusterRegisterCmd.Flags().Bool("reinstall-operator", false, "Re-run hypervisor operator Helm install even if that phase already succeeded (use with --resume)")
7070
clusterRegisterCmd.Flags().String("operator-chart", "", "Local path or OCI ref for the hypervisor operator chart (default: Harbor OCI or sibling checkout)")
7171
clusterRegisterCmd.Flags().String("operator-chart-version", "", "Helm chart version when using OCI (default: "+config.DefaultProxmoxOperatorChartVersion+")")
72-
clusterRegisterCmd.Flags().String("hypervisor-driver", "", "Optional. Uses the organization hypervisor driver when omitted. Must match the organization if set.")
72+
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).")
7373
clusterRegisterCmd.Flags().String("proxmox-instances-file", "", "YAML file with proxmox.instances list (or PROXMOX_INSTANCES_FILE)")
7474
clusterRegisterCmd.Flags().String("virtfusion-instances-file", "", "YAML file with virtfusion.instances list (or VIRTFUSION_INSTANCES_FILE)")
7575
clusterRegisterCmd.Flags().String("solusvm-instances-file", "", "YAML file with solusvm.instances list (or SOLUSVM_INSTANCES_FILE)")
@@ -351,6 +351,9 @@ func runClusterRegister(cmd *cobra.Command, args []string) error {
351351
if reused {
352352
log.Infof("Reusing agent '%s' (ID: %s)", name, agentID)
353353
}
354+
if err := persistAgentHypervisorDriver(ctx, apiClient, agentID, registerOpts.hypervisorDriver); err != nil {
355+
return fmt.Errorf("store hypervisor driver on agent: %w", err)
356+
}
354357

355358
if err := rejectStaleLocalCluster(ctx, previousLocalAgentID, agentID, force); err != nil {
356359
return err
@@ -747,6 +750,29 @@ func createAgent(ctx context.Context, apiClient *api.Client, name, agentIP, gate
747750
return *createResponse.Agent.Id, false, nil
748751
}
749752

753+
// persistAgentHypervisorDriver stores the hypervisor driver on the agent. Console
754+
// create leaves it empty; register (including --agent-id reuse) is what binds it.
755+
func persistAgentHypervisorDriver(ctx context.Context, apiClient *api.Client, agentID, hypervisorDriver string) error {
756+
apiDriver := hypervisorDriverToAPI(hypervisorDriver)
757+
if apiDriver == nil {
758+
return fmt.Errorf("hypervisor driver is required to register an agent")
759+
}
760+
genClient := apiClient.GetGeneratedClient()
761+
resp, err := apiClient.DoWithAutoRefresh(ctx, 3, func() (*http.Response, error) {
762+
return genClient.AgentServiceUpdateAgent(ctx, agentID, generated.AgentServiceUpdateAgentJSONRequestBody{
763+
HypervisorDriver: apiDriver,
764+
})
765+
})
766+
if err != nil {
767+
return fmt.Errorf("update agent hypervisor driver: %w", err)
768+
}
769+
defer func() { _ = resp.Body.Close() }()
770+
if resp.StatusCode >= 400 {
771+
return api.ParseError(resp)
772+
}
773+
return nil
774+
}
775+
750776
// preparePlatformVersions fetches server pins (unless offline), applies them to
751777
// config/state, and ensures helm/liqoctl are installed at the pinned versions.
752778
func preparePlatformVersions(
@@ -813,6 +839,10 @@ func handleResume(ctx context.Context, stateManager *state.Manager, apiClient *a
813839
log.Infof("Resuming installation for agent %s (%s)", installState.AgentID, installState.AgentName)
814840
log.Infof("Last phase: %s", installState.Phase)
815841

842+
if err := persistAgentHypervisorDriver(ctx, apiClient, installState.AgentID, registerOpts.hypervisorDriver); err != nil {
843+
return fmt.Errorf("store hypervisor driver on agent: %w", err)
844+
}
845+
816846
stateManager.SetRegisterScope(state.RegisterScope{
817847
DisableOffloading: registerOpts.disableOffloading,
818848
SkipOperatorInstall: registerOpts.skipOperatorInstall,

‎internal/cli/cluster_org.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ func listProviderOrganizations(ctx context.Context, client *api.Client) ([]provi
6969
return providerOrgsFromListJSON(body), nil
7070
}
7171

72-
// fetchOrganizationHypervisorDriver returns the canonical org driver, or empty
73-
// if the organization has not chosen one.
72+
// fetchOrganizationHypervisorDriver returns the canonical org driver derived
73+
// from registered agents, or empty if none have a hypervisor driver yet.
7474
func fetchOrganizationHypervisorDriver(ctx context.Context, client *api.Client) string {
7575
if client == nil {
7676
return ""

‎internal/cli/cluster_register_opts.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func resolveHypervisorDriver(flagRaw string, flagChanged bool, orgDriver string)
203203
if org != "" {
204204
return parseHypervisorDriver(org)
205205
}
206-
return "", UsageErrorf("this organization has no hypervisor driver")
206+
return "", UsageErrorf("this organization has no hypervisor driver yet. Pass --hypervisor-driver (proxmox, virtfusion, or solusvm) when registering the first agent")
207207
}
208208

209209
func hypervisorDriverToAPI(driver string) *generated.V1PlatformDriver {

‎internal/cli/cluster_register_opts_test.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cli
22

33
import (
44
"fmt"
5+
"strings"
56
"testing"
67

78
"github.com/noderings/cli/internal/config"
@@ -170,6 +171,8 @@ func TestResolveHypervisorDriver(t *testing.T) {
170171

171172
if _, err := resolveHypervisorDriver("", false, ""); err == nil {
172173
t.Fatal("expected error when org has no driver")
174+
} else if !strings.Contains(err.Error(), "--hypervisor-driver") {
175+
t.Fatalf("empty-org error should mention --hypervisor-driver, got %v", err)
173176
}
174177
got, err := resolveHypervisorDriver("", false, config.HypervisorDriverVirtFusion)
175178
if err != nil || got != config.HypervisorDriverVirtFusion {

‎internal/config/constants.go‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,23 @@ const (
3535
// DefaultNamespaceMappingStrategy is the default Liqo namespace mapping strategy.
3636
DefaultNamespaceMappingStrategy = "SelectedName"
3737

38+
// DefaultHarborRegistry is the container registry host for operator images
39+
// and charts. harbor.nrings.io is retired; do not use that hostname.
40+
DefaultHarborRegistry = "harbor.noderings.com"
41+
// DefaultHarborPublicProject is the public Harbor project. Provider-installed
42+
// Liqo, hypervisor operators, VNC gateway, and exporters live here so
43+
// clusters can pull without credentials. Private platform images (backend,
44+
// frontend, docs) stay under the noderings project.
45+
DefaultHarborPublicProject = "nrings"
46+
3847
// DefaultLiqoVersion is the default Liqo / liqoctl version pin.
3948
DefaultLiqoVersion = "v0.0.0-4600ebb8"
4049
// DefaultLiqoChartVersion is the Helm chart version (no leading v).
4150
DefaultLiqoChartVersion = "0.0.0-4600ebb8"
4251
// DefaultLiqoChartOCI is the OCI chart reference (without version tag).
43-
DefaultLiqoChartOCI = "oci://harbor.noderings.com/nrings/liqo"
52+
DefaultLiqoChartOCI = "oci://" + DefaultHarborRegistry + "/" + DefaultHarborPublicProject + "/liqo"
4453
// DefaultLiqoctlOCIRepo is the OCI project/repo prefix for liqoctl artifacts.
45-
DefaultLiqoctlOCIRepo = "harbor.noderings.com/nrings"
54+
DefaultLiqoctlOCIRepo = DefaultHarborRegistry + "/" + DefaultHarborPublicProject
4655
// DefaultLiqoNamespace is the Kubernetes namespace for Liqo components.
4756
DefaultLiqoNamespace = "liqo"
4857
// LiqoctlBinary is the Liqo CLI binary name expected on PATH.
@@ -76,13 +85,10 @@ const (
7685
// DefaultVNCGatewayNamespace is the provider-local namespace offloaded to the remote cluster.
7786
DefaultVNCGatewayNamespace = "vnc-gateway"
7887
// DefaultVNCGatewayImageRepository is the Harbor image RFB and Proxmox charts pull.
79-
DefaultVNCGatewayImageRepository = "harbor.noderings.com/nrings/vnc-gateway"
88+
DefaultVNCGatewayImageRepository = DefaultHarborRegistry + "/" + DefaultHarborPublicProject + "/vnc-gateway"
8089
// DefaultVNCGatewayImageTagProxmox is the stock Harbor tag. Proxmox readiness
8190
// and /v1/vnc/ws need this digest — do not retag a local-rfb build over it.
8291
DefaultVNCGatewayImageTagProxmox = "main"
83-
// DefaultHarborRegistry is the container registry host for operator images
84-
// and charts. harbor.nrings.io is retired; do not use it.
85-
DefaultHarborRegistry = "harbor.noderings.com"
8692
// DefaultVNCGatewayImageTagRFB is the local-rfb / current-gateway tag used by
8793
// VirtFusion and SolusVM (ready without Proxmox instances). Harbor publishes
8894
// both :main (Proxmox) and :rfb (VF/SVM). The CLI still loads a local build
@@ -115,9 +121,9 @@ const (
115121
DefaultFrontendBaseURL = "https://noderings.com"
116122

117123
// DefaultProxmoxOperatorChartOCI is the OCI chart for provider operator install.
118-
DefaultProxmoxOperatorChartOCI = "oci://harbor.noderings.com/nrings/proxmox-operator"
124+
DefaultProxmoxOperatorChartOCI = "oci://" + DefaultHarborRegistry + "/" + DefaultHarborPublicProject + "/proxmox-operator"
119125
// DefaultProxmoxOperatorCRDsChartOCI is CRDs-only; install on every provider so Liqo can watch both API groups.
120-
DefaultProxmoxOperatorCRDsChartOCI = "oci://harbor.noderings.com/nrings/proxmox-operator-crds"
126+
DefaultProxmoxOperatorCRDsChartOCI = "oci://" + DefaultHarborRegistry + "/" + DefaultHarborPublicProject + "/proxmox-operator-crds"
121127
// DefaultProxmoxOperatorChartVersion is the chart version (no leading v).
122128
DefaultProxmoxOperatorChartVersion = "0.1.2"
123129
// DefaultProxmoxOperatorHelmRelease is the Helm release name (workload = release-chart).
@@ -128,9 +134,9 @@ const (
128134
ProxmoxCRDAPIGroup = "vm.proxmox.com"
129135

130136
// DefaultVirtFusionOperatorChartOCI is the OCI chart for VirtFusion operator install.
131-
DefaultVirtFusionOperatorChartOCI = "oci://harbor.noderings.com/nrings/virtfusion-operator"
137+
DefaultVirtFusionOperatorChartOCI = "oci://" + DefaultHarborRegistry + "/" + DefaultHarborPublicProject + "/virtfusion-operator"
132138
// DefaultVirtFusionOperatorCRDsChartOCI is CRDs-only (install alongside Proxmox CRDs on every provider).
133-
DefaultVirtFusionOperatorCRDsChartOCI = "oci://harbor.noderings.com/nrings/virtfusion-operator-crds"
139+
DefaultVirtFusionOperatorCRDsChartOCI = "oci://" + DefaultHarborRegistry + "/" + DefaultHarborPublicProject + "/virtfusion-operator-crds"
134140
// DefaultVirtFusionOperatorChartVersion is the VirtFusion chart version (no leading v).
135141
DefaultVirtFusionOperatorChartVersion = "0.1.4"
136142
// DefaultVirtFusionOperatorHelmNamespace is the runtime namespace for the VirtFusion operator chart.
@@ -139,9 +145,9 @@ const (
139145
VirtFusionCRDAPIGroup = "vm.virtfusion.com"
140146

141147
// DefaultSolusVMOperatorChartOCI is the OCI chart for SolusVM 2 operator install.
142-
DefaultSolusVMOperatorChartOCI = "oci://harbor.noderings.com/nrings/solusvm-operator"
148+
DefaultSolusVMOperatorChartOCI = "oci://" + DefaultHarborRegistry + "/" + DefaultHarborPublicProject + "/solusvm-operator"
143149
// DefaultSolusVMOperatorCRDsChartOCI is CRDs-only (install alongside other hypervisor CRDs on every provider).
144-
DefaultSolusVMOperatorCRDsChartOCI = "oci://harbor.noderings.com/nrings/solusvm-operator-crds"
150+
DefaultSolusVMOperatorCRDsChartOCI = "oci://" + DefaultHarborRegistry + "/" + DefaultHarborPublicProject + "/solusvm-operator-crds"
145151
// DefaultSolusVMOperatorChartVersion is the SolusVM chart version (no leading v).
146152
DefaultSolusVMOperatorChartVersion = "0.1.3"
147153
// DefaultSolusVMOperatorHelmNamespace is the runtime namespace for the SolusVM operator chart.

‎internal/config/constants_vnc_test.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ func TestDefaultHarborRegistryIsNoderings(t *testing.T) {
66
if DefaultHarborRegistry != "harbor.noderings.com" {
77
t.Fatalf("DefaultHarborRegistry=%s want harbor.noderings.com (nrings.io is retired)", DefaultHarborRegistry)
88
}
9+
if DefaultHarborPublicProject != "nrings" {
10+
t.Fatalf("DefaultHarborPublicProject=%s want nrings (public provider images)", DefaultHarborPublicProject)
11+
}
12+
if DefaultVNCGatewayImageRepository != "harbor.noderings.com/nrings/vnc-gateway" {
13+
t.Fatalf("DefaultVNCGatewayImageRepository=%s want harbor.noderings.com/nrings/vnc-gateway", DefaultVNCGatewayImageRepository)
14+
}
15+
if DefaultLiqoChartOCI != "oci://harbor.noderings.com/nrings/liqo" {
16+
t.Fatalf("DefaultLiqoChartOCI=%s want oci://harbor.noderings.com/nrings/liqo", DefaultLiqoChartOCI)
17+
}
918
}
1019

1120
func TestResolveVNCGatewayImageTagDefaults(t *testing.T) {

0 commit comments

Comments
 (0)