Skip to content

Commit a763938

Browse files
committed
review fixes
1 parent 474fba0 commit a763938

File tree

12 files changed

+70
-57
lines changed

12 files changed

+70
-57
lines changed

api/v1beta1/cluster_types.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ type MachineDeploymentTopology struct {
157157

158158
// Variables can be used to customize the MachineDeployment through patches.
159159
// +optional
160-
Variables *ClusterVariablesOverrides `json:"variables,omitempty"`
160+
Variables *MachineDeploymentVariables `json:"variables,omitempty"`
161161
}
162162

163163
// ClusterVariable can be used to customize the Cluster through
@@ -177,14 +177,9 @@ type ClusterVariable struct {
177177
Value apiextensionsv1.JSON `json:"value"`
178178
}
179179

180-
// ClusterVariablesOverrides can be used to override top-level variables.
181-
// They must comply to the corresponding VariableClasses defined
182-
// in the ClusterClass.
183-
type ClusterVariablesOverrides struct {
184-
// Overrides can be used to override top-level variables.
185-
// They must comply to the corresponding VariableClasses defined
186-
// in the ClusterClass.
187-
// Only variables which are set top-level can be overridden.
180+
// MachineDeploymentVariables can be used to provide variables for a specific MachineDeployment.
181+
type MachineDeploymentVariables struct {
182+
// Overrides can be used to override Cluster level variables.
188183
// +optional
189184
Overrides []ClusterVariable `json:"overrides,omitempty"`
190185
}

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 23 additions & 23 deletions
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: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -973,10 +973,8 @@ spec:
973973
MachineDeployment through patches.
974974
properties:
975975
overrides:
976-
description: Overrides can be used to override top-level
977-
variables. They must comply to the corresponding
978-
VariableClasses defined in the ClusterClass. Only
979-
variables which are set top-level can be overridden.
976+
description: Overrides can be used to override Cluster
977+
level variables.
980978
items:
981979
description: ClusterVariable can be used to customize
982980
the Cluster through patches. It must comply

internal/controllers/topology/cluster/patches/variables/variables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func ControlPlane(controlPlaneTopology *clusterv1.ControlPlaneTopology, controlP
176176
func MachineDeployment(mdTopology *clusterv1.MachineDeploymentTopology, md *clusterv1.MachineDeployment) (VariableMap, error) {
177177
variables := VariableMap{}
178178

179-
// Add user defined variables from Cluster.spec.topology.variables.
179+
// Add variables overrides for the MachineDeployment.
180180
if mdTopology.Variables != nil {
181181
for _, variable := range mdTopology.Variables.Overrides {
182182
variables[variable.Name] = variable.Value

internal/controllers/topology/cluster/patches/variables/variables_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func TestMachineDeployment(t *testing.T) {
141141
Replicas: pointer.Int32(3),
142142
Name: "md-topology",
143143
Class: "md-class",
144-
Variables: &clusterv1.ClusterVariablesOverrides{
144+
Variables: &clusterv1.MachineDeploymentVariables{
145145
Overrides: []clusterv1.ClusterVariable{
146146
{
147147
Name: "location",
@@ -184,7 +184,7 @@ func TestMachineDeployment(t *testing.T) {
184184
mdTopology: &clusterv1.MachineDeploymentTopology{
185185
Name: "md-topology",
186186
Class: "md-class",
187-
Variables: &clusterv1.ClusterVariablesOverrides{
187+
Variables: &clusterv1.MachineDeploymentVariables{
188188
Overrides: []clusterv1.ClusterVariable{
189189
{
190190
Name: "location",

internal/test/builder/builders.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func (m *MachineDeploymentTopologyBuilder) Build() clusterv1.MachineDeploymentTo
196196
}
197197

198198
if len(m.variables) > 0 {
199-
md.Variables = &clusterv1.ClusterVariablesOverrides{
199+
md.Variables = &clusterv1.MachineDeploymentVariables{
200200
Overrides: m.variables,
201201
}
202202
}

internal/topology/variables/cluster_variable_defaulting.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,19 @@ import (
2929
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3030
)
3131

32-
// DefaultClusterVariables defaults variables which do not exist in clusterVariable, if they
33-
// have a default value in the corresponding schema in clusterClassVariable.
34-
func DefaultClusterVariables(clusterVariables []clusterv1.ClusterVariable, clusterClassVariables []clusterv1.ClusterClassVariable, fldPath *field.Path, createVariables bool) ([]clusterv1.ClusterVariable, field.ErrorList) {
32+
// DefaultClusterVariables defaults ClusterVariables.
33+
func DefaultClusterVariables(clusterVariables []clusterv1.ClusterVariable, clusterClassVariables []clusterv1.ClusterClassVariable, fldPath *field.Path) ([]clusterv1.ClusterVariable, field.ErrorList) {
34+
return defaultClusterVariables(clusterVariables, clusterClassVariables, true, fldPath)
35+
}
36+
37+
// DefaultMachineDeploymentVariables defaults MachineDeploymentVariables.
38+
func DefaultMachineDeploymentVariables(clusterVariables []clusterv1.ClusterVariable, clusterClassVariables []clusterv1.ClusterClassVariable, fldPath *field.Path) ([]clusterv1.ClusterVariable, field.ErrorList) {
39+
return defaultClusterVariables(clusterVariables, clusterClassVariables, false, fldPath)
40+
}
41+
42+
// defaultClusterVariables defaults variables.
43+
// If they do not exist yet, they are created if createVariables is set.
44+
func defaultClusterVariables(clusterVariables []clusterv1.ClusterVariable, clusterClassVariables []clusterv1.ClusterClassVariable, createVariables bool, fldPath *field.Path) ([]clusterv1.ClusterVariable, field.ErrorList) {
3545
var allErrs field.ErrorList
3646

3747
// Build maps for easier and faster access.

internal/topology/variables/cluster_variable_defaulting_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ func Test_DefaultClusterVariables(t *testing.T) {
230230
t.Run(tt.name, func(t *testing.T) {
231231
g := NewWithT(t)
232232

233-
vars, errList := DefaultClusterVariables(tt.clusterVariables, tt.clusterClassVariables,
234-
field.NewPath("spec", "topology", "variables"), tt.createVariables)
233+
vars, errList := defaultClusterVariables(tt.clusterVariables, tt.clusterClassVariables, tt.createVariables,
234+
field.NewPath("spec", "topology", "variables"))
235235

236236
if tt.wantErr {
237237
g.Expect(errList).NotTo(BeEmpty())

internal/topology/variables/cluster_variable_validation.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,18 @@ import (
2727
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2828
)
2929

30-
// ValidateClusterVariables validates clusterVariable via the schemas in the corresponding clusterClassVariable.
31-
func ValidateClusterVariables(clusterVariables []clusterv1.ClusterVariable, clusterClassVariables []clusterv1.ClusterClassVariable, fldPath *field.Path, validateRequired bool) field.ErrorList {
30+
// ValidateClusterVariables validates ClusterVariables.
31+
func ValidateClusterVariables(clusterVariables []clusterv1.ClusterVariable, clusterClassVariables []clusterv1.ClusterClassVariable, fldPath *field.Path) field.ErrorList {
32+
return validateClusterVariables(clusterVariables, clusterClassVariables, true, fldPath)
33+
}
34+
35+
// ValidateMachineDeploymentVariables validates ValidateMachineDeploymentVariables.
36+
func ValidateMachineDeploymentVariables(clusterVariables []clusterv1.ClusterVariable, clusterClassVariables []clusterv1.ClusterClassVariable, fldPath *field.Path) field.ErrorList {
37+
return validateClusterVariables(clusterVariables, clusterClassVariables, false, fldPath)
38+
}
39+
40+
// validateClusterVariables validates variables via the schemas in the corresponding clusterClassVariable.
41+
func validateClusterVariables(clusterVariables []clusterv1.ClusterVariable, clusterClassVariables []clusterv1.ClusterClassVariable, validateRequired bool, fldPath *field.Path) field.ErrorList {
3242
var allErrs field.ErrorList
3343

3444
// Build maps for easier and faster access.

internal/topology/variables/cluster_variable_validation_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ func Test_ValidateClusterVariables(t *testing.T) {
224224
t.Run(tt.name, func(t *testing.T) {
225225
g := NewWithT(t)
226226

227-
errList := ValidateClusterVariables(tt.clusterVariables, tt.clusterClassVariables,
228-
field.NewPath("spec", "topology", "variables"), tt.validateRequired)
227+
errList := validateClusterVariables(tt.clusterVariables, tt.clusterClassVariables,
228+
tt.validateRequired, field.NewPath("spec", "topology", "variables"))
229229

230230
if tt.wantErr {
231231
g.Expect(errList).NotTo(BeEmpty())

0 commit comments

Comments
 (0)