From 5e8f261a863295550673afc681a310d7981675a3 Mon Sep 17 00:00:00 2001 From: Saranya Jena Date: Mon, 16 May 2022 17:20:32 +0530 Subject: [PATCH] Added proper error messages for upgrade agent (#69) Signed-off-by: Saranya-jena --- pkg/apis/upgrade.go | 8 ++++---- pkg/cmd/upgrade/agent.go | 9 +++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/apis/upgrade.go b/pkg/apis/upgrade.go index 529a0f33..0a1c3a00 100644 --- a/pkg/apis/upgrade.go +++ b/pkg/apis/upgrade.go @@ -122,13 +122,13 @@ func UpgradeAgent(c context.Context, cred types.Credentials, projectID string, c }, "", true) if err != nil { - return "", err + return yamlOutput, err } utils.White.Print("\n", yamlOutput) err = os.Remove("agent-manifest.yaml") if err != nil { - return "", err + return "Error removing agent manifest: ", err } // Creating a backup for current agent-config in the SUBSCRIBER @@ -138,13 +138,13 @@ func UpgradeAgent(c context.Context, cred types.Credentials, projectID string, c configMapString = metadata.String() + configMapString err = ioutil.WriteFile(home+"/backupAgentConfig.yaml", []byte(configMapString), 0644) if err != nil { - return "", err + return "Error creating backup for agent config: ", err } utils.White_B.Print("\n ** A backup of agent-config configmap has been saved in your system's home directory as backupAgentConfig.yaml **\n") return "Manifest applied successfully", nil } else { - return "", errors.New("Unmatched status code:" + string(bodyBytes)) + return "GQL error: ", errors.New("Unmatched status code:" + string(bodyBytes)) } } diff --git a/pkg/cmd/upgrade/agent.go b/pkg/cmd/upgrade/agent.go index e473e237..ff38791d 100644 --- a/pkg/cmd/upgrade/agent.go +++ b/pkg/cmd/upgrade/agent.go @@ -48,8 +48,13 @@ var agentCmd = &cobra.Command{ fmt.Scanln(&cluster_id) } - _, err = apis.UpgradeAgent(context.Background(), credentials, projectID, cluster_id) - utils.PrintError(err) + output, err := apis.UpgradeAgent(context.Background(), credentials, projectID, cluster_id) + if err != nil { + utils.Red.Print(output) + utils.PrintError(err) + } else { + utils.White.Print(output) + } }, }