Skip to content

Commit

Permalink
Make sure to use microk8s-kubectl.wrapper (#3176)
Browse files Browse the repository at this point in the history
If we call kubectl simply, the system installed kubectl has precedence.
That may lead to some weird issues like an error due to a discrepancy
between kubectl cli and kubernetes API versions.

Closes: #3175
  • Loading branch information
nobuto-m authored and neoaggelos committed Jun 6, 2022
1 parent bdb1b48 commit 97ae582
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions scripts/wrappers/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import click
import yaml

kubeconfig = "--kubeconfig=" + os.path.expandvars("${SNAP_DATA}/credentials/client.config")
KUBECTL = os.path.expandvars("$SNAP/microk8s-kubectl.wrapper")


def get_current_arch():
Expand Down Expand Up @@ -166,14 +166,19 @@ def ensure_started():

def kubectl_get(cmd, namespace="--all-namespaces"):
if namespace == "--all-namespaces":
return run("kubectl", kubeconfig, "get", cmd, "--all-namespaces", die=False)
return run(KUBECTL, "get", cmd, "--all-namespaces", die=False)
else:
return run("kubectl", kubeconfig, "get", cmd, "-n", namespace, die=False)
return run(KUBECTL, "get", cmd, "-n", namespace, die=False)


def kubectl_get_clusterroles():
return run(
"kubectl", kubeconfig, "get", "clusterroles", "--show-kind", "--no-headers", die=False
KUBECTL,
"get",
"clusterroles",
"--show-kind",
"--no-headers",
die=False,
)


Expand Down

0 comments on commit 97ae582

Please sign in to comment.