-
Notifications
You must be signed in to change notification settings - Fork 67
Add snapshot property to Datasource class #1587
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| from ocp_resources.constants import TIMEOUT_4MINUTES | ||
| from ocp_resources.persistent_volume_claim import PersistentVolumeClaim | ||
| from ocp_resources.resource import NamespacedResource | ||
| from ocp_resources.volume_snapshot import VolumeSnapshot | ||
|
|
||
|
|
||
| class DataSource(NamespacedResource): | ||
|
|
@@ -39,19 +40,29 @@ def to_dict(self): | |
| }, | ||
| }) | ||
|
|
||
| @property | ||
| def pvc(self): | ||
| data_source_pvc = self.instance.spec.source.pvc | ||
| pvc_name = data_source_pvc.name | ||
| pvc_namespace = data_source_pvc.namespace | ||
| def _get_boot_source(self, boot_source_type): | ||
| boot_source = self.instance.spec.source.get(boot_source_type) | ||
| if not boot_source: | ||
| return None | ||
| boot_source_name = boot_source.name | ||
| boot_source_namespace = boot_source.namespace | ||
| try: | ||
| return PersistentVolumeClaim( | ||
| boot_source_object = PersistentVolumeClaim if boot_source_type == "pvc" else VolumeSnapshot | ||
| return boot_source_object( | ||
| client=self.client, | ||
| name=pvc_name, | ||
| namespace=pvc_namespace, | ||
| name=boot_source_name, | ||
| namespace=boot_source_namespace, | ||
| ) | ||
| except ResourceNotFoundError: | ||
| self.logger.warning( | ||
| f"dataSource {self.name} is pointing to a non-existing PVC, name:" | ||
| f" {pvc_name}, namespace: {pvc_namespace}" | ||
| f"dataSource {self.name} is pointing to a non-existing {boot_source_type}, name:" | ||
| f" {boot_source_name}, namespace: {boot_source_namespace}" | ||
| ) | ||
|
|
||
| @property | ||
| def pvc(self): | ||
| return self._get_boot_source(boot_source_type="pvc") | ||
|
|
||
| @property | ||
| def snapshot(self): | ||
| return self._get_boot_source(boot_source_type="snapshot") | ||
|
Comment on lines
+62
to
+68
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify - add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to clarify: You are suggesting that the only property should be
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, and add deprecation warning on
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi I have this PR in downstream. So If I change to |
||
Uh oh!
There was an error while loading. Please reload this page.