diff --git a/.dockerignore b/.dockerignore index 9af8280..dfeca22 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,11 +1,36 @@ # More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file -# Ignore everything by default and re-include only needed files -** +# Compatible with both Docker and Podman +# Use explicit exclusions (not negation patterns) for better compatibility -# Re-include Go source files (but not *_test.go) -!**/*.go +# Build artifacts and unnecessary files +bin/ +dist/ +.git/ +.github/ +docs/ +examples/ +hack/ +test/ +*.md +*.tape +*.gif +*.mp4 +*.svg +*.png + +# Test files **/*_test.go -# Re-include Go module files -!go.mod -!go.sum +# Cache directories +.cache/ + +# IDE and editor files +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# OS files +.DS_Store +Thumbs.db diff --git a/CONTEXT.md b/CONTEXT.md index 3a349c2..3c27c9e 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -96,7 +96,8 @@ generated: config/rbac/*.yaml (multiple files via kubebuilder) ### Build and Deploy * `make build` - builds controller binary -* `make docker-build` - builds container image +* `make docker-build` - builds container image with Docker +* `make podman-build` - builds container image with Podman * `make deploy` - deploys to current kubectl context * `make undeploy` - removes deployment diff --git a/Makefile b/Makefile index 5f9c8ef..1086ca3 100644 --- a/Makefile +++ b/Makefile @@ -62,8 +62,12 @@ CONTROLLER_GEN_PKG := sigs.k8s.io/controller-tools/cmd/controller-gen IMG_PREFIX ?= controller IMG_TAG ?= latest -# ENABLE_METRICS: If set to true, includes Prometheus Service resources. +# Kind cluster name for loading images +KIND_CLUSTER ?= nrr-test + +# ENABLE_METRICS: If set to true, includes Prometheus Service and ServiceMonitor resources. ENABLE_METRICS ?= false +# ENABLE_TLS: If set to true (and ENABLE_METRICS is true), configures metrics to use HTTPS with CertManager. ENABLE_TLS ?= false # ENABLE_WEBHOOK: If set to true, includes validating webhook. Requires ENABLE_TLS=true. ENABLE_WEBHOOK ?= false @@ -173,11 +177,16 @@ run: manifests generate fmt vet ## Run a controller from your host. go run ./cmd/main.go # If you wish to build the manager image targeting other platforms you can use the --platform flag. -# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it. +# (i.e. docker build --platform linux/arm64 or podman build --platform linux/arm64). +# However, you must enable docker buildKit for it. # More info: https://docs.docker.com/develop/develop-images/build_enhancements/ .PHONY: docker-build -docker-build: ## Build docker image with the manager. - DOCKER_BUILDKIT=1 $(CONTAINER_TOOL) build -t ${IMG_PREFIX}:${IMG_TAG} . +docker-build: ## Build container image with Docker. + DOCKER_BUILDKIT=1 docker build -t ${IMG_PREFIX}:${IMG_TAG} . + +.PHONY: podman-build +podman-build: ## Build container image with Podman. + podman build -t localhost/${IMG_PREFIX}:${IMG_TAG} . .PHONY: docker-push docker-push: ## Push docker image with the manager. @@ -197,9 +206,29 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG_PREFIX}:${IMG_TAG} . - $(CONTAINER_TOOL) buildx rm nrrcontroller-builder +.PHONY: kind-load +kind-load: ## Load the built image into kind cluster +ifeq ($(CONTAINER_TOOL),podman) + @echo "Loading Podman image into kind cluster: $(KIND_CLUSTER)" + @echo "Saving image to temporary tar archive..." + @$(CONTAINER_TOOL) save -o /tmp/controller-image.tar localhost/$(IMG_PREFIX):$(IMG_TAG) + @echo "Loading tar archive into kind cluster..." + @kind load image-archive /tmp/controller-image.tar --name $(KIND_CLUSTER) + @echo "Cleaning up temporary tar archive..." + @rm /tmp/controller-image.tar + @echo "Image loaded successfully!" +else + @echo "Loading Docker image into kind cluster: $(KIND_CLUSTER)" + @kind load docker-image $(IMG_PREFIX):$(IMG_TAG) --name $(KIND_CLUSTER) +endif + .PHONY: docker-build-reporter -docker-build-reporter: ## Build docker image with the reporter. - DOCKER_BUILDKIT=1 $(CONTAINER_TOOL) build -f Dockerfile.reporter -t ${IMG_PREFIX}:${IMG_TAG} . +docker-build-reporter: ## Build reporter container image with Docker. + DOCKER_BUILDKIT=1 docker build -f Dockerfile.reporter -t ${IMG_PREFIX}:${IMG_TAG} . + +.PHONY: podman-build-reporter +podman-build-reporter: ## Build reporter container image with Podman. + podman build -f Dockerfile.reporter -t ${IMG_PREFIX}:${IMG_TAG} . .PHONY: docker-push-reporter docker-push-reporter: ## Push docker image with the reporter. diff --git a/docs/TEST_README.md b/docs/TEST_README.md index 8d1ba17..38bae5b 100644 --- a/docs/TEST_README.md +++ b/docs/TEST_README.md @@ -15,7 +15,7 @@ The test uses a 3-node Kind cluster: ### Prerequisites -- [Docker](https://docs.docker.com/get-docker/) +- [Docker](https://docs.docker.com/get-docker/) or [Podman](https://podman.io/getting-started/installation) - [Kind](https://kind.sigs.k8s.io/docs/user/quick-start/#installation) - [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) - [Go](https://golang.org/doc/install) @@ -38,21 +38,44 @@ make install Build the controller image and load it into the Kind cluster nodes. +**Using Docker:** ```bash -# Build the image -make docker-build IMG_PREFIX=controller IMG_TAG=latest +# Build the image (uses defaults: IMG_PREFIX=controller IMG_TAG=latest) +make docker-build -# Load the image into the kind cluster -kind load docker-image controller:latest --name nrr-test +# Load the image into the kind cluster (uses default: KIND_CLUSTER=nrr-test) +make kind-load + +# Verify the image is loaded +docker exec -it nrr-test-control-plane crictl images | grep controller +``` + +**Using Podman:** +```bash +# Build the image (uses defaults: IMG_PREFIX=controller IMG_TAG=latest) +make podman-build + +# Load the image into the kind cluster (uses default: KIND_CLUSTER=nrr-test) +make kind-load CONTAINER_TOOL=podman + +# Verify the image is loaded +podman exec -it nrr-test-control-plane crictl images | grep controller ``` ### Step 3: Controller Deployment -Deploy the controller image to nrr-test-worker +Deploy the controller to the cluster. + +**Using Docker:** ```bash make deploy IMG_PREFIX=controller IMG_TAG=latest ``` +**Using Podman:** +```bash +make deploy IMG_PREFIX=localhost/controller IMG_TAG=latest +``` + Verify the controller is running on the control plane node (`nrr-test-control-plane`): ```bash kubectl get pods -n nrr-system -o wide