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

feat: optionally ignore failed snapshots #27

Merged
merged 1 commit into from
Apr 8, 2024
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
1 change: 1 addition & 0 deletions helm/charts/scheduled-volume-snapshotter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ helm upgrade --install scheduled-volume-snapshotter scheduled-volume-snapshotter
| `failedJobsHistoryLimit` | The number of failed jobs to retain | `1` |
| `rbac.enabled` | Flag indicating whether the rbac resources should be installed | `true` |
| `logLevel` | The Python log level for the jobs | `INFO` |
| `ignoreUnsuccessfulSnapshots` | Flag indicating if previously generated snapshots in a non-successful state should be considered when determining if a new snapshot needs to be generated | `false` |
| `podLabels` | Additional labels to add to the CronJob pods | `{}` |
| `podAnnotations` | Annotations to be added to pods | `{}` |
| `snapshotClasses` | Optional list of VolumeSnapshotClass resources | `[]` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ spec:
env:
- name: LOG_LEVEL
value: "{{ .Values.logLevel }}"
- name: IGNORE_UNSUCCESSFUL_SNAPSHOTS
value: "{{ .Values.ignoreUnsuccessfulSnapshots }}"
restartPolicy: Never
2 changes: 2 additions & 0 deletions helm/charts/scheduled-volume-snapshotter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ rbac:

logLevel: INFO

ignoreUnsuccessfulSnapshots: false

resources:
limits:
cpu: 100m
Expand Down
15 changes: 9 additions & 6 deletions snapshotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# strip off any trailing non-numeric characters
K8S_MAJOR_VERSION = int(re.split('[^0-9]', K8S_VERSION_INFO.major)[0])
K8S_MINOR_VERSION = int(re.split('[^0-9]', K8S_VERSION_INFO.minor)[0])
IGNORE_UNSUCCESSFUL_SNAPSHOTS = os.getenv('IGNORE_UNSUCCESSFUL_SNAPSHOTS', 'false').lower() == 'true'

SVS_CRD_GROUP = 'k8s.ryanorth.io'
SVS_CRD_VERSION = 'v1beta1'
Expand Down Expand Up @@ -57,12 +58,14 @@ def get_associated_snapshots(scheduled_snapshot, volume_snapshots):

def new_snapshot_needed(scheduled_snapshot, existing_snapshots):
try:
successful_snapshots = list(filter(
lambda s: (
s.get('status', {}).get('readyToUse', False)
or not s.get('status', {}).get('error', {})
), existing_snapshots
))
successful_snapshots = existing_snapshots
if not IGNORE_UNSUCCESSFUL_SNAPSHOTS:
successful_snapshots = list(filter(
lambda s: (
s.get('status', {}).get('readyToUse', False)
or not s.get('status', {}).get('error', {})
), existing_snapshots
))
raw_snapshot_frequency = scheduled_snapshot.get('spec', {}).get('snapshotFrequency')
if isinstance(raw_snapshot_frequency, int):
raw_snapshot_frequency = f'{str(raw_snapshot_frequency)}h'
Expand Down
Loading