Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resources ReclaimSpaceCronJob and ReclaimSpaceJob #1805

Merged
merged 34 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9b6eafa
support token creation for service account
dbasunag Apr 15, 2024
b0b456e
Merge branch 'RedHatQE:main' into main
dbasunag Apr 15, 2024
fb0ba81
updated doc strings etc.
dbasunag Apr 16, 2024
e2486e6
Merge branch 'main' of github.com:dbasunag/openshift-python-wrapper
dbasunag Apr 16, 2024
bc3e2f1
Merge branch 'main' into main
dbasunag Apr 18, 2024
b31fb07
Merge branch 'main' into main
dbasunag Apr 22, 2024
e314131
Merge branch 'main' into main
dbasunag Apr 23, 2024
94d0e0d
address review comments
dbasunag Apr 24, 2024
ed8cd13
Merge branch 'main' into main
dbasunag Apr 24, 2024
13f355b
Merge branch 'RedHatQE:main' into main
dbasunag May 2, 2024
f152562
Add reclaimspacecronjob and reclaimspacejob resources
dbasunag May 3, 2024
77b319d
Merge branch 'main' into add_resource
dbasunag May 6, 2024
b72d1be
updates to address review comments
dbasunag May 6, 2024
8d84ca4
Merge branch 'main' into add_resource
dbasunag May 7, 2024
f470e22
address tox failure
dbasunag May 8, 2024
e62cdff
Merge branch 'main' into add_resource
dbasunag May 13, 2024
4db9f75
Merge branch 'main' into add_resource
dbasunag May 15, 2024
3bea390
updates based on review comments
dbasunag May 16, 2024
d3decb1
Merge branch 'main' into add_resource
dbasunag May 21, 2024
80af81d
Merge branch 'main' into add_resource
dbasunag May 22, 2024
3928998
Merge branch 'main' into add_resource
dbasunag May 23, 2024
152e352
Merge branch 'main' into add_resource
dbasunag May 30, 2024
09bbd75
Update ocp_resources/reclaim_space_cron_job.py
dbasunag May 30, 2024
b061566
Merge branch 'main' into add_resource
dbasunag May 30, 2024
5ff29c1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 30, 2024
28806cc
updates based on reviews
dbasunag May 30, 2024
c83599c
fix precommit failure and wrong argument naming
dbasunag May 30, 2024
bb735a9
Merge branch 'main' into add_resource
dbasunag Jun 3, 2024
9d67071
minor update
dbasunag Jun 3, 2024
a63b7e9
fix indentation
dbasunag Jun 4, 2024
ed5254a
fix indentation
dbasunag Jun 4, 2024
ce92aff
Merge branch 'main' into add_resource
dbasunag Jun 6, 2024
22ec171
Merge branch 'main' into add_resource
dbasunag Jun 6, 2024
1fe5ff0
Based on review comment make all args optional
dbasunag Jun 6, 2024
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
70 changes: 70 additions & 0 deletions ocp_resources/reclaim_space_cron_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from ocp_resources.constants import TIMEOUT_4MINUTES
from ocp_resources.resource import NamespacedResource, MissingRequiredArgumentError


class ReclaimSpaceCronJob(NamespacedResource):
"""
https://github.com/csi-addons/kubernetes-csi-addons/blob/main/docs/reclaimspace.md
dbasunag marked this conversation as resolved.
Show resolved Hide resolved
"""

api_group = NamespacedResource.ApiGroup.CSIADDONS_OPENSHIFT_IO

def __init__(
self,
name=None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • define only args that are relevant to the resource
  • add typing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you are looking at the right commit. I already changed it

namespace=None,
client=None,
teardown=True,
privileged_client=None,
yaml_file=None,
delete_timeout=TIMEOUT_4MINUTES,
schedule=None,
job_template=None,
concurrency_policy=None,
successful_jobs_history_limit=None,
failed_jobs_history_limit=None,
**kwargs,
myakove marked this conversation as resolved.
Show resolved Hide resolved
):
"""
Args:
schedule (str): schedule of the reclaim space cron job
job_template (dict): describes the reclaim space job that would be created when a reclaim space cronjob
would be executed
Example: https://github.com/csi-addons/kubernetes-csi-addons/blob/main/docs/reclaimspace.md
concurrency_policy (str, optional): indicates how to treat concurrent execution of a job
successful_jobs_history_limit (int, optional): number of successful jobs to retain
failed_jobs_history_limit (int, optional): number of failed jobs to retain start at scheduled time
"""
super().__init__(
name=name,
namespace=namespace,
client=client,
teardown=teardown,
privileged_client=privileged_client,
yaml_file=yaml_file,
delete_timeout=delete_timeout,
**kwargs,
)
self.job_template = job_template
self.schedule = schedule
self.concurrency_policy = concurrency_policy
self.successful_jobs_history_limit = successful_jobs_history_limit
self.failed_jobs_history_limit = failed_jobs_history_limit
myakove marked this conversation as resolved.
Show resolved Hide resolved

def to_dict(self):
super().to_dict()
if not self.yaml_file:
if not (self.job_template and self.schedule):
raise MissingRequiredArgumentError(argument="'job_template' and 'schedule'")
self.res.update({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start with an empty resource and fill according to what is needed (i.e do not use self.res.update)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed a while back.

"spec": {
"jobTemplate": self.job_template,
"schedule": self.schedule,
}
})
if 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
if self.concurrency_policy:
self.res["spec"]["concurrencyPolicy"] = self.concurrency_policy
dbasunag marked this conversation as resolved.
Show resolved Hide resolved
71 changes: 71 additions & 0 deletions ocp_resources/reclaim_space_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from ocp_resources.constants import TIMEOUT_4MINUTES
from ocp_resources.resource import NamespacedResource, MissingRequiredArgumentError


class ReclaimSpaceJob(NamespacedResource):
"""
https://github.com/csi-addons/kubernetes-csi-addons/blob/main/docs/reclaimspace.md
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add link to the api

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


Args:
name (str): ReclaimSpaceJob name.
namespace (str): Namespace name.
client (DynamicClient): Dynamic client for connecting to a remote cluster.
teardown (bool): Indicates if this resource would need to be deleted.
privileged_client (DynamicClient): Instance of Dynamic client.
yaml_file (str): Yaml file for the resource.
delete_timeout (int): Timeout associated with delete action.
backoff_limit (int, Optional): The number of retries for a reclaim space job.
target (dict): Volume target on which the operation would be performed.
retryDeadlineSeconds (int, Optional): Optional. Duration in seconds relative to the start time that the
operation may beretried.
timeout (int, Optional): specifies the timeout in seconds for the grpc request sent to the CSI driver
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be under init

Copy link
Contributor Author

@dbasunag dbasunag May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been updated a while back.


api_group = NamespacedResource.ApiGroup.CSIADDONS_OPENSHIFT_IO

def __init__(
self,
name=None,
namespace=None,
client=None,
teardown=True,
privileged_client=None,
yaml_file=None,
delete_timeout=TIMEOUT_4MINUTES,
backoff_limit=None,
target=None,
retry_deadline_seconds=None,
timeout=None,
**kwargs,
):
super().__init__(
name=name,
namespace=namespace,
client=client,
teardown=teardown,
privileged_client=privileged_client,
yaml_file=yaml_file,
delete_timeout=delete_timeout,
**kwargs,
)
self.backoff_limit = backoff_limit
self.target = target
self.retry_deadline_seconds = retry_deadline_seconds
self.timeout = timeout

def to_dict(self):
super().to_dict()
if not self.yaml_file:
myakove marked this conversation as resolved.
Show resolved Hide resolved
if not self.target:
raise MissingRequiredArgumentError(argument="target")
spec_dict = {}
if self.target:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this if is not needd

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

spec_dict.update({"target": self.target})
if self.retry_deadline_seconds:
spec_dict.update({"retryDeadlineSeconds": self.retry_deadline_seconds})
if self.timeout:
spec_dict.update({"timeout": self.timeout})
if self.backoff_limit:
spec_dict.update({"backOffLimit": self.backoff_limit})
if spec_dict:
self.res.update({"spec": spec_dict})
1 change: 1 addition & 0 deletions ocp_resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ class ApiGroup:
CONFIG_OPENSHIFT_IO = "config.openshift.io"
CONSOLE_OPENSHIFT_IO = "console.openshift.io"
COORDINATION_K8S_IO = "coordination.k8s.io"
CSIADDONS_OPENSHIFT_IO = "csiaddons.openshift.io"
DATA_IMPORT_CRON_TEMPLATE_KUBEVIRT_IO = "dataimportcrontemplate.kubevirt.io"
DISCOVERY_K8S_IO = "discovery.k8s.io"
EVENTS_K8S_IO = "events.k8s.io"
Expand Down