From c43448ee2909ad20db8d602af3843a70ed14672d Mon Sep 17 00:00:00 2001 From: phala Date: Tue, 18 Jun 2024 23:15:30 +0200 Subject: [PATCH] Use kubectl instead of oc --- Dockerfile | 6 +++--- testsuite/__init__.py | 8 ++++++++ testsuite/openshift/client.py | 15 +++++++++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index ba48b4d7..6daf4c8a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,9 +8,9 @@ Bind a dir to /test-run-results to get reports " RUN useradd --no-log-init -u 1001 -g root -m testsuite RUN dnf install -y python3.11 python3.11-pip make git && dnf clean all -RUN curl https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gz >/tmp/oc.tgz && \ - tar xzf /tmp/oc.tgz -C /usr/local/bin && \ - rm /tmp/oc.tgz +RUN curl -LO "https://dl.k8s.io/release/v1.30.2/bin/linux/amd64/kubectl" && \ + mv kubectl /usr/local/bin &&\ + chmod +x /usr/local/bin/kubectl RUN curl -L https://github.com/cloudflare/cfssl/releases/download/v1.6.4/cfssl_1.6.4_linux_amd64 >/usr/bin/cfssl && \ chmod +x /usr/bin/cfssl diff --git a/testsuite/__init__.py b/testsuite/__init__.py index e69de29b..d3d14cfe 100644 --- a/testsuite/__init__.py +++ b/testsuite/__init__.py @@ -0,0 +1,8 @@ +"""Monkeypatching land""" + +import os + +from openshift_client import context + +# Default to kubectl instead of oc binary +context.default_oc_path = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_OC_PATH", "kubectl") diff --git a/testsuite/openshift/client.py b/testsuite/openshift/client.py index 569e88d4..b183e807 100644 --- a/testsuite/openshift/client.py +++ b/testsuite/openshift/client.py @@ -48,14 +48,12 @@ def context(self): @property def api_url(self): """Returns real API url""" - with self.context: - return oc.whoami("--show-server=true") + return self.inspect_context(jsonpath="{.clusters[*].cluster.server}") @property def token(self): """Returns real OpenShift token""" - with self.context: - return oc.whoami("-t") + return self.inspect_context(jsonpath="{.users[*].user.token}", raw=True) @cached_property def apps_url(self): @@ -106,6 +104,15 @@ def do_action(self, verb: str, *args, auto_raise: bool = True, parse_output: boo return oc.APIObject(string_to_model=result.out()) return result + def inspect_context(self, jsonpath, raw=False): + """Returns jsonpath from the current context""" + return ( + self.do_action("config", "view", f'--output=jsonpath="{jsonpath}"', f"--raw={raw}", "--minify=true") + .out() + .replace('"', "") + .strip() + ) + @property def project_exists(self): """Returns True if the project exists"""