Skip to content

Commit 6680414

Browse files
authored
feat: enable ClusterAccessReconciler's Reconcile method to be called during deletion (#197)
* improve clusteraccess library logic * have clusteraccess reconciler remember which requests are in deletion
1 parent 90bc43f commit 6680414

File tree

3 files changed

+277
-53
lines changed

3 files changed

+277
-53
lines changed

docs/libraries/clusteraccess.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ func (c *MyController) Reconcile(ctx context.Context, req reconcile.Request) (re
8888
The ClusterAccess Reconciler's `SkipWorkloadCluster` method can be used during initialization to disable creation of a `ClusterRequest` for a workload cluster.
8989
If for some reason the `AccessRequest` resources are required, they can be retrieved via `MCPAccessRequest` and `WorkloadAccessRequest`.
9090

91+
The ClusterAccess Reconciler remembers requests that are in deletion and won't create new resources for them. This means that `Reconcile` can safely be called at the beginning of a reconciliation that is going to delete resources and `ReconcileDelete` at the end of it, without the former one recreating resources the latter one has already removed.
92+
A request is considered to be 'in deletion' when `ReconcileDelete` is called for it and it stops being 'in deletion' when `ReconcileDelete` returns with a `RequeueAfter` value of zero and no error.
93+
9194
### ClusterAccess Reconciler - Advanced
9295

9396
Instantiate the ClusterAccess Reconciler during controller setup and store the instance in the controller's struct.
@@ -184,6 +187,9 @@ There are four getter methods that can be called after the cluster access has be
184187

185188
Note that not all of these methods will always return something. For example, a registration created via `ExistingCluster(...)` references a `Cluster` directly and can therefore not return a `ClusterRequest`. `Access` and `AccessRequest` will only work if either token-based access or OIDC-based access has been configured during the registration, otherwise there won't be any `AccessRequest`. Any method which cannot return the expected value due to the resource not being configured will simply return `nil` instead, without an error. The error is only returned if something goes wrong during retrieval of the resource.
186189

190+
The ClusterAccess Reconciler remembers requests that are in deletion and won't create new resources for them. This means that `Reconcile` can safely be called at the beginning of a reconciliation that is going to delete resources and `ReconcileDelete` at the end of it, without the former one recreating resources the latter one has already removed.
191+
A request is considered to be 'in deletion' when `ReconcileDelete` is called for it and it stops being 'in deletion' when `ReconcileDelete` returns with a `RequeueAfter` value of zero and no error.
192+
187193
#### Additional Data
188194

189195
While probably not required for most cases, there might be some situations in which the generation of resources requires more information than just the `reconcile.Request`, for example if the controller fetches some kind of configuration that specifies the required access permissions. The ClusterAccess library enables this by allowing arbitrary arguments to be passed into some methods: `Reconcile`, `ReconcileDelete`, as well as the four getter methods `Access`, `AccessRequest`, `ClusterRequest`, and `Cluster` take any amount of optional arguments. Additional arguments that are passed into any of these methods will be passed to the generator functions (which have been passed into `WithTokenAccessGenerator`, `WithOIDCAccessGenerator`, and `WithNamespaceGenerator` during creation of the `ClusterRegistration`), which can use the additional information for generating the namespace or the spec for `AccessRequest` or `ClusterRequest`.

0 commit comments

Comments
 (0)