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

Breaking changes in enumerators in Python 3.11 #52

Open
theoctober19th opened this issue Dec 12, 2023 · 1 comment
Open

Breaking changes in enumerators in Python 3.11 #52

theoctober19th opened this issue Dec 12, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@theoctober19th
Copy link
Member

theoctober19th commented Dec 12, 2023

Since Python3.11, the f-string f"{KubernetesResourceType.SERVICEACCOUNT}" evaluates to the literal "KubernetesResourceType.SERVICEACCOUNT" itself rather than the value of that enumerator (which is the string literal "serviceaccount"). As a result, creation of service account fails with the error.

Steps to reproduce

Use Python 3.11.x to reproduce.

from spark8t.domain import ServiceAccount
from spark8t.services import K8sServiceAccountRegistry, KubeInterface

interface = KubeInterface(kube_config_file="/home/bikalpa/.kube/config")
account = ServiceAccount(name="bikalpa", namespace="default", api_server=interface.api_server)
registry = K8sServiceAccountRegistry(kube_interface=interface)

registry.create(account)

Expected behavior

The service account should get created.

Actual behavior

An exception is raised. The following is the stack trace.

b'Error: must specify one of -f and -k\n\nerror: unknown command "KubernetesResourceType.SERVICEACCOUNT bikalpa"\nSee \'kubectl create -h\' for help and examples\n'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/bikalpa/canonical/spark-k8s-toolkit-py/spark8t/services.py", line 1157, in create
    self.kube_interface.create(
  File "/home/bikalpa/canonical/spark-k8s-toolkit-py/spark8t/services.py", line 883, in create
    self.exec(
  File "/home/bikalpa/canonical/spark-k8s-toolkit-py/spark8t/services.py", line 730, 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/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'kubectl --kubeconfig /home/bikalpa/.kube/config  --namespace default  --context microk8s create KubernetesResourceType.SERVICEACCOUNT bikalpa  -o name ' returned non-zero exit status 1.

Versions

Operating system: Ubuntu 23.04

Additional context

https://blog.pecar.me/python-enum

@theoctober19th theoctober19th added the bug Something isn't working label Dec 12, 2023
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant