From 5fb4d26e09742d46d49808566bb4b4f1470cc41a 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 f0393db22d81..0c825adac082 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 dc8f2c804e94..c16f2dfcc6c0 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.