canonical / spark-k8s-toolkit-py

Python package with tooling to seamlessly handle Spark Ops on K8s
Apache License 2.0
5 stars 4 forks source link

CLI crashes with exception on creating a service account in non-existent namespace #55

Open theoctober19th opened 10 months ago

theoctober19th commented 10 months ago

Steps to reproduce

  1. Try creating a new service account using CLI but provide a namespace that does not exist.
python spark8t/cli/service_account_registry.py create --username something --namespace something_that_does_not_exist

Expected behavior

Appropriate error message should be shown and the program should not crash.

Actual behavior

The program crashes with exception.

b'error: failed to create serviceaccount: namespaces "something_that_does_not_exist" not found\n'
Traceback (most recent call last):
  File "/home/bikalpa/canonical/spark-k8s-toolkit-py/spark8t/cli/service_account_registry.py", line 206, in <module>
    raise e
  File "/home/bikalpa/canonical/spark-k8s-toolkit-py/spark8t/cli/service_account_registry.py", line 200, in <module>
    main(args, logger)
  File "/home/bikalpa/canonical/spark-k8s-toolkit-py/spark8t/cli/service_account_registry.py", line 119, in main
    registry.create(service_account)
  File "/home/bikalpa/canonical/spark-k8s-toolkit-py/spark8t/services.py", line 1214, in create
    self.kube_interface.create(
  File "/home/bikalpa/canonical/spark-k8s-toolkit-py/spark8t/services.py", line 909, in create
    self.exec(
  File "/home/bikalpa/canonical/spark-k8s-toolkit-py/spark8t/services.py", line 757, in exec
    else execute_command_output(base_cmd)
  File "/home/bikalpa/canonical/spark-k8s-toolkit-py/spark8t/utils.py", line 285, in execute_command_output
    raise e
  File "/home/bikalpa/canonical/spark-k8s-toolkit-py/spark8t/utils.py", line 279, in execute_command_output
    output = subprocess.check_output(
  File "/usr/local/lib/python3.10/subprocess.py", line 421, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/local/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'kubectl --kubeconfig /home/bikalpa/.kube/config  --namespace something_that_does_not_exist  --context microk8s create serviceaccount something  -o name ' returned non-zero exit status 1.

Versions

Operating system: Ubuntu 23.04

Additional context

The bug exists for both backends (lightkube and kubectl)

github-actions[bot] commented 10 months ago

https://warthogs.atlassian.net/browse/DPE-3247