Skip to content

Cryptic error message when using skupper.v2.resource without platform defined on a host without the 'kubernetes' Python module #78

@hash-d

Description

@hash-d

If the module skupper.v2.resource is used without defining the platform, it defaults to kubernetes and fails when run against a host that has no Python module 'kubernetes' installed, even if it's being used to work on a system site.

The error:

The full traceback is:                                                                                                                                                                                               
  File "/tmp/ansible_skupper.v2.resource_payload_km4rxz4a/ansible_skupper.v2.resource_payload.zip/ansible_collections/skupper/v2/plugins/modules/resource.py", line 202, in run                                      
    k8s_client = K8sClient(kubeconfig, context)                                                                                                                                                                      
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                      
  File "/tmp/ansible_skupper.v2.resource_payload_km4rxz4a/ansible_skupper.v2.resource_payload.zip/ansible_collections/skupper/v2/plugins/module_utils/k8s.py", line 19, in __init__                                  
    self.kubeconfig = kubeconfig or os.path.join(                                                                                                                                                                    
                                    ^^                                                                                                                                                                               

I believe this is because of this part of plugins/module_utils/k8s.py

  try:                                                                                                                                                                                                               
      from kubernetes import client, config, dynamic                                                                                                                                                                 
      from kubernetes.dynamic.exceptions import ApiException                                                                                                                                                         
      import json                                                                                                                                                                                                    
      import yaml                                                                                                                                                                                                    
      import os                                                                                                                                                                                                      
  except ImportError:                                                                                                                                                                                                
      pass                                                                                                                                                                                                           

Possibly only the kubernetes modules should be on that try. os is part of the Python distribution, so that one should certainly not be there.

How to reproduce

Simply run the module skupper.v2.resource against a host that has no kubernetes Python module installed, see the error happen; install the module and run it again, and see it bypassed.

Expected behavior

This scenario is arguably invalid: if the module is being used for system sites, it should define a non-kubernetes platform. However, the error does not help pointing to the root issue. If the kubernetes module is installed, however, the error becomes a bit more clear:

Invalid kube-config file. No configuration found.

That could be improved to something like site is configured as platform 'kubernetes', but no kubeconfig was found.

In any case, hosts that are being used for system sites should not be expected to have the 'kubernetes' Python module. That's actually probably what that try is all about, but it's encompassing more than it should.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions