Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Improve Cluster variable defaulting/validation errors #9452

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL: Technically we produce this error during defaulting and validation, so we have two of them. But this gets deduplicated during error aggregation in apierrors.NewInvalid

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