Skip to content
Merged
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
42 changes: 33 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
# This variable is used to construct full image tags for bundle and catalog images.
#
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
# openshift.io/ceph-volsync-plugin-operator-bundle:$VERSION and openshift.io/ceph-volsync-plugin-operator-catalog:$VERSION.
IMAGE_TAG_BASE ?= openshift.io/ceph-volsync-plugin-operator
# quay.io/ramendr/ceph-volsync-plugin-operator-bundle:$VERSION and quay.io/ramendr/ceph-volsync-plugin-operator-catalog:$VERSION.
IMAGE_TAG_BASE ?= quay.io/ramendr/ceph-volsync-plugin-operator

# MOVER_IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for the mover plugin image.
MOVER_IMAGE_TAG_BASE ?= quay.io/ramendr/ceph-volsync-plugin-mover

# BUNDLE_IMG defines the image:tag used for the bundle.
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
Expand All @@ -50,7 +53,10 @@ endif
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
OPERATOR_SDK_VERSION ?= v1.41.1
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
IMG ?= $(IMAGE_TAG_BASE):v$(VERSION)

# MOVER_IMG defines the image:tag used for the mover plugin image.
MOVER_IMG ?= $(MOVER_IMAGE_TAG_BASE):v$(VERSION)

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -168,7 +174,7 @@ run: manifests generate fmt vet ## Run a controller from your host.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
.PHONY: docker-build
docker-build: ## Build docker image with the manager.
$(CONTAINER_TOOL) build -t ${IMG} .
$(CONTAINER_TOOL) build -t ${IMG} -f build/Containerfile.manager .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
Expand All @@ -183,13 +189,31 @@ docker-push: ## Push docker image with the manager.
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
.PHONY: docker-buildx
docker-buildx: ## Build and push docker image for the manager for cross-platform support
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
# copy existing Containerfile.manager and insert --platform=${BUILDPLATFORM} into Containerfile.manager.cross, and preserve the original Containerfile.manager
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Containerfile.manager > Containerfile.manager.cross
- $(CONTAINER_TOOL) buildx create --name ceph-volsync-plugin-operator-builder
$(CONTAINER_TOOL) buildx use ceph-volsync-plugin-operator-builder
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Containerfile.manager.cross .
- $(CONTAINER_TOOL) buildx rm ceph-volsync-plugin-operator-builder
rm Dockerfile.cross
rm Containerfile.manager.cross

.PHONY: docker-build-mover
docker-build-mover: ## Build docker image with the mover.
$(CONTAINER_TOOL) build -t ${MOVER_IMG} -f build/Containerfile.mover .

.PHONY: docker-push-mover
docker-push-mover: ## Push docker image with the mover.
$(CONTAINER_TOOL) push ${MOVER_IMG}

.PHONY: docker-buildx-mover
docker-buildx-mover: ## Build and push docker image for the mover for cross-platform support
# copy existing Containerfile.mover and insert --platform=${BUILDPLATFORM} into Containerfile.mover.cross, and preserve the original Containerfile.mover
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' build/Containerfile.mover > build/Containerfile.mover.cross
- $(CONTAINER_TOOL) buildx create --name ceph-volsync-plugin-mover-builder
$(CONTAINER_TOOL) buildx use ceph-volsync-plugin-mover-builder
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${MOVER_IMG} -f build/Containerfile.mover.cross .
- $(CONTAINER_TOOL) buildx rm ceph-volsync-plugin-mover-builder
rm build/Containerfile.mover.cross

.PHONY: build-installer
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
Expand Down Expand Up @@ -314,7 +338,7 @@ bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metada

.PHONY: bundle-build
bundle-build: ## Build the bundle image.
$(CONTAINER_TOOL) build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
$(CONTAINER_TOOL) build -f bundle.Containerfile.manager -t $(BUNDLE_IMG) .

.PHONY: bundle-push
bundle-push: ## Push the bundle image.
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile → build/Containerfile.manager
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ COPY go.sum go.sum
RUN go mod download

# Copy the go source
COPY cmd/main.go cmd/main.go
COPY cmd/manager/main.go cmd/manager/main.go

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/manager/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
31 changes: 31 additions & 0 deletions build/Containerfile.mover
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Build the mover binary
FROM golang:1.24 AS builder
ARG TARGETOS
ARG TARGETARCH

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY cmd/mover/main.go cmd/mover/main.go

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o mover cmd/mover/main.go

# Use distroless as minimal base image to package the mover binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/mover .
USER 65532:65532

ENTRYPOINT ["/mover"]
File renamed without changes.
21 changes: 21 additions & 0 deletions cmd/mover/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2025.

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

func main() {
// TODO: add mover job code here.
}
15 changes: 15 additions & 0 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ var (
// projectImage is the name of the image which will be build and loaded
// with the code source changes to be tested.
projectImage = "example.com/ceph-volsync-plugin-operator:v0.0.1"

// projectMoverImage is the name of the mover image which will be build and loaded
// with the code source changes to be tested.
projectMoverImage = "example.com/ceph-volsync-plugin-mover:v0.0.1"
)

// TestE2E runs the end-to-end (e2e) test suite for the project. These tests execute in an isolated,
Expand All @@ -64,6 +68,17 @@ var _ = BeforeSuite(func() {
err = utils.LoadImageToKindClusterWithName(projectImage)
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to load the manager(Operator) image into Kind")

By("building the mover image")
cmd = exec.Command("make", "docker-build-mover", fmt.Sprintf("MOVER_IMG=%s", projectMoverImage))
_, err = utils.Run(cmd)
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to build the mover) image")

// TODO(user): If you want to change the e2e test vendor from Kind, ensure the image is
// built and available before running the tests. Also, remove the following block.
By("loading the manager(Operator) image on Kind")
err = utils.LoadImageToKindClusterWithName(projectMoverImage)
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to load the mover image into Kind")

// The tests-e2e are intended to run on a temporary cluster that is created and destroyed for testing.
// To prevent errors when tests run in environments with CertManager already installed,
// we check for its presence before execution.
Expand Down