techno-tim / k3s-ansible

The easiest way to bootstrap a self-hosted High Availability Kubernetes cluster. A fully automated HA k3s etcd install with kube-vip, MetalLB, and more. Build. Destroy. Repeat.
https://technotim.live/posts/k3s-etcd-ansible/
Apache License 2.0
2.41k stars 1.05k forks source link

Test metallb-system namespace doesn't actually test to see if the namespace exists #350

Open travellingtechie opened 1 year ago

travellingtechie commented 1 year ago

While researching another issue, I realized the output of this command was just a long usage page, so in testing further I discovered that Test metallb-system namespace in k3s_server_post/tasks/metallb.yml always succeeds, even if the namespace doesn't exit

Expected Behavior

the command 'k3s kubectl -n metallb-system' should return a 1 if the namespace metallb-system doesn't exist

Current Behavior

it always returns 0, and just returns a usage page, doesn't actually test to see if the namespace exists

Steps to Reproduce

run k3s kubectl -n metallb-system from the command line, it doesn't check if the namespace exists, just returns usage.

1. 2. 3. 4.

Context (variables)

Operating system: Ubuntu 22.04

Hardware:

Variables Used

all.yml

NA

Possible Solution

I changed the task to:

- name: Test metallb-system namespace
  shell: >-
    k3s kubectl get namespaces | grep metallb-system
  changed_when: false
  with_items: "{{ groups[group_name_master | default('master')] }}"
  run_once: true

I had to change to shell from command to get the pip to work. There may be a more elegant solution.

timothystewart6 commented 3 months ago

PR is welcome!