Skip to content

Commit

Permalink
Merge pull request #1998 from elastx/issue#1997
Browse files Browse the repository at this point in the history
🐛 Make floatingIPNetwork a pointer and if there's only one external network use it as default
  • Loading branch information
k8s-ci-robot authored Apr 4, 2024
2 parents 78f7b3f + 9c66684 commit d2d1cb2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/conditions_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ const (

// MaxIPsReachedReason is set when the maximum number of floating IPs has been reached.
MaxIPsReachedReason = "MaxIPsReached"

// UnableToFindFloatingIPNetworkReason is used when the floating ip network is not found.
UnableToFindNetwork = "UnableToFindNetwork"
)
3 changes: 1 addition & 2 deletions api/v1alpha1/openstackfloatingippool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ type OpenStackFloatingIPPoolSpec struct {

// FloatingIPNetwork is the external network to use for floating ips, if there's only one external network it will be used by default
// +optional
FloatingIPNetwork infrav1.NetworkParam `json:"floatingIPNetwork"`
FloatingIPNetwork *infrav1.NetworkParam `json:"floatingIPNetwork"`

// The stratergy to use for reclaiming floating ips when they are released from a machine
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Enum=Retain;Delete
ReclaimPolicy ReclaimPolicy `json:"reclaimPolicy"`
}
Expand Down
6 changes: 5 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions api/v1beta1/conditions_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ const (
FloatingAddressFromPoolWaitingForIpamProviderReason = "WaitingForIPAMProvider"
// FloatingAddressFromPoolErrorReason is used when there is an error attaching an IP from the pool to an machine.
FloatingAddressFromPoolErrorReason = "FloatingIPError"
// UnableToFindFloatingIPNetworkReason is used when the floating ip network is not found.
UnableToFindFloatingIPNetworkReason = "UnableToFindFloatingIPNetwork"
)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion controllers/openstackfloatingippool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,19 @@ func (r *OpenStackFloatingIPPoolReconciler) reconcileFloatingIPNetwork(scope *sc
return err
}

network, err := networkingService.GetNetworkByParam(&pool.Spec.FloatingIPNetwork)
// If the pool does not have a network, we default to a external network if there's only one
var networkParam *infrav1.NetworkParam
if pool.Spec.FloatingIPNetwork == nil {
networkParam = &infrav1.NetworkParam{
Filter: &infrav1.NetworkFilter{},
}
} else {
networkParam = pool.Spec.FloatingIPNetwork
}

network, err := networkingService.GetNetworkByParam(networkParam, networking.ExternalNetworksOnly)
if err != nil {
conditions.MarkFalse(pool, infrav1alpha1.OpenstackFloatingIPPoolReadyCondition, infrav1alpha1.UnableToFindNetwork, clusterv1.ConditionSeverityError, "Failed to find network: %v", err)
return fmt.Errorf("failed to find network: %w", err)
}

Expand Down

0 comments on commit d2d1cb2

Please sign in to comment.