Skip to content

Commit

Permalink
Added proper error messages for upgrade agent (#69)
Browse files Browse the repository at this point in the history
Signed-off-by: Saranya-jena <saranya.jena@harness.io>
  • Loading branch information
Saranya-jena committed May 16, 2022
1 parent 7ea4b77 commit 5e8f261
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions pkg/apis/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
}
}
9 changes: 7 additions & 2 deletions pkg/cmd/upgrade/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
},
}

Expand Down

0 comments on commit 5e8f261

Please sign in to comment.