Skip to content

Commit

Permalink
Merge pull request #447 from pehala/kubectl_default
Browse files Browse the repository at this point in the history
Use kubectl instead of oc
  • Loading branch information
pehala authored Jun 19, 2024
2 parents 934981c + c43448e commit 54026d5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions testsuite/__init__.py
Original file line number Diff line number Diff line change
@@ -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")
15 changes: 11 additions & 4 deletions testsuite/openshift/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit 54026d5

Please sign in to comment.