Skip to content

Commit

Permalink
Merge pull request #1619 from 24sama/release-2.2-origin
Browse files Browse the repository at this point in the history
[release-2.2] Fix etcd script to delete other files when there is no space left on device
  • Loading branch information
ks-ci-bot authored Nov 22, 2022
2 parents 2ef69c6 + d776c54 commit 2d19e8e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apis/kubekey/v1alpha2/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const (
K8s = "k8s"
Registry = "registry"
DefaultEtcdBackupDir = "/var/backups/kube_etcd"
DefaultEtcdBackupPeriod = 30
DefaultEtcdBackupPeriod = 1440
DefaultKeepBackNumber = 5
DefaultEtcdBackupScriptDir = "/usr/local/bin/kube-scripts"
DefaultJoinCIDR = "100.64.0.0/16"
Expand Down
2 changes: 2 additions & 0 deletions pkg/bootstrap/os/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ func (r *RemoveNodeFiles) Execute(runtime connector.Runtime) error {
nodeFiles := []string{
"/etc/kubernetes",
"/etc/systemd/system/etcd.service",
"/etc/systemd/system/backup-etcd.service",
"/etc/systemd/system/backup-etcd.timer",
"/var/log/calico",
"/etc/cni",
"/var/log/pods/",
Expand Down
2 changes: 1 addition & 1 deletion pkg/etcd/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func (b *BackupETCD) Execute(runtime connector.Runtime) error {
"Hostname": runtime.RemoteHost().GetName(),
"Etcdendpoint": fmt.Sprintf("https://%s:2379", runtime.RemoteHost().GetInternalAddress()),
"Backupdir": b.KubeConf.Cluster.Etcd.BackupDir,
"KeepbackupNumber": b.KubeConf.Cluster.Etcd.KeepBackupNumber,
"KeepbackupNumber": b.KubeConf.Cluster.Etcd.KeepBackupNumber + 1,
"EtcdBackupScriptDir": b.KubeConf.Cluster.Etcd.BackupScriptDir,
},
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/etcd/templates/backup_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ import (
var EtcdBackupScript = template.Must(template.New("etcd-backup.sh").Parse(
dedent.Dedent(`#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
ETCDCTL_PATH='/usr/local/bin/etcdctl'
ENDPOINTS='{{ .Etcdendpoint }}'
ETCD_DATA_DIR="/var/lib/etcd"
Expand All @@ -52,6 +57,6 @@ export ETCDCTL_API=3;$ETCDCTL_PATH --endpoints="$ENDPOINTS" snapshot save $BACKU
sleep 3
cd $BACKUP_DIR/../;ls -lt |awk '{if(NR > '$KEEPBACKUPNUMBER'){print "rm -rf "$9}}'|sh
cd $BACKUP_DIR/../ && ls -lt |awk '{if(NR > '$KEEPBACKUPNUMBER'){print "rm -rf "$9}}'|sh
`)))
4 changes: 2 additions & 2 deletions pkg/etcd/templates/backup_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Description=Timer to backup ETCD
{{- if .OnCalendarStr }}
OnCalendar={{ .OnCalendarStr }}
{{- else }}
OnCalendar=*-*-* *:*/30:00
OnCalendar=*-*-* 02:00:00
{{- end }}
Unit=backup-etcd.service
[Install]
Expand All @@ -65,7 +65,7 @@ func BackupTimeOnCalendar(period int) string {
onCalendar = fmt.Sprintf("*-*-* 00/%s:%s:00", hour, minute)
}
} else {
onCalendar = "*-*-* 00:00:00"
onCalendar = "*-*-* 02:00:00"
}
return onCalendar
}

0 comments on commit 2d19e8e

Please sign in to comment.