After upgrading from ck1.18 to ck1.19, the namespace-list (and other namespace related) action doesn't work.
juju run-action kubernetes-master/0 --wait namespace-list
unit-kubernetes-master-0:
UnitId: kubernetes-master/0
id: "4"
message: exit status 1
results:
ReturnCode: 1
Stderr: |
The connection to the server localhost:8080 was refused - did you specify the right host or port?
Traceback (most recent call last):
File "/var/lib/juju/agents/unit-kubernetes-master-0/charm/actions/namespace-list", line 57, in <module>
namespace_list()
File "/var/lib/juju/agents/unit-kubernetes-master-0/charm/actions/namespace-list", line 23, in namespace_list
y = load(kubectl(['get', 'namespaces', '-o', 'yaml']))
File "/var/lib/juju/agents/unit-kubernetes-master-0/charm/actions/namespace-list", line 19, in kubectl
return check_output(cmd)
File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
**kwargs).stdout
File "/usr/lib/python3.6/subprocess.py", line 438, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['kubectl', 'get', 'namespaces', '-o', 'yaml']' returned non-zero exit status 1.
status: failed
timing:
completed: 2021-02-03 05:45:13 +0000 UTC
enqueued: 2021-02-03 05:45:12 +0000 UTC
started: 2021-02-03 05:45:12 +0000 UTC
Thanks for the report. I believe namespace-create and namespace-delete are also affected.
In Charmed Kubernetes 1.19, kube-apiserver no longer serves traffic on the insecure 8080 localhost port. Juju runs actions without the HOME environment variable set, so kubectl does not pick up the kubeconfig in /root/.kube/config automatically. I believe the fix here is to add --kubeconfig= /root/. kube/config to the kubectl call[1] in the namespace actions.
[1]: https:/ /github. com/charmed- kubernetes/ charm-kubernete s-master/ blob/036b0bc4cc 25d4a864266b3b9 329dd8d40affdc3 /actions/ namespace- create# L18