From ab6bb875fabb4c968d13e8f6b3f8a14626c85d05 Mon Sep 17 00:00:00 2001 From: bilbo Date: Fri, 5 Jan 2024 15:09:03 +0100 Subject: [PATCH] lint --- controllers/openstackmachine_controller.go | 84 +++++++++++----------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/controllers/openstackmachine_controller.go b/controllers/openstackmachine_controller.go index 7c14e3d4f3..0905ecc162 100644 --- a/controllers/openstackmachine_controller.go +++ b/controllers/openstackmachine_controller.go @@ -349,60 +349,60 @@ func (r *OpenStackMachineReconciler) reconcileFloatingAddressFromPool(ctx contex } } - if claim.Status.AddressRef.Name != "" { - address := &ipamv1.IPAddress{} - addressKey := client.ObjectKey{Namespace: openStackMachine.Namespace, Name: claim.Status.AddressRef.Name} + if claim.Status.AddressRef.Name == "" { + scope.Logger().Info("Waiting for IPAddressClaim to be allocated", "name", claim.Name) + openStackMachine.Status.FloatingAddressFromPoolReady = pointer.Bool(false) + conditions.MarkFalse(openStackMachine, infrav1.FloatingAddressFromPoolReadyCondition, infrav1.FloatingAddressFromPoolWaitingForIpamProviderReason, clusterv1.ConditionSeverityWarning, "") + return nil + } - if err := r.Client.Get(ctx, addressKey, address); err != nil { - return err - } + address := &ipamv1.IPAddress{} + addressKey := client.ObjectKey{Namespace: openStackMachine.Namespace, Name: claim.Status.AddressRef.Name} - instanceAddresses := instanceNS.Addresses() - for _, instanceAddress := range instanceAddresses { - if instanceAddress.Address == address.Spec.Address && instanceAddress.Type == corev1.NodeExternalIP { - openStackMachine.Status.FloatingAddressFromPoolReady = pointer.Bool(true) - conditions.MarkTrue(openStackMachine, infrav1.FloatingAddressFromPoolReadyCondition) - return nil - } - } + if err := r.Client.Get(ctx, addressKey, address); err != nil { + return err + } - fip, err := networkingService.GetFloatingIP(address.Spec.Address) - if err != nil { - return err - } - if fip == nil { - conditions.MarkFalse(openStackMachine, infrav1.FloatingAddressFromPoolReadyCondition, infrav1.FloatingAddressFromPoolErrorReason, clusterv1.ConditionSeverityError, "floating IP does not exist") - return fmt.Errorf("floating IP %q does not exist", address.Spec.Address) + instanceAddresses := instanceNS.Addresses() + for _, instanceAddress := range instanceAddresses { + if instanceAddress.Address == address.Spec.Address { + openStackMachine.Status.FloatingAddressFromPoolReady = pointer.Bool(true) + conditions.MarkTrue(openStackMachine, infrav1.FloatingAddressFromPoolReadyCondition) + return nil } + } - port, err := computeService.GetManagementPort(openStackCluster, instanceStatus) - if err != nil { + fip, err := networkingService.GetFloatingIP(address.Spec.Address) + if err != nil { + return err + } + if fip == nil { + conditions.MarkFalse(openStackMachine, infrav1.FloatingAddressFromPoolReadyCondition, infrav1.FloatingAddressFromPoolErrorReason, clusterv1.ConditionSeverityError, "floating IP does not exist") + return fmt.Errorf("floating IP %q does not exist", address.Spec.Address) + } + + port, err := computeService.GetManagementPort(openStackCluster, instanceStatus) + if err != nil { + return err + } + + // Add finalizer to claim to prevent deletion until the floating IP is released + if controllerutil.AddFinalizer(claim, infrav1.IPClaimMachineFinalizer) { + if err := r.Client.Update(ctx, claim); err != nil { return err } - - // Add finalizer to claim to prevent deletion until the floating IP is released - if controllerutil.AddFinalizer(claim, infrav1.IPClaimMachineFinalizer) { + } + if err = networkingService.AssociateFloatingIP(openStackMachine, fip, port.ID); err != nil { + // Remove finalizer since we failed to associate the floating IP + if controllerutil.RemoveFinalizer(claim, infrav1.IPClaimMachineFinalizer) { if err := r.Client.Update(ctx, claim); err != nil { return err } } - if err = networkingService.AssociateFloatingIP(openStackMachine, fip, port.ID); err != nil { - // Remove finalizer since we failed to associate the floating IP - if controllerutil.RemoveFinalizer(claim, infrav1.IPClaimMachineFinalizer) { - if err := r.Client.Update(ctx, claim); err != nil { - return err - } - } - return err - } - - openStackMachine.Status.FloatingAddressFromPoolReady = pointer.Bool(true) - conditions.MarkTrue(openStackMachine, infrav1.FloatingAddressFromPoolReadyCondition) - } else { - scope.Logger().Info("Waiting for IPAddressClaim to be allocated", "name", claim.Name) - openStackMachine.Status.FloatingAddressFromPoolReady = pointer.Bool(false) - conditions.MarkFalse(openStackMachine, infrav1.FloatingAddressFromPoolReadyCondition, infrav1.FloatingAddressFromPoolWaitingForIpamProviderReason, clusterv1.ConditionSeverityWarning, "") + return err } + openStackMachine.Status.FloatingAddressFromPoolReady = pointer.Bool(true) + conditions.MarkTrue(openStackMachine, infrav1.FloatingAddressFromPoolReadyCondition) return nil }