0

I am trying to deploy a resource to a kubernetes cluster via Cloudify UI, however I am getting the below error. Can anyone please help.

This is my blueprint.

tosca_definitions_version: cloudify_dsl_1_3

description: >
  This blueprint installs helm client, add repository to it and install
  chart(without values file and flags),using kubeconfig file content.
imports:
  - http://cloudify.co/spec/cloudify/5.0.5/types.yaml
  - plugin:cloudify-helm-plugin
  - plugin:cloudify-kubernetes-plugin?version= >=2.13.0

node_templates:
  sanity_pod:
    type: cloudify.kubernetes.resources.Pod
    properties:
      client_config:
        configuration: 
            file_content: { get_secret: **configuration_file_content** }
      definition:
        apiVersion: v1
        kind: Pod
        metadata:
          name: cloudify-nginx-withkubeConfig
        spec:
          containers:
          - name: nginx
            image: nginx:stable

The configuration_file_content is the kubeconfig file in yaml format (tried with json also) which has been uploaded to the Resource section in cloudify. During the deployment I am getting the below error.

[
  {
    "message": "string indices must be integers",
    "traceback": "Traceback (most recent call last):\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/cloudify_kubernetes/decorators.py\", line 285, in wrapper\n    authentication_property\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/cloudify_kubernetes/k8s/client.py\", line 127, in __init__\n    prepare_api = api_configuration.prepare_api()\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/cloudify_kubernetes/k8s/config.py\", line 34, in prepare_api\n    api = self._do_prepare_api()\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/cloudify_kubernetes/k8s/config.py\", line 172, in _do_prepare_api\n    **self.kwargs\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/cloudify_kubernetes/k8s/config.py\", line 34, in prepare_api\n    api = self._do_prepare_api()\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/cloudify_kubernetes/k8s/config.py\", line 109, in _do_prepare_api\n    os.path.expanduser(KUBE_CONFIG_DEFAULT_LOCATION)\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/kubernetes/config/kube_config.py\", line 199, in __init__\n    self.set_active_context(active_context)\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/kubernetes/config/kube_config.py\", line 250, in set_active_context\n    context_name = self._config['current-context']\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/kubernetes/config/kube_config.py\", line 611, in __getitem__\n    v = self.safe_get(key)\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/kubernetes/config/kube_config.py\", line 608, in safe_get\n    return self.value[key]\nTypeError: string indices must be integers\n",
    "type": "TypeError"
  },
  {
    "message": "Error encountered",
    "type": "RecoverableError",
    "traceback": "Traceback (most recent call last):\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/cloudify_kubernetes/decorators.py\", line 285, in wrapper\n    authentication_property\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/cloudify_kubernetes/k8s/client.py\", line 127, in __init__\n    prepare_api = api_configuration.prepare_api()\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/cloudify_kubernetes/k8s/config.py\", line 34, in prepare_api\n    api = self._do_prepare_api()\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/cloudify_kubernetes/k8s/config.py\", line 172, in _do_prepare_api\n    **self.kwargs\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/cloudify_kubernetes/k8s/config.py\", line 34, in prepare_api\n    api = self._do_prepare_api()\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/cloudify_kubernetes/k8s/config.py\", line 109, in _do_prepare_api\n    os.path.expanduser(KUBE_CONFIG_DEFAULT_LOCATION)\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/kubernetes/config/kube_config.py\", line 199, in __init__\n    self.set_active_context(active_context)\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/kubernetes/config/kube_config.py\", line 250, in set_active_context\n    context_name = self._config['current-context']\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/kubernetes/config/kube_config.py\", line 611, in __getitem__\n    v = self.safe_get(key)\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/kubernetes/config/kube_config.py\", line 608, in safe_get\n    return self.value[key]\nTypeError: string indices must be integers\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/opt/mgmtworker/env/lib/python3.6/site-packages/cloudify/dispatch.py\", line 411, in main\n    payload = handler.handle()\n  File \"/opt/mgmtworker/env/lib/python3.6/site-packages/cloudify/dispatch.py\", line 146, in handle\n    result = self._run_operation_func(ctx, kwargs)\n  File \"/opt/mgmtworker/env/lib/python3.6/site-packages/cloudify/dispatch.py\", line 154, in _run_operation_func\n    return self.func(*self.args, **kwargs)\n  File \"/opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/cloudify_kubernetes/decorators.py\", line 295, in wrapper\n    causes=[generate_traceback_exception()]\ncloudify.exceptions.RecoverableError: Error encountered\n"
  }
]

Any help would be highly appreciated. Thanks!!

  • can you verify the secret value , maybe by doing a simple python snippet , yaml.safe_load ? – AhMaD AbUIeSa Jan 26 '22 at 16:42
  • Thanks AhMaD AbUIeSa for your reply. Using the below snippet I am able to parse the yaml and it is returning the correct json response which is matching with my secret kubeconfig. This is snippet I am using for you reference. `import yaml with open("kconfig.yaml", "r") as stream: try: print(yaml.safe_load(stream)) except yaml.YAMLError as exc: print(exc)` – Mayukh Chakraborty Jan 27 '22 at 11:36
  • one more thing that I see from the exception , does your kube_config have current-context value as part of the yaml ? – AhMaD AbUIeSa Jan 27 '22 at 12:37
  • yes I have it. This is how my yaml looks like. `apiVersion: v1 clusters: - cluster: certificate-authority-data: XXXXXX server: YYY name: ZZZ contexts: - context: cluster: XXX user: WWW name: QQQ current-context: TTT kind: Config preferences: {} users: - name: PPP user: client-certificate-data: XXX client-key-data: YYY token: ZZZ` – Mayukh Chakraborty Jan 27 '22 at 14:07
  • Hi @AhMaDAbUIeSa, any further suggestions? – Mayukh Chakraborty Jan 31 '22 at 08:11
  • the only thing that I can suggest is to add this to the plugin code ```self.logger.info('file_content: {0}'.format(file_content))``` by adding it on line 105 , in this file /opt/mgmtworker/env/plugins/default_tenant/cloudify-kubernetes-plugin/2.13.5/lib/python3.6/site-packages/cloudify_kubernetes/k8s/config.py – AhMaD AbUIeSa Jan 31 '22 at 09:11
  • The output is same as the kubeconfig content in json format! – Mayukh Chakraborty Feb 01 '22 at 05:38
  • how about the type of file_content , it should be dict , so in the log above , let's see the `type(file_content)` – AhMaD AbUIeSa Feb 01 '22 at 07:22
  • It is not a dict. Showing – Mayukh Chakraborty Feb 01 '22 at 12:26
  • Can we connect on slack or any other channel? Please let me know. – Mayukh Chakraborty Feb 01 '22 at 12:33
  • ok , so that is the issue , try adding the kubeconfig to secrets as json format – AhMaD AbUIeSa Feb 01 '22 at 13:25
  • Tried adding the raw json and also tried uploading a json file, non of the approach is working. This is the json I am using. `{"apiVersion": "v1","clusters": [{"cluster": {"certificate-authority-data": "XXX","server": "XXX"},"name": "XXX"}],"contexts": [{"context": {"cluster": "XXX","user": "XXX"},"name": "XXX"}],"current-context": "XXX","kind": "Config","preferences": {},"users": [{"name": "XXX", "user": {"client-certificate-data": "XXX","client-key-data": "XXX","token": "XXX"}}]}` – Mayukh Chakraborty Feb 01 '22 at 15:52
  • Hi @AhMaDAbUIeSa, any more suggestions on this? – Mayukh Chakraborty Feb 11 '22 at 10:27
  • Can you try the latest version of Kubernetes plugin , I believe there was a fix introduced for file_content there https://github.com/cloudify-cosmo/cloudify-kubernetes-plugin/releases/tag/latest – AhMaD AbUIeSa Feb 12 '22 at 06:01
  • Thanks a ton AhMaD AbUieSa! Updating the plugin version resolved the issue. – Mayukh Chakraborty Feb 16 '22 at 09:24
  • Hi AhMaD AbUIeSa, do you know on how to do a helm chart deployment using cloudify? – Mayukh Chakraborty Mar 28 '22 at 08:43
  • there is a helm plugin that you can use for that – AhMaD AbUIeSa Mar 29 '22 at 07:52
  • Hi AhMaD AbUIeSa, any idea on how to upload a kubeconfig yaml file using cloudify's REST API. The following endpoint does not have anything which can upload a file to the Resource section within Secret. curl -X PUT \ -H "Content-Type: application/json" \ -H "Tenant: " \ -u : \ -d '{"value": , "update_if_exists": false, "visibility": "", "is_hidden_value": false}' \ – Mayukh Chakraborty Apr 27 '22 at 07:31
  • well the rest api only takes the value as string , but in cloudify-cli , you can pass the file and the logic there will read the file and take care of that [ cfy secrets create key -f {file_path} ] – AhMaD AbUIeSa Apr 27 '22 at 08:16

0 Answers0