diff --git a/tests/sanity/test_kubectl.py b/tests/sanity/test_kubectl.py index 76aefec..1795218 100644 --- a/tests/sanity/test_kubectl.py +++ b/tests/sanity/test_kubectl.py @@ -10,11 +10,11 @@ def test_kubectl_rock(): """Test kubectl rock.""" - image_variable = "ROCK_KUBECTL_1_30_2" + image_variable = "ROCK_KUBECTL" image = os.getenv(image_variable) assert image is not None, f"${image_variable} is not set" # check binary name and version. - process = docker_util.run_in_docker(image, False, "kubectl", "version") + process = docker_util.run_in_docker(image, ["kubectl", "version"], False) assert "Client Version: v1.30" in process.stdout diff --git a/tests/sanity/test_velero.py b/tests/sanity/test_velero.py index 5f66bd0..8696587 100644 --- a/tests/sanity/test_velero.py +++ b/tests/sanity/test_velero.py @@ -2,28 +2,40 @@ # Copyright 2024 Canonical, Ltd. # -import os +from k8s_test_harness.util import docker_util, env_util -from k8s_test_harness.util import docker_util - -def test_velero_rock(): +def _test_velero_rock(image_version, restic_version): """Test Velero rock.""" - - image_variable = "ROCK_VELERO_1_13_2" - image = os.getenv(image_variable) - assert image is not None, f"${image_variable} is not set" + rock = env_util.get_build_meta_info_for_rock_version( + "velero", image_version, "amd64" + ) + image = rock.image # check binary name and version. - process = docker_util.run_in_docker(image, False, "/velero", "version") + process = docker_util.run_in_docker(image, ["/velero", "version"], False) expected_err = "error finding Kubernetes API server config in --kubeconfig" assert expected_err in process.stderr - # check helper binary. - process = docker_util.run_in_docker(image, False, "/velero-helper") - expected_err = "at least one argument must be provided, the working mode" - assert expected_err in process.stderr + velero_version = docker_util.get_image_version(image) + if velero_version != "1.9.5": + # check helper binary. + process = docker_util.run_in_docker(image, ["/velero-helper"], False) + expected_err = "at least one argument must be provided, the working mode" + assert expected_err in process.stderr # check restic and its version. - process = docker_util.run_in_docker(image, True, "restic", "version") - assert "restic" in process.stdout and "0.15.0" in process.stdout + process = docker_util.run_in_docker(image, ["restic", "version"]) + assert "restic" in process.stdout and restic_version in process.stdout + + +def test_velero_rock_1_13_2(): + _test_velero_rock("1.13.2", "0.15.0") + + +def test_velero_rock_1_12_1(): + _test_velero_rock("1.12.1", "0.15.0") + + +def test_velero_rock_1_9_5(): + _test_velero_rock("1.9.5", "0.14.0") diff --git a/tests/tox.ini b/tests/tox.ini index c89f517..ad423fc 100644 --- a/tests/tox.ini +++ b/tests/tox.ini @@ -48,6 +48,7 @@ commands = pass_env = TEST_* ROCK_* + BUILT_ROCKS_METADATA [testenv:integration] description = Run integration tests @@ -57,6 +58,7 @@ commands = pass_env = TEST_* ROCK_* + BUILT_ROCKS_METADATA [flake8] max-line-length = 120 diff --git a/velero/1.12.1/rockcraft.yaml b/velero/1.12.1/rockcraft.yaml new file mode 100644 index 0000000..c0575c4 --- /dev/null +++ b/velero/1.12.1/rockcraft.yaml @@ -0,0 +1,73 @@ +# Dockerfile: https://github.com/vmware-tanzu/velero/blob/v1.12.1/Dockerfile +name: velero +summary: Velero rock +description: | + A rock containing Velero. Velero gives you tools to back up and restore + your Kubernetes cluster resources and persistent volumes. +license: Apache-2.0 +version: 1.12.1 + +base: bare +build-base: ubuntu@22.04 +run-user: _daemon_ + +platforms: + amd64: + arm64: + +environment: + APP_VERSION: 1.12.1 + RESTIC_VERSION: 0.15.0 + +parts: + add-base-files: + plugin: nil + stage-packages: + - base-files + + build-velero-binary: + plugin: go + source: https://github.com/vmware-tanzu/velero.git + source-type: git + source-tag: v${CRAFT_PROJECT_VERSION} + source-depth: 1 + build-snaps: + - go/1.20/stable + build-environment: + - CGO_ENABLED: 0 + - GO111MODULE: "on" + - GOOS: linux + - GOARCH: $CRAFT_ARCH_BUILD_FOR + - GOPROXY: https://proxy.golang.org + - VERSION: $CRAFT_PROJECT_VERSION + - PKG: github.com/vmware-tanzu/velero + - REGISTRY: canonical + - LDFLAGS: > + -X ${PKG}/pkg/buildinfo.Version=${VERSION} -X ${PKG}/pkg/buildinfo.ImageRegistry=${REGISTRY} + go-generate: + - ./cmd/velero + - ./cmd/velero-helper + organize: + bin/velero: ./ + bin/velero-helper: ./ + + build-restic-binary: + plugin: nil + source: https://github.com/restic/restic.git + source-type: git + source-tag: v0.15.0 + source-depth: 1 + build-snaps: + - go/1.21/stable + build-environment: + - CGO_ENABLED: 0 + - GO111MODULE: "on" + - GOOS: linux + - GOARCH: $CRAFT_ARCH_BUILD_FOR + - GOPROXY: https://proxy.golang.org + - RESTIC_CVE_PATCH: https://raw.githubusercontent.com/vmware-tanzu/velero/v${CRAFT_PROJECT_VERSION}/hack/fix_restic_cve.txt + override-build: | + set -x + curl "${RESTIC_CVE_PATCH}" | git apply - + go run build.go --goos "${GOOS}" --goarch "${GOARCH}" -o "${CRAFT_PART_INSTALL}/usr/bin/restic" + chmod +x "${CRAFT_PART_INSTALL}/usr/bin/restic" diff --git a/velero/rockcraft.yaml b/velero/1.13.2/rockcraft.yaml similarity index 100% rename from velero/rockcraft.yaml rename to velero/1.13.2/rockcraft.yaml diff --git a/velero/1.9.5/rockcraft.yaml b/velero/1.9.5/rockcraft.yaml new file mode 100644 index 0000000..501aac0 --- /dev/null +++ b/velero/1.9.5/rockcraft.yaml @@ -0,0 +1,71 @@ +# Dockerfile: https://github.com/vmware-tanzu/velero/blob/v1.9.5/Dockerfile +name: velero +summary: Velero rock +description: | + A rock containing Velero. Velero gives you tools to back up and restore + your Kubernetes cluster resources and persistent volumes. +license: Apache-2.0 +version: 1.9.5 + +base: bare +build-base: ubuntu@22.04 +run-user: _daemon_ + +platforms: + amd64: + arm64: + +environment: + APP_VERSION: 1.9.5 + RESTIC_VERSION: 0.14.0 + +parts: + add-base-files: + plugin: nil + stage-packages: + - base-files + + build-velero-binary: + plugin: go + source: https://github.com/vmware-tanzu/velero.git + source-type: git + source-tag: v${CRAFT_PROJECT_VERSION} + source-depth: 1 + build-snaps: + - go/1.18/stable + build-environment: + - CGO_ENABLED: 0 + - GO111MODULE: "on" + - GOOS: linux + - GOARCH: $CRAFT_ARCH_BUILD_FOR + - GOPROXY: https://proxy.golang.org + - VERSION: $CRAFT_PROJECT_VERSION + - PKG: github.com/vmware-tanzu/velero + - REGISTRY: canonical + - LDFLAGS: > + -X ${PKG}/pkg/buildinfo.Version=${VERSION} -X ${PKG}/pkg/buildinfo.ImageRegistry=${REGISTRY} + go-generate: + - ./cmd/velero + organize: + bin/velero: ./ + + build-restic-binary: + plugin: nil + source: https://github.com/restic/restic.git + source-type: git + source-tag: v0.14.0 + source-depth: 1 + build-snaps: + - go/1.19/stable + build-environment: + - CGO_ENABLED: 0 + - GO111MODULE: "on" + - GOOS: linux + - GOARCH: $CRAFT_ARCH_BUILD_FOR + - GOPROXY: https://proxy.golang.org + - RESTIC_CVE_PATCH: https://raw.githubusercontent.com/vmware-tanzu/velero/v${CRAFT_PROJECT_VERSION}/hack/modify_acces_denied_code.txt + override-build: | + set -x + curl "${RESTIC_CVE_PATCH}" | git apply - + go run build.go --goos "${GOOS}" --goarch "${GOARCH}" -o "${CRAFT_PART_INSTALL}/usr/bin/restic" + chmod +x "${CRAFT_PART_INSTALL}/usr/bin/restic"