Skip to content

Commit c43448e

Browse files
committed
Use kubectl instead of oc
1 parent ad5fa9a commit c43448e

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

Dockerfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Bind a dir to /test-run-results to get reports "
88
RUN useradd --no-log-init -u 1001 -g root -m testsuite
99
RUN dnf install -y python3.11 python3.11-pip make git && dnf clean all
1010

11-
RUN curl https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gz >/tmp/oc.tgz && \
12-
tar xzf /tmp/oc.tgz -C /usr/local/bin && \
13-
rm /tmp/oc.tgz
11+
RUN curl -LO "https://dl.k8s.io/release/v1.30.2/bin/linux/amd64/kubectl" && \
12+
mv kubectl /usr/local/bin &&\
13+
chmod +x /usr/local/bin/kubectl
1414

1515
RUN curl -L https://github.com/cloudflare/cfssl/releases/download/v1.6.4/cfssl_1.6.4_linux_amd64 >/usr/bin/cfssl && \
1616
chmod +x /usr/bin/cfssl

testsuite/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""Monkeypatching land"""
2+
3+
import os
4+
5+
from openshift_client import context
6+
7+
# Default to kubectl instead of oc binary
8+
context.default_oc_path = os.getenv("OPENSHIFT_CLIENT_PYTHON_DEFAULT_OC_PATH", "kubectl")

testsuite/openshift/client.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,12 @@ def context(self):
4848
@property
4949
def api_url(self):
5050
"""Returns real API url"""
51-
with self.context:
52-
return oc.whoami("--show-server=true")
51+
return self.inspect_context(jsonpath="{.clusters[*].cluster.server}")
5352

5453
@property
5554
def token(self):
5655
"""Returns real OpenShift token"""
57-
with self.context:
58-
return oc.whoami("-t")
56+
return self.inspect_context(jsonpath="{.users[*].user.token}", raw=True)
5957

6058
@cached_property
6159
def apps_url(self):
@@ -106,6 +104,15 @@ def do_action(self, verb: str, *args, auto_raise: bool = True, parse_output: boo
106104
return oc.APIObject(string_to_model=result.out())
107105
return result
108106

107+
def inspect_context(self, jsonpath, raw=False):
108+
"""Returns jsonpath from the current context"""
109+
return (
110+
self.do_action("config", "view", f'--output=jsonpath="{jsonpath}"', f"--raw={raw}", "--minify=true")
111+
.out()
112+
.replace('"', "")
113+
.strip()
114+
)
115+
109116
@property
110117
def project_exists(self):
111118
"""Returns True if the project exists"""

0 commit comments

Comments
 (0)