Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
Merge f8a2645 into 80aee07
Browse files Browse the repository at this point in the history
  • Loading branch information
hjacobs committed Apr 9, 2020
2 parents 80aee07 + f8a2645 commit fa35f01
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions restore-cronjobs-starting-deadline-seconds.py
@@ -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 **")

0 comments on commit fa35f01

Please sign in to comment.