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 Jun 6, 2022
1 parent 3223749 commit 90c02bb
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 @@ -13,7 +13,7 @@

LOG = logging.getLogger(__name__)

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 @@ -188,14 +188,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 90c02bb

Please sign in to comment.