Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 30 additions & 43 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,57 +1,44 @@
default_language_version:
python: python3
python: python3

repos:
- repo: https://github.com/myint/autoflake
rev: "v2.0.2"
hooks:
- id: autoflake
args:
- --in-place
- --remove-unused-variables
- --remove-all-unused-imports

- repo: https://github.com/hadialqattan/pycln
rev: "v2.1.3"
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.6.0"
hooks:
- id: pycln
- id: check-merge-conflict
- id: debug-statements
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md] # Do not process Markdown files.
- id: end-of-file-fixer
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: check-toml

- repo: https://github.com/pre-commit/mirrors-isort
rev: "v5.10.1"
- repo: https://github.com/PyCQA/flake8
rev: "7.1.0"
hooks:
- id: isort
- id: flake8
args: [--config=.flake8]
additional_dependencies: ["flake8-mutable"]

- repo: https://github.com/psf/black
rev: "23.1.0"
- repo: https://github.com/Yelp/detect-secrets
rev: v1.5.0
hooks:
- id: black
args: [--preview]
- id: detect-secrets

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.4.0"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.1
hooks:
- id: check-merge-conflict
- id: debug-statements
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md] # Do not process Markdown files.
- id: end-of-file-fixer
- id: check-ast
- id: check-builtin-literals
- id: ruff
- id: ruff-format

- repo: https://github.com/PyCQA/flake8
rev: "6.0.0"
- repo: https://github.com/renovatebot/pre-commit-hooks
rev: 37.426.0
hooks:
- id: flake8
args: [--max-line-length=120]
additional_dependencies: [
"git+https://github.com/RedHatQE/flake8-plugins.git",
"pep8-naming",
"flake8-comprehensions",
"flake8-mutable",
"flake8-simplify",
]
- id: renovate-config-validator

- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.4
hooks:
- id: detect-secrets
- id: gitleaks
1 change: 1 addition & 0 deletions examples/special_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Some resources have the same `kind` but different API groups.
For example: `Network` which exists in both operator.openshift.io and config.openshift.io API groups
"""

from ocp_resources.network import Network

# To get the Network resource which uses the default API in the class ("config.openshift.io")
Expand Down
10 changes: 4 additions & 6 deletions ocp_resources/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ def __init__(
def to_dict(self):
super().to_dict()
if not self.yaml_file:
self.res.update(
{
"spec": {
"includedNamespaces": self.included_namespaces,
}
self.res.update({
"spec": {
"includedNamespaces": self.included_namespaces,
}
)
})

if self.excluded_resources:
self.res["spec"]["excludedResources"] = self.excluded_resources
34 changes: 14 additions & 20 deletions ocp_resources/catalog_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,25 @@ def __init__(
self.image = image
self.display_name = display_name
self.publisher = publisher
self.update_strategy_registry_poll_interval = (
update_strategy_registry_poll_interval
)
self.update_strategy_registry_poll_interval = update_strategy_registry_poll_interval

def to_dict(self):
super().to_dict()
if not self.yaml_file:
self.res.update(
{
"spec": {
"sourceType": self.source_type,
"image": self.image,
"displayName": self.display_name,
"publisher": self.publisher,
}
self.res.update({
"spec": {
"sourceType": self.source_type,
"image": self.image,
"displayName": self.display_name,
"publisher": self.publisher,
}
)
})

if self.update_strategy_registry_poll_interval:
self.res["spec"].update(
{
"updateStrategy": {
"registryPoll": {
"interval": self.update_strategy_registry_poll_interval,
},
self.res["spec"].update({
"updateStrategy": {
"registryPoll": {
"interval": self.update_strategy_registry_poll_interval,
},
}
)
},
})
22 changes: 9 additions & 13 deletions ocp_resources/catalog_source_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,15 @@ def __init__(
def to_dict(self):
super().to_dict()
if not self.yaml_file:
self.res.update(
{
"spec": {
"source": self.source,
"targetNamespace": self.target_namespace,
"packages": self.packages,
"csDisplayName": self.cs_display_name,
"csPublisher": self.cs_publisher,
}
self.res.update({
"spec": {
"source": self.source,
"targetNamespace": self.target_namespace,
"packages": self.packages,
"csDisplayName": self.cs_display_name,
"csPublisher": self.cs_publisher,
}
)
})

def wait_for_csc_status(self, status, timeout=120):
"""
Expand Down Expand Up @@ -80,7 +78,5 @@ def wait_for_csc_status(self, status, timeout=120):

except TimeoutExpiredError:
if current_status:
self.logger.error(
f"Status of {self.kind} {self.name} is {current_status}"
)
self.logger.error(f"Status of {self.kind} {self.name} is {current_status}")
raise
4 changes: 1 addition & 3 deletions ocp_resources/cdi_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def wait_until_upload_url_changed(self, uploadproxy_url, timeout=TIMEOUT_4MINUTE
Returns:
bool: True if url is equal to uploadProxyURL.
"""
self.logger.info(
f"Wait for {self.kind} {self.name} to ensure current URL == uploadProxyURL"
)
self.logger.info(f"Wait for {self.kind} {self.name} to ensure current URL == uploadProxyURL")
samples = TimeoutSampler(
wait_timeout=timeout,
sleep=1,
Expand Down
4 changes: 1 addition & 3 deletions ocp_resources/controller_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ def to_dict(self):
super().to_dict()
if not self.yaml_file:
if self.owner_references:
self.res.setdefault("metadata", {}).update(
{"ownerReference": self.owner_references}
)
self.res.setdefault("metadata", {}).update({"ownerReference": self.owner_references})
if self.revision_object:
self.res.update({"data": self.revision_object.res})
25 changes: 8 additions & 17 deletions ocp_resources/cron_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,20 @@ def to_dict(self):
super().to_dict()
if not self.yaml_file:
if not (self.job_template and self.schedule):
raise ValueError(
"yaml_file or parameters 'job_template' and 'schedule' are"
" required."
)
self.res.update(
{
"spec": {
"jobTemplate": self.job_template,
"schedule": self.schedule,
}
raise ValueError("yaml_file or parameters 'job_template' and 'schedule' are" " required.")
self.res.update({
"spec": {
"jobTemplate": self.job_template,
"schedule": self.schedule,
}
)
})
if self.timezone:
self.res["spec"]["timezone"] = self.timezone
if self.suspend:
self.res["spec"]["suspend"] = self.suspend
if self.successful_jobs_history_limit:
self.res["spec"][
"successfulJobsHistoryLimit"
] = self.successful_jobs_history_limit
self.res["spec"]["successfulJobsHistoryLimit"] = self.successful_jobs_history_limit
if self.failed_jobs_history_limit:
self.res["spec"][
"failedJobsHistoryLimit"
] = self.failed_jobs_history_limit
self.res["spec"]["failedJobsHistoryLimit"] = self.failed_jobs_history_limit
if self.concurrency_policy:
self.res["spec"]["concurrencyPolicy"] = self.concurrency_policy
12 changes: 4 additions & 8 deletions ocp_resources/csi_storage_capacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,10 @@ def to_dict(self):
super().to_dict()
if not self.yaml_file:
if not self.storage_class_name:
raise ValueError(
"yaml_file or parameter 'storage_class_name' is required."
)
self.res.update(
{
"storageClassName": self.storage_class_name,
}
)
raise ValueError("yaml_file or parameter 'storage_class_name' is required.")
self.res.update({
"storageClassName": self.storage_class_name,
})
if self.maximum_volume_size:
self.res["maximumVolumeSize"] = self.maximum_volume_size
if self.node_topology:
Expand Down
5 changes: 1 addition & 4 deletions ocp_resources/daemonset.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ def wait_until_deployed(self, timeout=TIMEOUT_4MINUTES):
status = sample.items[0].status
desired_number_scheduled = status.desiredNumberScheduled
number_ready = status.numberReady
if (
desired_number_scheduled > 0
and desired_number_scheduled == number_ready
):
if desired_number_scheduled > 0 and desired_number_scheduled == number_ready:
return

def delete(self, wait=False, timeout=TIMEOUT_4MINUTES, body=None):
Expand Down
30 changes: 10 additions & 20 deletions ocp_resources/data_import_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,21 @@ def to_dict(self):
if self.image_stream and self.url:
raise ValueError("imageStream and url can not coexist")

self.res.update(
{
"spec": {
"template": {
"spec": {
"source": {
"registry": {"pullMethod": self.pull_method}
},
"storage": {
"resources": {"requests": {"storage": self.size}}
},
}
self.res.update({
"spec": {
"template": {
"spec": {
"source": {"registry": {"pullMethod": self.pull_method}},
"storage": {"resources": {"requests": {"storage": self.size}}},
}
}
}
)
})
spec = self.res["spec"]["template"]["spec"]
if self.bind_immediate_annotation:
self.res["metadata"].setdefault("annotations", {}).update(
{
f"{NamespacedResource.ApiGroup.CDI_KUBEVIRT_IO}/storage.bind.immediate.requested": (
"true"
)
}
)
self.res["metadata"].setdefault("annotations", {}).update({
f"{NamespacedResource.ApiGroup.CDI_KUBEVIRT_IO}/storage.bind.immediate.requested": ("true")
})
if self.image_stream:
spec["source"]["registry"]["imageStream"] = self.image_stream
if self.url:
Expand Down
12 changes: 5 additions & 7 deletions ocp_resources/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ def __init__(
def to_dict(self):
super().to_dict()
if not self.yaml_file:
self.res.update(
{
"spec": {
"source": self.source,
},
}
)
self.res.update({
"spec": {
"source": self.source,
},
})

@property
def pvc(self):
Expand Down
Loading