rundeck-plugins / kubernetes

52 stars 61 forks source link

Error when trying to create a Deployment or a Pod #105

Open sdmorel opened 3 years ago

sdmorel commented 3 years ago

Hello,

I'm testing this plugin and I got the Resource Model working just fine. But when I try to use one of the workflow steps to create a Deployment or a Pod I get the following error:

[Kubernetes-Create-Deployment] step started, config: {image=registry.example.com/busybox:1.33.0, debug=true, container_name=busybox, verify_ssl=false, replicas=1, name=busybox-deployment, namespace=rundeck-dev, api_version=apps/v1, labels=app=busybox}
[Kubernetes-Create-Deployment] executing: [python, -u, /home/rundeck/libext/cache/kubernetes-plugin-2.0.3/deployment-create.py]
DEBUG: kubernetes-model-source: Log level configured for DEBUG
DEBUG: kubernetes-model-source: Creating job from data:
DEBUG: kubernetes-model-source: {'api_version': 'apps/v1', 'name': 'busybox-deployment', 'container_name': 'busybox', 'image': 'registry.example.com/busybox:1.33.0', 'ports': None, 'replicas': '1', 'namespace': 'rundeck-dev', 'labels': 'app=busybox'}
DEBUG: kubernetes-plugin: config file
DEBUG: kubernetes-plugin: None
DEBUG: kubernetes-plugin: -------------------
DEBUG: kubernetes-plugin: getting from default config file
Traceback (most recent call last):
  File "/home/rundeck/libext/cache/kubernetes-plugin-2.0.3/deployment-create.py", line 128, in <module>
    main()
  File "/home/rundeck/libext/cache/kubernetes-plugin-2.0.3/deployment-create.py", line 123, in main
    deployment = create_deployment_object(data)
  File "/home/rundeck/libext/cache/kubernetes-plugin-2.0.3/deployment-create.py", line 19, in create_deployment_object
    template_spec = common.create_pod_template_spec(data=data)
  File "/home/rundeck/libext/cache/kubernetes-plugin-2.0.3/common.py", line 264, in create_pod_template_spec
    for port in data["ports"].split(','):
AttributeError: 'NoneType' object has no attribute 'split'
[Kubernetes-Create-Deployment]: result code: 1

And the deployment is not created in Kubernetes. This happens for any Pod with the ports field empty.

But when I deploy nginx with the port filed filled in, the following error occurs, but for some reason the deployment is created in Kubernetes.

[Kubernetes-Create-Deployment] step started, config: {image=registry.example.com/nginx:1.19.10-alpine, debug=true, container_name=nginx, verify_ssl=false, replicas=1, name=nginx-deployment, namespace=rundeck-dev, api_version=apps/v1, ports=80, labels=app=nginx}
[Kubernetes-Create-Deployment] executing: [python, -u, /home/rundeck/libext/cache/kubernetes-plugin-2.0.3/deployment-create.py]
DEBUG: kubernetes-model-source: Log level configured for DEBUG
DEBUG: kubernetes-model-source: Creating job from data:
DEBUG: kubernetes-model-source: {'api_version': 'apps/v1', 'name': 'nginx-deployment', 'container_name': 'nginx', 'image': 'registry.example.com/nginx:1.19.10-alpine', 'ports': '80', 'replicas': '1', 'namespace': 'rundeck-dev', 'labels': 'app=nginx'}
DEBUG: kubernetes-plugin: config file
DEBUG: kubernetes-plugin: None
DEBUG: kubernetes-plugin: -------------------
DEBUG: kubernetes-plugin: getting from default config file
Traceback (most recent call last):
  File "/home/rundeck/libext/cache/kubernetes-plugin-2.0.3/deployment-create.py", line 128, in <module>
    main()
  File "/home/rundeck/libext/cache/kubernetes-plugin-2.0.3/deployment-create.py", line 124, in main
    create_deployment(apiV1, deployment, data)
  File "/home/rundeck/libext/cache/kubernetes-plugin-2.0.3/deployment-create.py", line 60, in create_deployment
    print(common.parseJson(api_response.status))
  File "/home/rundeck/libext/cache/kubernetes-plugin-2.0.3/common.py", line 258, in parseJson
    return json.dumps(obj, cls=ObjectEncoder)
  File "/usr/lib/python3.6/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.6/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.6/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/home/rundeck/libext/cache/kubernetes-plugin-2.0.3/common.py", line 254, in default
    return {k.lstrip('_'): v for k, v in vars(obj).items()}
TypeError: vars() argument must have __dict__ attribute
[Kubernetes-Create-Deployment]: result code: 1

Using the Kubernetes/Generic/Create workflow step returns the same error in the Nginx deployment case. Again, in this case the deployment is created in Kubernetes.

DEBUG: kubernetes-model-source: Log level configured for DEBUG
Traceback (most recent call last):
  File "/home/rundeck/libext/cache/kubernetes-plugin-2.0.3/create-from-yaml.py", line 139, in <module>
    main()
  File "/home/rundeck/libext/cache/kubernetes-plugin-2.0.3/create-from-yaml.py", line 40, in main
    print(common.parseJson(resp.status))
  File "/home/rundeck/libext/cache/kubernetes-plugin-2.0.3/common.py", line 258, in parseJson
    return json.dumps(obj, cls=ObjectEncoder)
  File "/usr/lib/python3.6/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.6/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.6/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/home/rundeck/libext/cache/kubernetes-plugin-2.0.3/common.py", line 254, in default
    return {k.lstrip('_'): v for k, v in vars(obj).items()}
TypeError: vars() argument must have __dict__ attribute
Failed: NonZeroResultCode: Script result code was: 1

The Kubernetes cluster is v1.14.5, the Rundeck instance has Python 3.6.9 and kubernetes==12.0.1 installed.

blbradley commented 2 years ago

I'm experiencing TypeError: vars() argument must have __dict__ attribute, did you ever figure this out?

kdebisschop commented 2 years ago

The OP was using kubernetes==12.0.1 but the plugin requires 11.0.0