Skip to content

Commit b203ca8

Browse files
committed
address comments
1 parent a26c864 commit b203ca8

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

internal/controller/linodecluster_controller.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
utilerrors "k8s.io/apimachinery/pkg/util/errors"
3131
"k8s.io/client-go/tools/record"
32+
"k8s.io/client-go/util/retry"
3233
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3334
kutil "sigs.k8s.io/cluster-api/util"
3435
conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
@@ -153,7 +154,9 @@ func (r *LinodeClusterReconciler) reconcileVPCLabel(ctx context.Context, cluster
153154
}
154155
labels[clusterv1.ClusterNameLabel] = clusterScope.LinodeCluster.Name
155156
linodeVPC.SetLabels(labels)
156-
return clusterScope.Client.Update(ctx, &linodeVPC)
157+
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
158+
return clusterScope.Client.Update(ctx, &linodeVPC)
159+
})
157160
}
158161

159162
//nolint:cyclop // can't make it simpler with existing API
@@ -189,8 +192,7 @@ func (r *LinodeClusterReconciler) reconcile(
189192
return res, err
190193
}
191194

192-
err := r.reconcileVPCLabel(ctx, clusterScope, logger)
193-
if err != nil {
195+
if err := r.reconcileVPCLabel(ctx, clusterScope, logger); err != nil {
194196
return res, err
195197
}
196198

internal/controller/linodemachine_controller.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3333
utilerrors "k8s.io/apimachinery/pkg/util/errors"
3434
"k8s.io/client-go/tools/record"
35+
"k8s.io/client-go/util/retry"
3536
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3637
kutil "sigs.k8s.io/cluster-api/util"
3738
conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
@@ -209,7 +210,9 @@ func (r *LinodeMachineReconciler) reconcileFirewallLabel(ctx context.Context, lo
209210
}
210211
labels[clusterv1.ClusterNameLabel] = machineScope.Machine.Labels[clusterv1.ClusterNameLabel]
211212
linodeFW.SetLabels(labels)
212-
return machineScope.Client.Update(ctx, &linodeFW)
213+
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
214+
return machineScope.Client.Update(ctx, &linodeFW)
215+
})
213216
}
214217

215218
// reconcilePGLabel adds the cluster-name label to placement group referenced in the machineScope if it does not already exist
@@ -236,7 +239,9 @@ func (r *LinodeMachineReconciler) reconcilePGLabel(ctx context.Context, logger l
236239
}
237240
labels[clusterv1.ClusterNameLabel] = machineScope.Machine.Labels[clusterv1.ClusterNameLabel]
238241
linodePG.ObjectMeta.SetLabels(labels)
239-
return machineScope.Client.Update(ctx, &linodePG)
242+
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
243+
return machineScope.Client.Update(ctx, &linodePG)
244+
})
240245
}
241246

242247
// reconcileLabel adds the cluster-name label to placement groups and firewalls that are difference in the machine spec

0 commit comments

Comments
 (0)