Skip to content

Commit cd0b906

Browse files
dbasunagmyakovernetser
authored
debug log would print raw data and readme is updated to reflect that (#2248)
* debug log would print raw data and readme is updated to reflect that * updates * updated readme * minor fix * remove the warning about debug level * updates based on reviews * Update README.md Co-authored-by: Ruth Netser <[email protected]> --------- Co-authored-by: Meni Yakove <[email protected]> Co-authored-by: Ruth Netser <[email protected]>
1 parent a31b98e commit cd0b906

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

README.md

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# openshift-python-wrapper (`wrapper`)
2+
23
Pypi: [openshift-python-wrapper](https://pypi.org/project/openshift-python-wrapper)
34
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)
45
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.
1415

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

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

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

2728
## Installation
29+
2830
From source:
31+
2932
```bash
3033
git clone https://github.com/RedHatQE/openshift-python-wrapper.git
3134
cd openshift-python-wrapper
3235
python setup.py install --user
3336
```
37+
3438
From pypi:
39+
3540
```bash
3641
pip install openshift-python-wrapper --user
3742
```
3843

3944
## Release new version
40-
### requirements:
41-
* Export GitHub token
45+
46+
### requirements
47+
48+
- Export GitHub token
49+
4250
```bash
4351
export GITHUB_TOKEN=<your_github_token>
4452
```
45-
* [release-it](https://github.com/release-it/release-it)
53+
54+
- [release-it](https://github.com/release-it/release-it)
55+
4656
```bash
4757
sudo npm install --global release-it
4858
npm install --save-dev @release-it/bumper
4959
```
50-
### usage:
51-
* Create a release, run from the relevant branch.
52-
To create a 4.11 release, run:
60+
61+
### usage
62+
63+
- Create a release, run from the relevant branch.
64+
To create a 4.11 release, run:
65+
5366
```bash
5467
git checkout v4.11
5568
git pull
5669
release-it # Follow the instructions
5770
```
5871

5972
## docs
73+
6074
Hosted on readthedocs.io [openshift-python-wrapper](https://openshift-python-wrapper.readthedocs.io/en/latest/)
6175

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

6681
## Logging configuration
67-
To change log level export OPENSHIFT_PYTHON_WRAPPER_LOG_LEVEL:
82+
83+
To change log level export OPENSHIFT_PYTHON_WRAPPER_LOG_LEVEL:
6884

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

89+
- By default some sensitive information is hashed in the logs, and if running with DEBUG the log output can be corrupted.
90+
In secure environments user can set `OPENSHIFT_PYTHON_WRAPPER_HASH_LOG_DATA="false"` environment variable to disable the log hashing.
91+
92+
```bash
93+
export OPENSHIFT_PYTHON_WRAPPER_HASH_LOG_DATA="false"
94+
```
95+
7396
## Code check
97+
7498
We use pre-commit for code check.
99+
75100
```bash
76101
pre-commit install
77102
```
78103

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

81106
## Contribute to the project
107+
82108
To contribute new additions or changes to the project, please refer to the [contribution guide](CONTRIBUTING.md) first.

ocp_resources/resource.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -912,9 +912,15 @@ def delete(self, wait: bool = False, timeout: int = TIMEOUT_4MINUTES, body: Dict
912912

913913
if self.exists:
914914
try:
915-
hashed_data = self.hash_resource_dict(resource_dict=self.instance.to_dict())
916-
self.logger.info(f"Deleting {hashed_data}")
917-
self.logger.debug(f"\n{yaml.dump(hashed_data)}")
915+
_instance_dict = self.instance.to_dict()
916+
if isinstance(_instance_dict, dict):
917+
hashed_data = self.hash_resource_dict(resource_dict=_instance_dict)
918+
self.logger.info(f"Deleting {hashed_data}")
919+
self.logger.debug(f"\n{yaml.dump(hashed_data)}")
920+
921+
else:
922+
self.logger.warning(f"{self.kind}: {self.name} instance.to_dict() return was not a dict")
923+
918924
self.api.delete(name=self.name, namespace=self.namespace, body=body)
919925

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

1283+
if os.environ.get("OPENSHIFT_PYTHON_WRAPPER_HASH_LOG_DATA", "true") == "false":
1284+
return resource_dict
1285+
12771286
if self.keys_to_hash and self.hash_log_data:
12781287
resource_dict = copy.deepcopy(resource_dict)
12791288
for key_name in self.keys_to_hash:
12801289
resource_dict = replace_key_with_hashed_value(resource_dict=resource_dict, key_name=key_name)
1290+
12811291
return resource_dict
12821292

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

0 commit comments

Comments
 (0)