From d3e8e9a9c2a3291670598d7f4b588b4cc111dfd4 Mon Sep 17 00:00:00 2001 From: Xun Jiang Date: Tue, 6 May 2025 11:38:12 +0800 Subject: [PATCH] Remove pushing images to GCR. Remove dependency with GCR. Signed-off-by: Xun Jiang --- .github/workflows/e2e-test-kind.yaml | 4 + .github/workflows/push.yml | 15 -- Makefile | 8 - hack/docker-push.sh | 1 - test/Makefile | 4 +- test/e2e/README.md | 10 +- test/e2e/backup/backup.go | 4 +- test/e2e/bsl-mgmt/deletion.go | 4 +- test/e2e/e2e_suite_test.go | 6 + test/types.go | 1 + test/util/k8s/deployment.go | 2 +- test/util/k8s/pod.go | 2 +- test/util/kibishii/kibishii_utils.go | 3 +- test/util/velero/install.go | 2 +- test/util/velero/velero_utils.go | 213 +++++++++++---------------- 15 files changed, 117 insertions(+), 162 deletions(-) diff --git a/.github/workflows/e2e-test-kind.yaml b/.github/workflows/e2e-test-kind.yaml index 2227c7036..ff3187051 100644 --- a/.github/workflows/e2e-test-kind.yaml +++ b/.github/workflows/e2e-test-kind.yaml @@ -121,6 +121,8 @@ jobs: curl -LO https://dl.k8s.io/release/v${{ matrix.k8s }}/bin/linux/amd64/kubectl sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl + git clone https://github.com/vmware-tanzu-experiments/distributed-data-generator.git -b main /tmp/kibishii + GOPATH=~/go \ CLOUD_PROVIDER=kind \ OBJECT_STORE_PROVIDER=aws \ @@ -132,7 +134,9 @@ jobs: ADDITIONAL_CREDS_FILE=/tmp/credential \ ADDITIONAL_BSL_BUCKET=additional-bucket \ VELERO_IMAGE=velero:pr-test-linux-amd64 \ + PLUGINS=velero/velero-plugin-for-aws:latest \ GINKGO_LABELS="${{ matrix.labels }}" \ + KIBISHII_DIRECTORY=/tmp/kibishii/kubernetes/yaml/ \ make -C test/ run-e2e timeout-minutes: 30 - name: Upload debug bundle diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 7b47b0777..212167e98 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -20,15 +20,6 @@ jobs: uses: actions/setup-go@v5 with: go-version-file: 'go.mod' - - id: 'auth' - uses: google-github-actions/auth@v2 - with: - credentials_json: '${{ secrets.GCS_SA_KEY }}' - - name: 'set up GCloud SDK' - uses: google-github-actions/setup-gcloud@v2 - - name: 'use gcloud CLI' - run: | - gcloud info - name: Set up QEMU id: qemu uses: docker/setup-qemu-action@v3 @@ -52,12 +43,6 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.out verbose: true - # Use the JSON key in secret to login gcr.io - - uses: 'docker/login-action@v3' - with: - registry: 'gcr.io' # or REGION.docker.pkg.dev - username: '_json_key' - password: '${{ secrets.GCR_SA_KEY }}' # Only try to publish the container image from the root repo; forks don't have permission to do so and will always get failures. - name: Publish container image if: github.repository == 'vmware-tanzu/velero' diff --git a/Makefile b/Makefile index 175cfbd53..7309fe9af 100644 --- a/Makefile +++ b/Makefile @@ -34,11 +34,9 @@ REGISTRY ?= velero # docker buildx create --name=velero-builder --driver=docker-container --bootstrap --use --config ./buildkitd.toml # Refer to https://github.com/docker/buildx/issues/1370#issuecomment-1288516840 for more details INSECURE_REGISTRY ?= false -GCR_REGISTRY ?= gcr.io/velero-gcp # Image name IMAGE ?= $(REGISTRY)/$(BIN) -GCR_IMAGE ?= $(GCR_REGISTRY)/$(BIN) # We allow the Dockerfile to be configurable to enable the use of custom Dockerfiles # that pull base images from different registries. @@ -81,10 +79,8 @@ TAG_LATEST ?= false ifeq ($(TAG_LATEST), true) IMAGE_TAGS ?= $(IMAGE):$(VERSION) $(IMAGE):latest - GCR_IMAGE_TAGS ?= $(GCR_IMAGE):$(VERSION) $(GCR_IMAGE):latest else IMAGE_TAGS ?= $(IMAGE):$(VERSION) - GCR_IMAGE_TAGS ?= $(GCR_IMAGE):$(VERSION) endif # check buildx is enabled only if docker is in path @@ -116,7 +112,6 @@ CLI_PLATFORMS ?= linux-amd64 linux-arm linux-arm64 darwin-amd64 darwin-arm64 win BUILD_OUTPUT_TYPE ?= docker BUILD_OS ?= linux BUILD_ARCH ?= amd64 -BUILD_TAG_GCR ?= false BUILD_WINDOWS_VERSION ?= ltsc2022 ifeq ($(BUILD_OUTPUT_TYPE), docker) @@ -134,9 +129,6 @@ ALL_OS_ARCH.windows = $(foreach os, $(filter windows,$(ALL_OS)), $(foreach arch, ALL_OS_ARCH = $(ALL_OS_ARCH.linux)$(ALL_OS_ARCH.windows) ALL_IMAGE_TAGS = $(IMAGE_TAGS) -ifeq ($(BUILD_TAG_GCR), true) - ALL_IMAGE_TAGS += $(GCR_IMAGE_TAGS) -endif # set git sha and tree state GIT_SHA = $(shell git rev-parse HEAD) diff --git a/hack/docker-push.sh b/hack/docker-push.sh index 67117476b..b54f01038 100755 --- a/hack/docker-push.sh +++ b/hack/docker-push.sh @@ -113,5 +113,4 @@ TAG_LATEST="$TAG_LATEST" \ BUILD_OS="$BUILD_OS" \ BUILD_ARCH="$BUILD_ARCH" \ BUILD_OUTPUT_TYPE=$OUTPUT_TYPE \ -BUILD_TAG_GCR=true \ make all-containers \ No newline at end of file diff --git a/test/Makefile b/test/Makefile index 5523716f6..1f8f3a0aa 100644 --- a/test/Makefile +++ b/test/Makefile @@ -102,6 +102,7 @@ OBJECT_STORE_PROVIDER ?= INSTALL_VELERO ?= true REGISTRY_CREDENTIAL_FILE ?= KIBISHII_DIRECTORY ?= github.com/vmware-tanzu-experiments/distributed-data-generator/kubernetes/yaml/ +IMAGE_REGISTRY_PROXY ?= # Flags to create an additional BSL for multiple credentials tests @@ -219,7 +220,8 @@ run-e2e: ginkgo --default-cls-service-account-name=$(DEFAULT_CLS_SERVICE_ACCOUNT_NAME) \ --standby-cls-service-account-name=$(STANDBY_CLS_SERVICE_ACCOUNT_NAME) \ --kibishii-directory=$(KIBISHII_DIRECTORY) \ - --disable-informer-cache=$(DISABLE_INFORMER_CACHE) + --disable-informer-cache=$(DISABLE_INFORMER_CACHE) \ + --image-registry-proxy=$(IMAGE_REGISTRY_PROXY) .PHONY: run-perf run-perf: ginkgo diff --git a/test/e2e/README.md b/test/e2e/README.md index 331c2920a..7e7dcf04d 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -328,26 +328,26 @@ STANDBY_CLUSTER=wl-antreav1311 \ DEFAULT_CLUSTER_NAME=192.168.0.4 \ STANDBY_CLUSTER_NAME=192.168.0.3 \ FEATURES=EnableCSI \ -PLUGINS=gcr.io/velero-gcp/velero-plugin-for-aws:main \ +PLUGINS=velero/velero-plugin-for-aws:main \ HAS_VSPHERE_PLUGIN=false \ OBJECT_STORE_PROVIDER=aws \ CREDS_FILE=$HOME/aws-credential \ BSL_CONFIG=region=us-east-1 \ BSL_BUCKET=nightly-normal-account4-test \ BSL_PREFIX=nightly \ -ADDITIONAL_BSL_PLUGINS=gcr.io/velero-gcp/velero-plugin-for-aws:main \ +ADDITIONAL_BSL_PLUGINS=velero/velero-plugin-for-aws:main \ ADDITIONAL_OBJECT_STORE_PROVIDER=aws \ ADDITIONAL_BSL_CONFIG=region=us-east-1 \ ADDITIONAL_BSL_BUCKET=nightly-restrict-account-test \ ADDITIONAL_BSL_PREFIX=nightly \ ADDITIONAL_CREDS_FILE=$HOME/aws-credential \ -VELERO_IMAGE=gcr.io/velero-gcp/velero:main \ -RESTORE_HELPER_IMAGE=gcr.io/velero-gcp/velero-restore-helper:main \ +VELERO_IMAGE=velero/velero:main \ +RESTORE_HELPER_IMAGE=velero/velero:main \ VERSION=main \ SNAPSHOT_MOVE_DATA=true \ STANDBY_CLUSTER_CLOUD_PROVIDER=vsphere \ STANDBY_CLUSTER_OBJECT_STORE_PROVIDER=aws \ -STANDBY_CLUSTER_PLUGINS=gcr.io/velero-gcp/velero-plugin-for-aws:main \ +STANDBY_CLUSTER_PLUGINS=velero/velero-plugin-for-aws:main \ DISABLE_INFORMER_CACHE=true \ REGISTRY_CREDENTIAL_FILE=$HOME/.docker/config.json \ GINKGO_LABELS=Migration \ diff --git a/test/e2e/backup/backup.go b/test/e2e/backup/backup.go index 2f252171b..91678b5b2 100644 --- a/test/e2e/backup/backup.go +++ b/test/e2e/backup/backup.go @@ -172,7 +172,9 @@ func BackupRestoreTest(backupRestoreTestConfig BackupRestoreTestConfig) { Expect(VeleroInstall(context.Background(), &veleroCfg, false)).To(Succeed()) } - Expect(VeleroAddPluginsForProvider(context.TODO(), veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, veleroCfg.AdditionalBSLProvider, veleroCfg.AddBSLPlugins)).To(Succeed()) + plugins, err := GetPlugins(context.TODO(), veleroCfg, false) + Expect(err).To(Succeed()) + Expect(AddPlugins(plugins, veleroCfg)).To(Succeed()) // Create Secret for additional BSL secretName := fmt.Sprintf("bsl-credentials-%s", UUIDgen) diff --git a/test/e2e/bsl-mgmt/deletion.go b/test/e2e/bsl-mgmt/deletion.go index 51584d85b..fd6660056 100644 --- a/test/e2e/bsl-mgmt/deletion.go +++ b/test/e2e/bsl-mgmt/deletion.go @@ -106,7 +106,9 @@ func BslDeletionTest(useVolumeSnapshots bool) { } By(fmt.Sprintf("Add an additional plugin for provider %s", veleroCfg.AdditionalBSLProvider), func() { - Expect(VeleroAddPluginsForProvider(context.TODO(), veleroCfg.VeleroCLI, veleroCfg.VeleroNamespace, veleroCfg.AdditionalBSLProvider, veleroCfg.AddBSLPlugins)).To(Succeed()) + plugins, err := GetPlugins(context.TODO(), veleroCfg, false) + Expect(err).To(Succeed()) + Expect(AddPlugins(plugins, veleroCfg)).To(Succeed()) }) additionalBsl := fmt.Sprintf("bsl-%s", UUIDgen) diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index 36aaf819e..911d0006a 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -349,6 +349,12 @@ func init() { 1, "Velero backup's item block worker count.", ) + flag.StringVar( + &test.VeleroCfg.ImageRegistryProxy, + "image-registry-proxy", + "", + "The image registry proxy, e.g. when the DockerHub access limitation is reached, can use available proxy to replace. Default is nil.", + ) } // Add label [SkipVanillaZfs]: diff --git a/test/types.go b/test/types.go index 325329c28..c326d4bd7 100644 --- a/test/types.go +++ b/test/types.go @@ -128,6 +128,7 @@ type VeleroConfig struct { EKSPolicyARN string FailFast bool HasVspherePlugin bool + ImageRegistryProxy string } type VeleroCfgInPerf struct { diff --git a/test/util/k8s/deployment.go b/test/util/k8s/deployment.go index 3499be4ce..c41a0a393 100644 --- a/test/util/k8s/deployment.go +++ b/test/util/k8s/deployment.go @@ -53,7 +53,7 @@ func NewDeployment(name, ns string, replicas int32, labels map[string]string, co containers = []corev1api.Container{ { Name: DefaultContainerName, - Image: "gcr.io/velero-gcp/busybox:latest", + Image: "busybox:1.37.0", Command: []string{"sleep", "1000000"}, // Make pod obeys the restricted pod security standards. SecurityContext: &corev1api.SecurityContext{ diff --git a/test/util/k8s/pod.go b/test/util/k8s/pod.go index e4ac52951..2a9b9ef9a 100644 --- a/test/util/k8s/pod.go +++ b/test/util/k8s/pod.go @@ -76,7 +76,7 @@ func CreatePod(client TestClient, ns, name, sc, pvcName string, volumeNameList [ Containers: []corev1api.Container{ { Name: name, - Image: "gcr.io/velero-gcp/busybox", + Image: "busybox:1.37.0", Command: []string{"sleep", "3600"}, VolumeMounts: vmList, // Make pod obeys the restricted pod security standards. diff --git a/test/util/kibishii/kibishii_utils.go b/test/util/kibishii/kibishii_utils.go index e701856ad..fb767cecd 100644 --- a/test/util/kibishii/kibishii_utils.go +++ b/test/util/kibishii/kibishii_utils.go @@ -19,6 +19,7 @@ package kibishii import ( "fmt" "os/exec" + "path" "strconv" "strings" "time" @@ -275,7 +276,7 @@ func installKibishii(ctx context.Context, namespace string, cloudPlatform, veler } // We use kustomize to generate YAML for Kibishii from the checked-in yaml directories kibishiiInstallCmd := exec.CommandContext(ctx, "kubectl", "apply", "-n", namespace, "-k", - kibishiiDirectory+cloudPlatform, "--timeout=90s") + path.Join(kibishiiDirectory, cloudPlatform), "--timeout=90s") _, stderr, err := veleroexec.RunCommand(kibishiiInstallCmd) fmt.Printf("Install Kibishii cmd: %s\n", kibishiiInstallCmd) if err != nil { diff --git a/test/util/velero/install.go b/test/util/velero/install.go index 2c58dea94..e2e44e1b1 100644 --- a/test/util/velero/install.go +++ b/test/util/velero/install.go @@ -84,7 +84,7 @@ func VeleroInstall(ctx context.Context, veleroCfg *test.VeleroConfig, isStandbyC } } - pluginsTmp, err := getPlugins(ctx, *veleroCfg) + pluginsTmp, err := GetPlugins(ctx, *veleroCfg, true) if err != nil { return errors.WithMessage(err, "Failed to get provider plugins") } diff --git a/test/util/velero/velero_utils.go b/test/util/velero/velero_utils.go index 0b64ba60c..69c84b1c2 100644 --- a/test/util/velero/velero_utils.go +++ b/test/util/velero/velero_utils.go @@ -27,6 +27,7 @@ import ( "os" "os/exec" "os/user" + "path" "path/filepath" "reflect" "regexp" @@ -57,78 +58,51 @@ const RestoreObjectsPrefix = "restores" const PluginsObjectsPrefix = "plugins" var ImagesMatrix = map[string]map[string][]string{ - "v1.10": { - "aws": {"gcr.io/velero-gcp/velero-plugin-for-aws:v1.6.0"}, - "azure": {"gcr.io/velero-gcp/velero-plugin-for-microsoft-azure:v1.6.0"}, - "vsphere": {"gcr.io/velero-gcp/velero-plugin-for-vsphere:v1.5.1"}, - "gcp": {"gcr.io/velero-gcp/velero-plugin-for-gcp:v1.6.0"}, - "csi": {"gcr.io/velero-gcp/velero-plugin-for-csi:v0.4.0"}, - "velero": {"gcr.io/velero-gcp/velero:v1.10.2"}, - "velero-restore-helper": {"gcr.io/velero-gcp/velero-restore-helper:v1.10.2"}, - }, - "v1.11": { - "aws": {"gcr.io/velero-gcp/velero-plugin-for-aws:v1.7.0"}, - "azure": {"gcr.io/velero-gcp/velero-plugin-for-microsoft-azure:v1.7.0"}, - "vsphere": {"gcr.io/velero-gcp/velero-plugin-for-vsphere:v1.5.1"}, - "gcp": {"gcr.io/velero-gcp/velero-plugin-for-gcp:v1.7.0"}, - "csi": {"gcr.io/velero-gcp/velero-plugin-for-csi:v0.5.0"}, - "velero": {"gcr.io/velero-gcp/velero:v1.11.1"}, - "velero-restore-helper": {"gcr.io/velero-gcp/velero-restore-helper:v1.11.1"}, - }, - "v1.12": { - "aws": {"gcr.io/velero-gcp/velero-plugin-for-aws:v1.8.0"}, - "azure": {"gcr.io/velero-gcp/velero-plugin-for-microsoft-azure:v1.8.0"}, - "vsphere": {"gcr.io/velero-gcp/velero-plugin-for-vsphere:v1.5.1"}, - "gcp": {"gcr.io/velero-gcp/velero-plugin-for-gcp:v1.8.0"}, - "csi": {"gcr.io/velero-gcp/velero-plugin-for-csi:v0.6.0"}, - "velero": {"gcr.io/velero-gcp/velero:v1.12.4"}, - "velero-restore-helper": {"gcr.io/velero-gcp/velero-restore-helper:v1.12.4"}, - }, "v1.13": { - "aws": {"gcr.io/velero-gcp/velero-plugin-for-aws:v1.9.2"}, - "azure": {"gcr.io/velero-gcp/velero-plugin-for-microsoft-azure:v1.9.2"}, - "vsphere": {"gcr.io/velero-gcp/velero-plugin-for-vsphere:v1.5.2"}, - "gcp": {"gcr.io/velero-gcp/velero-plugin-for-gcp:v1.9.2"}, - "csi": {"gcr.io/velero-gcp/velero-plugin-for-csi:v0.7.1"}, - "datamover": {"gcr.io/velero-gcp/velero-plugin-for-aws:v1.9.2"}, - "velero": {"gcr.io/velero-gcp/velero:v1.13.2"}, - "velero-restore-helper": {"gcr.io/velero-gcp/velero-restore-helper:v1.13.2"}, + "aws": {"velero/velero-plugin-for-aws:v1.9.2"}, + "azure": {"velero/velero-plugin-for-microsoft-azure:v1.9.2"}, + "vsphere": {"velero/velero-plugin-for-vsphere:v1.5.2"}, + "gcp": {"velero/velero-plugin-for-gcp:v1.9.2"}, + "csi": {"velero/velero-plugin-for-csi:v0.7.1"}, + "datamover": {"velero/velero-plugin-for-aws:v1.9.2"}, + "velero": {"velero/velero:v1.13.2"}, + "velero-restore-helper": {"velero/velero-restore-helper:v1.13.2"}, }, "v1.14": { - "aws": {"gcr.io/velero-gcp/velero-plugin-for-aws:v1.10.1"}, - "azure": {"gcr.io/velero-gcp/velero-plugin-for-microsoft-azure:v1.10.1"}, - "vsphere": {"gcr.io/velero-gcp/velero-plugin-for-vsphere:v1.5.2"}, - "gcp": {"gcr.io/velero-gcp/velero-plugin-for-gcp:v1.10.1"}, - "datamover": {"gcr.io/velero-gcp/velero-plugin-for-aws:v1.10.1"}, - "velero": {"gcr.io/velero-gcp/velero:v1.14.1"}, - "velero-restore-helper": {"gcr.io/velero-gcp/velero-restore-helper:v1.14.1"}, + "aws": {"velero/velero-plugin-for-aws:v1.10.1"}, + "azure": {"velero/velero-plugin-for-microsoft-azure:v1.10.1"}, + "vsphere": {"velero/velero-plugin-for-vsphere:v1.5.2"}, + "gcp": {"velero/velero-plugin-for-gcp:v1.10.1"}, + "datamover": {"velero/velero-plugin-for-aws:v1.10.1"}, + "velero": {"velero/velero:v1.14.1"}, + "velero-restore-helper": {"velero/velero-restore-helper:v1.14.1"}, }, "v1.15": { - "aws": {"gcr.io/velero-gcp/velero-plugin-for-aws:v1.11.0"}, - "azure": {"gcr.io/velero-gcp/velero-plugin-for-microsoft-azure:v1.11.0"}, - "vsphere": {"gcr.io/velero-gcp/velero-plugin-for-vsphere:v1.5.2"}, - "gcp": {"gcr.io/velero-gcp/velero-plugin-for-gcp:v1.11.0"}, - "datamover": {"gcr.io/velero-gcp/velero-plugin-for-aws:v1.11.0"}, - "velero": {"gcr.io/velero-gcp/velero:v1.15.2"}, - "velero-restore-helper": {"gcr.io/velero-gcp/velero-restore-helper:v1.15.2"}, + "aws": {"velero/velero-plugin-for-aws:v1.11.0"}, + "azure": {"velero/velero-plugin-for-microsoft-azure:v1.11.0"}, + "vsphere": {"velero/velero-plugin-for-vsphere:v1.5.2"}, + "gcp": {"velero/velero-plugin-for-gcp:v1.11.0"}, + "datamover": {"velero/velero-plugin-for-aws:v1.11.0"}, + "velero": {"velero/velero:v1.15.2"}, + "velero-restore-helper": {"velero/velero-restore-helper:v1.15.2"}, }, "v1.16": { - "aws": {"gcr.io/velero-gcp/velero-plugin-for-aws:v1.12.0"}, - "azure": {"gcr.io/velero-gcp/velero-plugin-for-microsoft-azure:v1.12.0"}, - "vsphere": {"gcr.io/velero-gcp/velero-plugin-for-vsphere:v1.5.2"}, - "gcp": {"gcr.io/velero-gcp/velero-plugin-for-gcp:v1.12.0"}, - "datamover": {"gcr.io/velero-gcp/velero-plugin-for-aws:v1.12.0"}, - "velero": {"gcr.io/velero-gcp/velero:v1.15.0"}, - "velero-restore-helper": {"gcr.io/velero-gcp/velero:v1.16.0"}, + "aws": {"velero/velero-plugin-for-aws:v1.12.0"}, + "azure": {"velero/velero-plugin-for-microsoft-azure:v1.12.0"}, + "vsphere": {"velero/velero-plugin-for-vsphere:v1.5.2"}, + "gcp": {"velero/velero-plugin-for-gcp:v1.12.0"}, + "datamover": {"velero/velero-plugin-for-aws:v1.12.0"}, + "velero": {"velero/velero:v1.15.0"}, + "velero-restore-helper": {"velero/velero:v1.16.0"}, }, "main": { - "aws": {"gcr.io/velero-gcp/velero-plugin-for-aws:main"}, - "azure": {"gcr.io/velero-gcp/velero-plugin-for-microsoft-azure:main"}, - "vsphere": {"gcr.io/velero-gcp/velero-plugin-for-vsphere:v1.5.2"}, - "gcp": {"gcr.io/velero-gcp/velero-plugin-for-gcp:main"}, - "datamover": {"gcr.io/velero-gcp/velero-plugin-for-aws:main"}, - "velero": {"gcr.io/velero-gcp/velero:main"}, - "velero-restore-helper": {"gcr.io/velero-gcp/velero-restore-helper:main"}, + "aws": {"velero/velero-plugin-for-aws:main"}, + "azure": {"velero/velero-plugin-for-microsoft-azure:main"}, + "vsphere": {"velero/velero-plugin-for-vsphere:v1.5.2"}, + "gcp": {"velero/velero-plugin-for-gcp:main"}, + "datamover": {"velero/velero-plugin-for-aws:main"}, + "velero": {"velero/velero:main"}, + "velero-restore-helper": {"velero/velero-restore-helper:main"}, }, } @@ -147,6 +121,12 @@ func SetImagesToDefaultValues(config VeleroConfig, version string) (VeleroConfig versionWithoutPatch) } + if config.ImageRegistryProxy != "" { + for index := range images { + images[index][0] = path.Join(config.ImageRegistryProxy, images[index][0]) + } + } + ret.VeleroImage = images[Velero][0] ret.RestoreHelperImage = images[VeleroRestoreHelper][0] @@ -177,7 +157,7 @@ func SetImagesToDefaultValues(config VeleroConfig, version string) (VeleroConfig return ret, nil } -func getPluginsByVersion(version string, cloudProvider string, needDataMoverPlugin bool) ([]string, error) { +func getPluginsByVersion(version string, cloudProvider string, needDataMoverPlugin bool, imageRegistryProxy string) ([]string, error) { var cloudMap map[string][]string arr := strings.Split(version, ".") if len(arr) >= 3 { @@ -192,6 +172,12 @@ func getPluginsByVersion(version string, cloudProvider string, needDataMoverPlug var plugins []string var ok bool + if imageRegistryProxy != "" { + for index := range cloudMap { + cloudMap[index][0] = path.Join(imageRegistryProxy, cloudMap[index][0]) + } + } + if slices.Contains(LocalCloudProviders, cloudProvider) { plugins, ok = cloudMap[AWS] if !ok { @@ -673,37 +659,45 @@ func VeleroVersion(ctx context.Context, veleroCLI, veleroNamespace string) error return nil } -// getProviderPlugins only provide plugin for specific cloud provider -func getProviderPlugins(ctx context.Context, veleroCLI string, cloudProvider string) ([]string, error) { - if cloudProvider == "" { - return []string{}, errors.New("CloudProvider should be provided") - } +// GetPlugins will collect all kinds plugins for VeleroInstall, such as provider +// plugins(cloud provider/object store provider, if object store provider is not +// provided, it should be set to value as cloud provider's), feature plugins (CSI/Datamover) +func GetPlugins(ctx context.Context, veleroCfg VeleroConfig, defaultBSL bool) ([]string, error) { + veleroCLI := veleroCfg.VeleroCLI + cloudProvider := veleroCfg.CloudProvider + objectStoreProvider := veleroCfg.ObjectStoreProvider + providerPlugins := veleroCfg.Plugins + imageRegistryProxy := veleroCfg.ImageRegistryProxy + needDataMoverPlugin := false + var plugins []string version, err := GetVeleroVersion(ctx, veleroCLI, true) if err != nil { return nil, errors.WithMessage(err, "failed to get velero version") } - plugins, err := getPluginsByVersion(version, cloudProvider, false) - if err != nil { - return nil, errors.WithMessagef(err, "Fail to get plugin by provider %s and version %s", cloudProvider, version) + // Read the plugins for the additional BSL here. + if defaultBSL == false { + fmt.Printf("Additional BSL provider = %s\n", veleroCfg.AdditionalBSLProvider) + fmt.Printf("Additional BSL plugins = %v\n", veleroCfg.AddBSLPlugins) + + if veleroCfg.AddBSLPlugins == "" { + if veleroCfg.AdditionalBSLProvider == "" { + return []string{}, errors.New("AdditionalBSLProvider should be provided.") + } + + plugins, err = getPluginsByVersion(version, cloudProvider, false, imageRegistryProxy) + if err != nil { + return nil, errors.WithMessagef(err, "Fail to get plugin by provider %s and version %s", cloudProvider, version) + } + } else { + plugins = append(plugins, veleroCfg.AddBSLPlugins) + } + + return plugins, nil } - return plugins, nil -} - -// getPlugins will collect all kinds plugins for VeleroInstall, such as provider -// plugins(cloud provider/object store provider, if object store provider is not -// provided, it should be set to value as cloud provider's), feature plugins (CSI/Datamover) -func getPlugins(ctx context.Context, veleroCfg VeleroConfig) ([]string, error) { - veleroCLI := veleroCfg.VeleroCLI - cloudProvider := veleroCfg.CloudProvider - objectStoreProvider := veleroCfg.ObjectStoreProvider - providerPlugins := veleroCfg.Plugins - needDataMoverPlugin := false - // Fetch the plugins for the provider before checking for the object store provider below. - var plugins []string if len(providerPlugins) > 0 { plugins = strings.Split(providerPlugins, ",") } else { @@ -714,47 +708,30 @@ func getPlugins(ctx context.Context, veleroCfg VeleroConfig) ([]string, error) { objectStoreProvider = cloudProvider } - var version string - var err error if veleroCfg.VeleroVersion != "" { version = veleroCfg.VeleroVersion - } else { - version, err = GetVeleroVersion(ctx, veleroCLI, true) - if err != nil { - return nil, errors.WithMessage(err, "failed to get velero version") - } } + if veleroCfg.SnapshotMoveData && veleroCfg.DataMoverPlugin == "" && !veleroCfg.IsUpgradeTest { needDataMoverPlugin = true } - plugins, err = getPluginsByVersion(version, cloudProvider, needDataMoverPlugin) + + plugins, err = getPluginsByVersion(version, cloudProvider, needDataMoverPlugin, imageRegistryProxy) if err != nil { return nil, errors.WithMessagef(err, "Fail to get plugin by provider %s and version %s", objectStoreProvider, version) } } + return plugins, nil } -// VeleroAddPluginsForProvider determines which plugins need to be installed for a provider and -// installs them in the current Velero installation, skipping over those that are already installed. -func VeleroAddPluginsForProvider(ctx context.Context, veleroCLI string, veleroNamespace string, provider string, plugin string) error { - var err error - var plugins []string - if plugin == "" { - plugins, err = getProviderPlugins(ctx, veleroCLI, provider) - } else { - plugins = append(plugins, plugin) - } - fmt.Printf("provider cmd = %v\n", provider) - fmt.Printf("plugins cmd = %v\n", plugins) - if err != nil { - return errors.WithMessage(err, "Failed to get plugins") - } +// AddPlugins installs them in the current Velero installation, skipping over those that are already installed. +func AddPlugins(plugins []string, veleroCfg VeleroConfig) error { for _, plugin := range plugins { stdoutBuf := new(bytes.Buffer) stderrBuf := new(bytes.Buffer) - installPluginCmd := exec.CommandContext(ctx, veleroCLI, "--namespace", veleroNamespace, "plugin", "add", plugin, "--confirm") + installPluginCmd := exec.CommandContext(context.TODO(), veleroCfg.VeleroCLI, "--namespace", veleroCfg.VeleroNamespace, "plugin", "add", plugin, "--confirm") fmt.Printf("installPluginCmd cmd =%v\n", installPluginCmd) installPluginCmd.Stdout = stdoutBuf installPluginCmd.Stderr = stderrBuf @@ -1447,14 +1424,6 @@ func UpdateVeleroDeployment(ctx context.Context, veleroCfg VeleroConfig) ([]stri } cmds = append(cmds, cmd) - args := fmt.Sprintf("s#\\\"image\\\"\\: \\\"velero\\/velero\\:v[0-9]*.[0-9]*.[0-9]\\\"#\\\"image\\\"\\: \\\"gcr.io\\/velero-gcp\\/nightly\\/velero\\:%s\\\"#g", veleroCfg.VeleroVersion) - - cmd = &common.OsCommandLine{ - Cmd: "sed", - Args: []string{args}, - } - cmds = append(cmds, cmd) - cmd = &common.OsCommandLine{ Cmd: "sed", Args: []string{fmt.Sprintf("s#\\\"server\\\",#\\\"server\\\",\\\"--uploader-type=%s\\\",#g", veleroCfg.UploaderType)}, @@ -1497,14 +1466,6 @@ func UpdateNodeAgent(ctx context.Context, veleroCfg VeleroConfig, dsjson string) } cmds = append(cmds, cmd) - args := fmt.Sprintf("s#\\\"image\\\"\\: \\\"velero\\/velero\\:v[0-9]*.[0-9]*.[0-9]\\\"#\\\"image\\\"\\: \\\"gcr.io\\/velero-gcp\\/nightly\\/velero\\:%s\\\"#g", veleroCfg.VeleroVersion) - - cmd = &common.OsCommandLine{ - Cmd: "sed", - Args: []string{args}, - } - cmds = append(cmds, cmd) - cmd = &common.OsCommandLine{ Cmd: "sed", Args: []string{"s#\\\"name\\\"\\: \\\"restic\\\"#\\\"name\\\"\\: \\\"node-agent\\\"#g"},