Skip to content

Commit 9b3c174

Browse files
committed
feat: Add defaultVolumesToFsBackup field to Backup
And use class generator to generate all backup.velero.io resource As well as backup_postgresql_cnpg_noobaa_io.py because they share the same `class-generator -k Backup` According to the velero code definition: // DefaultVolumesToFsBackup specifies whether pod volume file system backup should be used // for all volumes by default. // +optional // +nullable DefaultVolumesToFsBackup *bool `json:"defaultVolumesToFsBackup,omitempty"` Signed-off-by: Qixuan Wang <qwang@redhat.com>
1 parent 7c92608 commit 9b3c174

4 files changed

Lines changed: 359 additions & 0 deletions

File tree

ocp_resources/backup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
from typing import Any
2+
from warnings import warn
23

34
from ocp_resources.resource import NamespacedResource
45

6+
warn(
7+
"backup.py module will be removed in the next release, please import `Backup` from backup_velero.io.py "
8+
"or backup_postgresql_cnpg_noobaa_io.py instead",
9+
DeprecationWarning,
10+
stacklevel=2,
11+
)
12+
513

614
class Backup(NamespacedResource):
715
"""
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md
2+
3+
4+
from typing import Any
5+
6+
from ocp_resources.exceptions import MissingRequiredArgumentError
7+
from ocp_resources.resource import NamespacedResource
8+
9+
10+
class Backup(NamespacedResource):
11+
"""
12+
A Backup resource is a request for a PostgreSQL backup by the user.
13+
"""
14+
15+
api_group: str = NamespacedResource.ApiGroup.POSTGRESQL_CNPG_NOOBAA_IO
16+
17+
def __init__(
18+
self,
19+
cluster: dict[str, Any] | None = None,
20+
method: str | None = None,
21+
online: bool | None = None,
22+
online_configuration: dict[str, Any] | None = None,
23+
plugin_configuration: dict[str, Any] | None = None,
24+
target: str | None = None,
25+
**kwargs: Any,
26+
) -> None:
27+
r"""
28+
Args:
29+
cluster (dict[str, Any]): The cluster to backup
30+
31+
method (str): The backup method to be used, possible options are
32+
`barmanObjectStore`, `volumeSnapshot` or `plugin`. Defaults to:
33+
`barmanObjectStore`.
34+
35+
online (bool): Whether the default type of backup with volume snapshots is online/hot
36+
(`true`, default) or offline/cold (`false`) Overrides the default
37+
setting specified in the cluster field
38+
'.spec.backup.volumeSnapshot.online'
39+
40+
online_configuration (dict[str, Any]): Configuration parameters to control the online/hot backup with volume
41+
snapshots Overrides the default settings specified in the cluster
42+
'.backup.volumeSnapshot.onlineConfiguration' stanza
43+
44+
plugin_configuration (dict[str, Any]): Configuration parameters passed to the plugin managing this backup
45+
46+
target (str): The policy to decide which instance should perform this backup. If
47+
empty, it defaults to `cluster.spec.backup.target`. Available
48+
options are empty string, `primary` and `prefer-standby`.
49+
`primary` to have backups run always on primary instances,
50+
`prefer-standby` to have backups run preferably on the most
51+
updated standby, if available.
52+
53+
"""
54+
super().__init__(**kwargs)
55+
56+
self.cluster = cluster
57+
self.method = method
58+
self.online = online
59+
self.online_configuration = online_configuration
60+
self.plugin_configuration = plugin_configuration
61+
self.target = target
62+
63+
def to_dict(self) -> None:
64+
65+
super().to_dict()
66+
67+
if not self.kind_dict and not self.yaml_file:
68+
if self.cluster is None:
69+
raise MissingRequiredArgumentError(argument="self.cluster")
70+
71+
self.res["spec"] = {}
72+
_spec = self.res["spec"]
73+
74+
_spec["cluster"] = self.cluster
75+
76+
if self.method is not None:
77+
_spec["method"] = self.method
78+
79+
if self.online is not None:
80+
_spec["online"] = self.online
81+
82+
if self.online_configuration is not None:
83+
_spec["onlineConfiguration"] = self.online_configuration
84+
85+
if self.plugin_configuration is not None:
86+
_spec["pluginConfiguration"] = self.plugin_configuration
87+
88+
if self.target is not None:
89+
_spec["target"] = self.target
90+
91+
# End of generated code

ocp_resources/backup_velero_io.py

Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md
2+
3+
4+
from typing import Any
5+
6+
from ocp_resources.resource import NamespacedResource
7+
8+
9+
class Backup(NamespacedResource):
10+
"""
11+
Backup is a Velero resource that represents the capture of Kubernetes
12+
cluster state at a point in time (API objects and associated volume state).
13+
"""
14+
15+
api_group: str = NamespacedResource.ApiGroup.VELERO_IO
16+
17+
def __init__(
18+
self,
19+
csi_snapshot_timeout: str | None = None,
20+
datamover: str | None = None,
21+
default_volumes_to_fs_backup: bool | None = None,
22+
default_volumes_to_restic: bool | None = None,
23+
excluded_cluster_scoped_resources: list[Any] | None = None,
24+
excluded_namespace_scoped_resources: list[Any] | None = None,
25+
excluded_namespaces: list[Any] | None = None,
26+
excluded_resources: list[Any] | None = None,
27+
hooks: dict[str, Any] | None = None,
28+
include_cluster_resources: bool | None = None,
29+
included_cluster_scoped_resources: list[Any] | None = None,
30+
included_namespace_scoped_resources: list[Any] | None = None,
31+
included_namespaces: list[Any] | None = None,
32+
included_resources: list[Any] | None = None,
33+
item_operation_timeout: str | None = None,
34+
label_selector: dict[str, Any] | None = None,
35+
metadata: dict[str, Any] | None = None,
36+
or_label_selectors: list[Any] | None = None,
37+
ordered_resources: dict[str, Any] | None = None,
38+
resource_policy: dict[str, Any] | None = None,
39+
snapshot_move_data: bool | None = None,
40+
snapshot_volumes: bool | None = None,
41+
storage_location: str | None = None,
42+
ttl: str | None = None,
43+
uploader_config: dict[str, Any] | None = None,
44+
volume_snapshot_locations: list[Any] | None = None,
45+
**kwargs: Any,
46+
) -> None:
47+
r"""
48+
Args:
49+
csi_snapshot_timeout (str): CSISnapshotTimeout specifies the time used to wait for CSI
50+
VolumeSnapshot status turns to ReadyToUse during creation, before
51+
returning error as timeout. The default value is 10 minute.
52+
53+
datamover (str): DataMover specifies the data mover to be used by the backup. If
54+
DataMover is "" or "velero", the built-in data mover will be used.
55+
56+
default_volumes_to_fs_backup (bool): DefaultVolumesToFsBackup specifies whether pod volume file system
57+
backup should be used for all volumes by default.
58+
59+
default_volumes_to_restic (bool): DefaultVolumesToRestic specifies whether restic should be used to take
60+
a backup of all pod volumes by default. Deprecated: this field is
61+
no longer used and will be removed entirely in future. Use
62+
DefaultVolumesToFsBackup instead.
63+
64+
excluded_cluster_scoped_resources (list[Any]): ExcludedClusterScopedResources is a slice of cluster-scoped resource
65+
type names to exclude from the backup. If set to "*", all cluster-
66+
scoped resource types are excluded. The default value is empty.
67+
68+
69+
excluded_namespace_scoped_resources (list[Any]): ExcludedNamespaceScopedResources is a slice of namespace-scoped
70+
resource type names to exclude from the backup. If set to "*", all
71+
namespace-scoped resource types are excluded. The default value is
72+
empty.
73+
74+
excluded_namespaces (list[Any]): ExcludedNamespaces contains a list of namespaces that are not included
75+
in the backup.
76+
77+
excluded_resources (list[Any]): ExcludedResources is a slice of resource names that are not included
78+
in the backup.
79+
80+
hooks (dict[str, Any]): Hooks represent custom behaviors that should be executed at different
81+
phases of the backup.
82+
83+
include_cluster_resources (bool): IncludeClusterResources specifies whether cluster-scoped resources
84+
should be included for consideration in the backup.
85+
86+
included_cluster_scoped_resources (list[Any]): IncludedClusterScopedResources is a slice of cluster-scoped resource
87+
type names to include in the backup. If set to "*", all cluster-
88+
scoped resource types are included. The default value is empty,
89+
which means only related cluster-scoped resources are included.
90+
91+
included_namespace_scoped_resources (list[Any]): IncludedNamespaceScopedResources is a slice of namespace-scoped
92+
resource type names to include in the backup. The default value is
93+
"*".
94+
95+
included_namespaces (list[Any]): IncludedNamespaces is a slice of namespace names to include objects
96+
from. If empty, all namespaces are included.
97+
98+
included_resources (list[Any]): IncludedResources is a slice of resource names to include in the
99+
backup. If empty, all resources are included.
100+
101+
item_operation_timeout (str): ItemOperationTimeout specifies the time used to wait for asynchronous
102+
BackupItemAction operations The default value is 4 hour.
103+
104+
label_selector (dict[str, Any]): LabelSelector is a metav1.LabelSelector to filter with when adding
105+
individual objects to the backup. If empty or nil, all objects are
106+
included. Optional.
107+
108+
metadata (dict[str, Any]): No field description from API
109+
110+
or_label_selectors (list[Any]): OrLabelSelectors is list of metav1.LabelSelector to filter with when
111+
adding individual objects to the backup. If multiple provided they
112+
will be joined by the OR operator. LabelSelector as well as
113+
OrLabelSelectors cannot co-exist in backup request, only one of
114+
them can be used.
115+
116+
ordered_resources (dict[str, Any]): OrderedResources specifies the backup order of resources of specific
117+
Kind. The map key is the resource name and value is a list of
118+
object names separated by commas. Each resource name has format
119+
"namespace/objectname". For cluster resources, simply use
120+
"objectname".
121+
122+
resource_policy (dict[str, Any]): ResourcePolicy specifies the referenced resource policies that backup
123+
should follow
124+
125+
snapshot_move_data (bool): SnapshotMoveData specifies whether snapshot data should be moved
126+
127+
snapshot_volumes (bool): SnapshotVolumes specifies whether to take snapshots of any PV's
128+
referenced in the set of objects included in the Backup.
129+
130+
storage_location (str): StorageLocation is a string containing the name of a
131+
BackupStorageLocation where the backup should be stored.
132+
133+
ttl (str): TTL is a time.Duration-parseable string describing how long the Backup
134+
should be retained for.
135+
136+
uploader_config (dict[str, Any]): UploaderConfig specifies the configuration for the uploader.
137+
138+
volume_snapshot_locations (list[Any]): VolumeSnapshotLocations is a list containing names of
139+
VolumeSnapshotLocations associated with this backup.
140+
141+
142+
"""
143+
super().__init__(**kwargs)
144+
145+
self.csi_snapshot_timeout = csi_snapshot_timeout
146+
self.datamover = datamover
147+
self.default_volumes_to_fs_backup = default_volumes_to_fs_backup
148+
self.default_volumes_to_restic = default_volumes_to_restic
149+
self.excluded_cluster_scoped_resources = excluded_cluster_scoped_resources
150+
self.excluded_namespace_scoped_resources = excluded_namespace_scoped_resources
151+
self.excluded_namespaces = excluded_namespaces
152+
self.excluded_resources = excluded_resources
153+
self.hooks = hooks
154+
self.include_cluster_resources = include_cluster_resources
155+
self.included_cluster_scoped_resources = included_cluster_scoped_resources
156+
self.included_namespace_scoped_resources = included_namespace_scoped_resources
157+
self.included_namespaces = included_namespaces
158+
self.included_resources = included_resources
159+
self.item_operation_timeout = item_operation_timeout
160+
self.label_selector = label_selector
161+
self.metadata = metadata
162+
self.or_label_selectors = or_label_selectors
163+
self.ordered_resources = ordered_resources
164+
self.resource_policy = resource_policy
165+
self.snapshot_move_data = snapshot_move_data
166+
self.snapshot_volumes = snapshot_volumes
167+
self.storage_location = storage_location
168+
self.ttl = ttl
169+
self.uploader_config = uploader_config
170+
self.volume_snapshot_locations = volume_snapshot_locations
171+
172+
def to_dict(self) -> None:
173+
174+
super().to_dict()
175+
176+
if not self.kind_dict and not self.yaml_file:
177+
self.res["spec"] = {}
178+
_spec = self.res["spec"]
179+
180+
if self.csi_snapshot_timeout is not None:
181+
_spec["csiSnapshotTimeout"] = self.csi_snapshot_timeout
182+
183+
if self.datamover is not None:
184+
_spec["datamover"] = self.datamover
185+
186+
if self.default_volumes_to_fs_backup is not None:
187+
_spec["defaultVolumesToFsBackup"] = self.default_volumes_to_fs_backup
188+
189+
if self.default_volumes_to_restic is not None:
190+
_spec["defaultVolumesToRestic"] = self.default_volumes_to_restic
191+
192+
if self.excluded_cluster_scoped_resources is not None:
193+
_spec["excludedClusterScopedResources"] = self.excluded_cluster_scoped_resources
194+
195+
if self.excluded_namespace_scoped_resources is not None:
196+
_spec["excludedNamespaceScopedResources"] = self.excluded_namespace_scoped_resources
197+
198+
if self.excluded_namespaces is not None:
199+
_spec["excludedNamespaces"] = self.excluded_namespaces
200+
201+
if self.excluded_resources is not None:
202+
_spec["excludedResources"] = self.excluded_resources
203+
204+
if self.hooks is not None:
205+
_spec["hooks"] = self.hooks
206+
207+
if self.include_cluster_resources is not None:
208+
_spec["includeClusterResources"] = self.include_cluster_resources
209+
210+
if self.included_cluster_scoped_resources is not None:
211+
_spec["includedClusterScopedResources"] = self.included_cluster_scoped_resources
212+
213+
if self.included_namespace_scoped_resources is not None:
214+
_spec["includedNamespaceScopedResources"] = self.included_namespace_scoped_resources
215+
216+
if self.included_namespaces is not None:
217+
_spec["includedNamespaces"] = self.included_namespaces
218+
219+
if self.included_resources is not None:
220+
_spec["includedResources"] = self.included_resources
221+
222+
if self.item_operation_timeout is not None:
223+
_spec["itemOperationTimeout"] = self.item_operation_timeout
224+
225+
if self.label_selector is not None:
226+
_spec["labelSelector"] = self.label_selector
227+
228+
if self.metadata is not None:
229+
_spec["metadata"] = self.metadata
230+
231+
if self.or_label_selectors is not None:
232+
_spec["orLabelSelectors"] = self.or_label_selectors
233+
234+
if self.ordered_resources is not None:
235+
_spec["orderedResources"] = self.ordered_resources
236+
237+
if self.resource_policy is not None:
238+
_spec["resourcePolicy"] = self.resource_policy
239+
240+
if self.snapshot_move_data is not None:
241+
_spec["snapshotMoveData"] = self.snapshot_move_data
242+
243+
if self.snapshot_volumes is not None:
244+
_spec["snapshotVolumes"] = self.snapshot_volumes
245+
246+
if self.storage_location is not None:
247+
_spec["storageLocation"] = self.storage_location
248+
249+
if self.ttl is not None:
250+
_spec["ttl"] = self.ttl
251+
252+
if self.uploader_config is not None:
253+
_spec["uploaderConfig"] = self.uploader_config
254+
255+
if self.volume_snapshot_locations is not None:
256+
_spec["volumeSnapshotLocations"] = self.volume_snapshot_locations
257+
258+
# End of generated code
259+

ocp_resources/resource.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ class ApiGroup:
549549
PERFORMANCE_OPENSHIFT_IO: str = "performance.openshift.io"
550550
POLICY: str = "policy"
551551
POOL_KUBEVIRT_IO: str = "pool.kubevirt.io"
552+
POSTGRESQL_CNPG_NOOBAA_IO = "postgresql.cnpg.noobaa.io"
552553
PROJECT_OPENSHIFT_IO: str = "project.openshift.io"
553554
QUOTA_OPENSHIFT_IO: str = "quota.openshift.io"
554555
RBAC_AUTHORIZATION_K8S_IO: str = "rbac.authorization.k8s.io"

0 commit comments

Comments
 (0)