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

Allow cluster exceptions #787

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion create-cr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
name="etcd-backup-$(date "+%Y%m%d%H%M%S")"
guest_backup="${1}"
clusters_regex="${2:-.*}"
clusters_to_exclude_regex="${3:-.*}"

# Check guest backup.
if [ "${guest_backup}" != "true" ] && [ "${guest_backup}" != "false" ]
then
# Print usage.
echo "Usage: ${0} <true|false>"
echo "Usage: ${0} <true|false> [clusters_regex] [clusters_to_exclude_regex]"
# Exit erroneously.
exit 1
fi
Expand All @@ -22,4 +23,5 @@ metadata:
spec:
guestBackup: ${guest_backup}
clustersRegex: "${clusters_regex}"
clustersToExcludeRegex: "${clusters_to_exclude_regex}"
END
5 changes: 5 additions & 0 deletions helm/etcd-backup-operator/templates/crds/etcd-backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ spec:
clusters have to be backed up
nullable: true
type: string
clustersToExcludeRegex:
description: clustersToExcludeRegex is a regexp string indicating which workload
clusters will not to be backed up
nullable: true
type: string
guestBackup:
description: GuestBackup is a boolean indicating if the workload clusters
have to be backed up
Expand Down
3 changes: 3 additions & 0 deletions helm/etcd-backup-operator/templates/cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ spec:
args:
- {{ not $.Values.testingEnvironment | quote }}
- {{ $schedule.clusters | quote }}
{{- if $schedule.clusters_to_exclude }}
- {{ $schedule.clusters_to_exclude | quote }}
{{- end }}
restartPolicy: Never
{{- end }}
6 changes: 4 additions & 2 deletions helm/etcd-backup-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ schedules:
- cronjob: "0 */6 * * *"
clusters: ".*"
# - cronjob: 0 */6 * * *
# clusters: '^(?!<cluster-id>)' #all clusters but the id defined
# clusters: '^(<cluster-id>)' #cluster ids to backup
# clusters_to_exclude: '^(<cluster-id2>)' #cluster ids to skip backup
# - cronjob: 0 3 * * * *
# clusters: '<cluster-id>' # only one cluster
# clusters: '<cluster-id>' # multiple clusters
# clusters_to_exclude: '^(<cluster-id2>|<cluster-id3>)' #multiple clusters to skip backup

etcdDataDir: ""
clientCertsDir: "/etc/kubernetes/ssl/etcd/"
Expand Down
11 changes: 9 additions & 2 deletions service/controller/resource/etcdbackup/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,18 @@ func (r *Resource) runBackupOnAllInstances(ctx context.Context, obj interface{},
if err != nil {
return false, microerror.Mask(err)
}

re := regexp2.MustCompile(customObject.Spec.ClustersRegex, 0)
re2 := regexp2.MustCompile(customObject.Spec.clustersToExcludeRegex, 0)
for _, guestInstance := range guestInstances {
if isMatch, _ := re.MatchString(guestInstance.Name); isMatch {
instances = append(instances, guestInstance)
if isMatch, _ := clustersToIncludeRegex.MatchString(guestInstance.Name); !isMatch {
continue
}
if isMatch, _ := clustersToExcludeRegex.MatchString(guestInstance.Name); isMatch {
continue
}

instances = append(instances, guestInstance)
}
}
}
Expand Down