Skip to content

Commit 1b7490a

Browse files
authored
Merge pull request #7243 from sbueringer/pr-relax-md-var-validation
🌱 ClusterClass: relax validation of MD variables overrides of opt variables
2 parents 80c4450 + ebf2161 commit 1b7490a

File tree

4 files changed

+2
-151
lines changed

4 files changed

+2
-151
lines changed

internal/topology/variables/cluster_variable_validation.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,6 @@ func validateClusterVariablesDefined(clusterVariables []clusterv1.ClusterVariabl
102102
return allErrs
103103
}
104104

105-
// ValidateTopLevelClusterVariablesExist validates that all overrides have a corresponding top-level variable.
106-
func ValidateTopLevelClusterVariablesExist(clusterVariablesOverrides []clusterv1.ClusterVariable, clusterVariables []clusterv1.ClusterVariable, fldPath *field.Path) field.ErrorList {
107-
var allErrs field.ErrorList
108-
109-
// Build map for easier and faster access.
110-
clusterVariablesMap := getClusterVariablesMap(clusterVariables)
111-
112-
for i, clusterVariableOverride := range clusterVariablesOverrides {
113-
if _, ok := clusterVariablesMap[clusterVariableOverride.Name]; !ok {
114-
return field.ErrorList{field.Invalid(fldPath.Index(i).Child("name"), clusterVariableOverride.Name,
115-
fmt.Sprintf("variable override with name %q is missing a corresponding top-level variable", clusterVariableOverride.Name))}
116-
}
117-
}
118-
119-
return allErrs
120-
}
121-
122105
// ValidateClusterVariable validates a clusterVariable.
123106
func ValidateClusterVariable(clusterVariable *clusterv1.ClusterVariable, clusterClassVariable *clusterv1.ClusterClassVariable, fldPath *field.Path) field.ErrorList {
124107
// Parse JSON value.

internal/topology/variables/cluster_variable_validation_test.go

Lines changed: 0 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -236,135 +236,6 @@ func Test_ValidateClusterVariables(t *testing.T) {
236236
}
237237
}
238238

239-
func Test_ValidateTopLevelClusterVariablesExist(t *testing.T) {
240-
tests := []struct {
241-
name string
242-
clusterVariablesOverrides []clusterv1.ClusterVariable
243-
clusterVariables []clusterv1.ClusterVariable
244-
wantErr bool
245-
}{
246-
{
247-
name: "Pass if all variable overrides have corresponding top-level variables.",
248-
clusterVariablesOverrides: []clusterv1.ClusterVariable{
249-
{
250-
Name: "cpu",
251-
Value: apiextensionsv1.JSON{
252-
Raw: []byte(`1`),
253-
},
254-
},
255-
{
256-
Name: "zone",
257-
Value: apiextensionsv1.JSON{
258-
Raw: []byte(`"longerThanOneCharacter"`),
259-
},
260-
},
261-
},
262-
clusterVariables: []clusterv1.ClusterVariable{
263-
{
264-
Name: "cpu",
265-
Value: apiextensionsv1.JSON{
266-
Raw: []byte(`1`),
267-
},
268-
},
269-
{
270-
Name: "zone",
271-
Value: apiextensionsv1.JSON{
272-
Raw: []byte(`"longerThanOneCharacter"`),
273-
},
274-
},
275-
},
276-
},
277-
{
278-
name: "Pass if there are no variable overrides and no top-level variables.",
279-
clusterVariablesOverrides: []clusterv1.ClusterVariable{},
280-
clusterVariables: []clusterv1.ClusterVariable{},
281-
},
282-
{
283-
name: "Pass if there are no variable overrides.",
284-
clusterVariablesOverrides: []clusterv1.ClusterVariable{},
285-
clusterVariables: []clusterv1.ClusterVariable{
286-
{
287-
Name: "cpu",
288-
Value: apiextensionsv1.JSON{
289-
Raw: []byte(`1`),
290-
},
291-
},
292-
{
293-
Name: "zone",
294-
Value: apiextensionsv1.JSON{
295-
Raw: []byte(`"longerThanOneCharacter"`),
296-
},
297-
},
298-
},
299-
},
300-
{
301-
name: "Error if a variable override is missing the corresponding top-level variables.",
302-
clusterVariablesOverrides: []clusterv1.ClusterVariable{
303-
{
304-
Name: "cpu",
305-
Value: apiextensionsv1.JSON{
306-
Raw: []byte(`1`),
307-
},
308-
},
309-
{
310-
Name: "zone",
311-
Value: apiextensionsv1.JSON{
312-
Raw: []byte(`"longerThanOneCharacter"`),
313-
},
314-
},
315-
},
316-
clusterVariables: []clusterv1.ClusterVariable{
317-
{
318-
Name: "zone",
319-
Value: apiextensionsv1.JSON{
320-
Raw: []byte(`"longerThanOneCharacter"`),
321-
},
322-
},
323-
},
324-
wantErr: true,
325-
},
326-
{
327-
name: "Pass if not every top-level variable has an override.",
328-
clusterVariablesOverrides: []clusterv1.ClusterVariable{
329-
{
330-
Name: "zone",
331-
Value: apiextensionsv1.JSON{
332-
Raw: []byte(`"longerThanOneCharacter"`),
333-
},
334-
},
335-
},
336-
clusterVariables: []clusterv1.ClusterVariable{
337-
{
338-
Name: "cpu",
339-
Value: apiextensionsv1.JSON{
340-
Raw: []byte(`1`),
341-
},
342-
},
343-
{
344-
Name: "zone",
345-
Value: apiextensionsv1.JSON{
346-
Raw: []byte(`"longerThanOneCharacter"`),
347-
},
348-
},
349-
},
350-
},
351-
}
352-
for _, tt := range tests {
353-
t.Run(tt.name, func(t *testing.T) {
354-
g := NewWithT(t)
355-
356-
errList := ValidateTopLevelClusterVariablesExist(tt.clusterVariablesOverrides, tt.clusterVariables,
357-
field.NewPath("spec", "topology", "workers", "machineDeployments").Index(0).Child("variables", "overrides"))
358-
359-
if tt.wantErr {
360-
g.Expect(errList).NotTo(BeEmpty())
361-
return
362-
}
363-
g.Expect(errList).To(BeEmpty())
364-
})
365-
}
366-
}
367-
368239
func Test_ValidateClusterVariable(t *testing.T) {
369240
tests := []struct {
370241
name string

internal/webhooks/cluster.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,6 @@ func (webhook *Cluster) validateTopology(ctx context.Context, oldCluster, newClu
259259
continue
260260
}
261261

262-
allErrs = append(allErrs, variables.ValidateTopLevelClusterVariablesExist(md.Variables.Overrides, newCluster.Spec.Topology.Variables,
263-
fldPath.Child("workers", "machineDeployments").Index(i).Child("variables", "overrides"))...)
264-
265262
allErrs = append(allErrs, variables.ValidateMachineDeploymentVariables(md.Variables.Overrides, clusterClass.Spec.Variables,
266263
fldPath.Child("workers", "machineDeployments").Index(i).Child("variables", "overrides"))...)
267264
}

internal/webhooks/cluster_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ func TestClusterTopologyValidation(t *testing.T) {
757757
expectErr: true,
758758
},
759759
{
760-
name: "should fail when variable override is missing the corresponding top-level variable",
760+
name: "should pass even when variable override is missing the corresponding top-level variable",
761761
clusterClassVariables: []clusterv1.ClusterClassVariable{
762762
{
763763
Name: "cpu",
@@ -782,7 +782,7 @@ func TestClusterTopologyValidation(t *testing.T) {
782782
Build()).
783783
Build()).
784784
Build(),
785-
expectErr: true,
785+
expectErr: false,
786786
},
787787
}
788788

0 commit comments

Comments
 (0)