Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#9452 from sbueringer/pr-improve-we…
Browse files Browse the repository at this point in the history
…bhook-err

🌱 Improve Cluster variable defaulting/validation errors
  • Loading branch information
k8s-ci-robot authored Sep 21, 2023
2 parents 332882b + fec166c commit 753fa61
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 753fa61

Please sign in to comment.