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 hack/clean-e2e-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ while IFS= read -r name; do
fi

# Convert to a format that date can parse (handle both RFC3339 and 'YYYY-MM-DD HH:MM:SS...' formats)
normalized=$(echo "${created}" | sed 's/ /T/' | sed 's/ UTC$//')
normalized=$(echo "${created}" | sed 's/ /T/; s/ UTC$//')
created_ts=$(date -u -jf "%Y-%m-%dT%H:%M:%S" "${normalized%.*}" +%s 2>/dev/null \
|| date -u -d "${normalized}" +%s 2>/dev/null \
|| date -u -d "${created}" +%s 2>/dev/null \
Expand Down
42 changes: 33 additions & 9 deletions internal/controller/cloudscalecluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,17 @@ func TestCloudscaleClusterReconciler_Reconcile_EntryPoint(t *testing.T) {
// reconcileNormal to decide when to flip Status.Initialization.Provisioned.
func TestIsInfrastructureProvisioned(t *testing.T) {
cases := []struct {
name string
lbEnabled bool
networks []infrastructurev1beta2.NetworkStatus
endpointHost string
endpointPort int32
lbID string
lbPoolID string
lbListenerID string
wantProvisioned bool
name string
lbEnabled bool
networks []infrastructurev1beta2.NetworkStatus
endpointHost string
endpointPort int32
lbID string
lbPoolID string
lbListenerID string
floatingIP *infrastructurev1beta2.FloatingIPSpec
statusFloatingIP string
wantProvisioned bool
}{
{
name: "LB enabled and all resources present",
Expand Down Expand Up @@ -114,6 +116,26 @@ func TestIsInfrastructureProvisioned(t *testing.T) {
lbEnabled: false,
networks: []infrastructurev1beta2.NetworkStatus{{Name: "test", NetworkID: "network-123", SubnetID: "subnet-123", Managed: true}},
},
{
name: "Floating IP requested but status floating IP empty",
lbEnabled: false,
networks: []infrastructurev1beta2.NetworkStatus{{Name: "test", NetworkID: "network-123", SubnetID: "subnet-123", Managed: true}},
endpointHost: "1.2.3.4",
endpointPort: 6443,
floatingIP: &infrastructurev1beta2.FloatingIPSpec{Address: "203.0.113.10"},
statusFloatingIP: "",
wantProvisioned: false,
},
{
name: "Floating IP requested and status floating IP set",
lbEnabled: false,
networks: []infrastructurev1beta2.NetworkStatus{{Name: "test", NetworkID: "network-123", SubnetID: "subnet-123", Managed: true}},
endpointHost: "1.2.3.4",
endpointPort: 6443,
floatingIP: &infrastructurev1beta2.FloatingIPSpec{Address: "185.0.0.0"},
statusFloatingIP: "185.0.0.0",
wantProvisioned: true,
},
}

for _, tc := range cases {
Expand All @@ -126,12 +148,14 @@ func TestIsInfrastructureProvisioned(t *testing.T) {
ControlPlaneLoadBalancer: infrastructurev1beta2.LoadBalancerSpec{
Enabled: new(tc.lbEnabled),
},
FloatingIP: tc.floatingIP,
},
Status: infrastructurev1beta2.CloudscaleClusterStatus{
Networks: tc.networks,
LoadBalancerID: tc.lbID,
LoadBalancerPoolID: tc.lbPoolID,
LoadBalancerListenerID: tc.lbListenerID,
FloatingIP: tc.statusFloatingIP,
},
},
}
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/cloudscalemachine_servergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func (r *CloudscaleMachineReconciler) reconcileServerGroup(ctx context.Context,
// If we already have a server group ID, verify it still exists
if machineScope.CloudscaleMachine.Status.ServerGroupID != "" {
getCtx, cancel := context.WithTimeout(ctx, cloudscale.ReadTimeout)
defer cancel()
_, err := machineScope.CloudscaleClient.ServerGroups.Get(getCtx, machineScope.CloudscaleMachine.Status.ServerGroupID)
cancel()
if err == nil {
return ctrl.Result{}, nil
}
Expand All @@ -77,8 +77,8 @@ func (r *CloudscaleMachineReconciler) reconcileServerGroup(ctx context.Context,
// Search for existing server group by name and zone using cluster-level tags
// so that all machines in the cluster can find the same server group.
listCtx, cancelList := context.WithTimeout(ctx, cloudscale.ReadTimeout)
defer cancelList()
groups, err := machineScope.CloudscaleClient.ServerGroups.List(listCtx, cloudscalesdk.WithTagFilter(clusterOwnershipTags(machineScope.CloudscaleCluster)))
cancelList()
if err != nil {
return ctrl.Result{}, fmt.Errorf("listing server groups: %w", err)
}
Expand All @@ -101,8 +101,8 @@ func (r *CloudscaleMachineReconciler) reconcileServerGroup(ctx context.Context,
}

createCtx, cancelCreate := context.WithTimeout(ctx, cloudscale.WriteTimeout)
defer cancelCreate()
group, err := machineScope.CloudscaleClient.ServerGroups.Create(createCtx, req)
cancelCreate()
if err != nil {
if cloudscale.IsTimeoutError(err) {
requeueAfter := 5 * time.Second
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func validateCloudscaleResources(proxy framework.ClusterProxy, namespace, cluste
Expect(ptr.Deref(cloudscaleCluster.Status.Initialization.Provisioned, false)).To(BeTrue(), "CloudscaleCluster should be provisioned")

// Validate control plane endpoint
Expect(cloudscaleCluster.Spec.ControlPlaneEndpoint).NotTo(BeNil(), "ControlPlaneEndpoint should be set")
Expect(cloudscaleCluster.Spec.ControlPlaneEndpoint).NotTo(BeZero(), "ControlPlaneEndpoint should be set")
Expect(cloudscaleCluster.Spec.ControlPlaneEndpoint.Host).NotTo(BeEmpty(), "ControlPlaneEndpoint.Host should be set")
Expect(cloudscaleCluster.Spec.ControlPlaneEndpoint.Port).To(Equal(int32(6443)), "ControlPlaneEndpoint.Port should be 6443")

Expand Down