Skip to content

Commit

Permalink
Merge pull request #1620 from 24sama/release-2.1-origin
Browse files Browse the repository at this point in the history
[release-2.1] 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 9e8c788 + 6626887 commit 92fbd5c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 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 = 720
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
7 changes: 4 additions & 3 deletions pkg/etcd/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ package etcd

import (
"fmt"
"github.com/kubesphere/kubekey/pkg/files"
"path/filepath"
"strings"

"github.com/pkg/errors"

kubekeyapiv1alpha2 "github.com/kubesphere/kubekey/apis/kubekey/v1alpha2"
"github.com/kubesphere/kubekey/pkg/common"
"github.com/kubesphere/kubekey/pkg/core/action"
"github.com/kubesphere/kubekey/pkg/core/connector"
"github.com/kubesphere/kubekey/pkg/core/util"
"github.com/kubesphere/kubekey/pkg/etcd/templates"
"github.com/kubesphere/kubekey/pkg/files"
"github.com/kubesphere/kubekey/pkg/utils"
"github.com/pkg/errors"
)

type EtcdNode struct {
Expand Down Expand Up @@ -389,7 +390,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,
"EtcdBackupPeriod": b.KubeConf.Cluster.Etcd.BackupPeriod,
"EtcdBackupScriptDir": b.KubeConf.Cluster.Etcd.BackupScriptDir,
"EtcdBackupHour": templates.BackupTimeInterval(runtime, b.KubeConf),
Expand Down
14 changes: 10 additions & 4 deletions pkg/etcd/templates/backup_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@
package templates

import (
"strconv"
"text/template"

"github.com/lithammer/dedent"

"github.com/kubesphere/kubekey/pkg/common"
"github.com/kubesphere/kubekey/pkg/core/connector"
"github.com/kubesphere/kubekey/pkg/core/logger"
"github.com/lithammer/dedent"
"strconv"
"text/template"
)

// EtcdBackupScriptTmpl defines the template of etcd backup script.
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 Down Expand Up @@ -57,7 +63,7 @@ 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
if [[ ! $ETCDBACKUPHOUR ]]; then
time="*/$ETCDBACKUPPERIOD * * * *"
Expand Down

0 comments on commit 92fbd5c

Please sign in to comment.