Skip to content

Commit d2d1cb2

Browse files
authored
Merge pull request #1998 from elastx/issue#1997
🐛 Make floatingIPNetwork a pointer and if there's only one external network use it as default
2 parents 78f7b3f + 9c66684 commit d2d1cb2

File tree

6 files changed

+24
-4
lines changed

6 files changed

+24
-4
lines changed

api/v1alpha1/conditions_consts.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ const (
2222

2323
// MaxIPsReachedReason is set when the maximum number of floating IPs has been reached.
2424
MaxIPsReachedReason = "MaxIPsReached"
25+
26+
// UnableToFindFloatingIPNetworkReason is used when the floating ip network is not found.
27+
UnableToFindNetwork = "UnableToFindNetwork"
2528
)

api/v1alpha1/openstackfloatingippool_types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ type OpenStackFloatingIPPoolSpec struct {
6363

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

6868
// The stratergy to use for reclaiming floating ips when they are released from a machine
69-
// +kubebuilder:validation:Optional
7069
// +kubebuilder:validation:Enum=Retain;Delete
7170
ReclaimPolicy ReclaimPolicy `json:"reclaimPolicy"`
7271
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta1/conditions_consts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,6 @@ const (
6161
FloatingAddressFromPoolWaitingForIpamProviderReason = "WaitingForIPAMProvider"
6262
// FloatingAddressFromPoolErrorReason is used when there is an error attaching an IP from the pool to an machine.
6363
FloatingAddressFromPoolErrorReason = "FloatingIPError"
64+
// UnableToFindFloatingIPNetworkReason is used when the floating ip network is not found.
65+
UnableToFindFloatingIPNetworkReason = "UnableToFindFloatingIPNetwork"
6466
)

config/crd/bases/infrastructure.cluster.x-k8s.io_openstackfloatingippools.yaml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/openstackfloatingippool_controller.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,19 @@ func (r *OpenStackFloatingIPPoolReconciler) reconcileFloatingIPNetwork(scope *sc
398398
return err
399399
}
400400

401-
network, err := networkingService.GetNetworkByParam(&pool.Spec.FloatingIPNetwork)
401+
// If the pool does not have a network, we default to a external network if there's only one
402+
var networkParam *infrav1.NetworkParam
403+
if pool.Spec.FloatingIPNetwork == nil {
404+
networkParam = &infrav1.NetworkParam{
405+
Filter: &infrav1.NetworkFilter{},
406+
}
407+
} else {
408+
networkParam = pool.Spec.FloatingIPNetwork
409+
}
410+
411+
network, err := networkingService.GetNetworkByParam(networkParam, networking.ExternalNetworksOnly)
402412
if err != nil {
413+
conditions.MarkFalse(pool, infrav1alpha1.OpenstackFloatingIPPoolReadyCondition, infrav1alpha1.UnableToFindNetwork, clusterv1.ConditionSeverityError, "Failed to find network: %v", err)
403414
return fmt.Errorf("failed to find network: %w", err)
404415
}
405416

0 commit comments

Comments
 (0)