From fec166c028416e099bfe07ce32115c0154d1138b Mon Sep 17 00:00:00 2001 From: Stefan Bueringer Date: Mon, 18 Sep 2023 18:57:16 +0200 Subject: [PATCH] Improve Cluster variable defaulting/validation errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Büringer buringerst@vmware.com --- .../topology/variables/cluster_variable_defaulting.go | 8 ++++++-- .../topology/variables/cluster_variable_validation.go | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/topology/variables/cluster_variable_defaulting.go b/internal/topology/variables/cluster_variable_defaulting.go index 442998f2fe40..3f4a38ad344c 100644 --- a/internal/topology/variables/cluster_variable_defaulting.go +++ b/internal/topology/variables/cluster_variable_defaulting.go @@ -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" @@ -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. diff --git a/internal/topology/variables/cluster_variable_validation.go b/internal/topology/variables/cluster_variable_validation.go index 992bc600c67d..1b4a07772640 100644 --- a/internal/topology/variables/cluster_variable_validation.go +++ b/internal/topology/variables/cluster_variable_validation.go @@ -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.