Skip to content

Commit 724eac5

Browse files
g-gastonsbueringer
andcommitted
Amend CRS proposal to include Reconcile mode
Co-authored-by: Stefan Büringer <[email protected]>
1 parent 8df9ac7 commit 724eac5

File tree

1 file changed

+92
-7
lines changed

1 file changed

+92
-7
lines changed

docs/proposals/20200220-cluster-resource-set.md

Lines changed: 92 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ status: experimental
2828
* [Story 2](#story-2)
2929
* [Story 3](#story-3)
3030
* [Implementation Details/Notes/Constraints](#implementation-detailsnotesconstraints)
31-
* [Data model changes](#data-model-changes)
31+
* [Data model changes to existing API types](#data-model-changes-to-existing-api-types)
3232
* [ClusterResourceSet Object Definition](#clusterresourceset-object-definition)
33+
* [ClusterResourceSetBinding Object Definition](#clusterresourcesetbinding-object-definition)
34+
* [ApplyOnce mode](#applyonce-mode)
35+
* [Reconcile mode](#reconcile-mode)
3336
* [Risks and Mitigations](#risks-and-mitigations)
37+
* [Drift](#drift)
38+
* [Deletion](#deletion)
3439
* [Alternatives](#alternatives)
3540
* [Upgrade Strategy](#upgrade-strategy)
3641
* [Additional Details](#additional-details)
@@ -59,7 +64,7 @@ To achieve this, ClusterResourceSet CRD is introduced that will be responsible f
5964

6065
### Goals
6166

62-
- Provide a means to specify a set of resources to apply automatically to newly-created and existing Clusters. Resources will be applied only once.
67+
- Provide a means to specify a set of resources to apply automatically to newly-created and existing Clusters. Resources will be reapplied when their definition changes.
6368
- Support additions to the resource list by applying the new added resources to both new and existing matching clusters.
6469
- Provide a way to see which ClusterResourceSets are applied to a particular cluster using a new CRD, `ClusterResourceSetBinding`.
6570
- Support both json and yaml resources.
@@ -69,7 +74,6 @@ To achieve this, ClusterResourceSet CRD is introduced that will be responsible f
6974
- Replace or compete with the Cluster Addons subproject.
7075
- Support deletion of resources from clusters. Deleting a resource from a ClusterResourceSet or deleting a ClusterResourceSet does not result in deletion of those resources from clusters.
7176
- Lifecycle management of the installed resources (such as CNI).
72-
- Support reconciliation of resources on resource hash change and/or periodically. This can be a future enhancement work.
7377

7478

7579
## Proposal
@@ -121,13 +125,16 @@ spec:
121125
kind: ConfigMap
122126
```
123127
124-
Initially, the only supported mode will be `ApplyOnce` and it will be the default mode if no mode is provided. In the future, we may consider adding a `Reconcile` mode that reapplies the resources on resource hash change and/or periodically.
128+
The supported modes will be:
129+
* `ApplyOnce`. This will be the default mode if no mode is provided. Resources are only applied once.
130+
* `Reconcile`. Resources are reapplied when the content of the `ConfigMap` or `Secret` that defines them changes.
131+
125132
If ClusterResourceSet resources will be managed by an operator after they are applied by ClusterResourceSet controller, "ApplyOnce" mode must be used so that reconciliation on those resources can be delegated to the operator.
126133

127134
Each item in the resources specifies a kind (must be either ConfigMap or Secret) and a name. Each referenced ConfigMap/Secret contains yaml/json content as value.
128135
`ClusterResourceSet` object will be added as owner to its resources.
129136

130-
*** Secrets as Resources***
137+
***Secrets as Resources***
131138

132139
Both `Secrets` and `ConfigMaps` `data` fields can be a list of key-value pairs. Any key is acceptable, and as value, there can be multiple objects in yaml or json format.
133140

@@ -176,7 +183,7 @@ stringData:
176183
namespace: system
177184
```
178185

179-
*** ConfigMaps as Resources***
186+
***ConfigMaps as Resources***
180187

181188
Similar to `Secrets`, `ConfigMaps` can be created using a yaml/json file: `kubectl create configmap calico-addon --from-file=calico1.yaml,calico2.yaml`
182189
Multiple keys in the data field and then multiple objects in each value are supported.
@@ -253,13 +260,91 @@ When a `ClusterResourceSet` is deleted, it will be removed from the `bindings` l
253260
In case of new resource addition to a `ClusterResourceSet`, that `ClusterResourceSet` will be reconciled immediately and the new resource will be applied to all matching clusters because
254261
the new resource does not exist in any `ClusterResourceBinding` lists.
255262

263+
#### `ApplyOnce` mode
264+
256265
When the same resource exist in multiple `ClusterResourceSets`, only the first one will be applied but the resource will appear as applied in all `ClusterResourceSets` in the `ClusterResourceSetsBinding/bindings`.
257266
Similarly, if a resource is manually created in the workload cluster, when a `ClusterResourceSet` is applied with that resource, it will not update the existing resource to avoid any overwrites but in `ClusterResourceSetBinding`, that resource will show as applied.
258267

259-
As a note, if providing different values for some fields in the resources for different clusters is needed such as CNIs podCIDRs, some templating mechanism for variable substitution in the resources can be used, but not provided by `ClusterResourceSet`.
268+
#### `Reconcile` mode
269+
270+
***Detecting changes***
271+
`ClusterResourceBindings` will contain consistent hash for the resource/s definitions. We will use this to detect changes, comparing the hash of the current resource/s definition with the one stored in the `ClusterResourceBindings`.
272+
273+
Note that this hash will change when any of the resources is updated, a resource is added or a resource is removed. This means that all resources in the same `ConfigMap` or `Secret`, and not only the one that changed, will be reapplied in any of these 3 cases. It also means that resources removed from `ConfigMap` or `Secret` won't be deleted from the target clusters.
274+
275+
In the next *before-after* example we can see that only one resource has changed (`ConfigMap` `calico-configmap`). However, all the 3 resources (`calico-secret1`, `calico-secret2` and `calico-configmap`) will be reapplied.
276+
277+
Before:
278+
```yaml
279+
apiVersion: v1
280+
kind: ConfigMap
281+
metadata:
282+
name: calico-addon
283+
data:
284+
calico1.yaml: |-
285+
kind: Secret
286+
apiVersion: v1
287+
metadata:
288+
name: calico-secret1
289+
namespace: mysecrets
290+
---
291+
kind: Secret
292+
apiVersion: v1
293+
metadata:
294+
name: calico-secret2
295+
namespace: mysecrets
296+
calico2.yaml: |-
297+
kind: ConfigMap
298+
apiVersion: v1
299+
metadata:
300+
name: calico-configmap
301+
namespace: myconfigmaps
302+
data:
303+
key: "original value"
304+
```
305+
306+
After:
307+
```yaml
308+
apiVersion: v1
309+
kind: ConfigMap
310+
metadata:
311+
name: calico-addon
312+
data:
313+
calico1.yaml: |-
314+
kind: Secret
315+
apiVersion: v1
316+
metadata:
317+
name: calico-secret1
318+
namespace: mysecrets
319+
---
320+
kind: Secret
321+
apiVersion: v1
322+
metadata:
323+
name: calico-secret2
324+
namespace: mysecrets
325+
calico2.yaml: |-
326+
kind: ConfigMap
327+
apiVersion: v1
328+
metadata:
329+
name: calico-configmap
330+
namespace: myconfigmaps
331+
data:
332+
key: "value that changed"
333+
```
260334

261335
### Risks and Mitigations
262336

337+
#### Drift
338+
339+
The proposed solution only deals with changes in the resources' definitions and not with changes in the real objects in the workload clusters. If those objects are modified or deleted in the workload clusters, the `ClusterResourceSet`'s controller won't do anything and they will remain unchanged until their definition in the management cluster is updated.
340+
341+
This could potentially be mitigated by:
342+
* Implementing a "periodic" reconciliation mode where resources are reapplied with a certain frequency even if their hash hasn't changed.
343+
344+
#### Deletion
345+
346+
Resource deletion is not supported. If a resource is removed from a `ConfigMap` or `Secret`, the hash for the CRS will change so the resources that haven't been removed will be reapplied. However, the removed resourced won't be deleted.
347+
263348
## Alternatives
264349

265350
The Alternatives section is used to highlight and record other possible approaches to delivering the value proposed by a proposal.

0 commit comments

Comments
 (0)