diff --git a/hack/clean-e2e-images.sh b/hack/clean-e2e-images.sh index 15b2b3e..a57a9b7 100755 --- a/hack/clean-e2e-images.sh +++ b/hack/clean-e2e-images.sh @@ -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 \ diff --git a/internal/controller/cloudscalecluster_controller_test.go b/internal/controller/cloudscalecluster_controller_test.go index 2568020..10f01e9 100644 --- a/internal/controller/cloudscalecluster_controller_test.go +++ b/internal/controller/cloudscalecluster_controller_test.go @@ -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", @@ -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 { @@ -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, }, }, } diff --git a/internal/controller/cloudscalemachine_servergroup.go b/internal/controller/cloudscalemachine_servergroup.go index b2dcfce..7e58e92 100644 --- a/internal/controller/cloudscalemachine_servergroup.go +++ b/internal/controller/cloudscalemachine_servergroup.go @@ -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 } @@ -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) } @@ -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 diff --git a/test/e2e/helpers.go b/test/e2e/helpers.go index e341a2e..fad8612 100644 --- a/test/e2e/helpers.go +++ b/test/e2e/helpers.go @@ -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")