From 7897da4be4ca6d6be9831fc5734707f156fa46cf Mon Sep 17 00:00:00 2001 From: yipeng1030 <58055769+yipeng1030@users.noreply.github.com> Date: Wed, 8 Jan 2025 11:27:38 +0800 Subject: [PATCH] fix: fix explain-config cmd (#532) --- pkg/cmd/cluster/config_observer.go | 5 +++++ pkg/cmd/cluster/errors.go | 1 + 2 files changed, 6 insertions(+) diff --git a/pkg/cmd/cluster/config_observer.go b/pkg/cmd/cluster/config_observer.go index 4a3c71502..145214152 100644 --- a/pkg/cmd/cluster/config_observer.go +++ b/pkg/cmd/cluster/config_observer.go @@ -168,6 +168,11 @@ func (r *configObserverOptions) printExplainConfigure(configSpecs configSpecsTyp return nil } + if tpl.ConfigConstraint == nil { + fmt.Printf("\n%s\n", fmt.Sprintf(noConfigConstraintPrompt, printer.BoldYellow(tplName))) + return nil + } + confSpec := tpl.ConfigConstraint.Spec if confSpec.ParametersSchema == nil { fmt.Printf("\n%s\n", fmt.Sprintf(notConfigSchemaPrompt, printer.BoldYellow(tplName))) diff --git a/pkg/cmd/cluster/errors.go b/pkg/cmd/cluster/errors.go index 4459d652b..2688b4949 100644 --- a/pkg/cmd/cluster/errors.go +++ b/pkg/cmd/cluster/errors.go @@ -41,6 +41,7 @@ var ( notFoundConfigFileErrorMessage = "cannot find config file[name=%s] in the configspec[name=%s], all configfiles: %v" notSupportFileUpdateErrorMessage = "not supported file[%s] for updating, current supported files: %v" + noConfigConstraintPrompt = "cannot find configConstraint for template[%s]" notConfigSchemaPrompt = "The config template[%s] is not defined in schema and parameter explanation info cannot be generated." cue2openAPISchemaFailedPrompt = "The cue schema may not satisfy the conversion constraints of openAPISchema and parameter explanation info cannot be generated." restartConfirmPrompt = "The parameter change incurs a cluster restart, which brings the cluster down for a while. Enter to continue...\n, "