Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DPE-2082] User-friendly output when no primary account is defined #21

Merged
merged 8 commits into from
Jun 21, 2023

Conversation

deusebio
Copy link
Contributor

@deusebio deusebio commented Jun 16, 2023

When no account is found, we produce readable output instead of stacktraces.

Output currently in main

$ spark-client.service-account-registry get-primary
Traceback (most recent call last):
  File "/snap/spark-client/x2/lib/python3.10/site-packages/spark8t/cli/service_account_registry.py", line 181, in <module>
    raise NoAccountFound()
spark8t.exceptions.NoAccountFound

and

$ spark-client.service-account-registry get-config --username=not-existing                                                                                            
Error from server (NotFound): serviceaccounts "not-existing" not found
Traceback (most recent call last):
  File "/snap/spark-client/x2/lib/python3.10/site-packages/spark8t/cli/service_account_registry.py", line 165, in <module>
    maybe_service_account = registry.get(input_service_account.id)
  File "/snap/spark-client/x2/lib/python3.10/site-packages/spark8t/services.py", line 1261, in get
    service_account_raw = self.kube_interface.get_service_account(
  File "/snap/spark-client/x2/lib/python3.10/site-packages/spark8t/services.py", line 727, in get_service_account
    service_account_raw = self.exec(cmd, namespace=self.namespace)
  File "/snap/spark-client/x2/lib/python3.10/site-packages/spark8t/services.py", line 709, in exec
    parse_yaml_shell_output(base_cmd)
  File "/snap/spark-client/x2/lib/python3.10/site-packages/spark8t/utils.py", line 179, in parse_yaml_shell_output
    subprocess.check_output(cmd, shell=True, stderr=None).decode("utf-8")
  File "/usr/lib/python3.10/subprocess.py", line 420, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.10/subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'kubectl --kubeconfig /home/deusebio/.kube/config  --namespace default  --context microk8s get serviceaccount not-existing -n default -o yaml ' returned non-zero exit status 1.

Output proposed in the PR

$ python -m spark8t.cli.service_account_registry get-primary                       
2023-06-20 10:37:32.000+0200 INFO [spark8t.cli.service_account_registry] (MainThread) (main) Using K8s context: microk8s
2023-06-20 10:37:32.000+0200 WARNING [spark8t.services.K8sServiceAccountRegistry] (MainThread) (get_primary) There are no primary service account available.
2023-06-20 10:37:32.000+0200 ERROR [spark8t.cli.service_account_registry] (MainThread) (<module>) Primary account not found

and

$  python -m spark8t.cli.service_account_registry get-config --username=not-existing
2023-06-20 10:37:47.000+0200 INFO [spark8t.cli.service_account_registry] (MainThread) (main) Using K8s context: microk8s
2023-06-20 10:37:47.000+0200 ERROR [spark8t.cli.service_account_registry] (MainThread) (<module>) Account default:not-existing not found

Copy link

@grobbie grobbie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Small remark but you should tell the user what they could do to resolve the issue in the error message. ie. what command they need to run.

spark8t/exceptions.py Outdated Show resolved Hide resolved
spark8t/services.py Show resolved Hide resolved
@deusebio deusebio merged commit 8ea6156 into canonical:main Jun 21, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants