Coverage for ocp_resources/reclaim_space_cron_job.py: 0%
25 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-30 10:48 +0200
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-30 10:48 +0200
1from __future__ import annotations
2from typing import Any, Dict, Optional
3from ocp_resources.resource import NamespacedResource, MissingRequiredArgumentError
6class ReclaimSpaceCronJob(NamespacedResource):
7 """
8 https://github.com/csi-addons/kubernetes-csi-addons/blob/main/apis/csiaddons/v1alpha1/reclaimspacecronjob_types.go
9 """
11 api_group = NamespacedResource.ApiGroup.CSIADDONS_OPENSHIFT_IO
13 def __init__(
14 self,
15 schedule: Optional[str] = "",
16 job_template: Optional[Dict[str, Any]] = None,
17 concurrency_policy: Optional[str] = "",
18 successful_jobs_history_limit: Optional[int] = None,
19 failed_jobs_history_limit: Optional[int] = None,
20 **kwargs: Any,
21 ) -> None:
22 """
23 Args:
24 schedule (Optional, str): schedule of the reclaim space cron job
25 job_template (Optional, dict): describes the reclaim space job that would be created when a reclaim space cronjob
26 would be executed
27 Example: https://github.com/csi-addons/kubernetes-csi-addons/blob/main/docs/reclaimspace.md
28 concurrency_policy (str, optional): indicates how to treat concurrent execution of a job
29 successful_jobs_history_limit (int, optional): number of successful jobs to retain
30 failed_jobs_history_limit (int, optional): number of failed jobs to retain start at scheduled time
31 """
32 super().__init__(
33 **kwargs,
34 )
35 self.job_template = job_template
36 self.schedule = schedule
37 self.concurrency_policy = concurrency_policy
38 self.successful_jobs_history_limit = successful_jobs_history_limit
39 self.failed_jobs_history_limit = failed_jobs_history_limit
41 def to_dict(self) -> None:
42 super().to_dict()
43 if not self.kind_dict and not self.yaml_file:
44 if not (self.job_template and self.schedule):
45 raise MissingRequiredArgumentError(argument="'job_template' and 'schedule'")
46 self.res["spec"] = {"jobTemplate": self.job_template, "schedule": self.schedule}
47 spec_dict = self.res["spec"]
48 if self.successful_jobs_history_limit:
49 spec_dict["successfulJobsHistoryLimit"] = self.successful_jobs_history_limit
50 if self.failed_jobs_history_limit:
51 spec_dict["failedJobsHistoryLimit"] = self.failed_jobs_history_limit
52 if self.concurrency_policy:
53 spec_dict["concurrencyPolicy"] = self.concurrency_policy