This repository has been archived by the owner on Oct 3, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python3 | ||
"""Restore the startingDeadlineSeconds value from last-applied-configuration for all CronJobs.""" | ||
import argparse | ||
import json | ||
|
||
import pykube | ||
from pykube import CronJob | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--dry-run", action="store_true") | ||
args = parser.parse_args() | ||
|
||
api = pykube.HTTPClient(pykube.KubeConfig.from_env()) | ||
for cronjob in CronJob.objects(api).filter(namespace=pykube.all): | ||
if cronjob.obj["spec"].get("startingDeadlineSeconds") == 0: | ||
last_applied_config_json = cronjob.annotations.get( | ||
"kubectl.kubernetes.io/last-applied-configuration" | ||
) | ||
if last_applied_config_json: | ||
last_applied_config = json.loads(last_applied_config_json) | ||
original_value = last_applied_config["spec"].get("startingDeadlineSeconds") | ||
if original_value is not None and original_value != 0: | ||
cronjob.obj["spec"]["startingDeadlineSeconds"] = original_value | ||
print( | ||
f"Updating startingDeadlineSeconds for {cronjob.namespace}/{cronjob.name} to {original_value}.." | ||
) | ||
if not args.dry_run: | ||
cronjob.update() | ||
else: | ||
print("** DRY-RUN **") |