Skip to content

Commit 96f2a50

Browse files
claudewikkyk
authored andcommitted
test(e2e): verify ProxmoxMachine status addresses are populated
Add an e2e test that creates a workload cluster and verifies that every ProxmoxMachine has populated Status.Addresses with at least one MachineHostName and one MachineInternalIP entry. This would have caught the state machine bug fixed in c5fbf14 where reconcilePowerState set the wrong condition reason, causing reconcileMachineAddresses to be skipped entirely and leaving ProxmoxMachine.Status.Addresses empty. The helper verifyProxmoxMachineAddresses is added to common.go so it can be reused by other e2e specs. ref: 710, 714 https://claude.ai/code/session_01PEJQFPT9TvRGqFYJ1t3U1R
1 parent 22fd914 commit 96f2a50

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

test/e2e/capmox_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,33 @@ var _ = Describe("Workload cluster creation", func() {
137137
})
138138
})
139139

140+
Context("[Generic] Creating a cluster and verifying ProxmoxMachine status addresses", func() {
141+
It("Should have populated addresses on ProxmoxMachine status", func() {
142+
By("Creating a cluster with 1 control-plane and 1 worker node")
143+
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
144+
ClusterProxy: bootstrapClusterProxy,
145+
ConfigCluster: clusterctl.ConfigClusterInput{
146+
LogFolder: clusterctlLogFolder,
147+
ClusterctlConfigPath: clusterctlConfigPath,
148+
KubeconfigPath: bootstrapClusterProxy.GetKubeconfigPath(),
149+
InfrastructureProvider: clusterctl.DefaultInfrastructureProvider,
150+
Flavor: clusterctl.DefaultFlavor,
151+
Namespace: namespace.Name,
152+
ClusterName: clusterName,
153+
KubernetesVersion: e2eConfig.MustGetVariable(KubernetesVersion),
154+
ControlPlaneMachineCount: pointer.Int64Ptr(1),
155+
WorkerMachineCount: pointer.Int64Ptr(1),
156+
},
157+
WaitForClusterIntervals: e2eConfig.GetIntervals(specName, "wait-cluster"),
158+
WaitForControlPlaneIntervals: e2eConfig.GetIntervals(specName, "wait-control-plane"),
159+
WaitForMachineDeployments: e2eConfig.GetIntervals(specName, "wait-worker-nodes"),
160+
}, result)
161+
162+
By("Verifying ProxmoxMachine status addresses are populated")
163+
verifyProxmoxMachineAddresses(ctx, bootstrapClusterProxy, namespace.Name, clusterName)
164+
})
165+
})
166+
140167
Context("[Flatcar] Creating a highly available control-plane cluster with flatcar", func() {
141168
It("Should create a HA cluster with flatcar", func() {
142169
By("Creating a flatcar high available cluster")

test/e2e/common.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ import (
2525
"path/filepath"
2626

2727
. "github.com/onsi/ginkgo/v2"
28+
. "github.com/onsi/gomega"
2829
corev1 "k8s.io/api/core/v1"
2930
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3031
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
3132
"sigs.k8s.io/cluster-api/test/framework"
3233
"sigs.k8s.io/cluster-api/util"
34+
"sigs.k8s.io/controller-runtime/pkg/client"
35+
36+
infrav1 "github.com/ionos-cloud/cluster-api-provider-proxmox/api/v1alpha2"
3337
)
3438

3539
func Byf(format string, a ...interface{}) {
@@ -122,3 +126,42 @@ func dumpSpecResourcesAndCleanup(ctx context.Context, input cleanupInput) {
122126
input.AdditionalCleanup()
123127
}
124128
}
129+
130+
// verifyProxmoxMachineAddresses lists all ProxmoxMachine objects for a given cluster
131+
// and verifies that each machine has populated Status.Addresses with at least one
132+
// MachineHostName and one MachineInternalIP entry.
133+
// This catches state machine bugs where reconcileMachineAddresses is skipped.
134+
func verifyProxmoxMachineAddresses(ctx context.Context, clusterProxy framework.ClusterProxy, namespace, clusterName string) {
135+
Byf("Listing ProxmoxMachine objects for cluster %q in namespace %q", clusterName, namespace)
136+
machineList := &infrav1.ProxmoxMachineList{}
137+
Expect(clusterProxy.GetClient().List(ctx, machineList,
138+
client.InNamespace(namespace),
139+
client.MatchingLabels{clusterv1.ClusterNameLabel: clusterName},
140+
)).To(Succeed(), "Failed to list ProxmoxMachines")
141+
142+
Expect(machineList.Items).ToNot(BeEmpty(), "Expected at least one ProxmoxMachine for cluster %q", clusterName)
143+
144+
for i := range machineList.Items {
145+
machine := &machineList.Items[i]
146+
Byf("Verifying addresses for ProxmoxMachine %q", machine.Name)
147+
148+
Expect(machine.Status.Addresses).ToNot(BeEmpty(),
149+
"ProxmoxMachine %q has no addresses in Status.Addresses", machine.Name)
150+
151+
hasHostName := false
152+
hasInternalIP := false
153+
for _, addr := range machine.Status.Addresses {
154+
switch addr.Type {
155+
case clusterv1.MachineHostName:
156+
hasHostName = true
157+
case clusterv1.MachineInternalIP:
158+
hasInternalIP = true
159+
}
160+
}
161+
162+
Expect(hasHostName).To(BeTrue(),
163+
"ProxmoxMachine %q has no MachineHostName address", machine.Name)
164+
Expect(hasInternalIP).To(BeTrue(),
165+
"ProxmoxMachine %q has no MachineInternalIP address", machine.Name)
166+
}
167+
}

0 commit comments

Comments
 (0)