Skip to content

Commit ac6a030

Browse files
authored
Add sync-period flag (#511)
1 parent 298a447 commit ac6a030

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

cloud/scope/powervs_machine.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ func (m *PowerVSMachineScope) SetNotReady() {
317317
m.IBMPowerVSMachine.Status.Ready = false
318318
}
319319

320+
func (m *PowerVSMachineScope) IsReady() bool {
321+
return m.IBMPowerVSMachine.Status.Ready
322+
}
323+
320324
func (m *PowerVSMachineScope) SetInstanceID(id *string) {
321325
if id != nil {
322326
m.IBMPowerVSMachine.Status.InstanceID = *id

controllers/ibmpowervsmachine_controller.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controllers
1818

1919
import (
2020
"context"
21+
"time"
2122

2223
"github.com/go-logr/logr"
2324
"github.com/pkg/errors"
@@ -158,14 +159,14 @@ func (r *IBMPowerVSMachineReconciler) reconcileNormal(ctx context.Context, machi
158159
if !machineScope.Cluster.Status.InfrastructureReady {
159160
machineScope.Info("Cluster infrastructure is not ready yet")
160161
conditions.MarkFalse(machineScope.IBMPowerVSMachine, v1beta1.InstanceReadyCondition, v1beta1.WaitingForClusterInfrastructureReason, clusterv1.ConditionSeverityInfo, "")
161-
return ctrl.Result{}, nil
162+
return ctrl.Result{RequeueAfter: 1 * time.Minute}, nil
162163
}
163164

164165
// Make sure bootstrap data is available and populated.
165166
if machineScope.Machine.Spec.Bootstrap.DataSecretName == nil {
166167
machineScope.Info("Bootstrap data secret reference is not yet available")
167168
conditions.MarkFalse(machineScope.IBMPowerVSMachine, v1beta1.InstanceReadyCondition, v1beta1.WaitingForBootstrapDataReason, clusterv1.ConditionSeverityInfo, "")
168-
return ctrl.Result{}, nil
169+
return ctrl.Result{RequeueAfter: 1 * time.Minute}, nil
169170
}
170171

171172
controllerutil.AddFinalizer(machineScope.IBMPowerVSMachine, v1beta1.IBMPowerVSMachineFinalizer)
@@ -193,6 +194,7 @@ func (r *IBMPowerVSMachineReconciler) reconcileNormal(ctx context.Context, machi
193194
case v1beta1.PowerVSInstanceStateSHUTOFF:
194195
machineScope.SetNotReady()
195196
conditions.MarkFalse(machineScope.IBMPowerVSMachine, v1beta1.InstanceReadyCondition, v1beta1.InstanceStoppedReason, clusterv1.ConditionSeverityError, "")
197+
return ctrl.Result{}, nil
196198
case v1beta1.PowerVSInstanceStateACTIVE:
197199
machineScope.SetReady()
198200
conditions.MarkTrue(machineScope.IBMPowerVSMachine, v1beta1.InstanceReadyCondition)
@@ -205,5 +207,10 @@ func (r *IBMPowerVSMachineReconciler) reconcileNormal(ctx context.Context, machi
205207
}
206208
machineScope.SetProviderID()
207209

208-
return ctrl.Result{}, nil
210+
// Requeue after 2 minute if machine is not ready to update status of the machine properly
211+
if !machineScope.IsReady() {
212+
return ctrl.Result{RequeueAfter: 2 * time.Minute}, nil
213+
} else {
214+
return ctrl.Result{}, nil
215+
}
209216
}

main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var (
4343
metricsAddr string
4444
enableLeaderElection bool
4545
healthAddr string
46+
syncPeriod time.Duration
4647

4748
scheme = runtime.NewScheme()
4849
setupLog = ctrl.Log.WithName("setup")
@@ -71,7 +72,6 @@ func main() {
7172
setupLog.Info("Watching cluster-api objects only in namespace for reconciliation", "namespace", watchNamespace)
7273
}
7374

74-
syncPeriod := 15 * time.Second
7575
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
7676
Scheme: scheme,
7777
MetricsBindAddress: metricsAddr,
@@ -191,4 +191,11 @@ func initFlags(fs *pflag.FlagSet) {
191191
":9440",
192192
"The address the health endpoint binds to.",
193193
)
194+
195+
fs.DurationVar(
196+
&syncPeriod,
197+
"sync-period",
198+
10*time.Minute,
199+
"The minimum interval at which watched resources are reconciled.",
200+
)
194201
}

0 commit comments

Comments
 (0)