diff --git a/Dockerfile.dbg b/Dockerfile.dbg index 5fa058cc..f728d09b 100644 --- a/Dockerfile.dbg +++ b/Dockerfile.dbg @@ -26,16 +26,9 @@ RUN set -x && bzip2 -d restic.bz2 \ && chmod 755 restic -RUN set -x \ - && curl -fsSL -o redis-dump-go.tar.gz https://github.com/yannh/redis-dump-go/releases/download/v{REDIS_DUMP_VER}/redis-dump-go_{REDIS_DUMP_VER}_{ARG_OS}_{ARG_ARCH}.tar.gz \ - && tar -xzf redis-dump-go.tar.gz \ - && chmod 755 redis-dump-go - - - FROM {ARG_FROM} -LABEL org.opencontainers.image.source https://github.com/stashed/redis +LABEL org.opencontainers.image.source https://github.com/stashed/etcd ENV DEBIAN_FRONTEND noninteractive ENV DEBCONF_NONINTERACTIVE_SEEN true @@ -46,7 +39,6 @@ RUN set -x \ && rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man /tmp/* COPY --from=0 restic /bin/restic -COPY --from=0 redis-dump-go /bin/redis-dump-go COPY bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN} ENTRYPOINT ["/{ARG_BIN}"] diff --git a/Dockerfile.in b/Dockerfile.in index 85f8c885..ce647005 100644 --- a/Dockerfile.in +++ b/Dockerfile.in @@ -26,16 +26,10 @@ RUN set -x && bzip2 -d restic.bz2 \ && chmod 755 restic -RUN set -x \ - && curl -fsSL -o redis-dump-go.tar.gz https://github.com/yannh/redis-dump-go/releases/download/v{REDIS_DUMP_VER}/redis-dump-go_{REDIS_DUMP_VER}_{ARG_OS}_{ARG_ARCH}.tar.gz \ - && tar -xzf redis-dump-go.tar.gz \ - && chmod 755 redis-dump-go - - FROM {ARG_FROM} -LABEL org.opencontainers.image.source https://github.com/stashed/redis +LABEL org.opencontainers.image.source https://github.com/stashed/etcd ENV DEBIAN_FRONTEND noninteractive ENV DEBCONF_NONINTERACTIVE_SEEN true @@ -46,7 +40,6 @@ RUN set -x \ && rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man /tmp/* COPY --from=0 /restic /bin/restic -COPY --from=0 redis-dump-go /bin/redis-dump-go COPY bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN} USER nobody diff --git a/Makefile b/Makefile index e980d5e6..4de14dea 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ SHELL=/bin/bash -o pipefail GO_PKG := stash.appscode.dev REPO := $(notdir $(shell pwd)) -BIN := stash-redis +BIN := stash-etcd COMPRESS ?= no # Where to push the docker image. @@ -43,7 +43,6 @@ else endif RESTIC_VER := 0.12.0-ac.20210727 -REDIS_DUMP_VER := 0.5.1 ### ### These variables should not need tweaking. @@ -59,8 +58,8 @@ BIN_PLATFORMS := $(DOCKER_PLATFORMS) OS := $(if $(GOOS),$(GOOS),$(shell go env GOOS)) ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH)) -BASEIMAGE_PROD ?= redis:6.2.5 -BASEIMAGE_DBG ?= redis:6.2.5 +BASEIMAGE_PROD ?= gcr.io/etcd-development/etcd:v3.5.0 +BASEIMAGE_DBG ?= gcr.io/etcd-development/etcd:v3.5.0 IMAGE := $(REGISTRY)/$(BIN) VERSION_PROD := $(VERSION) @@ -223,7 +222,6 @@ bin/.container-$(DOTFILE_IMAGE)-%: bin/$(OS)_$(ARCH)/$(BIN) $(DOCKERFILE_%) -e 's|{ARG_OS}|$(OS)|g' \ -e 's|{ARG_FROM}|$(BASEIMAGE_$*)|g' \ -e 's|{RESTIC_VER}|$(RESTIC_VER)|g' \ - -e 's|{REDIS_DUMP_VER}|$(REDIS_DUMP_VER)|g' \ $(DOCKERFILE_$*) > bin/.dockerfile-$*-$(OS)_$(ARCH) @DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform $(OS)/$(ARCH) --load --pull -t $(IMAGE):$(TAG_$*) -f bin/.dockerfile-$*-$(OS)_$(ARCH) . @docker images -q $(IMAGE):$(TAG_$*) > $@ @@ -369,5 +367,5 @@ clean: .PHONY: push-to-kind push-to-kind: container @echo "Loading docker image into kind cluster...." - @kind load docker-image $(REGISTRY)/stash-redis:$(TAG) + @kind load docker-image $(REGISTRY)/stash-etcd:$(TAG) @echo "Image has been pushed successfully into kind cluster." diff --git a/README.md b/README.md index 9dbb512a..f88a495d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -[![Go Report Card](https://goreportcard.com/badge/stash.appscode.dev/redis)](https://goreportcard.com/report/stash.appscode.dev/redis) -![CI](https://github.com/stashed/redis/workflows/CI/badge.svg) -[![Docker Pulls](https://img.shields.io/docker/pulls/stashed/stash-redis.svg)](https://hub.docker.com/r/stashed/stash-redis/) +[![Go Report Card](https://goreportcard.com/badge/stash.appscode.dev/etcd)](https://goreportcard.com/report/stash.appscode.dev/etcd) +![CI](https://github.com/stashed/etcd/workflows/CI/badge.svg) +[![Docker Pulls](https://img.shields.io/docker/pulls/stashed/stash-etcd.svg)](https://hub.docker.com/r/stashed/stash-etcd/) [![Slack](https://shields.io/badge/Join_Slack-salck?color=4A154B&logo=slack)](https://slack.appscode.com) [![Twitter](https://img.shields.io/twitter/follow/kubestash.svg?style=social&logo=twitter&label=Follow)](https://twitter.com/intent/follow?screen_name=KubeStash) -# Redis +# Etcd -Redis backup and restore plugin for [Stash by AppsCode](https://stash.run). +Etcd backup and restore plugin for [Stash by AppsCode](https://stash.run). ## Support diff --git a/cmd/stash-redis/main.go b/cmd/stash-redis/main.go index e705a3cd..57bcde15 100644 --- a/cmd/stash-redis/main.go +++ b/cmd/stash-redis/main.go @@ -21,7 +21,7 @@ import ( "runtime" _ "stash.appscode.dev/apimachinery/client/clientset/versioned/fake" - "stash.appscode.dev/redis/pkg" + "stash.appscode.dev/etcd/pkg" "gomodules.xyz/logs" _ "k8s.io/client-go/kubernetes/fake" diff --git a/go.mod b/go.mod index 61efcab5..83520eca 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module stash.appscode.dev/redis +module stash.appscode.dev/etcd go 1.15 diff --git a/pkg/backup.go b/pkg/backup.go index e8ddafc7..8ce7d46a 100644 --- a/pkg/backup.go +++ b/pkg/backup.go @@ -42,7 +42,7 @@ func NewCmdBackup() *cobra.Command { var ( masterURL string kubeconfigPath string - opt = redisOptions{ + opt = etcdOptions{ waitTimeout: 300, setupOptions: restic.SetupOptions{ ScratchDir: restic.DefaultScratchDir, @@ -50,14 +50,14 @@ func NewCmdBackup() *cobra.Command { }, backupOptions: restic.BackupOptions{ Host: restic.DefaultHost, - StdinFileName: RedisDumpFile, + StdinFileName: EtcdBackupFile, }, } ) cmd := &cobra.Command{ - Use: "backup-redis", - Short: "Takes a backup of Redis DB", + Use: "backup-etcd", + Short: "Takes a backup of Etcd DB", DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { flags.EnsureRequiredFlags(cmd, "appbinding", "provider", "secret-dir") @@ -89,7 +89,7 @@ func NewCmdBackup() *cobra.Command { Name: opt.appBindingName, } var backupOutput *restic.BackupOutput - backupOutput, err = opt.backupRedis(targetRef) + backupOutput, err = opt.backupEtcd(targetRef) if err != nil { backupOutput = &restic.BackupOutput{ BackupTargetStatus: api_v1beta1.BackupTargetStatus{ @@ -114,7 +114,7 @@ func NewCmdBackup() *cobra.Command { }, } - cmd.Flags().StringVar(&opt.redisArgs, "redis-args", opt.redisArgs, "Additional arguments") + cmd.Flags().StringVar(&opt.etcdArgs, "etcd-args", opt.etcdArgs, "Additional arguments") cmd.Flags().Int32Var(&opt.waitTimeout, "wait-timeout", opt.waitTimeout, "Time limit to wait for the database to be ready") cmd.Flags().StringVar(&masterURL, "master", masterURL, "The address of the Kubernetes API server (overrides any value in kubeconfig)") @@ -150,7 +150,7 @@ func NewCmdBackup() *cobra.Command { return cmd } -func (opt *redisOptions) backupRedis(targetRef api_v1beta1.TargetRef) (*restic.BackupOutput, error) { +func (opt *etcdOptions) backupEtcd(targetRef api_v1beta1.TargetRef) (*restic.BackupOutput, error) { // if any pre-backup actions has been assigned to it, execute them actionOptions := api_util.ActionOptions{ StashClient: opt.stashClient, @@ -198,12 +198,12 @@ func (opt *redisOptions) backupRedis(targetRef api_v1beta1.TargetRef) (*restic.B // setup pipe command backupCmd := restic.Command{ - Name: RedisDumpCMD, + Name: EtcdBackupCMD, Args: []interface{}{ "-host", appBinding.Spec.ClientConfig.Service.Name, }, } - for _, arg := range strings.Fields(opt.redisArgs) { + for _, arg := range strings.Fields(opt.etcdArgs) { backupCmd.Args = append(backupCmd.Args, arg) } diff --git a/pkg/restore.go b/pkg/restore.go index ce0f272b..45fc190d 100644 --- a/pkg/restore.go +++ b/pkg/restore.go @@ -40,7 +40,7 @@ func NewCmdRestore() *cobra.Command { var ( masterURL string kubeconfigPath string - opt = redisOptions{ + opt = etcdOptions{ setupOptions: restic.SetupOptions{ ScratchDir: restic.DefaultScratchDir, EnableCache: false, @@ -48,14 +48,14 @@ func NewCmdRestore() *cobra.Command { waitTimeout: 300, dumpOptions: restic.DumpOptions{ Host: restic.DefaultHost, - FileName: RedisDumpFile, + FileName: EtcdBackupFile, }, } ) cmd := &cobra.Command{ - Use: "restore-redis", - Short: "Restores Redis DB Backup", + Use: "restore-etcd", + Short: "Restores Etcd DB Backup", DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { flags.EnsureRequiredFlags(cmd, "appbinding", "provider", "secret-dir") @@ -85,7 +85,7 @@ func NewCmdRestore() *cobra.Command { } var restoreOutput *restic.RestoreOutput - restoreOutput, err = opt.restoreRedis(targetRef) + restoreOutput, err = opt.restoreEtcd(targetRef) if err != nil { restoreOutput = &restic.RestoreOutput{ RestoreTargetStatus: api_v1beta1.RestoreMemberStatus{ @@ -109,7 +109,7 @@ func NewCmdRestore() *cobra.Command { }, } - cmd.Flags().StringVar(&opt.redisArgs, "redis-args", opt.redisArgs, "Additional arguments") + cmd.Flags().StringVar(&opt.etcdArgs, "etcd-args", opt.etcdArgs, "Additional arguments") cmd.Flags().Int32Var(&opt.waitTimeout, "wait-timeout", opt.waitTimeout, "Time limit to wait for the database to be ready") cmd.Flags().StringVar(&masterURL, "master", masterURL, "The address of the Kubernetes API server (overrides any value in kubeconfig)") @@ -137,7 +137,7 @@ func NewCmdRestore() *cobra.Command { return cmd } -func (opt *redisOptions) restoreRedis(targetRef api_v1beta1.TargetRef) (*restic.RestoreOutput, error) { +func (opt *etcdOptions) restoreEtcd(targetRef api_v1beta1.TargetRef) (*restic.RestoreOutput, error) { // apply nice, ionice settings from env var err error opt.setupOptions.Nice, err = v1.NiceSettingsFromEnv() @@ -169,13 +169,13 @@ func (opt *redisOptions) restoreRedis(targetRef api_v1beta1.TargetRef) (*restic. // setup pipe command restoreCmd := restic.Command{ - Name: RedisRestoreCMD, + Name: EtcdRestoreCMD, Args: []interface{}{ "--pipe", "-h", appBinding.Spec.ClientConfig.Service.Name, }, } - for _, arg := range strings.Fields(opt.redisArgs) { + for _, arg := range strings.Fields(opt.etcdArgs) { restoreCmd.Args = append(restoreCmd.Args, arg) } // if port is specified, append port in the arguments diff --git a/pkg/root.go b/pkg/root.go index 4df21475..9259fce9 100644 --- a/pkg/root.go +++ b/pkg/root.go @@ -31,9 +31,9 @@ var licenseApiService string func NewRootCmd() *cobra.Command { var rootCmd = &cobra.Command{ - Use: "stash-redis", - Short: `Redis backup & restore plugin for Stash by AppsCode`, - Long: `Redis backup & restore plugin for Stash by AppsCode. For more information, visit here: https://stash.run`, + Use: "stash-etcd", + Short: `Etcd backup & restore plugin for Stash by AppsCode`, + Long: `Etcd backup & restore plugin for Stash by AppsCode. For more information, visit here: https://stash.run`, DisableAutoGenTag: true, PersistentPreRunE: func(c *cobra.Command, args []string) error { cli.SendAnalytics(c, v.Version.Version) diff --git a/pkg/util.go b/pkg/util.go index 0f979018..20bf5b91 100644 --- a/pkg/util.go +++ b/pkg/util.go @@ -33,16 +33,16 @@ import ( ) const ( - RedisUser = "username" - RedisPassword = "password" - RedisDumpFile = "dumpfile.resp" - RedisDumpCMD = "redis-dump-go" - RedisRestoreCMD = "redis-cli" - EnvRedisCLIAuth = "REDISCLI_AUTH" - EnvRedisDumpGoAuth = "REDISDUMPGO_AUTH" + EtcdUser = "username" + EtcdPassword = "password" + EtcdBackupFile = "snapshot.db" + EtcdBackupCMD = "etcdctl" + EtcdRestoreCMD = "etcdctl" + EnvEtcdUser = "ETCD_USERNAME" + EnvEtcdPassword = "ETCD_PASSWORD" ) -type redisOptions struct { +type etcdOptions struct { kubeClient kubernetes.Interface stashClient stash.Interface catalogClient appcatalog_cs.Interface @@ -50,7 +50,7 @@ type redisOptions struct { namespace string backupSessionName string appBindingName string - redisArgs string + etcdArgs string waitTimeout int32 outputDir string @@ -76,7 +76,7 @@ func (wrapper *SessionWrapper) SetEnv(key, value string) { wrapper.Session.SetEnv(key, value) } -func (opt *redisOptions) waitForDBReady(appBinding *appcatalog.AppBinding) error { +func (opt *etcdOptions) waitForDBReady(appBinding *appcatalog.AppBinding) error { klog.Infoln("Waiting for the database to be ready.....") sh := NewSessionWrapper() args := []interface{}{ @@ -96,7 +96,7 @@ func (opt *redisOptions) waitForDBReady(appBinding *appcatalog.AppBinding) error } return wait.PollImmediate(time.Second*5, time.Minute*5, func() (bool, error) { - err := sh.Command("redis-cli", args...).Run() + err := sh.Command("etcd-cli", args...).Run() if err != nil { return false, nil } @@ -104,7 +104,7 @@ func (opt *redisOptions) waitForDBReady(appBinding *appcatalog.AppBinding) error }) } -func (opt *redisOptions) setCredentials(sh Shell, appBinding *appcatalog.AppBinding) error { +func (opt *etcdOptions) setCredentials(sh Shell, appBinding *appcatalog.AppBinding) error { // if credential secret is not provided in AppBinding, then nothing to do. if appBinding.Spec.Secret == nil { return nil @@ -122,10 +122,10 @@ func (opt *redisOptions) setCredentials(sh Shell, appBinding *appcatalog.AppBind return err } - // set auth env for redis-cli - sh.SetEnv(EnvRedisCLIAuth, string(secret.Data[RedisPassword])) + // set auth env for username + sh.SetEnv(EnvEtcdUser, string(secret.Data[EtcdUser])) - // set auth env for redis-dump-go - sh.SetEnv(EnvRedisDumpGoAuth, string(secret.Data[RedisPassword])) + // set auth env for password + sh.SetEnv(EnvEtcdPassword, string(secret.Data[EtcdPassword])) return nil }