From ada7d87b2279f9e12446e4c4929c3cd6864a8e1d Mon Sep 17 00:00:00 2001 From: Fabian Kramm Date: Tue, 24 Sep 2024 09:54:26 +0200 Subject: [PATCH] fix: improve error message (cherry picked from commit 1eb301b48e649720ec29f8ad48d44d0dcc6f702a) --- cmd/vclusterctl/cmd/platform/reset.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/vclusterctl/cmd/platform/reset.go b/cmd/vclusterctl/cmd/platform/reset.go index 4e450f978..44947e615 100644 --- a/cmd/vclusterctl/cmd/platform/reset.go +++ b/cmd/vclusterctl/cmd/platform/reset.go @@ -97,6 +97,22 @@ func (cmd *PasswordCmd) Run() error { return err } + // check if cluster has platform installed + apiResourceList, err := managementClient.Discovery().ServerResourcesForGroupVersion(storagev1.GroupVersion.String()) + if err != nil { + return fmt.Errorf("looks like the api group storage.loft.sh couldn't be found (%w). Please make sure you select the kube context the platform was installed in for this command to work", err) + } + found := false + for _, apiResource := range apiResourceList.APIResources { + if apiResource.Kind == "User" { + found = true + break + } + } + if !found { + return fmt.Errorf("resource User in api group storage.loft.sh couldn't be found. Please make sure you select the kube context the platform was installed in for this command to work") + } + // get user cmd.Log.Infof("Resetting password of user %s", cmd.User) user, err := managementClient.Loft().StorageV1().Users().Get(context.Background(), cmd.User, metav1.GetOptions{}) @@ -111,7 +127,7 @@ func (cmd *PasswordCmd) Run() error { if cmd.Namespace == "" { namespace, err := clihelper.VClusterPlatformInstallationNamespace(context.Background()) if err != nil { - return fmt.Errorf("failed to find platform namespace") + return fmt.Errorf("failed to find platform namespace: %w", err) } cmd.Namespace = namespace