aws-samples / amazon-k8s-node-drainer

Gracefully drain Kubernetes pods from EKS worker nodes during autoscaling scale-in events.
Other
199 stars 56 forks source link

'str' object has no attribute 'path' #14

Closed taruntmr closed 5 years ago

taruntmr commented 5 years ago

Hi,

Scenario 1: When I try to use the provided instructions as it is I get the following error:

[ERROR] AttributeError: 'str' object has no attribute 'path' Traceback (most recent call last): File "/var/task/handler.py", line 129, in lambda_handler return _lambda_handler(k8s.config, k8s.client, event) File "/var/task/handler.py", line 114, in _lambda_handler k8s_config.load_kube_config(KUBE_FILEPATH) File "/var/task/kubernetes/config/kube_config.py", line 649, in load_kube_config loader.load_and_set(config) File "/var/task/kubernetes/config/kube_config.py", line 461, in load_and_set self._load_authentication() File "/var/task/kubernetes/config/kube_config.py", line 205, in _load_authentication if self._load_user_token(): File "/var/task/kubernetes/config/kube_config.py", line 395, in _load_user_token base_path = self._get_base_path(self._user.path)

Scenario 2: When I update the create_kube_config from: 'user': 'lambda'

to: 'user': [ 'lambda' ]

I get the following error:

[ERROR] ApiException: (401) Reason: Unauthorized HTTP response headers: HTTPHeaderDict({'Audit-Id': '71f53e5f-1fe3-420a-9db9-5d59bbca405d', 'Content-Type': 'application/json', 'Date': 'Tue, 16 Jul 2019 06:08:44 GMT', 'Content-Length': '129'}) HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Unauthorized","reason":"Unauthorized","code":401}

My configmap aws-auth is as follows:

# apiVersion: v1 data: mapRoles: |

svozza commented 5 years ago

Can you do a print statements in create_kube_config to see exactly where it's failing?

mlafeldt commented 5 years ago

Same here.

[ERROR] AttributeError: 'str' object has no attribute 'path'
Traceback (most recent call last):
  File "/var/task/handler.py", line 156, in lambda_handler
    return _lambda_handler(k8s.config, k8s.client, event)
  File "/var/task/handler.py", line 128, in _lambda_handler
    k8s_config.load_kube_config(KUBE_FILEPATH)
  File "/var/task/kubernetes/config/kube_config.py", line 649, in load_kube_config
    loader.load_and_set(config)
  File "/var/task/kubernetes/config/kube_config.py", line 461, in load_and_set
    self._load_authentication()
  File "/var/task/kubernetes/config/kube_config.py", line 205, in _load_authentication
    if self._load_user_token():
  File "/var/task/kubernetes/config/kube_config.py", line 395, in _load_user_token
    base_path = self._get_base_path(self._user.path)

The problem is that _load_user_token fails at self._user.path:

    def _load_user_token(self):
        base_path = self._get_base_path(self._user.path)
        token = FileOrData(
            self._user, 'tokenFile', 'token',
            file_base_path=base_path,
            base64_file_content=False).as_data()
        if token:
            self.token = "Bearer %s" % token
            return True
mlafeldt commented 5 years ago

Found out that this is caused by Kubernetes client version 10. The sample only works with v9. See #15.