rundeck-plugins / kubernetes

51 stars 59 forks source link

TypeError: __init__() got an unexpected keyword argument 'assert_hostname' #4

Closed YoavNordmann closed 3 years ago

YoavNordmann commented 6 years ago

Hi

I am having a lot of trouble setting up this plugin. My setup: I am running Rundeck inside a Kubernetes cluster, which I wish to manage using the same Rundeck. Furthermore, I want to use the same Rundeck to run commands and kubernetes jobs on the same cluster.

I have not succeeded in showing the kubernetes nodes as well as configuring the run of a simple "hello world" kubernetes job.

In the authentication section I have the following: Cluster URL: mylab-master01.mylab.lab Token: Token String of default token from kubernetes Verify SSL: Unchecked SSL Certificate Path: Blank

The following is the output of my job running.

13:23:20 1. Kubernetes / Job / Create [workflow] Begin step: 1,NodeDispatch
13:23:20 1: Workflow step executing: StepExecutionItem{type='NodeDispatch', keepgoingOnSuccess=false, hasFailureHandler=false}
13:23:20 preparing for sequential execution on 1 nodes
13:23:20 Executing command on node: localhost, NodeEntryImpl{tags=[], attributes={nodename=localhost, hostname=localhost, osFamily=unix, osVersion=3.10.0-327.36.3.el7.x86_64, osArch=amd64, description=Rundeck server node, osName=Linux, username=rundeck, tags=}, project='null'}
13:23:20 [workflow] beginExecuteNodeStep(localhost): NodeDispatch: StepExecutionItem{type='NodeDispatch', keepgoingOnSuccess=false, hasFailureHandler=false}
13:23:20 [Kubernetes-Create-Job] step started, config: {debug=true, container_name=hello world Container, verify_ssl=false, image_pull_policy=Always, name=my job, namespace=default, api_version=batch/v1, job_restart_policy=Never, container_image=hello-world:latest, url=mylab-master01.mylab.lab, token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImRlZmF1bHQtdG9rZW4tenM5OHQiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGVmYXVsdCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImI4YjAyMjRlLWY1NjctMTFlNy1hZjQ0LTAwNTA1NjhlNzU0NiIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpkZWZhdWx0OmRlZmF1bHQifQ.b7gfoLkWCwH_7KeuyGcLqyW9kJTtfJzjePt887xGFWz468y3jhMxU_QeID49d1x4PMeEbx73G35I3vQ6s3Nn0mh5Hrg0pVsWiyd6x0fIdxW9bNpNuJsHD5oIbbhM-GXKaUBJ2Inwqc5tloXjYnh67Vb4P816xYPnPkaw_ejDuEEHc3LrS4SQpNoy22z_URELhYGpRBEmcGODZm_VFxq8jt72B5xED0AO5jBRFaCNQns95ZIvFB0IfKuUzIk2PN369Wx-th3UvaKfpfjhTBbeF4wc4X5XLcRjTGWeYklwNXB2cLxiPbDlBsDQsj8RW-gHZz7peFIOViDcR1wrEEJZ6w}
13:23:20 [Kubernetes-Create-Job] executing: [python, -u, /var/lib/rundeck/libext/cache/kubernetes-plugin-1.0.4/job-create.py]
13:23:20 DEBUG: kubernetes-model-source: Log level configured for DEBUG
13:23:20 DEBUG: kubernetes-model-source: Creating job
13:23:20 DEBUG: kubernetes-model-source: {'image_pull_policy': 'Always', 'name': 'my job', 'job_restart_policy': 'Never', 'namespace': 'default', 'container_name': 'hello world Container', 'container_image': 'hello-world:latest', 'api_version': 'batch/v1'}
13:23:20 DEBUG: kubernetes-model-source: new job:
13:23:21 DEBUG: kubernetes-model-source: {'api_version': 'batch/v1',
13:23:21 'kind': 'Job',
13:23:21 'metadata': {'annotations': None,
13:23:21 'cluster_name': None,
13:23:21 'creation_timestamp': None,
13:23:21 'deletion_grace_period_seconds': None,
13:23:21 'deletion_timestamp': None,
13:23:21 'finalizers': None,
13:23:21 'generate_name': None,
13:23:21 'generation': None,
13:23:21 'initializers': None,
13:23:21 'labels': None,
13:23:21 'name': 'my job',
13:23:21 'namespace': 'default',
13:23:21 'owner_references': None,
13:23:21 'resource_version': None,
13:23:21 'self_link': None,
13:23:21 'uid': None},
13:23:21 'spec': {'active_deadline_seconds': None,
13:23:21 'backoff_limit': None,
13:23:21 'completions': None,
13:23:21 'manual_selector': None,
13:23:21 'parallelism': None,
13:23:21 'selector': None,
13:23:21 'template': {'metadata': {'annotations': None,
13:23:21 'cluster_name': None,
13:23:21 'creation_timestamp': None,
13:23:21 'deletion_grace_period_seconds': None,
13:23:21 'deletion_timestamp': None,
13:23:21 'finalizers': None,
13:23:21 'generate_name': None,
13:23:21 'generation': None,
13:23:21 'initializers': None,
13:23:21 'labels': None,
13:23:21 'name': 'my job',
13:23:21 'namespace': None,
13:23:21 'owner_references': None,
13:23:21 'resource_version': None,
13:23:21 'self_link': None,
13:23:21 'uid': None},
13:23:21 'spec': {'active_deadline_seconds': None,
13:23:21 'affinity': None,
13:23:21 'automount_service_account_token': None,
13:23:21 'containers': [{'args': None,
13:23:21 'command': None,
13:23:21 'env': [],
13:23:21 'env_from': None,
13:23:21 'image': 'hello-world:latest',
13:23:21 'image_pull_policy': 'Always',
13:23:21 'lifecycle': None,
13:23:21 'liveness_probe': None,
13:23:21 'name': 'hello world Container',
13:23:21 'ports': None,
13:23:21 'readiness_probe': None,
13:23:21 'resources': None,
13:23:21 'security_context': None,
13:23:21 'stdin': None,
13:23:21 'stdin_once': None,
13:23:21 'termination_message_path': None,
13:23:21 'termination_message_policy': None,
13:23:21 'tty': None,
13:23:21 'volume_devices': None,
13:23:21 'volume_mounts': None,
13:23:21 'working_dir': None}],
13:23:21 'dns_config': None,
13:23:21 'dns_policy': None,
13:23:21 'host_aliases': None,
13:23:21 'host_ipc': None,
13:23:21 'host_network': None,
13:23:21 'host_pid': None,
13:23:21 'hostname': None,
13:23:21 'image_pull_secrets': None,
13:23:21 'init_containers': None,
13:23:21 'node_name': None,
13:23:21 'node_selector': None,
13:23:21 'priority': None,
13:23:21 'priority_class_name': None,
13:23:21 'restart_policy': 'Never',
13:23:21 'scheduler_name': None,
13:23:21 'security_context': None,
13:23:21 'service_account': None,
13:23:21 'service_account_name': None,
13:23:21 'share_process_namespace': None,
13:23:21 'subdomain': None,
13:23:21 'termination_grace_period_seconds': None,
13:23:21 'tolerations': None,
13:23:21 'volumes': None}}},
13:23:21 'status': None}
13:23:21 Traceback (most recent call last):
13:23:21 File "/var/lib/rundeck/libext/cache/kubernetes-plugin-1.0.4/job-create.py", line 208, in
13:23:21 main()
13:23:21 File "/var/lib/rundeck/libext/cache/kubernetes-plugin-1.0.4/job-create.py", line 197, in main
13:23:21 namespace=data["namespace"]
13:23:21 File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/apis/batch_v1_api.py", line 58, in create_namespaced_job
13:23:21 (data) = self.create_namespaced_job_with_http_info(namespace, body, **kwargs)
13:23:21 File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/apis/batch_v1_api.py", line 143, in create_namespaced_job_with_http_info
13:23:21 collection_formats=collection_formats)
13:23:21 File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/api_client.py", line 321, in call_api
13:23:21 _return_http_data_only, collection_formats, _preload_content, _request_timeout)
13:23:21 File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/api_client.py", line 155, in __call_api
13:23:21 _request_timeout=_request_timeout)
13:23:21 File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/api_client.py", line 364, in request
13:23:21 body=body)
13:23:21 File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/rest.py", line 266, in POST
13:23:21 body=body)
13:23:21 File "/usr/local/lib/python2.7/dist-packages/kubernetes/client/rest.py", line 166, in request
13:23:21 headers=headers)
13:23:21 File "/usr/local/lib/python2.7/dist-packages/urllib3/request.py", line 70, in request
13:23:21 **urlopen_kw)
13:23:21 File "/usr/local/lib/python2.7/dist-packages/urllib3/request.py", line 148, in request_encode_body
13:23:21 return self.urlopen(method, url, **extra_kw)
13:23:21 File "/usr/local/lib/python2.7/dist-packages/urllib3/poolmanager.py", line 321, in urlopen
13:23:21 response = conn.urlopen(method, u.request_uri, **kw)
13:23:21 File "/usr/local/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 589, in urlopen
13:23:21 conn = self._get_conn(timeout=pool_timeout)
13:23:21 File "/usr/local/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 251, in _get_conn
13:23:21 return conn or self._new_conn()
13:23:21 File "/usr/local/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 212, in _new_conn
13:23:21 strict=self.strict, **self.conn_kw)
13:23:21 File "/usr/local/lib/python2.7/dist-packages/urllib3/connection.py", line 125, in init
13:23:21 _HTTPConnection.init(self, *args, **kw)
13:23:21 TypeError: init() got an unexpected keyword argument 'assert_hostname'
13:23:21 [Kubernetes-Create-Job]: result code: 1
13:23:21 Failed: NonZeroResultCode: Script result code was: 1

Please help

Thank you

Yoav

ltamaster commented 6 years ago

Hi @YoavNordmann

Did you try to use the Cluster URL like http://mylab-master01.mylab.lab ?

Thanks Luis

ltamaster commented 6 years ago

Hi @YoavNordmann

I reproduced, you need to use http:// o https:// on the URL

screenshot 2018-06-15 11 08 57
majgis commented 6 years ago

I was struggling with this error as well

I found the following:

  1. Use the value set for kubectl, it just works, which you can find like this:
$ cat ~/.kube/config | grep server:
    server: https://192.168.99.101:8443
  1. Note that the kubectl proxy entrypoint does not work (could not isolate why).
YoavNordmann commented 6 years ago

I had to remove a change made in version 1.0.3 Specifically line 72: "c.assert_hostname = False".

After this change it worked !

ltamaster commented 6 years ago

Hey @YoavNordmann, where is your cluster located? I added that because I found an issue with glcoud.

Thanks Luis

YoavNordmann commented 6 years ago

I am running minikube on my laptop, and our testing kube is an on premise kubernetes cluster. no amazon, no google, no nothing...

Yoav

thebeancounter commented 5 years ago

having the same issue here

wadelu commented 3 years ago

Still facing this issue, with from rundeck 3.2.9 ~ 3.3.3 and latest plug 2.0.1 Tried URL both with http or https and /root/.kube/config only, not working.

Traceback (most recent call last):
  File "/home/rundeck/libext/cache/kubernetes-plugin-2.0.1/pods-resource-model.py", line 262, in <module>
    main()
  File "/home/rundeck/libext/cache/kubernetes-plugin-2.0.1/pods-resource-model.py", line 232, in main
    watch=False,
  File "/usr/local/lib/python3.5/dist-packages/kubernetes/client/api/core_v1_api.py", line 16864, in list_pod_for_all_namespaces
    return self.list_pod_for_all_namespaces_with_http_info(**kwargs)  # noqa: E501
  File "/usr/local/lib/python3.5/dist-packages/kubernetes/client/api/core_v1_api.py", line 16981, in list_pod_for_all_namespaces_with_http_info
    collection_formats=collection_formats)
  File "/usr/local/lib/python3.5/dist-packages/kubernetes/client/api_client.py", line 353, in call_api
    _preload_content, _request_timeout, _host)
  File "/usr/local/lib/python3.5/dist-packages/kubernetes/client/api_client.py", line 184, in __call_api
    _request_timeout=_request_timeout)
  File "/usr/local/lib/python3.5/dist-packages/kubernetes/client/api_client.py", line 377, in request
    headers=headers)
  File "/usr/local/lib/python3.5/dist-packages/kubernetes/client/rest.py", line 243, in GET
    query_params=query_params)
  File "/usr/local/lib/python3.5/dist-packages/kubernetes/client/rest.py", line 216, in request
    headers=headers)
  File "/usr/local/lib/python3.5/dist-packages/urllib3/request.py", line 76, in request
    method, url, fields=fields, headers=headers, **urlopen_kw
  File "/usr/local/lib/python3.5/dist-packages/urllib3/request.py", line 97, in request_encode_url
    return self.urlopen(method, url, **extra_kw)
  File "/usr/local/lib/python3.5/dist-packages/urllib3/poolmanager.py", line 336, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 659, in urlopen
    conn = self._get_conn(timeout=pool_timeout)
  File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 279, in _get_conn
    return conn or self._new_conn()
  File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 238, in _new_conn
    **self.conn_kw
  File "/usr/local/lib/python3.5/dist-packages/urllib3/connection.py", line 115, in __init__
    _HTTPConnection.__init__(self, *args, **kw)
TypeError: __init__() got an unexpected keyword argument 'assert_hostname'
pshycomore commented 3 years ago

Hi, I have commented out the assert_hostname from main... and it works for me... def main(): .. c.assert_hostname = False Configuration.set_default(c) ..

wadelu commented 3 years ago

Hi, I have commented out the assert_hostname from main... and it works for me... def main(): .. c.assert_hostname = False Configuration.set_default(c) ..

Hi @pshycomore assert_hostname-not-found ,

Thank you very much for you reply!

I searched pods-resource-model.py but cannot found these lines, would you pls tell me which file it's in?

Thank you very much!

wadelu commented 3 years ago

Hi, I have commented out the assert_hostname from main... and it works for me... def main(): .. c.assert_hostname = False Configuration.set_default(c) .. Hi @pshycomore

I updated common.py as your suggestion, it's works now. Thank you very much! Do you know if there some other impact if we comments it out?

halradaideh commented 3 years ago

I am facing this issue on RunDeck 3.3.4 with python 3.6 and kubernetes plugin version 2.0.1

@ltamaster

halradaideh commented 3 years ago

removing the two following lines solved the issue

c.assert_hostname = False
Configuration.set_default(c)

can this fix be merged to the master and have new release ?

pshycomore commented 3 years ago

Hi, I have been working on the examples/pods_exec.py Assert_hostname is suppose to check if the name is in the SSLcertificate. But for most of us we just connect locally. So in our client calls we can bypass. Also this combination:

def main(): c = Configuration() Configuration.set_default(c) config.load_kube_config() c.assert_hostname = False core_v1 = core_v1_api.CoreV1Api() exec_commands(core_v1)

Would sound better to me as we initialize, and the complement with the load_kube_config. This strangely works, but it looks like the c.assert_hostname has really no effect. For the moment, I would recommend to bypass and if needed check the SSL certificate hostname in an other way. This may be a urllib3 bug...

in short replace by: def main(): config.load_kube_config()
core_v1 = core_v1_api.CoreV1Api() exec_commands(core_v1)
Cos kube config has all the connexion details.