From 81520a9b86c0eb85c12bea4547bdc60d1c3773a1 Mon Sep 17 00:00:00 2001 From: Steve Kriss Date: Mon, 11 Jun 2018 10:16:03 -0700 Subject: [PATCH 1/2] rename restic-init-container to ark-restic-restore-helper Signed-off-by: Steve Kriss --- ...r.alpine => Dockerfile-ark-restic-restore-helper.alpine | 4 ++-- Makefile | 6 +++--- .../main.go | 0 pkg/restore/restic_restore_action.go | 7 +++++-- 4 files changed, 10 insertions(+), 7 deletions(-) rename Dockerfile-restic-init-container.alpine => Dockerfile-ark-restic-restore-helper.alpine (87%) rename cmd/{restic-init-container => ark-restic-restore-helper}/main.go (100%) diff --git a/Dockerfile-restic-init-container.alpine b/Dockerfile-ark-restic-restore-helper.alpine similarity index 87% rename from Dockerfile-restic-init-container.alpine rename to Dockerfile-ark-restic-restore-helper.alpine index cdc6c2329..1f0cd42d1 100644 --- a/Dockerfile-restic-init-container.alpine +++ b/Dockerfile-ark-restic-restore-helper.alpine @@ -16,8 +16,8 @@ FROM alpine:3.7 MAINTAINER Steve Kriss -ADD /bin/linux/amd64/restic-init-container . +ADD /bin/linux/amd64/ark-restic-restore-helper . USER nobody:nobody -ENTRYPOINT [ "/restic-init-container" ] \ No newline at end of file +ENTRYPOINT [ "/ark-restic-restore-helper" ] \ No newline at end of file diff --git a/Makefile b/Makefile index 3ec816ea3..8946ec2b7 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ IMAGE := $(REGISTRY)/$(BIN) # If you want to build AND push all containers, see the 'all-push' rule. all: @$(MAKE) build - @$(MAKE) build BIN=restic-init-container + @$(MAKE) build BIN=ark-restic-restore-helper build-%: @$(MAKE) --no-print-directory ARCH=$* build @@ -117,7 +117,7 @@ DOTFILE_IMAGE = $(subst :,_,$(subst /,_,$(IMAGE))-$(VERSION)) all-containers: $(MAKE) container - $(MAKE) container BIN=restic-init-container + $(MAKE) container BIN=ark-restic-restore-helper container: verify test .container-$(DOTFILE_IMAGE) container-name .container-$(DOTFILE_IMAGE): _output/bin/$(GOOS)/$(GOARCH)/$(BIN) $(DOCKERFILE) @@ -130,7 +130,7 @@ container-name: all-push: $(MAKE) push - $(MAKE) push BIN=restic-init-container + $(MAKE) push BIN=ark-restic-restore-helper push: .push-$(DOTFILE_IMAGE) push-name .push-$(DOTFILE_IMAGE): .container-$(DOTFILE_IMAGE) diff --git a/cmd/restic-init-container/main.go b/cmd/ark-restic-restore-helper/main.go similarity index 100% rename from cmd/restic-init-container/main.go rename to cmd/ark-restic-restore-helper/main.go diff --git a/pkg/restore/restic_restore_action.go b/pkg/restore/restic_restore_action.go index 28f86965d..c0fb8c398 100644 --- a/pkg/restore/restic_restore_action.go +++ b/pkg/restore/restic_restore_action.go @@ -65,8 +65,11 @@ func (a *resticRestoreAction) Execute(obj runtime.Unstructured, restore *api.Res log.Info("Restic snapshot ID annotations found") initContainer := corev1.Container{ - Name: restic.InitContainer, - Image: "gcr.io/heptio-images/restic-init-container:latest", + Name: restic.InitContainer, + // TODO don't hardcode the tag as "latest". We should probably be defaulting + // to a tag that matches the Ark binary version, and possibly allowing it to + // be overriden via cmd-line flag to Ark. + Image: "gcr.io/heptio-images/ark-restic-restore-helper:latest", Args: []string{string(restore.UID)}, Env: []corev1.EnvVar{ { From d7134b1df280bf2007d0bbdcf2166856cf53c9ab Mon Sep 17 00:00:00 2001 From: Steve Kriss Date: Mon, 11 Jun 2018 10:34:22 -0700 Subject: [PATCH 2/2] use Ark version as the tag for the restore-helper image in init container Signed-off-by: Steve Kriss --- pkg/restore/restic_restore_action.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/pkg/restore/restic_restore_action.go b/pkg/restore/restic_restore_action.go index c0fb8c398..9a5c33a66 100644 --- a/pkg/restore/restic_restore_action.go +++ b/pkg/restore/restic_restore_action.go @@ -17,6 +17,8 @@ limitations under the License. package restore import ( + "fmt" + "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -25,20 +27,33 @@ import ( "k8s.io/apimachinery/pkg/runtime" api "github.com/heptio/ark/pkg/apis/ark/v1" + "github.com/heptio/ark/pkg/buildinfo" "github.com/heptio/ark/pkg/restic" "github.com/heptio/ark/pkg/util/kube" ) type resticRestoreAction struct { - logger logrus.FieldLogger + logger logrus.FieldLogger + initContainerImage string } func NewResticRestoreAction(logger logrus.FieldLogger) ItemAction { return &resticRestoreAction{ - logger: logger, + logger: logger, + initContainerImage: initContainerImage(), } } +func initContainerImage() string { + tag := buildinfo.Version + if tag == "" { + tag = "latest" + } + + // TODO allow full image URL to be overriden via CLI flag. + return fmt.Sprintf("gcr.io/heptio-images/ark-restic-restore-helper:%s", tag) +} + func (a *resticRestoreAction) AppliesTo() (ResourceSelector, error) { return ResourceSelector{ IncludedResources: []string{"pods"}, @@ -65,11 +80,8 @@ func (a *resticRestoreAction) Execute(obj runtime.Unstructured, restore *api.Res log.Info("Restic snapshot ID annotations found") initContainer := corev1.Container{ - Name: restic.InitContainer, - // TODO don't hardcode the tag as "latest". We should probably be defaulting - // to a tag that matches the Ark binary version, and possibly allowing it to - // be overriden via cmd-line flag to Ark. - Image: "gcr.io/heptio-images/ark-restic-restore-helper:latest", + Name: restic.InitContainer, + Image: a.initContainerImage, Args: []string{string(restore.UID)}, Env: []corev1.EnvVar{ {