Skip to content

Commit 6b3f021

Browse files
authored
⚠️ Adjust CC & Cluster controller to block on variable conflicts, deprecate definitionFrom (kubernetes-sigs#10841)
* Deprecate definitionFrom, adjust CC & Cluster controller to block on conflicts * fix review findings
1 parent bcb0efd commit 6b3f021

File tree

22 files changed

+1059
-1100
lines changed

22 files changed

+1059
-1100
lines changed

api/v1beta1/cluster_types.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ type Topology struct {
103103
// patches. They must comply to the corresponding
104104
// VariableClasses defined in the ClusterClass.
105105
// +optional
106+
// +listType=map
107+
// +listMapKey=name
106108
Variables []ClusterVariable `json:"variables,omitempty"`
107109
}
108110

@@ -319,10 +321,10 @@ type ClusterVariable struct {
319321
// Name of the variable.
320322
Name string `json:"name"`
321323

322-
// DefinitionFrom specifies where the definition of this Variable is from. DefinitionFrom is `inline` when the
323-
// definition is from the ClusterClass `.spec.variables` or the name of a patch defined in the ClusterClass
324-
// `.spec.patches` where the patch is external and provides external variables.
325-
// This field is mandatory if the variable has `DefinitionsConflict: true` in ClusterClass `status.variables[]`
324+
// DefinitionFrom specifies where the definition of this Variable is from.
325+
//
326+
// Deprecated: This field is deprecated, must not be set anymore and is going to be removed in the next apiVersion.
327+
//
326328
// +optional
327329
DefinitionFrom string `json:"definitionFrom,omitempty"`
328330

@@ -340,20 +342,26 @@ type ClusterVariable struct {
340342
type ControlPlaneVariables struct {
341343
// Overrides can be used to override Cluster level variables.
342344
// +optional
345+
// +listType=map
346+
// +listMapKey=name
343347
Overrides []ClusterVariable `json:"overrides,omitempty"`
344348
}
345349

346350
// MachineDeploymentVariables can be used to provide variables for a specific MachineDeployment.
347351
type MachineDeploymentVariables struct {
348352
// Overrides can be used to override Cluster level variables.
349353
// +optional
354+
// +listType=map
355+
// +listMapKey=name
350356
Overrides []ClusterVariable `json:"overrides,omitempty"`
351357
}
352358

353359
// MachinePoolVariables can be used to provide variables for a specific MachinePool.
354360
type MachinePoolVariables struct {
355361
// Overrides can be used to override Cluster level variables.
356362
// +optional
363+
// +listType=map
364+
// +listMapKey=name
357365
Overrides []ClusterVariable `json:"overrides,omitempty"`
358366
}
359367

api/v1beta1/zz_generated.openapi.go

Lines changed: 33 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/cluster.x-k8s.io_clusters.yaml

Lines changed: 28 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/book/src/tasks/experimental-features/runtime-sdk/implement-topology-mutation-hook.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ status:
9696
description: "comma-separated list of machine or domain names excluded from using the proxy."
9797
- name: http-proxy
9898
# definitionsConflict is true if there are non-equal definitions for a variable.
99+
# Note: This conflict has to be resolved, until then corresponding Clusters are not reconciled.
99100
definitionsConflict: true
100101
definitions:
101102
- from: inline
@@ -121,13 +122,15 @@ Variables that are defined by an external DiscoverVariables hook will have the n
121122
Variables that are defined in the ClusterClass `.spec.variables` will have `inline` as the value of `from`.
122123
Note: `inline` is a reserved name for patches. It cannot be used as the name of an external patch to avoid conflicts.
123124

124-
If all variables that share a name have equivalent schemas the variable definitions are not in conflict. These variables can
125-
be set without providing `definitionFrom` value - [see below](#setting-values-for-variables-in-the-cluster). The CAPI components will
126-
consider variable definitions to be equivalent when they share a name and their schema is exactly equal.
125+
If all variables that share a name have equivalent schemas the variable definitions are not in conflict. The CAPI components will
126+
consider variable definitions to be equivalent when they share a name and their schema is exactly equal. If variables are in conflict
127+
the `VariablesReconciled` will be set to false and the conflict has to be resolved. While there are variable conflicts, corresponding
128+
Clusters will **not be reconciled**.
129+
130+
Note: We enforce that variable conflicts have to be resolved by ClusterClass authors, so that defining Cluster topology is as simply as possible for end users.
127131

128132
### Setting values for variables in the Cluster
129-
Setting variables that are defined with external variable definitions requires attention to be paid to variable definition conflicts, as exposed in the ClusterClass status.
130-
Variable values are set in Cluster `.spec.topology.variables`.
133+
Variables that are defined with external variable definitions can be set like regular variables in Cluster `.spec.topology.variables`.
131134

132135
```yaml
133136
apiVersion: cluster.x-k8s.io/v1beta1
@@ -136,18 +139,10 @@ kind: Cluster
136139
spec:
137140
topology:
138141
variables:
139-
# `definitionFrom` is not needed as this variable does not have conflicting definitions.
140142
- name: no-proxy
141143
value: "internal.domain.com"
142-
# variables with the same name but different definitions require values for each individual schema.
143144
- name: http-proxy
144-
definitionFrom: inline
145145
value: http://proxy.example2.com:1234
146-
- name: http-proxy
147-
definitionFrom: lbImageRepository
148-
value:
149-
host: proxy.example2.com
150-
port: 1234
151146
```
152147

153148
## Using one or multiple external patch extensions

internal/controllers/clusterclass/clusterclass_controller.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,21 @@ func (r *Reconciler) reconcileVariables(ctx context.Context, clusterClass *clust
284284
return statusVarList[i].Name < statusVarList[j].Name
285285
})
286286
clusterClass.Status.Variables = statusVarList
287+
288+
variablesWithConflict := []string{}
289+
for _, v := range clusterClass.Status.Variables {
290+
if v.DefinitionsConflict {
291+
variablesWithConflict = append(variablesWithConflict, v.Name)
292+
}
293+
}
294+
295+
if len(variablesWithConflict) > 0 {
296+
err := fmt.Errorf("the following variables have conflicting schemas: %s", strings.Join(variablesWithConflict, ","))
297+
conditions.MarkFalse(clusterClass, clusterv1.ClusterClassVariablesReconciledCondition, clusterv1.VariableDiscoveryFailedReason, clusterv1.ConditionSeverityError,
298+
"VariableDiscovery failed: %s", err)
299+
return errors.Wrapf(err, "failed to discover variables for ClusterClass %s", clusterClass.Name)
300+
}
301+
287302
conditions.MarkTrue(clusterClass, clusterv1.ClusterClassVariablesReconciledCondition)
288303
return nil
289304
}

0 commit comments

Comments
 (0)