Skip to content

Commit 1f20f21

Browse files
committed
handle conflicts for updating access key finalizer
1 parent 23e5d08 commit 1f20f21

File tree

5 files changed

+42
-47
lines changed

5 files changed

+42
-47
lines changed

api/v1alpha2/linodecluster_types.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ type LinodeClusterSpec struct {
3333
// The Linode Region the LinodeCluster lives in.
3434
Region string `json:"region"`
3535

36-
// ControlPlaneEndpoint represents the endpoint used to communicate with
37-
// the LinodeCluster control plane.
36+
// ControlPlaneEndpoint represents the endpoint used to communicate with the LinodeCluster control plane.
3837
// If ControlPlaneEndpoint is unset then the Nodebalancer ip will be used.
3938
// +optional
4039
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
@@ -48,25 +47,22 @@ type LinodeClusterSpec struct {
4847
VPCRef *corev1.ObjectReference `json:"vpcRef,omitempty"`
4948

5049
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
51-
// VPCID is the ID of an existing VPC in Linode. This allows using a VPC
52-
// that is not managed by CAPL.
50+
// VPCID is the ID of an existing VPC in Linode. This allows using a VPC that is not managed by CAPL.
5351
// +optional
5452
VPCID *int `json:"vpcID,omitempty"`
5553

5654
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
5755
// +optional
58-
// NodeBalancerFirewallRef is a reference to a NodeBalancer Firewall object.
59-
// This makes the linode use the specified NodeBalancer Firewall.
56+
// NodeBalancerFirewallRef is a reference to a NodeBalancer Firewall object. This makes the linode use the specified NodeBalancer Firewall.
6057
NodeBalancerFirewallRef *corev1.ObjectReference `json:"nodeBalancerFirewallRef,omitempty"`
6158

62-
// ObjectStore defines a supporting Object Storage bucket for cluster
63-
// operations. This is currently used for bootstrapping (e.g. Cloud-init).
59+
// ObjectStore defines a supporting Object Storage bucket for cluster operations. This is currently used for
60+
// bootstrapping (e.g. Cloud-init).
6461
// +optional
6562
ObjectStore *ObjectStore `json:"objectStore,omitempty"`
6663

67-
// CredentialsRef is a reference to a Secret that contains the credentials
68-
// to use for provisioning this cluster. If not supplied then the
69-
// credentials of the controller will be used.
64+
// CredentialsRef is a reference to a Secret that contains the credentials to use for provisioning this cluster. If not
65+
// supplied then the credentials of the controller will be used.
7066
// +optional
7167
CredentialsRef *corev1.SecretReference `json:"credentialsRef,omitempty"`
7268
}

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ spec:
5959
properties:
6060
controlPlaneEndpoint:
6161
description: |-
62-
ControlPlaneEndpoint represents the endpoint used to communicate with
63-
the LinodeCluster control plane.
62+
ControlPlaneEndpoint represents the endpoint used to communicate with the LinodeCluster control plane.
6463
If ControlPlaneEndpoint is unset then the Nodebalancer ip will be used.
6564
properties:
6665
host:
@@ -77,9 +76,8 @@ spec:
7776
type: object
7877
credentialsRef:
7978
description: |-
80-
CredentialsRef is a reference to a Secret that contains the credentials
81-
to use for provisioning this cluster. If not supplied then the
82-
credentials of the controller will be used.
79+
CredentialsRef is a reference to a Secret that contains the credentials to use for provisioning this cluster. If not
80+
supplied then the credentials of the controller will be used.
8381
properties:
8482
name:
8583
description: name is unique within a namespace to reference a
@@ -191,9 +189,9 @@ spec:
191189
rule: self == oldSelf
192190
type: object
193191
nodeBalancerFirewallRef:
194-
description: |-
195-
NodeBalancerFirewallRef is a reference to a NodeBalancer Firewall object.
196-
This makes the linode use the specified NodeBalancer Firewall.
192+
description: NodeBalancerFirewallRef is a reference to a NodeBalancer
193+
Firewall object. This makes the linode use the specified NodeBalancer
194+
Firewall.
197195
properties:
198196
apiVersion:
199197
description: API version of the referent.
@@ -240,8 +238,8 @@ spec:
240238
rule: self == oldSelf
241239
objectStore:
242240
description: |-
243-
ObjectStore defines a supporting Object Storage bucket for cluster
244-
operations. This is currently used for bootstrapping (e.g. Cloud-init).
241+
ObjectStore defines a supporting Object Storage bucket for cluster operations. This is currently used for
242+
bootstrapping (e.g. Cloud-init).
245243
properties:
246244
credentialsRef:
247245
description: CredentialsRef is a reference to a Secret that contains
@@ -269,9 +267,8 @@ spec:
269267
description: The Linode Region the LinodeCluster lives in.
270268
type: string
271269
vpcID:
272-
description: |-
273-
VPCID is the ID of an existing VPC in Linode. This allows using a VPC
274-
that is not managed by CAPL.
270+
description: VPCID is the ID of an existing VPC in Linode. This allows
271+
using a VPC that is not managed by CAPL.
275272
type: integer
276273
x-kubernetes-validations:
277274
- message: Value is immutable

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ spec:
5353
properties:
5454
controlPlaneEndpoint:
5555
description: |-
56-
ControlPlaneEndpoint represents the endpoint used to communicate with
57-
the LinodeCluster control plane.
56+
ControlPlaneEndpoint represents the endpoint used to communicate with the LinodeCluster control plane.
5857
If ControlPlaneEndpoint is unset then the Nodebalancer ip will be used.
5958
properties:
6059
host:
@@ -73,9 +72,8 @@ spec:
7372
type: object
7473
credentialsRef:
7574
description: |-
76-
CredentialsRef is a reference to a Secret that contains the credentials
77-
to use for provisioning this cluster. If not supplied then the
78-
credentials of the controller will be used.
75+
CredentialsRef is a reference to a Secret that contains the credentials to use for provisioning this cluster. If not
76+
supplied then the credentials of the controller will be used.
7977
properties:
8078
name:
8179
description: name is unique within a namespace to reference
@@ -187,9 +185,9 @@ spec:
187185
rule: self == oldSelf
188186
type: object
189187
nodeBalancerFirewallRef:
190-
description: |-
191-
NodeBalancerFirewallRef is a reference to a NodeBalancer Firewall object.
192-
This makes the linode use the specified NodeBalancer Firewall.
188+
description: NodeBalancerFirewallRef is a reference to a NodeBalancer
189+
Firewall object. This makes the linode use the specified
190+
NodeBalancer Firewall.
193191
properties:
194192
apiVersion:
195193
description: API version of the referent.
@@ -236,8 +234,8 @@ spec:
236234
rule: self == oldSelf
237235
objectStore:
238236
description: |-
239-
ObjectStore defines a supporting Object Storage bucket for cluster
240-
operations. This is currently used for bootstrapping (e.g. Cloud-init).
237+
ObjectStore defines a supporting Object Storage bucket for cluster operations. This is currently used for
238+
bootstrapping (e.g. Cloud-init).
241239
properties:
242240
credentialsRef:
243241
description: CredentialsRef is a reference to a Secret
@@ -266,9 +264,8 @@ spec:
266264
description: The Linode Region the LinodeCluster lives in.
267265
type: string
268266
vpcID:
269-
description: |-
270-
VPCID is the ID of an existing VPC in Linode. This allows using a VPC
271-
that is not managed by CAPL.
267+
description: VPCID is the ID of an existing VPC in Linode.
268+
This allows using a VPC that is not managed by CAPL.
272269
type: integer
273270
x-kubernetes-validations:
274271
- message: Value is immutable

docs/src/reference/out.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,13 @@ _Appears in:_
355355
| Field | Description | Default | Validation |
356356
| --- | --- | --- | --- |
357357
| `region` _string_ | The Linode Region the LinodeCluster lives in. | | |
358-
| `controlPlaneEndpoint` _[APIEndpoint](#apiendpoint)_ | ControlPlaneEndpoint represents the endpoint used to communicate with<br />the LinodeCluster control plane.<br />If ControlPlaneEndpoint is unset then the Nodebalancer ip will be used. | | |
358+
| `controlPlaneEndpoint` _[APIEndpoint](#apiendpoint)_ | ControlPlaneEndpoint represents the endpoint used to communicate with the LinodeCluster control plane.<br />If ControlPlaneEndpoint is unset then the Nodebalancer ip will be used. | | |
359359
| `network` _[NetworkSpec](#networkspec)_ | NetworkSpec encapsulates all things related to Linode network. | | |
360360
| `vpcRef` _[ObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#objectreference-v1-core)_ | | | |
361-
| `vpcID` _integer_ | VPCID is the ID of an existing VPC in Linode. This allows using a VPC<br />that is not managed by CAPL. | | |
362-
| `nodeBalancerFirewallRef` _[ObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#objectreference-v1-core)_ | NodeBalancerFirewallRef is a reference to a NodeBalancer Firewall object.<br />This makes the linode use the specified NodeBalancer Firewall. | | |
363-
| `objectStore` _[ObjectStore](#objectstore)_ | ObjectStore defines a supporting Object Storage bucket for cluster<br />operations. This is currently used for bootstrapping (e.g. Cloud-init). | | |
364-
| `credentialsRef` _[SecretReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#secretreference-v1-core)_ | CredentialsRef is a reference to a Secret that contains the credentials<br />to use for provisioning this cluster. If not supplied then the<br />credentials of the controller will be used. | | |
361+
| `vpcID` _integer_ | VPCID is the ID of an existing VPC in Linode. This allows using a VPC that is not managed by CAPL. | | |
362+
| `nodeBalancerFirewallRef` _[ObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#objectreference-v1-core)_ | NodeBalancerFirewallRef is a reference to a NodeBalancer Firewall object. This makes the linode use the specified NodeBalancer Firewall. | | |
363+
| `objectStore` _[ObjectStore](#objectstore)_ | ObjectStore defines a supporting Object Storage bucket for cluster operations. This is currently used for<br />bootstrapping (e.g. Cloud-init). | | |
364+
| `credentialsRef` _[SecretReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#secretreference-v1-core)_ | CredentialsRef is a reference to a Secret that contains the credentials to use for provisioning this cluster. If not<br />supplied then the credentials of the controller will be used. | | |
365365

366366

367367
#### LinodeClusterStatus

internal/controller/linodeobjectstoragebucket_controller.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
utilerrors "k8s.io/apimachinery/pkg/util/errors"
2929
"k8s.io/client-go/tools/record"
30+
"k8s.io/client-go/util/retry"
3031
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3132
kutil "sigs.k8s.io/cluster-api/util"
3233
conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
@@ -173,13 +174,14 @@ func (r *LinodeObjectStorageBucketReconciler) reconcileApply(ctx context.Context
173174
bScope.Logger.Error(err, "failed to update bucket finalizer")
174175
return err
175176
}
176-
177-
if err := bScope.AddAccessKeyRefFinalizer(ctx, bScope.Bucket.Name); err != nil {
178-
bScope.Logger.Error(err, "failed to update access key finalizer")
177+
// Retry on conflict to handle the case where the access key is being updated concurrently.
178+
if err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
179+
return bScope.AddAccessKeyRefFinalizer(ctx, bScope.Bucket.Name)
180+
}); err != nil {
181+
bScope.Logger.Error(err, "failed to add access key finalizer")
179182
r.setFailure(bScope, err)
180183
return err
181184
}
182-
183185
}
184186

185187
bucket, err := services.EnsureAndUpdateObjectStorageBucket(ctx, bScope)
@@ -216,7 +218,10 @@ func (r *LinodeObjectStorageBucketReconciler) reconcileDelete(ctx context.Contex
216218
// Don't delete the bucket if the ForceDeleteBucket is false since there could be data in it that causes deletion to fail.
217219

218220
if bScope.Bucket.Spec.AccessKeyRef != nil {
219-
if err := bScope.RemoveAccessKeyRefFinalizer(ctx, bScope.Bucket.Name); err != nil {
221+
// Retry on conflict to handle the case where the access key is being updated concurrently.
222+
if err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
223+
return bScope.RemoveAccessKeyRefFinalizer(ctx, bScope.Bucket.Name)
224+
}); err != nil {
220225
bScope.Logger.Error(err, "failed to remove access key finalizer")
221226
r.setFailure(bScope, err)
222227
return err

0 commit comments

Comments
 (0)