Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Spin datamgr to datamgr_install and datamgr_server #494

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Dockerfile-backup-driver
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@
# limitations under the License.

FROM photon:4.0
COPY /bin/linux/amd64/lib/vmware-vix-disklib/lib64/* /vddkLibs/
ADD /bin/linux/amd64/backup-driver* /backup-driver
ENTRYPOINT ["/backup-driver"]
5 changes: 3 additions & 2 deletions Dockerfile-datamgr
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
FROM busybox:1.33.1 AS busybox

FROM photon:4.0
ADD /bin/linux/amd64/data-* /datamgr
ADD /bin/linux/amd64/data-manager-for-plugin-install /datamgr-install
ADD /bin/linux/amd64/data-manager-for-plugin /datamgr-server
COPY /bin/linux/amd64/lib/vmware-vix-disklib/lib64/* /vddkLibs/
COPY --from=busybox /bin/sh /bin/sh
COPY --from=busybox /bin/cp /bin/cp
COPY --from=busybox /bin/tar /bin/tar
COPY --from=busybox /bin/ls /bin/ls
ENTRYPOINT ["/datamgr"]
ENTRYPOINT ["/datamgr-install & /datamgr-server"]
1 change: 0 additions & 1 deletion Dockerfile-plugin
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ ADD /bin/linux/amd64/velero-* /plugins/
ADD /bin/linux/amd64/data-* /
ADD /bin/linux/amd64/backup-driver* /
COPY /bin/linux/amd64/install.sh /scripts/
COPY /bin/linux/amd64/lib/vmware-vix-disklib/lib64/* /plugins/
ENV LD_LIBRARY_PATH=/plugins
COPY --from=busybox /bin/sh /bin/sh
COPY --from=busybox /bin/chmod /bin/chmod
Expand Down
68 changes: 62 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ VDDK_LIBS:= $(LIB_DIR)/vmware-vix-disklib-distrib/lib64
# The binary to build (just the basename).
PLUGIN_BIN ?= velero-plugin-for-vsphere
DATAMGR_BIN ?= data-manager-for-plugin
DATAMGR_INSTALL_BIN ?= data-manager-for-plugin-install
DATAMGR_SERVER_BIN ?= data-manager-for-plugin-server
BACKUPDRIVER_BIN ?= backup-driver
VSPHERE_ASTROLABE ?= vsphere-astrolabe

Expand Down Expand Up @@ -70,14 +72,22 @@ ifeq (,$(wildcard $(GOPATH)/src/$(VDDK_LIBS)))
$(error "$(GOPATH)/src/$(VDDK_LIBS) cannot find vddk libs in path. Please refer to: https://github.com/vmware/virtual-disks#dependency, download the VDDK tarball to the directory $(GOPATH)/src/$(LIB_DIR)/ and untar it")
endif

plugin: datamgr backup-driver
plugin: datamgr-install backup-driver
@echo "making: $@"
$(MAKE) build BIN=$(PLUGIN_BIN) VERSION=$(VERSION)

datamgr:
@echo "making: $@"
$(MAKE) build BIN=$(DATAMGR_BIN) VERSION=$(VERSION)

datamgr-install:
@echo "making: $@"
$(MAKE) build BIN=$(DATAMGR_INSTALL_BIN) VERSION=$(VERSION)

datamgr-server:
@echo "making: $@"
$(MAKE) build BIN=$(DATAMGR_SERVER_BIN) VERSION=$(VERSION)

backup-driver:
@echo "making: $@"
$(MAKE) build BIN=$(BACKUPDRIVER_BIN) VERSION=$(VERSION)
Expand Down Expand Up @@ -139,6 +149,45 @@ shell: build-dirs
$(BUILDER_IMAGE) \
/bin/sh $(CMD)

build-datamgr-server: _output/bin/$(GOOS)/$(GOARCH)/$(DATAMGR_SERVER_BIN)/

_output/bin/$(GOOS)/$(GOARCH)/$(DATAMGR_SERVER_BIN): build-dirs copy-astrolabe
@echo "building: $@"
$(MAKE) shell-datamgr-server CMD="-c '\
GOOS=$(GOOS) \
GOARCH=$(GOARCH) \
REGISTRY=$(REGISTRY) \
VERSION=$(VERSION) \
PKG=$(PKG) \
BIN=$(BIN) \
GIT_SHA=$(GIT_SHA) \
GIT_DIRTY=\"$(GIT_DIRTY)\" \
OUTPUT_DIR=/output/$(GOOS)/$(GOARCH) \
GO111MODULE=on \
GOFLAGS=-mod=readonly \
./hack/build.sh'"

shell-datamgr-server: build-dirs
@echo "running docker: $@"
docker run \
-e GOFLAGS \
-i $(TTY) \
--rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd)/.libs/vmware-vix-disklib-distrib:/usr/local/vmware-vix-disklib-distrib:delegated \
-v $$(pwd)/.go/pkg:/go/pkg:delegated \
-v $$(pwd)/.go/src:/go/src:delegated \
-v $$(pwd)/.go/std:/go/std:delegated \
-v $$(pwd):/go/src/$(PKG):delegated \
-v "$$(pwd)/_output/bin:/output:delegated" \
-v $$(pwd)/.go/std/$(GOOS)_$(GOARCH):/usr/local/go/pkg/$(GOOS)_$(GOARCH)_static:delegated \
-v "$$(pwd)/.go/go-build:/.cache/go-build:delegated" \
-e CGO_ENABLED=1 \
-e GOPATH=/go \
-w /go/src/$(PKG) \
$(BUILDER_IMAGE) \
/bin/sh $(CMD)

build-dirs:
@mkdir -p _output/bin/$(GOOS)/$(GOARCH)
@mkdir -p .go/src/$(PKG) .go/pkg .go/bin .go/std/$(GOOS)/$(GOARCH) .go/go-build
Expand Down Expand Up @@ -166,20 +215,27 @@ copy-vix-libs:
copy-install-script:
cp $$(pwd)/scripts/install.sh _output/bin/$(GOOS)/$(GOARCH)

build-container: copy-vix-libs container-name
build-container: container-name
cp $(DOCKERFILE) _output/bin/$(GOOS)/$(GOARCH)/$(DOCKERFILE)
docker build -t $(IMAGE):$(VERSION) -f _output/bin/$(GOOS)/$(GOARCH)/$(DOCKERFILE) _output

build-datamgr-server-container: copy-vix-libs container-name
cp $(DOCKERFILE) _output/bin/$(GOOS)/$(GOARCH)/$(DOCKERFILE)
docker build -t $(IMAGE):$(VERSION) -f _output/bin/$(GOOS)/$(GOARCH)/$(DOCKERFILE) _output

plugin-container: all copy-install-script
$(MAKE) build-container IMAGE=$(PLUGIN_IMAGE) DOCKERFILE=$(PLUGIN_DOCKERFILE) VERSION=$(VERSION)

datamgr-container: datamgr
$(MAKE) build-container BIN=$(DATAMGR_BIN) IMAGE=$(DATAMGR_IMAGE) DOCKERFILE=$(DATAMGR_DOCKERFILE) VERSION=$(VERSION)
datamgr-install-container: datamgr-install
$(MAKE) build-container BIN=$(DATAMGR_BIN_INSTALL) IMAGE=$(DATAMGR_IMAGE) DOCKERFILE=$(DATAMGR_DOCKERFILE) VERSION=$(VERSION)

datamgr-server-container: datamgr-server
$(MAKE) build-container BIN=$(DATAMGR_BIN_SERVER) IMAGE=$(DATAMGR_IMAGE) DOCKERFILE=$(DATAMGR_DOCKERFILE) VERSION=$(VERSION)

backup-driver-container: backup-driver
$(MAKE) build-container BIN=$(BACKUPDRIVER_BIN) IMAGE=$(BACKUPDRIVER_IMAGE) DOCKERFILE=$(BACKUPDRIVER_DOCKERFILE) VERSION=$(VERSION)

container: plugin-container datamgr-container backup-driver-container
container: plugin-container datamgr-install-container datamgr-server-container backup-driver-container

update:
@echo "updating CRDs"
Expand All @@ -188,7 +244,7 @@ update:
push-plugin: plugin-container
docker push $(PLUGIN_IMAGE):$(VERSION)

push-datamgr: datamgr-container
push-datamgr: datamgr-install-container datamgr-server-container
docker push $(DATAMGR_IMAGE):$(VERSION)

push-backup-driver: backup-driver-container
Expand Down
36 changes: 36 additions & 0 deletions cmd/data-manager-for-plugin-install/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2020 the Velero contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"os"
"path/filepath"

"github.com/vmware-tanzu/velero-plugin-for-vsphere/pkg/cmd"
"github.com/vmware-tanzu/velero-plugin-for-vsphere/pkg/cmd/datamgr_install"

"k8s.io/klog"
)

func main() {
defer klog.Flush()

baseName := filepath.Base(os.Args[0])

err := datamgr_install.NewCommand(baseName).Execute()
cmd.CheckError(err)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"path/filepath"

"github.com/vmware-tanzu/velero-plugin-for-vsphere/pkg/cmd"
"github.com/vmware-tanzu/velero-plugin-for-vsphere/pkg/cmd/datamgr"
"github.com/vmware-tanzu/velero-plugin-for-vsphere/pkg/cmd/datamgr_server"

"k8s.io/klog"
)
Expand All @@ -31,6 +31,6 @@ func main() {

baseName := filepath.Base(os.Args[0])

err := datamgr.NewCommand(baseName).Execute()
err := datamgr_server.NewCommand(baseName).Execute()
cmd.CheckError(err)
}
2 changes: 0 additions & 2 deletions deployment/create-deployment-for-backupdriver-guest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ spec:
value: velero
- name: VELERO_SCRATCH_DIR
value: /scratch
- name: LD_LIBRARY_PATH
value: /vddkLibs
image: dpcpinternal/backup-driver:<backup-driver image tag>
imagePullPolicy: IfNotPresent
name: backup-driver
Expand Down
2 changes: 0 additions & 2 deletions deployment/create-deployment-for-backupdriver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ spec:
value: velero
- name: VELERO_SCRATCH_DIR
value: /scratch
- name: LD_LIBRARY_PATH
value: /vddkLibs
image: dpcpinternal/backup-driver:<backup-driver image tag>
imagePullPolicy: IfNotPresent
name: backup-driver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package datamgr
package datamgr_install

import (
"flag"
"fmt"
"os"

"github.com/vmware-tanzu/velero-plugin-for-vsphere/pkg/cmd/datamgr/cli/install"
"github.com/vmware-tanzu/velero-plugin-for-vsphere/pkg/cmd/datamgr/cli/server"

"github.com/spf13/cobra"
"github.com/vmware-tanzu/velero-plugin-for-vsphere/pkg/cmd/datamgr_install/cli/install"
"k8s.io/klog"

"github.com/vmware-tanzu/velero/pkg/client"
Expand All @@ -51,7 +49,6 @@ func NewCommand(name string) *cobra.Command {
f.BindFlags(c.PersistentFlags())

c.AddCommand(
server.NewCommand(f),
install.NewCommand(f),
)

Expand Down
61 changes: 61 additions & 0 deletions pkg/cmd/datamgr_server/datamgr_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright 2020 the Velero contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package datamgr_server

import (
"flag"
"fmt"
"os"

"github.com/vmware-tanzu/velero-plugin-for-vsphere/pkg/cmd/datamgr_server/cli/server"

"github.com/spf13/cobra"
"k8s.io/klog"

"github.com/vmware-tanzu/velero/pkg/client"
//"github.com/vmware-tanzu/velero/pkg/features"
)

func NewCommand(name string) *cobra.Command {
// Load the config here so that we can extract features from it.
config, err := client.LoadConfig()
if err != nil {
fmt.Fprintf(os.Stderr, "WARNING: Error reading config file: %v\n", err)
}

c := &cobra.Command{
Use: name,
Short: "Upload and download snapshots of persistent volume on vSphere kubernetes cluster",
Long: `Data manager is a component in Velero vSphere plugin for
moving local snapshotted data from/to remote durable persistent storage.
Specifically, the data manager component is supposed to be running
in separate container from the velero server`,
}

f := client.NewFactory(name, config)
f.BindFlags(c.PersistentFlags())

c.AddCommand(
server.NewCommand(f),
)

// init and add the klog flags
klog.InitFlags(flag.CommandLine)
c.PersistentFlags().AddGoFlagSet(flag.CommandLine)

return c
}
4 changes: 0 additions & 4 deletions pkg/install/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment
Name: "VELERO_SCRATCH_DIR",
Value: "/scratch",
},
{
Name: "LD_LIBRARY_PATH",
Value: "/vddkLibs",
},
},
Resources: c.resources,
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

cp /plugins/* /target/.
/backup-driver install
/data-manager-for-plugin install
/data-manager-for-plugin-install install