apiVersion: batch/v1
kind: CronJob
metadata:
name: cronjob-maintenance-ex
namespace: ns-maintenance-ex
spec:
schedule: "0 15 * * 0"
jobTemplate:
spec:
backoffLimit: 0
template:
spec:
serviceAccountName: sa-maintenance-ex
containers:
- name: c-maintenance-ex
image: google/cloud-sdk:latest
command:
- "/bin/bash"
- "-c"
- |
set -e;
apt-get update;
apt-get install -y jq;
apt-get clean;
CLUSTER_NAME='gke-pilot-versionup-dev-autopilot';
ZONE='asia-northeast1';
NEW_EXCLUSION_NAME="exclusion-$(date '+%Y%m%d')";
PERIOD='20 days';
gcloud container clusters update $CLUSTER_NAME --zone $ZONE --add-maintenance-exclusion-name $NEW_EXCLUSION_NAME --add-maintenance-exclusion-start $(date +"%Y-%m-%dT%H:%M:%S%z") --add-maintenance-exclusion-end $(date -d "$PERIOD" +"%Y-%m-%dT%H:%M:%S%z");
echo 'New maintenance exclusion created successfully.';
EXCLUSION_NAMES=$(gcloud container clusters describe $CLUSTER_NAME --zone $ZONE --format='json' | jq -r '.maintenancePolicy.window.maintenanceExclusions | keys[]');
EXCLUSION_NAMES_ARRAY=($EXCLUSION_NAMES);
if [ $