Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bilbobrovall committed Jan 5, 2024
1 parent ef85850 commit 655c789
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 0 additions & 1 deletion config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ rules:
- create
- delete
- get
- list
- patch
- update
- watch
Expand Down
21 changes: 14 additions & 7 deletions controllers/openstackmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const (
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=openstackmachines,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=openstackmachines/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=machines;machines/status,verbs=get;list;watch
// +kubebuilder:rbac:groups=ipam.cluster.x-k8s.io,resources=ipaddressclaims;ipaddressclaims/status,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=ipam.cluster.x-k8s.io,resources=ipaddressclaims;ipaddressclaims/status,verbs=get;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=ipam.cluster.x-k8s.io,resources=ipaddresses;ipaddresses/status,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=secrets;,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=events,verbs=get;list;watch;create;update;patch
Expand Down Expand Up @@ -359,7 +359,7 @@ func (r *OpenStackMachineReconciler) reconcileFloatingAddressFromPool(ctx contex

instanceAddresses := instanceNS.Addresses()
for _, instanceAddress := range instanceAddresses {
if instanceAddress.Address == address.Spec.Address {
if instanceAddress.Address == address.Spec.Address && instanceAddress.Type == corev1.NodeExternalIP {
openStackMachine.Status.FloatingAddressFromPoolReady = pointer.Bool(true)
conditions.MarkTrue(openStackMachine, infrav1.FloatingAddressFromPoolReadyCondition)
return nil
Expand All @@ -372,23 +372,30 @@ func (r *OpenStackMachineReconciler) reconcileFloatingAddressFromPool(ctx contex
}
if fip == nil {
conditions.MarkFalse(openStackMachine, infrav1.FloatingAddressFromPoolReadyCondition, infrav1.FloatingAddressFromPoolErrorReason, clusterv1.ConditionSeverityError, "floating IP does not exist")
return errors.New("floating IP does not exist in ")
return fmt.Errorf("floating IP %q does not exist", address.Spec.Address)
}

port, err := computeService.GetManagementPort(openStackCluster, instanceStatus)
if err != nil {
return err
}

if err = networkingService.AssociateFloatingIP(openStackMachine, fip, port.ID); 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
}
}
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 {
Expand Down

0 comments on commit 655c789

Please sign in to comment.