diff --git a/README.md b/README.md index 3bfd10a3f5..2b4f34aa5f 100644 --- a/README.md +++ b/README.md @@ -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/) @@ -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. @@ -25,31 +26,43 @@ 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 + ```bash export 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 @@ -57,21 +70,33 @@ 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 #` 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= # 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 ``` @@ -79,4 +104,5 @@ 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. diff --git a/ocp_resources/resource.py b/ocp_resources/resource.py index 6f2e19d94c..f1038c4892 100644 --- a/ocp_resources/resource.py +++ b/ocp_resources/resource.py @@ -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: @@ -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: