Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kubernetes-sigs/cluster-api-provider-openstack
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c22ae58a6da6cc8a1e562307e96cee844d07ffa2
Choose a base ref
..
head repository: kubernetes-sigs/cluster-api-provider-openstack
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cee39c96fe08c38d789006131ab60b5c1d8e56f3
Choose a head ref
52 changes: 26 additions & 26 deletions controllers/openstackcluster_controller.go
Original file line number Diff line number Diff line change
@@ -148,13 +148,13 @@ func (r *OpenStackClusterReconciler) reconcileDelete(ctx context.Context, scope
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
}

clusterName := names.ClusterName(cluster)
clusterResourceName := names.ClusterResourceName(cluster)

// A bastion may have been created if cluster initialisation previously reached populating the network status
// We attempt to delete it even if no status was written, just in case
if openStackCluster.Status.Network != nil {
// Attempt to resolve bastion resources before delete. We don't need to worry about starting if the resources have changed on update.
if _, err := resolveBastionResources(scope, clusterName, openStackCluster); err != nil {
if _, err := resolveBastionResources(scope, clusterResourceName, openStackCluster); err != nil {
return reconcile.Result{}, err
}

@@ -174,15 +174,15 @@ func (r *OpenStackClusterReconciler) reconcileDelete(ctx context.Context, scope
return reconcile.Result{}, err
}

if err = loadBalancerService.DeleteLoadBalancer(openStackCluster, clusterName); err != nil {
if err = loadBalancerService.DeleteLoadBalancer(openStackCluster, clusterResourceName); err != nil {
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to delete load balancer: %w", err))
return reconcile.Result{}, fmt.Errorf("failed to delete load balancer: %w", err)
}
}

// if ManagedSubnets was not set, no network was created.
if len(openStackCluster.Spec.ManagedSubnets) > 0 {
if err = networkingService.DeleteRouter(openStackCluster, clusterName); err != nil {
if err = networkingService.DeleteRouter(openStackCluster, clusterResourceName); err != nil {
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to delete router: %w", err))
return ctrl.Result{}, fmt.Errorf("failed to delete router: %w", err)
}
@@ -192,13 +192,13 @@ func (r *OpenStackClusterReconciler) reconcileDelete(ctx context.Context, scope
return reconcile.Result{}, fmt.Errorf("failed to delete ports: %w", err)
}

if err = networkingService.DeleteNetwork(openStackCluster, clusterName); err != nil {
if err = networkingService.DeleteNetwork(openStackCluster, clusterResourceName); err != nil {
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to delete network: %w", err))
return ctrl.Result{}, fmt.Errorf("failed to delete network: %w", err)
}
}

if err = networkingService.DeleteSecurityGroups(openStackCluster, clusterName); err != nil {
if err = networkingService.DeleteSecurityGroups(openStackCluster, clusterResourceName); err != nil {
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to delete security groups: %w", err))
return reconcile.Result{}, fmt.Errorf("failed to delete security groups: %w", err)
}
@@ -218,7 +218,7 @@ func contains(arr []string, target string) bool {
return false
}

func resolveBastionResources(scope *scope.WithLogger, clusterName string, openStackCluster *infrav1.OpenStackCluster) (bool, error) {
func resolveBastionResources(scope *scope.WithLogger, clusterResourceName string, openStackCluster *infrav1.OpenStackCluster) (bool, error) {
// Resolve and store resources for the bastion
if openStackCluster.Spec.Bastion != nil && openStackCluster.Spec.Bastion.Enabled {
if openStackCluster.Status.Bastion == nil {
@@ -234,7 +234,7 @@ func resolveBastionResources(scope *scope.WithLogger, clusterName string, openSt
}
changed, err := compute.ResolveMachineSpec(scope,
openStackCluster.Spec.Bastion.Spec, resolved,
clusterName, bastionName(clusterName),
clusterResourceName, bastionName(clusterResourceName),
openStackCluster, getBastionSecurityGroupID(openStackCluster))
if err != nil {
return false, err
@@ -397,8 +397,8 @@ func reconcileNormal(scope *scope.WithLogger, cluster *clusterv1.Cluster, openSt
func reconcileBastion(scope *scope.WithLogger, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster) (*ctrl.Result, error) {
scope.Logger().V(4).Info("Reconciling Bastion")

clusterName := names.ClusterName(cluster)
changed, err := resolveBastionResources(scope, clusterName, openStackCluster)
clusterResourceName := names.ClusterResourceName(cluster)
changed, err := resolveBastionResources(scope, clusterResourceName, openStackCluster)
if err != nil {
return nil, err
}
@@ -501,10 +501,10 @@ func reconcileBastion(scope *scope.WithLogger, cluster *clusterv1.Cluster, openS
return nil, err
}

return bastionAddFloatingIP(openStackCluster, clusterName, port, networkingService)
return bastionAddFloatingIP(openStackCluster, clusterResourceName, port, networkingService)
}

func bastionAddFloatingIP(openStackCluster *infrav1.OpenStackCluster, clusterName string, port *ports.Port, networkingService *networking.Service) (*reconcile.Result, error) {
func bastionAddFloatingIP(openStackCluster *infrav1.OpenStackCluster, clusterResourceName string, port *ports.Port, networkingService *networking.Service) (*reconcile.Result, error) {
fp, err := networkingService.GetFloatingIPByPortID(port.ID)
if err != nil {
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to get or create floating IP for bastion: %w", err))
@@ -526,7 +526,7 @@ func bastionAddFloatingIP(openStackCluster *infrav1.OpenStackCluster, clusterNam
floatingIP = openStackCluster.Spec.Bastion.FloatingIP
}
// Check if there is an existing floating IP attached to bastion, in case where FloatingIP would not yet have been stored in cluster status
fp, err = networkingService.GetOrCreateFloatingIP(openStackCluster, openStackCluster, clusterName, floatingIP)
fp, err = networkingService.GetOrCreateFloatingIP(openStackCluster, openStackCluster, clusterResourceName, floatingIP)
if err != nil {
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to get or create floating IP for bastion: %w", err))
return nil, fmt.Errorf("failed to get or create floating IP for bastion: %w", err)
@@ -573,8 +573,8 @@ func bastionToInstanceSpec(openStackCluster *infrav1.OpenStackCluster, cluster *
return instanceSpec, nil
}

func bastionName(clusterName string) string {
return fmt.Sprintf("%s-bastion", clusterName)
func bastionName(clusterResourceName string) string {
return fmt.Sprintf("%s-bastion", clusterResourceName)
}

// getBastionSecurityGroupID returns the ID of the bastion security group if
@@ -619,7 +619,7 @@ func bastionHashHasChanged(computeHash string, clusterAnnotations map[string]str
}

func reconcileNetworkComponents(scope *scope.WithLogger, cluster *clusterv1.Cluster, openStackCluster *infrav1.OpenStackCluster) error {
clusterName := names.ClusterName(cluster)
clusterResourceName := names.ClusterResourceName(cluster)

networkingService, err := networking.NewService(scope)
if err != nil {
@@ -639,20 +639,20 @@ func reconcileNetworkComponents(scope *scope.WithLogger, cluster *clusterv1.Clus
return err
}
} else if len(openStackCluster.Spec.ManagedSubnets) == 1 {
if err := reconcileProvisionedNetworkComponents(networkingService, openStackCluster, clusterName); err != nil {
if err := reconcileProvisionedNetworkComponents(networkingService, openStackCluster, clusterResourceName); err != nil {
return err
}
} else {
return fmt.Errorf("failed to reconcile network: ManagedSubnets only supports one element, %d provided", len(openStackCluster.Spec.ManagedSubnets))
}

err = networkingService.ReconcileSecurityGroups(openStackCluster, clusterName)
err = networkingService.ReconcileSecurityGroups(openStackCluster, clusterResourceName)
if err != nil {
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to reconcile security groups: %w", err))
return fmt.Errorf("failed to reconcile security groups: %w", err)
}

return reconcileControlPlaneEndpoint(scope, networkingService, openStackCluster, clusterName)
return reconcileControlPlaneEndpoint(scope, networkingService, openStackCluster, clusterResourceName)
}

// reconcilePreExistingNetworkComponents reconciles the cluster network status when the cluster is
@@ -716,18 +716,18 @@ func reconcilePreExistingNetworkComponents(scope *scope.WithLogger, networkingSe
return nil
}

func reconcileProvisionedNetworkComponents(networkingService *networking.Service, openStackCluster *infrav1.OpenStackCluster, clusterName string) error {
err := networkingService.ReconcileNetwork(openStackCluster, clusterName)
func reconcileProvisionedNetworkComponents(networkingService *networking.Service, openStackCluster *infrav1.OpenStackCluster, clusterResourceName string) error {
err := networkingService.ReconcileNetwork(openStackCluster, clusterResourceName)
if err != nil {
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to reconcile network: %w", err))
return fmt.Errorf("failed to reconcile network: %w", err)
}
err = networkingService.ReconcileSubnet(openStackCluster, clusterName)
err = networkingService.ReconcileSubnet(openStackCluster, clusterResourceName)
if err != nil {
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to reconcile subnets: %w", err))
return fmt.Errorf("failed to reconcile subnets: %w", err)
}
err = networkingService.ReconcileRouter(openStackCluster, clusterName)
err = networkingService.ReconcileRouter(openStackCluster, clusterResourceName)
if err != nil {
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to reconcile router: %w", err))
return fmt.Errorf("failed to reconcile router: %w", err)
@@ -739,7 +739,7 @@ func reconcileProvisionedNetworkComponents(networkingService *networking.Service
// reconcileControlPlaneEndpoint configures the control plane endpoint for the
// cluster, creating it if necessary, and updates ControlPlaneEndpoint in the
// cluster spec.
func reconcileControlPlaneEndpoint(scope *scope.WithLogger, networkingService *networking.Service, openStackCluster *infrav1.OpenStackCluster, clusterName string) error {
func reconcileControlPlaneEndpoint(scope *scope.WithLogger, networkingService *networking.Service, openStackCluster *infrav1.OpenStackCluster, clusterResourceName string) error {
// Calculate the port that we will use for the API server
apiServerPort := getAPIServerPort(openStackCluster)

@@ -756,7 +756,7 @@ func reconcileControlPlaneEndpoint(scope *scope.WithLogger, networkingService *n
return err
}

terminalFailure, err := loadBalancerService.ReconcileLoadBalancer(openStackCluster, clusterName, apiServerPort)
terminalFailure, err := loadBalancerService.ReconcileLoadBalancer(openStackCluster, clusterResourceName, apiServerPort)
if err != nil {
// if it's terminalFailure (not Transient), set the Failure reason and message
if terminalFailure {
@@ -781,7 +781,7 @@ func reconcileControlPlaneEndpoint(scope *scope.WithLogger, networkingService *n
// API server load balancer is disabled, but floating IP is not. Create
// a floating IP to be attached directly to a control plane host.
case !pointer.BoolDeref(openStackCluster.Spec.DisableAPIServerFloatingIP, false):
fp, err := networkingService.GetOrCreateFloatingIP(openStackCluster, openStackCluster, clusterName, openStackCluster.Spec.APIServerFloatingIP)
fp, err := networkingService.GetOrCreateFloatingIP(openStackCluster, openStackCluster, clusterResourceName, openStackCluster.Spec.APIServerFloatingIP)
if err != nil {
handleUpdateOSCError(openStackCluster, fmt.Errorf("floating IP cannot be got or created: %w", err))
return fmt.Errorf("floating IP cannot be got or created: %w", err)
32 changes: 16 additions & 16 deletions controllers/openstackmachine_controller.go
Original file line number Diff line number Diff line change
@@ -150,26 +150,26 @@ func (r *OpenStackMachineReconciler) Reconcile(ctx context.Context, req ctrl.Req
}
scope := scope.NewWithLogger(clientScope, log)

clusterName := fmt.Sprintf("%s-%s", cluster.Namespace, cluster.Name)
clusterResourceName := fmt.Sprintf("%s-%s", cluster.Namespace, cluster.Name)

// Handle deleted machines
if !openStackMachine.DeletionTimestamp.IsZero() {
return r.reconcileDelete(scope, clusterName, infraCluster, machine, openStackMachine)
return r.reconcileDelete(scope, clusterResourceName, infraCluster, machine, openStackMachine)
}

// Handle non-deleted clusters
return r.reconcileNormal(ctx, scope, clusterName, infraCluster, machine, openStackMachine)
return r.reconcileNormal(ctx, scope, clusterResourceName, infraCluster, machine, openStackMachine)
}

func resolveMachineResources(scope *scope.WithLogger, clusterName string, openStackCluster *infrav1.OpenStackCluster, openStackMachine *infrav1.OpenStackMachine, machine *clusterv1.Machine) (bool, error) {
func resolveMachineResources(scope *scope.WithLogger, clusterResourceName string, openStackCluster *infrav1.OpenStackCluster, openStackMachine *infrav1.OpenStackMachine, machine *clusterv1.Machine) (bool, error) {
resolved := openStackMachine.Status.Resolved
if resolved == nil {
resolved = &infrav1.ResolvedMachineSpec{}
}
// Resolve and store resources
changed, err := compute.ResolveMachineSpec(scope,
&openStackMachine.Spec, resolved,
clusterName, openStackMachine.Name,
clusterResourceName, openStackMachine.Name,
openStackCluster, getManagedSecurityGroup(openStackCluster, machine))
if err != nil {
return false, err
@@ -240,7 +240,7 @@ func (r *OpenStackMachineReconciler) SetupWithManager(ctx context.Context, mgr c
Complete(r)
}

func (r *OpenStackMachineReconciler) reconcileDelete(scope *scope.WithLogger, clusterName string, openStackCluster *infrav1.OpenStackCluster, machine *clusterv1.Machine, openStackMachine *infrav1.OpenStackMachine) (ctrl.Result, error) { //nolint:unparam
func (r *OpenStackMachineReconciler) reconcileDelete(scope *scope.WithLogger, clusterResourceName string, openStackCluster *infrav1.OpenStackCluster, machine *clusterv1.Machine, openStackMachine *infrav1.OpenStackMachine) (ctrl.Result, error) { //nolint:unparam
scope.Logger().Info("Reconciling Machine delete")

computeService, err := compute.NewService(scope)
@@ -255,7 +255,7 @@ func (r *OpenStackMachineReconciler) reconcileDelete(scope *scope.WithLogger, cl

// We may have resources to adopt if the cluster is ready
if openStackCluster.Status.Ready && openStackCluster.Status.Network != nil {
if _, err := resolveMachineResources(scope, clusterName, openStackCluster, openStackMachine, machine); err != nil {
if _, err := resolveMachineResources(scope, clusterResourceName, openStackCluster, openStackMachine, machine); err != nil {
return ctrl.Result{}, err
}
}
@@ -266,7 +266,7 @@ func (r *OpenStackMachineReconciler) reconcileDelete(scope *scope.WithLogger, cl
return ctrl.Result{}, err
}

err = loadBalancerService.DeleteLoadBalancerMember(openStackCluster, machine, openStackMachine, clusterName)
err = loadBalancerService.DeleteLoadBalancerMember(openStackCluster, machine, openStackMachine, clusterResourceName)
if err != nil {
conditions.MarkFalse(openStackMachine, infrav1.APIServerIngressReadyCondition, infrav1.LoadBalancerMemberErrorReason, clusterv1.ConditionSeverityWarning, "Machine could not be removed from load balancer: %v", err)
return ctrl.Result{}, err
@@ -477,7 +477,7 @@ func (r *OpenStackMachineReconciler) reconcileDeleteFloatingAddressFromPool(scop
return r.Client.Update(context.Background(), claim)
}

func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope *scope.WithLogger, clusterName string, openStackCluster *infrav1.OpenStackCluster, machine *clusterv1.Machine, openStackMachine *infrav1.OpenStackMachine) (_ ctrl.Result, reterr error) {
func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope *scope.WithLogger, clusterResourceName string, openStackCluster *infrav1.OpenStackCluster, machine *clusterv1.Machine, openStackMachine *infrav1.OpenStackMachine) (_ ctrl.Result, reterr error) {
var err error

// If the OpenStackMachine is in an error state, return early.
@@ -498,7 +498,7 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope
return ctrl.Result{RequeueAfter: waitForClusterInfrastructureReadyDuration}, nil
}

if changed, err := resolveMachineResources(scope, clusterName, openStackCluster, openStackMachine, machine); changed || err != nil {
if changed, err := resolveMachineResources(scope, clusterResourceName, openStackCluster, openStackMachine, machine); changed || err != nil {
return ctrl.Result{}, err
}

@@ -611,7 +611,7 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope
return ctrl.Result{}, nil
}

err = r.reconcileAPIServerLoadBalancer(scope, openStackCluster, openStackMachine, instanceStatus, instanceNS, clusterName)
err = r.reconcileAPIServerLoadBalancer(scope, openStackCluster, openStackMachine, instanceStatus, instanceNS, clusterResourceName)
if err != nil {
return ctrl.Result{}, err
}
@@ -620,7 +620,7 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope
return ctrl.Result{}, nil
}

func (r *OpenStackMachineReconciler) reconcileAPIServerLoadBalancer(scope *scope.WithLogger, openStackCluster *infrav1.OpenStackCluster, openStackMachine *infrav1.OpenStackMachine, instanceStatus *compute.InstanceStatus, instanceNS *compute.InstanceNetworkStatus, clusterName string) error {
func (r *OpenStackMachineReconciler) reconcileAPIServerLoadBalancer(scope *scope.WithLogger, openStackCluster *infrav1.OpenStackCluster, openStackMachine *infrav1.OpenStackMachine, instanceStatus *compute.InstanceStatus, instanceNS *compute.InstanceNetworkStatus, clusterResourceName string) error {
scope.Logger().Info("Reconciling APIServerLoadBalancer")
computeService, err := compute.NewService(scope)
if err != nil {
@@ -633,7 +633,7 @@ func (r *OpenStackMachineReconciler) reconcileAPIServerLoadBalancer(scope *scope
}

if openStackCluster.Spec.APIServerLoadBalancer.IsEnabled() {
err = r.reconcileLoadBalancerMember(scope, openStackCluster, openStackMachine, instanceNS, clusterName)
err = r.reconcileLoadBalancerMember(scope, openStackCluster, openStackMachine, instanceNS, clusterResourceName)
if err != nil {
conditions.MarkFalse(openStackMachine, infrav1.APIServerIngressReadyCondition, infrav1.LoadBalancerMemberErrorReason, clusterv1.ConditionSeverityError, "Reconciling load balancer member failed: %v", err)
return fmt.Errorf("reconcile load balancer member: %w", err)
@@ -646,7 +646,7 @@ func (r *OpenStackMachineReconciler) reconcileAPIServerLoadBalancer(scope *scope
case openStackCluster.Spec.APIServerFloatingIP != nil:
floatingIPAddress = openStackCluster.Spec.APIServerFloatingIP
}
fp, err := networkingService.GetOrCreateFloatingIP(openStackMachine, openStackCluster, clusterName, floatingIPAddress)
fp, err := networkingService.GetOrCreateFloatingIP(openStackMachine, openStackCluster, clusterResourceName, floatingIPAddress)
if err != nil {
conditions.MarkFalse(openStackMachine, infrav1.APIServerIngressReadyCondition, infrav1.FloatingIPErrorReason, clusterv1.ConditionSeverityError, "Floating IP cannot be obtained or created: %v", err)
return fmt.Errorf("get or create floating IP %v: %w", floatingIPAddress, err)
@@ -789,14 +789,14 @@ func getManagedSecurityGroup(openStackCluster *infrav1.OpenStackCluster, machine
return nil
}

func (r *OpenStackMachineReconciler) reconcileLoadBalancerMember(scope *scope.WithLogger, openStackCluster *infrav1.OpenStackCluster, openStackMachine *infrav1.OpenStackMachine, instanceNS *compute.InstanceNetworkStatus, clusterName string) error {
func (r *OpenStackMachineReconciler) reconcileLoadBalancerMember(scope *scope.WithLogger, openStackCluster *infrav1.OpenStackCluster, openStackMachine *infrav1.OpenStackMachine, instanceNS *compute.InstanceNetworkStatus, clusterResourceName string) error {
ip := instanceNS.IP(openStackCluster.Status.Network.Name)
loadbalancerService, err := loadbalancer.NewService(scope)
if err != nil {
return err
}

return loadbalancerService.ReconcileLoadBalancerMember(openStackCluster, openStackMachine, clusterName, ip)
return loadbalancerService.ReconcileLoadBalancerMember(openStackCluster, openStackMachine, clusterResourceName, ip)
}

// OpenStackClusterToOpenStackMachines is a handler.ToRequestsFunc to be used to enqeue requests for reconciliation
Loading