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
81 changes: 53 additions & 28 deletions internal/cli/cluster_pterodactyl.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ func applyPterodactylRelease(cmd *cobra.Command, install pterodactylInstall) err
if err := nrinstall.AnnotateOperatorCRDsKeep(ctx, kubeconfig, nil); err != nil {
return err
}
// Local chart checkouts need the Alloy subchart vendored (same as proxmox-operator).
if !strings.HasPrefix(install.Chart, "oci://") {
dep := exec.CommandContext(ctx, "helm", "dependency", "build", install.Chart)
dep.Stdout = cmd.OutOrStdout()
dep.Stderr = cmd.ErrOrStderr()
if err := dep.Run(); err != nil {
return fmt.Errorf("helm dependency build for pterodactyl-operator: %w", err)
}
}
helmArgs := pterodactylHelmArgs(install, kubeconfig)
helm := exec.CommandContext(ctx, "helm", helmArgs...)
helm.Stdout = cmd.OutOrStdout()
Expand All @@ -263,7 +272,9 @@ func applyPterodactylRelease(cmd *cobra.Command, install pterodactylInstall) err
if err := nrinstall.EnsurePterodactylLiqoRBAC(ctx, kubeconfig); err != nil {
return fmt.Errorf("update Liqo reflection RBAC: %w", err)
}
fmt.Fprintln(cmd.OutOrStdout(), "panel keys are stored only in the agent Secret")
if _, err := fmt.Fprintln(cmd.OutOrStdout(), "panel keys are stored only in the agent Secret"); err != nil {
return err
}
return nil
}

Expand All @@ -273,6 +284,8 @@ func pterodactylHelmArgs(install pterodactylInstall, kubeconfig string) []string
"--namespace", install.Namespace,
"--create-namespace",
"--set", "crds.enabled=false",
"--set", "consoleGateway.enabled=true",
"--set-string", "consoleGateway.namespace=" + config.DefaultPterodactylConsoleNamespace,
"--set-string", "panel.url=" + install.PanelURL,
"--set-string", "panel.existingSecret=" + install.SecretName,
}
Expand Down Expand Up @@ -417,33 +430,45 @@ func withKubeconfig(kubeconfig string, args ...string) []string {
}

func applyPanelSecret(ctx context.Context, install pterodactylInstall, kubeconfig string) error {
ns := exec.CommandContext(ctx, "kubectl", withKubeconfig(kubeconfig, "create", "namespace", install.Namespace)...)
if out, err := ns.CombinedOutput(); err != nil && !strings.Contains(string(out), "AlreadyExists") {
return fmt.Errorf("create namespace: %w", err)
}
manifest := map[string]any{
"apiVersion": "v1",
"kind": "Secret",
"metadata": map[string]string{
"name": install.SecretName,
"namespace": install.Namespace,
},
"type": "Opaque",
"data": map[string]string{
"PANEL_URL": base64.StdEncoding.EncodeToString([]byte(install.PanelURL)),
"APPLICATION_KEY": base64.StdEncoding.EncodeToString([]byte(install.ApplicationKey)),
"CLIENT_KEY": base64.StdEncoding.EncodeToString([]byte(install.ClientKey)),
"PANEL_USER_ID": base64.StdEncoding.EncodeToString([]byte(install.PanelUserID)),
},
}
raw, err := json.Marshal(manifest)
if err != nil {
return fmt.Errorf("encode panel secret: %w", err)
}
apply := exec.CommandContext(ctx, "kubectl", withKubeconfig(kubeconfig, "apply", "-f", "-")...)
apply.Stdin = strings.NewReader(string(raw))
if _, err := apply.CombinedOutput(); err != nil {
return fmt.Errorf("write panel secret: %w", err)
// Same as Proxmox credentials: operator Helm NS plus the offloaded console NS.
namespaces := []string{install.Namespace, config.DefaultPterodactylConsoleNamespace}
for _, namespace := range namespaces {
ns := exec.CommandContext(ctx, "kubectl", withKubeconfig(kubeconfig, "create", "namespace", namespace)...)
if out, err := ns.CombinedOutput(); err != nil && !strings.Contains(string(out), "AlreadyExists") {
return fmt.Errorf("create namespace %s: %w", namespace, err)
}
manifest := map[string]any{
"apiVersion": "v1",
"kind": "Secret",
"metadata": map[string]any{
"name": install.SecretName,
"namespace": namespace,
"annotations": map[string]string{
// Panel keys must never appear on the mothership via Liqo.
"liqo.io/skip-reflection": "true",
},
},
"type": "Opaque",
"data": map[string]string{
"PANEL_URL": base64.StdEncoding.EncodeToString([]byte(install.PanelURL)),
"APPLICATION_KEY": base64.StdEncoding.EncodeToString([]byte(install.ApplicationKey)),
"CLIENT_KEY": base64.StdEncoding.EncodeToString([]byte(install.ClientKey)),
"PANEL_USER_ID": base64.StdEncoding.EncodeToString([]byte(install.PanelUserID)),
},
}
raw, err := json.Marshal(manifest)
if err != nil {
return fmt.Errorf("encode panel secret: %w", err)
}
apply := exec.CommandContext(ctx, "kubectl", withKubeconfig(kubeconfig, "apply", "-f", "-")...)
apply.Stdin = strings.NewReader(string(raw))
if out, err := apply.CombinedOutput(); err != nil {
msg := strings.TrimSpace(string(out))
if msg == "" {
msg = err.Error()
}
return fmt.Errorf("write panel secret in %s: %s", namespace, msg)
}
}
return nil
}
8 changes: 8 additions & 0 deletions internal/cli/cluster_pterodactyl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"testing"

"github.com/spf13/cobra"

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

func clearPterodactylEnv(t *testing.T) {
Expand Down Expand Up @@ -47,6 +49,12 @@ func TestPterodactylHelmArgsDisablesCRDSubchart(t *testing.T) {
if !strings.Contains(joined, "--set crds.enabled=false") {
t.Fatalf("operator chart must not adopt CRDs installed before peering: %s", joined)
}
if !strings.Contains(joined, "consoleGateway.enabled=true") {
t.Fatalf("console gateway must be enabled for Liqo offload parity with vnc-gateway: %s", joined)
}
if !strings.Contains(joined, "consoleGateway.namespace="+config.DefaultPterodactylConsoleNamespace) {
t.Fatalf("console gateway must land in %s: %s", config.DefaultPterodactylConsoleNamespace, joined)
}
}

func TestPterodactylHelmArgsSetsAlloy(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions internal/cli/cluster_register_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,14 @@ func collectOffloadNamespaces(opts clusterRegisterOpts) []string {
out = append(out, ns)
}

// VNC first (production default). The game console Service is offloaded the same
// way when --pterodactyl is set: local pterodactyl-system, remote {agentID}-pterodactyl-system.
// VNC first (production default). Game console is the same shape: offload
// pterodactyl-console only (local → {agentID}-pterodactyl-console). Operator,
// exporter, and Alloy stay in pterodactyl-system and are not offloaded.
// Operator is only included when explicitly set via --operator-namespace
// (normally offloaded from the remote cluster after inbound peering).
add(opts.vncGatewayNamespace)
if opts.installPterodactyl {
add(config.DefaultPterodactylOperatorHelmNamespace)
add(config.DefaultPterodactylConsoleNamespace)
}
add(opts.operatorNamespace)
for _, ns := range opts.offloadNamespaces {
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cluster_register_opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestCollectOffloadNamespaces(t *testing.T) {
vncGatewayNamespace: config.DefaultVNCGatewayNamespace,
installPterodactyl: true,
})
wantGame := []string{config.DefaultVNCGatewayNamespace, config.DefaultPterodactylOperatorHelmNamespace}
wantGame := []string{config.DefaultVNCGatewayNamespace, config.DefaultPterodactylConsoleNamespace}
if len(withGame) != len(wantGame) {
t.Fatalf("got %v, want %v", withGame, wantGame)
}
Expand Down
19 changes: 14 additions & 5 deletions internal/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const (
// DefaultProxmoxOperatorCRDsChartOCI is CRDs-only; install on every provider so Liqo can watch both API groups.
DefaultProxmoxOperatorCRDsChartOCI = "oci://" + DefaultHarborRegistry + "/" + DefaultHarborPublicProject + "/proxmox-operator-crds"
// DefaultProxmoxOperatorChartVersion is the chart version (no leading v).
DefaultProxmoxOperatorChartVersion = "0.1.9"
DefaultProxmoxOperatorChartVersion = "0.1.10"
// DefaultProxmoxOperatorHelmRelease is the Helm release name (workload = release-chart).
DefaultProxmoxOperatorHelmRelease = "operator"
// DefaultProxmoxOperatorHelmNamespace is the runtime namespace for the operator chart.
Expand All @@ -153,7 +153,7 @@ const (
// DefaultVirtFusionOperatorCRDsChartOCI is CRDs-only (install alongside Proxmox CRDs on every provider).
DefaultVirtFusionOperatorCRDsChartOCI = "oci://" + DefaultHarborRegistry + "/" + DefaultHarborPublicProject + "/virtfusion-operator-crds"
// DefaultVirtFusionOperatorChartVersion is the VirtFusion chart version (no leading v).
DefaultVirtFusionOperatorChartVersion = "0.1.9"
DefaultVirtFusionOperatorChartVersion = "0.1.10"
// DefaultVirtFusionOperatorHelmNamespace is the runtime namespace for the VirtFusion operator chart.
DefaultVirtFusionOperatorHelmNamespace = "virtfusion-system"
// VirtFusionCRDAPIGroup is the API group registered by virtfusion-operator CRDs.
Expand All @@ -164,7 +164,7 @@ const (
// DefaultSolusVMOperatorCRDsChartOCI is CRDs-only (install alongside other hypervisor CRDs on every provider).
DefaultSolusVMOperatorCRDsChartOCI = "oci://" + DefaultHarborRegistry + "/" + DefaultHarborPublicProject + "/solusvm-operator-crds"
// DefaultSolusVMOperatorChartVersion is the SolusVM chart version (no leading v).
DefaultSolusVMOperatorChartVersion = "0.1.9"
DefaultSolusVMOperatorChartVersion = "0.1.10"
// DefaultSolusVMOperatorHelmNamespace is the runtime namespace for the SolusVM operator chart.
DefaultSolusVMOperatorHelmNamespace = "solusvm-system"
// SolusVMCRDAPIGroup is the API group registered by solusvm-operator CRDs.
Expand All @@ -173,9 +173,12 @@ const (
// Pterodactyl is a second release on the agent, not a hypervisor driver.
DefaultPterodactylOperatorChartOCI = "oci://" + DefaultHarborRegistry + "/" + DefaultHarborPublicProject + "/pterodactyl-operator"
DefaultPterodactylOperatorCRDsChartOCI = "oci://" + DefaultHarborRegistry + "/" + DefaultHarborPublicProject + "/pterodactyl-operator-crds"
DefaultPterodactylOperatorChartVersion = "0.1.0"
DefaultPterodactylOperatorChartVersion = "0.1.10"
DefaultPterodactylOperatorHelmNamespace = "pterodactyl-system"
PterodactylCRDAPIGroup = "gs.pterodactyl.com"
// DefaultPterodactylConsoleNamespace is provider-local and offloaded like vnc-gateway.
// pterodactyl-system (operator, exporter, Alloy) stays local on the agent.
DefaultPterodactylConsoleNamespace = "pterodactyl-console"
PterodactylCRDAPIGroup = "gs.pterodactyl.com"
// DefaultHypervisorCRDsHelmNamespace is where standalone CRD charts are
// installed (cluster-scoped CRDs, not the operator runtime namespace).
DefaultHypervisorCRDsHelmNamespace = "kube-system"
Expand Down Expand Up @@ -212,6 +215,7 @@ const (
SuffixHelmVirtFusionOperator = "-virtfusion-operator"
SuffixHelmSolusVMOperator = "-solusvm-operator"
SuffixHelmPterodactylOperator = "-pterodactyl-operator"
SuffixHelmPterodactylConsole = "-console"
SuffixHelmAlloy = "-alloy"
SuffixHelmExporter = "-exporter"
SuffixHelmVNCGateway = "-vnc-gateway"
Expand Down Expand Up @@ -336,6 +340,11 @@ func HelmPterodactylExporterDeployName(release string) string {
return HelmPterodactylOperatorDeployName(release) + SuffixHelmExporter
}

// HelmPterodactylConsoleDeployName returns the console bridge Deployment in pterodactyl-console.
func HelmPterodactylConsoleDeployName(release string) string {
return HelmPterodactylOperatorDeployName(release) + SuffixHelmPterodactylConsole
}

// HelmSolusVMVNCGatewayDeployName returns the SolusVM VNC gateway Deployment name.
func HelmSolusVMVNCGatewayDeployName(release string) string {
return HelmSolusVMOperatorDeployName(release) + SuffixHelmVNCGateway
Expand Down
3 changes: 2 additions & 1 deletion internal/install/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ func (c *ClusterCleaner) UnpeerLiqo(ctx context.Context, remoteKubeconfig string
// and a later register is not blocked by a leftover RemoteNamespaceName.
//
// DeleteAgent on the platform only unoffloads the mothership operator namespace. The
// provider-local offload (vnc-gateway) lives here and must be removed locally.
// provider-local offloads (vnc-gateway, pterodactyl-console) live here and must be
// removed locally.
func (c *ClusterCleaner) UnoffloadNamespaces(ctx context.Context) error {
namespaces, err := c.listOffloadedNamespaces(ctx)
if err != nil {
Expand Down
46 changes: 24 additions & 22 deletions internal/verify/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@ const (
DefaultDeploymentReplicas int32 = 1

// Check display names (stable report identifiers, not Kubernetes object names).
CheckNameScope = "scope"
CheckNameAPI = "api"
CheckNameNodes = "nodes"
CheckNameNamespace = "namespace"
CheckNameNamespaces = "namespaces"
CheckNameCalicoNode = "calico-node"
CheckNameHealth = "health"
CheckNamePeer = "peer"
CheckNameClient = "client"
CheckNameProvisioned = "provisioned"
CheckNameInboundPeering = "inbound-peering"
CheckNameServiceStatus = "service-status"
CheckNameRemoteNamespace = "remote-namespace"
CheckNameHelmWorkloads = "helm-workloads"
CheckNameHelmNamespace = "helm-namespace"
CheckNameCRDs = "crds"
CheckNameOperatorDeploy = "operator-deployment"
CheckNameAlloy = "alloy"
CheckNameExporter = "exporter"
CheckNameVNCNamespace = "vnc-namespace"
CheckNameVNCGateway = "vnc-gateway"
CheckNameMimirSecret = "mimir-secret"
CheckNameScope = "scope"
CheckNameAPI = "api"
CheckNameNodes = "nodes"
CheckNameNamespace = "namespace"
CheckNameNamespaces = "namespaces"
CheckNameCalicoNode = "calico-node"
CheckNameHealth = "health"
CheckNamePeer = "peer"
CheckNameClient = "client"
CheckNameProvisioned = "provisioned"
CheckNameInboundPeering = "inbound-peering"
CheckNameServiceStatus = "service-status"
CheckNameRemoteNamespace = "remote-namespace"
CheckNameHelmWorkloads = "helm-workloads"
CheckNameHelmNamespace = "helm-namespace"
CheckNameCRDs = "crds"
CheckNameOperatorDeploy = "operator-deployment"
CheckNameAlloy = "alloy"
CheckNameExporter = "exporter"
CheckNameVNCNamespace = "vnc-namespace"
CheckNameVNCGateway = "vnc-gateway"
CheckNamePterodactylConsoleNS = "pterodactyl-console-namespace"
CheckNamePterodactylConsole = "pterodactyl-console"
CheckNameMimirSecret = "mimir-secret"
)
19 changes: 19 additions & 0 deletions internal/verify/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,25 @@ func (v *Verifier) checkPterodactylOperator(ctx context.Context, sec SectionResu
sec.Checks = append(sec.Checks, checkDeployment(ctx, cs, SectionOperator, CheckNameExporter,
helmNS, config.HelmPterodactylExporterDeployName(release))...)

consoleNS := config.DefaultPterodactylConsoleNamespace
if _, err := cs.CoreV1().Namespaces().Get(ctx, consoleNS, metav1.GetOptions{}); err != nil {
message := fmt.Sprintf("namespace %s: %v", consoleNS, err)
if apierrors.IsNotFound(err) {
message = fmt.Sprintf("namespace %s missing: %v", consoleNS, err)
}
sec.Checks = append(sec.Checks, Check{
Section: SectionOperator, Name: CheckNamePterodactylConsoleNS, Status: StatusFail,
Message: message,
})
} else {
sec.Checks = append(sec.Checks, Check{
Section: SectionOperator, Name: CheckNamePterodactylConsoleNS, Status: StatusPass,
Message: fmt.Sprintf("namespace %s present", consoleNS),
})
sec.Checks = append(sec.Checks, checkDeployment(ctx, cs, SectionOperator, CheckNamePterodactylConsole,
consoleNS, config.HelmPterodactylConsoleDeployName(release))...)
}

sec.Checks = append(sec.Checks, mimirSecretCheck(ctx, cs, helmNS)...)
return sec
}
Expand Down
9 changes: 8 additions & 1 deletion internal/verify/verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,12 @@ func TestPterodactylOnlyVerifyChecksPterodactylChart(t *testing.T) {
release := opts.OperatorRelease
replicas := int32(1)
ready := appsv1.DeploymentStatus{ReadyReplicas: 1, UpdatedReplicas: 1}
consoleNS := config.DefaultPterodactylConsoleNamespace
clientset := fake.NewClientset(
readyNode("provider", false),
&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: config.DefaultOperatorRemoteNamespace}},
&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: ns}},
&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: consoleNS}},
&appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{Name: config.HelmPterodactylOperatorDeployName(release), Namespace: ns},
Spec: appsv1.DeploymentSpec{Replicas: &replicas},
Expand All @@ -336,6 +338,11 @@ func TestPterodactylOnlyVerifyChecksPterodactylChart(t *testing.T) {
Spec: appsv1.DeploymentSpec{Replicas: &replicas},
Status: ready,
},
&appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{Name: config.HelmPterodactylConsoleDeployName(release), Namespace: consoleNS},
Spec: appsv1.DeploymentSpec{Replicas: &replicas},
Status: ready,
},
&appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{Name: config.HelmAlloyDaemonSetName(release), Namespace: ns},
Status: appsv1.DaemonSetStatus{DesiredNumberScheduled: 1, NumberReady: 1},
Expand All @@ -351,7 +358,7 @@ func TestPterodactylOnlyVerifyChecksPterodactylChart(t *testing.T) {
v := newVerifier(opts, fakeKubeClient{clientset: clientset}, nil)

section := v.checkOperator(context.Background())
for _, name := range []string{CheckNameHelmNamespace, CheckNameCRDs, CheckNameOperatorDeploy, CheckNameAlloy, CheckNameExporter, CheckNameMimirSecret} {
for _, name := range []string{CheckNameHelmNamespace, CheckNameCRDs, CheckNameOperatorDeploy, CheckNameAlloy, CheckNameExporter, CheckNamePterodactylConsoleNS, CheckNamePterodactylConsole, CheckNameMimirSecret} {
check := findCheck(t, section, name)
if check.Status != StatusPass {
t.Fatalf("%s status=%s message=%s", name, check.Status, check.Message)
Expand Down
Loading