Skip to content

Commit

Permalink
Improve Cluster variable defaulting/validation errors
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer [email protected]
  • Loading branch information
sbueringer authored and k8s-infra-cherrypick-robot committed Sep 21, 2023
1 parent 816e2d1 commit 5fb4d26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions internal/topology/variables/cluster_variable_defaulting.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package variables
import (
"encoding/json"
"fmt"
"strings"

"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand Down Expand Up @@ -49,8 +50,11 @@ func defaultClusterVariables(values []clusterv1.ClusterVariable, definitions []c
// - variables with the same name do not have a mix of empty and non-empty DefinitionFrom.
valuesIndex, err := newValuesIndex(values)
if err != nil {
return nil, append(allErrs, field.Invalid(fldPath, values,
fmt.Sprintf("cluster variables not valid: %s", err)))
var valueStrings []string
for _, v := range values {
valueStrings = append(valueStrings, fmt.Sprintf("Name: %s DefinitionFrom: %s", v.Name, v.DefinitionFrom))
}
return nil, append(allErrs, field.Invalid(fldPath, "["+strings.Join(valueStrings, ",")+"]", fmt.Sprintf("cluster variables not valid: %s", err)))
}

// Get an index for each variable name and definition.
Expand Down
6 changes: 5 additions & 1 deletion internal/topology/variables/cluster_variable_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ func validateClusterVariables(values []clusterv1.ClusterVariable, definitions []
// - variables with the same name do not have a mix of empty and non-empty DefinitionFrom.
valuesMap, err := newValuesIndex(values)
if err != nil {
return append(allErrs, field.Invalid(fldPath, values, fmt.Sprintf("cluster variables not valid: %s", err)))
var valueStrings []string
for _, v := range values {
valueStrings = append(valueStrings, fmt.Sprintf("Name: %s DefinitionFrom: %s", v.Name, v.DefinitionFrom))
}
return append(allErrs, field.Invalid(fldPath, "["+strings.Join(valueStrings, ",")+"]", fmt.Sprintf("cluster variables not valid: %s", err)))
}

// Get an index of definitions for each variable name and definition from the ClusterClass variable.
Expand Down

0 comments on commit 5fb4d26

Please sign in to comment.