Skip to content

Commit

Permalink
fix: improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianKramm committed Sep 24, 2024
1 parent dcbbeef commit 1eb301b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cmd/vclusterctl/cmd/platform/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand All @@ -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
Expand Down

0 comments on commit 1eb301b

Please sign in to comment.