Skip to content

Commit

Permalink
Merge pull request #1623 from 24sama/release-1.1-origin
Browse files Browse the repository at this point in the history
[release-1.1] Fix etcd script to delete other files when there is no space left on device
  • Loading branch information
24sama authored Nov 22, 2022
2 parents 7f4b70f + ec787c8 commit 3970f5c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
5 changes: 3 additions & 2 deletions apis/kubekey/v1alpha1/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import (
"os"
"strings"

"github.com/kubesphere/kubekey/pkg/util"
log "github.com/sirupsen/logrus"

"github.com/kubesphere/kubekey/pkg/util"
)

const (
Expand Down Expand Up @@ -60,7 +61,7 @@ const (
Worker = "worker"
K8s = "k8s"
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
9 changes: 6 additions & 3 deletions pkg/cluster/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ package delete
import (
"bufio"
"fmt"
"github.com/kubesphere/kubekey/pkg/util"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"unicode"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"

kubekeyapiv1alpha1 "github.com/kubesphere/kubekey/apis/kubekey/v1alpha1"
"github.com/kubesphere/kubekey/pkg/config"
"github.com/kubesphere/kubekey/pkg/util"
"github.com/kubesphere/kubekey/pkg/util/executor"
"github.com/kubesphere/kubekey/pkg/util/manager"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)

func ResetCluster(clusterCfgFile string, logger *log.Logger, verbose bool) error {
Expand Down Expand Up @@ -263,6 +264,8 @@ var (
"/etc/etcd.env",
"/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
11 changes: 8 additions & 3 deletions pkg/etcd/tmpl/etcdbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ import (
"strconv"
"text/template"

"github.com/lithammer/dedent"

kubekeyapiv1alpha1 "github.com/kubesphere/kubekey/apis/kubekey/v1alpha1"
"github.com/kubesphere/kubekey/pkg/util"
"github.com/kubesphere/kubekey/pkg/util/manager"
"github.com/lithammer/dedent"
)

// EtcdBackupScriptTmpl defines the template of etcd backup script.
var EtcdBackupScriptTmpl = template.Must(template.New("etcdBackupScript").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 @@ -44,7 +49,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 Expand Up @@ -82,7 +87,7 @@ func EtcdBackupScript(mgr *manager.Manager, node *kubekeyapiv1alpha1.HostCfg) (s
"Hostname": node.Name,
"Etcdendpoint": fmt.Sprintf("https://%s:2379", node.InternalAddress),
"Backupdir": mgr.Cluster.Kubernetes.EtcdBackupDir,
"KeepbackupNumber": mgr.Cluster.Kubernetes.KeepBackupNumber,
"KeepbackupNumber": mgr.Cluster.Kubernetes.KeepBackupNumber + 1,
"EtcdBackupPeriod": mgr.Cluster.Kubernetes.EtcdBackupPeriod,
"EtcdBackupScriptDir": mgr.Cluster.Kubernetes.EtcdBackupScriptDir,
"EtcdBackupHour": etcdBackupHour,
Expand Down

0 comments on commit 3970f5c

Please sign in to comment.