Skip to content

[BUG] Double dash CLI arguments do not work in k8s-version-recency-check #492

Closed

Description

@matofeder

Double dash CLI arguments --config and --kubeconfig do not work as expected. Is seems that they are not recognized by the script k8s-version-recency-check.py.

See the STDOUT when --config is used:

$ python kaas/k8s-version-recency/k8s-version-recency-check.py --config config.yaml -k kubeconfig.yaml 
The config file under couldn't be found, falling back to the default config.

See the STDOUT when --kubeconfig is used:

$ python kaas/k8s-version-recency/k8s-version-recency-check.py -c config.yaml --kubeconfig kubeconfig.yaml
WARNING: Config not found: 
Traceback (most recent call last):
  File "/home/mato/Dev/ifne/scs/standards/Tests/kaas/k8s-version-recency/k8s-version-recency-check.py", line 467, in <module>
    return_code = asyncio.run(main(sys.argv[1:]))
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/mato/Dev/ifne/scs/standards/Tests/kaas/k8s-version-recency/k8s-version-recency-check.py", line 445, in main
    cluster_version, cluster_name = await get_k8s_cluster_version(config.kubeconfig)
  File "/home/mato/Dev/ifne/scs/standards/Tests/kaas/k8s-version-recency/k8s-version-recency-check.py", line 380, in get_k8s_cluster_version
    cluster_config = await kubernetes_asyncio.config.load_kube_config(kubeconfig)
  File "/home/mato/Dev/ifne/scs/standards/.venv/lib/python3.10/site-packages/kubernetes_asyncio/config/kube_config.py", line 598, in load_kube_config
    loader = _get_kube_config_loader_for_yaml_file(
  File "/home/mato/Dev/ifne/scs/standards/.venv/lib/python3.10/site-packages/kubernetes_asyncio/config/kube_config.py", line 562, in _get_kube_config_loader_for_yaml_file
    return KubeConfigLoader(
  File "/home/mato/Dev/ifne/scs/standards/.venv/lib/python3.10/site-packages/kubernetes_asyncio/config/kube_config.py", line 149, in __init__
    self.set_active_context(active_context)
  File "/home/mato/Dev/ifne/scs/standards/.venv/lib/python3.10/site-packages/kubernetes_asyncio/config/kube_config.py", line 160, in set_active_context
    context_name = self._config['current-context']
  File "/home/mato/Dev/ifne/scs/standards/.venv/lib/python3.10/site-packages/kubernetes_asyncio/config/kube_config.py", line 447, in __getitem__
    raise ConfigException(
kubernetes_asyncio.config.config_exception.ConfigException: Invalid kube-config file. Expected key current-context in kube-config

Single-dash versions -c and -k work as expected.

Notes:

  • it would be great to improve error handling in the case when the kubeconfig is not found
  • why not to use argparse python builtin lib for parsing the args?

Activity

  1. added
    bug
    Container
    on Mar 4, 2024
  2. added
    SCS-VP10
    on Mar 4, 2024
  3. added this to the R6 (v7.0.0) milestone on Mar 4, 2024
  4. mbuechse commented on Mar 4, 2024

    @mbuechse
    Contributor

    As far as I can tell, the k8s-recency-check.py is being superseded soon by PR standards/#488. The use of getopt is due to historical reasons, I guess, but if we really switch to another library, we can as well go for click (which is already being used by the new flavor-name cli).

  5. cah-hbaum commented on Mar 4, 2024

    @cah-hbaum
    Contributor

    Yeah getoptwas more due to historical reasons and the test is superseded soon as @mbuechse mentioned.
    Also, in the future, we probably want to convert this test to Golang in order to make it better integrated with Sonobuoy.

  6. mbuechse commented on Mar 4, 2024

    @mbuechse
    Contributor

    FYI, the error is in this line

            opts, args = getopt.gnu_getopt(argv, "c:k:h", ["config", "kubeconfig", "help"])

    It should read

            opts, args = getopt.gnu_getopt(argv, "c:k:h", ["config=", "kubeconfig=", "help"])

    And any extraneous arguments (args not empty) should lead to a critical error.

  7. matofeder commented on Mar 4, 2024

    @matofeder
    MemberAuthor

    @mbuechse, @cah-hbaum thanks for your quick reponses!

    Then I would say we can close this one after #488 is merged because I see it as irrelevant then.

  8. mbuechse commented on Mar 4, 2024

    @mbuechse
    Contributor

    @matofeder Well, thanks very much for spotting the error!

  9. martinmo commented on Mar 5, 2024

    @martinmo
    Member

    Closing this because #488 was merged.

  10. added 2 commits that reference this issue on Mar 6, 2024
    e0c1b74
    72cd26f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ContainerSCS-VP10bug

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions