Skip to content

Commit 76071d9

Browse files
committed
Adds ipam scheme and fixes some comments from pr
1 parent f5a9494 commit 76071d9

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

controllers/openstackmachine_controller.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,6 @@ func (r *OpenStackMachineReconciler) reconcileDelete(scope scope.Scope, cluster
301301
// reconcileFloatingAddressFromPool creates IPAddressClaims for the OpenStackMachine if the OpenStackMachine has a
302302
// FloatingAddressFromPool specified. It then associates the IPAddressClaim with the instance.
303303
func (r *OpenStackMachineReconciler) reconcileFloatingAddressFromPool(ctx context.Context, scope scope.Scope, openStackMachine *infrav1.OpenStackMachine, openStackCluster *infrav1.OpenStackCluster, instanceStatus *compute.InstanceStatus, instanceNS *compute.InstanceNetworkStatus) error {
304-
if openStackMachine.Spec.FloatingAddressFromPool == nil {
305-
conditions.MarkTrue(openStackMachine, infrav1.FloatingAddressFromPoolReadyCondition)
306-
openStackMachine.Status.FloatingAddressFromPoolReady = pointer.BoolPtr(true)
307-
return nil
308-
}
309-
310304
networkingService, err := networking.NewService(scope)
311305
if err != nil {
312306
return err
@@ -362,7 +356,7 @@ func (r *OpenStackMachineReconciler) reconcileFloatingAddressFromPool(ctx contex
362356
instanceAddresses := instanceNS.Addresses()
363357
for _, instanceAddress := range instanceAddresses {
364358
if instanceAddress.Address == address.Spec.Address {
365-
openStackMachine.Status.FloatingAddressFromPoolReady = pointer.BoolPtr(true)
359+
openStackMachine.Status.FloatingAddressFromPoolReady = pointer.Bool(true)
366360
conditions.MarkTrue(openStackMachine, infrav1.FloatingAddressFromPoolReadyCondition)
367361
return nil
368362
}
@@ -391,18 +385,19 @@ func (r *OpenStackMachineReconciler) reconcileFloatingAddressFromPool(ctx contex
391385
return err
392386
}
393387
}
394-
openStackMachine.Status.FloatingAddressFromPoolReady = pointer.BoolPtr(true)
388+
openStackMachine.Status.FloatingAddressFromPoolReady = pointer.Bool(true)
395389
conditions.MarkTrue(openStackMachine, infrav1.FloatingAddressFromPoolReadyCondition)
396390
} else {
397391
scope.Logger().Info("Waiting for IPAddressClaim to be allocated", "name", claim.Name)
398-
openStackMachine.Status.FloatingAddressFromPoolReady = pointer.BoolPtr(false)
392+
openStackMachine.Status.FloatingAddressFromPoolReady = pointer.Bool(false)
399393
conditions.MarkFalse(openStackMachine, infrav1.FloatingAddressFromPoolReadyCondition, infrav1.FloatingAddressFromPoolWaitingForIpamProviderReason, clusterv1.ConditionSeverityWarning, "")
400394
}
401395
return nil
402396
}
403397

404398
func (r *OpenStackMachineReconciler) reconcileDeleteFloatingAddressFromPool(scope scope.Scope, openStackMachine *infrav1.OpenStackMachine) error {
405-
scope.Logger().Info("Reconciling floating IP claims delete")
399+
log := scope.Logger().WithValues("openStackMachine", openStackMachine.Name)
400+
log.Info("Reconciling Machine delete floating address from pool")
406401
if openStackMachine.Spec.FloatingAddressFromPool == nil {
407402
return nil
408403
}
@@ -496,7 +491,7 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope
496491

497492
switch instanceStatus.State() {
498493
case infrav1.InstanceStateActive:
499-
if pointer.BoolDeref(openStackMachine.Status.FloatingAddressFromPoolReady, false) {
494+
if openStackMachine.Spec.FloatingAddressFromPool != nil && pointer.BoolDeref(openStackMachine.Status.FloatingAddressFromPoolReady, false) {
500495
scope.Logger().Info("Machine instance state is ACTIVE", "id", instanceStatus.ID())
501496
conditions.MarkTrue(openStackMachine, infrav1.InstanceReadyCondition)
502497
} else {

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
_ "k8s.io/component-base/logs/json/register"
3535
"k8s.io/klog/v2"
3636
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
37+
ipamv1 "sigs.k8s.io/cluster-api/exp/ipam/api/v1alpha1"
3738
ctrl "sigs.k8s.io/controller-runtime"
3839
"sigs.k8s.io/controller-runtime/pkg/client"
3940
"sigs.k8s.io/controller-runtime/pkg/client/config"
@@ -78,6 +79,7 @@ var (
7879
func init() {
7980
_ = clientgoscheme.AddToScheme(scheme)
8081
_ = clusterv1.AddToScheme(scheme)
82+
_ = ipamv1.AddToScheme(scheme)
8183
_ = infrav1.AddToScheme(scheme)
8284
_ = infrav1alpha5.AddToScheme(scheme)
8385
_ = infrav1alpha6.AddToScheme(scheme)

pkg/utils/names/names.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
const (
25-
FloatingAddressIPClaimNameSuffix = "floating-address"
25+
FloatingAddressIPClaimNameSuffix = "floating-ip-address"
2626
)
2727

2828
func GetDescription(clusterName string) string {

0 commit comments

Comments
 (0)