Skip to content
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# openshift-python-wrapper (`wrapper`)

Pypi: [openshift-python-wrapper](https://pypi.org/project/openshift-python-wrapper)
A python wrapper for [kubernetes-python-client](https://github.com/kubernetes-client/python) with support for [RedHat Container Virtualization](https://www.openshift.com/learn/topics/virtualization)
Docs: [openshift-python-wrapper docs](https://openshift-python-wrapper.readthedocs.io/en/latest/)
Expand All @@ -14,7 +15,7 @@ The wrapper handles it all and provides simple and intuitive functionality.

![Alt Text](examples/pod_example.gif)

Both developers or testers can use the wrapper. The code is modular and easy to maintain.
Both developers or testers can use the wrapper. The code is modular and easy to maintain.
Instead of writing custom code for every API, you can use the wrapper that provides a consistent interface for interacting with APIs.
It saves time, avoids code duplications, and reduces the chance of errors.

Expand All @@ -25,58 +26,83 @@ Resources can even be saved for debugging.
Resource manifests and logs can be easily collected.

## Installation

From source:

```bash
git clone https://github.com/RedHatQE/openshift-python-wrapper.git
cd openshift-python-wrapper
python setup.py install --user
```

From pypi:

```bash
pip install openshift-python-wrapper --user
```

## Release new version
### requirements:
* Export GitHub token

### requirements

- Export GitHub token

Comment thread
myakove marked this conversation as resolved.
```bash
export GITHUB_TOKEN=<your_github_token>
```
* [release-it](https://github.com/release-it/release-it)

- [release-it](https://github.com/release-it/release-it)

```bash
sudo npm install --global release-it
npm install --save-dev @release-it/bumper
```
### usage:
* Create a release, run from the relevant branch.
To create a 4.11 release, run:

### usage

- Create a release, run from the relevant branch.
To create a 4.11 release, run:

```bash
git checkout v4.11
git pull
release-it # Follow the instructions
```

## docs

Hosted on readthedocs.io [openshift-python-wrapper](https://openshift-python-wrapper.readthedocs.io/en/latest/)

## PR dependency

For PR dependency we use [dpulls](https://www.dpulls.com/)
To make PR depends on other PR add `depends on #<PR NUMBER>` in the PR description.

## Logging configuration
To change log level export OPENSHIFT_PYTHON_WRAPPER_LOG_LEVEL:

To change log level export OPENSHIFT_PYTHON_WRAPPER_LOG_LEVEL:

```bash
export OPENSHIFT_PYTHON_WRAPPER_LOG_LEVEL=<LOG_LEVEL> # can be: "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"
```

- By default some sensitive information is hashed in the logs, and if running with DEBUG the log output can be corrupted.
In secure environments user can set `OPENSHIFT_PYTHON_WRAPPER_HASH_LOG_DATA="false"` environment variable to disable the log hashing.

```bash
export OPENSHIFT_PYTHON_WRAPPER_HASH_LOG_DATA="false"
```

## Code check

We use pre-commit for code check.

```bash
pre-commit install
```

Some code examples locate at [examples](examples) directory

## Contribute to the project

To contribute new additions or changes to the project, please refer to the [contribution guide](CONTRIBUTING.md) first.
16 changes: 13 additions & 3 deletions ocp_resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,9 +912,15 @@ def delete(self, wait: bool = False, timeout: int = TIMEOUT_4MINUTES, body: Dict

if self.exists:
try:
hashed_data = self.hash_resource_dict(resource_dict=self.instance.to_dict())
self.logger.info(f"Deleting {hashed_data}")
self.logger.debug(f"\n{yaml.dump(hashed_data)}")
_instance_dict = self.instance.to_dict()
if isinstance(_instance_dict, dict):
hashed_data = self.hash_resource_dict(resource_dict=_instance_dict)
self.logger.info(f"Deleting {hashed_data}")
self.logger.debug(f"\n{yaml.dump(hashed_data)}")

else:
self.logger.warning(f"{self.kind}: {self.name} instance.to_dict() return was not a dict")

self.api.delete(name=self.name, namespace=self.namespace, body=body)

if wait:
Expand Down Expand Up @@ -1274,10 +1280,14 @@ def hash_resource_dict(self, resource_dict: Dict[Any, Any]) -> Dict[Any, Any]:
if not isinstance(resource_dict, dict):
raise ValueError("Expected a dictionary as the first argument")

if os.environ.get("OPENSHIFT_PYTHON_WRAPPER_HASH_LOG_DATA", "true") == "false":
return resource_dict

if self.keys_to_hash and self.hash_log_data:
resource_dict = copy.deepcopy(resource_dict)
for key_name in self.keys_to_hash:
resource_dict = replace_key_with_hashed_value(resource_dict=resource_dict, key_name=key_name)

return resource_dict

def get_condition_message(self, condition_type: str, condition_status: str = "") -> str:
Expand Down