Skip to content

Commit

Permalink
Remove openshift dependencies (#1288)
Browse files Browse the repository at this point in the history
* Remove openshift python module dependencies, use kubernetes

* Remove openshift python module dependencies, use kubernetes
  • Loading branch information
myakove authored Jul 27, 2023
1 parent 1c68067 commit ac33478
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 64 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# openshift-python-wrapper
Pypi: [openshift-python-wrapper](https://pypi.org/project/openshift-python-wrapper)
A python wrapper for [openshift-restclient-python](https://github.com/openshift/openshift-restclient-python) with support for RedHat Container Virtualization. ([Openshift Virtualization](https://www.openshift.com/learn/topics/virtualization))
A python wrapper for [kubernetes-python-client](https://github.com/kubernetes-client/python) with support for RedHat Container Virtualization. ([Openshift Virtualization](https://www.openshift.com/learn/topics/virtualization))
Docs: [openshift-python-wrapper docs](https://openshift-python-wrapper.readthedocs.io/en/latest/)

## Installation
Expand Down
4 changes: 2 additions & 2 deletions ocp_resources/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from kubernetes.dynamic.exceptions import ForbiddenError
from openshift.dynamic.exceptions import (
from kubernetes.dynamic.exceptions import (
ForbiddenError,
InternalServerError,
NotFoundError,
ServerTimeoutError,
Expand Down
2 changes: 1 addition & 1 deletion ocp_resources/data_source.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from openshift.dynamic.exceptions import ResourceNotFoundError
from kubernetes.dynamic.exceptions import ResourceNotFoundError

from ocp_resources.constants import TIMEOUT_4MINUTES
from ocp_resources.persistent_volume_claim import PersistentVolumeClaim
Expand Down
2 changes: 1 addition & 1 deletion ocp_resources/node_network_configuration_policy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re

from openshift.dynamic.exceptions import ConflictError
from kubernetes.dynamic.exceptions import ConflictError

from ocp_resources.constants import TIMEOUT_4MINUTES
from ocp_resources.node import Node
Expand Down
2 changes: 1 addition & 1 deletion ocp_resources/node_network_state.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time

from openshift.dynamic.exceptions import ConflictError
from kubernetes.dynamic.exceptions import ConflictError

from ocp_resources.constants import TIMEOUT_4MINUTES
from ocp_resources.resource import Resource
Expand Down
16 changes: 10 additions & 6 deletions ocp_resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
import kubernetes
import yaml
from benedict import benedict
from kubernetes.dynamic.exceptions import ForbiddenError, MethodNotAllowedError
from openshift.dynamic import DynamicClient
from openshift.dynamic.exceptions import ConflictError, NotFoundError
from openshift.dynamic.resource import ResourceField
from kubernetes.dynamic import DynamicClient
from kubernetes.dynamic.exceptions import (
ConflictError,
ForbiddenError,
MethodNotAllowedError,
NotFoundError,
)
from kubernetes.dynamic.resource import ResourceField
from packaging.version import Version
from simple_logger.logger import get_logger

Expand Down Expand Up @@ -1106,8 +1110,8 @@ def get(
dyn_client (DynamicClient): Open connection to remote cluster
config_file (str): Path to config file for connecting to remote cluster.
context (str): Context name for connecting to remote cluster.
singular_name (str): Resource kind (in lowercase), in use where we have multiple matches for resource
raw (bool): If True return raw object from openshift-restclient-python
singular_name (str): Resource kind (in lowercase), in use where we have multiple matches for resource.
raw (bool): If True return raw object.
Returns:
Expand Down
2 changes: 1 addition & 1 deletion ocp_resources/virtual_machine_instance.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import shlex

import xmltodict
from openshift.dynamic.exceptions import ResourceNotFoundError
from kubernetes.dynamic.exceptions import ResourceNotFoundError

from ocp_resources.constants import PROTOCOL_ERROR_EXCEPTION_DICT, TIMEOUT_4MINUTES
from ocp_resources.node import Node
Expand Down
2 changes: 1 addition & 1 deletion ocp_resources/virtual_machine_restore.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from openshift.dynamic.exceptions import ResourceNotFoundError
from kubernetes.dynamic.exceptions import ResourceNotFoundError

from ocp_resources.constants import PROTOCOL_ERROR_EXCEPTION_DICT, TIMEOUT_4MINUTES
from ocp_resources.resource import NamespacedResource
Expand Down
2 changes: 1 addition & 1 deletion ocp_resources/virtual_machine_snapshot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from openshift.dynamic.exceptions import ResourceNotFoundError
from kubernetes.dynamic.exceptions import ResourceNotFoundError

from ocp_resources.constants import PROTOCOL_ERROR_EXCEPTION_DICT, TIMEOUT_4MINUTES
from ocp_resources.resource import NamespacedResource
Expand Down
91 changes: 63 additions & 28 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ profile = "black"
[tool.poetry]
name = "openshift-python-wrapper"
version = "0.0.0"
description = "Wrapper around https://github.com/openshift/openshift-restclient-python"
description = "Wrapper around https://github.com/kubernetes-client/python"
authors = ["Meni Yakove <[email protected]>", "Ruth Netser <[email protected]>"]
readme = "README.md"
license = "Apache-2.0"
Expand All @@ -39,6 +39,11 @@ Download = "https://pypi.org/project/openshift-python-wrapper/"
[tool.poetry.group.dev.dependencies]
ipdb = "^0.13.13"


[tool.poetry.group.tests.dependencies]
pytest = "^7.4.0"
requests = "^2.31.0"

[tool.poetry-dynamic-versioning.substitution]
files = ["VERSION"]

Expand All @@ -52,7 +57,6 @@ build-backend = "poetry_dynamic_versioning.backend"

[tool.poetry.dependencies]
python = "^3.8"
openshift = "^0.13.2"
xmltodict = "^0.13.0"
colorlog = "^6.7.0"
kubernetes = "^27.2.0"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_resources.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import kubernetes
import pytest
from openshift.dynamic import DynamicClient
from kubernetes.dynamic import DynamicClient

from ocp_resources.namespace import Namespace
from ocp_resources.pod import Pod
Expand Down
37 changes: 19 additions & 18 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py{38,39,310,311}, unittests, validate-resources
envlist = py{38,39,310,311}, unittests, validate-resources, tests
skipsdist = True

[flake8]
Expand All @@ -16,35 +16,36 @@ setenv =
PYTHONPATH = {toxinidir}
passenv =
KUBECONFIG
deps =
pytest
commands =
pip install pip -U
pip install .
pip install jinja2 PyYaml
pytest -o log_cli=true tests/test_resources.py -k 'not kubevirt'
sh -c 'curl -sSL https://install.python-poetry.org | python3 -'
poetry install
poetry run pytest -o log_cli=true tests/test_resources.py -k 'not kubevirt'
allowlist_externals =
sh
poetry

[testenv:unittests]
basepython = python3
setenv =
PYTHONPATH = {toxinidir}
deps =
pytest
commands =
pip install pip -U
pip install .
pytest -o log_cli=true tests/unittests
sh -c 'curl -sSL https://install.python-poetry.org | python3 -'
poetry install
poetry run pytest -o log_cli=true tests/unittests
allowlist_externals =
sh
poetry

[testenv:validate-resources]
basepython = python3
setenv =
PYTHONPATH = {toxinidir}
passenv =
KUBECONFIG
deps =
pytest
requests
commands =
pip install pip -U
pip install .
pytest tests/test_validate_resources.py
sh -c 'curl -sSL https://install.python-poetry.org | python3 -'
poetry install
poetry run pytest tests/test_validate_resources.py
allowlist_externals =
sh
poetry

0 comments on commit ac33478

Please sign in to comment.