From 954735e0428f7acf91c90f82026f9989674bfb89 Mon Sep 17 00:00:00 2001 From: Igor Troyanovsky Date: Thu, 20 Apr 2023 18:56:06 +0300 Subject: [PATCH] configurable engine for container images --- .../ansible/v1/scaffolds/internal/templates/makefile.go | 6 ++++-- .../helm/v1/scaffolds/internal/templates/makefile.go | 6 ++++-- internal/plugins/manifests/v2/init.go | 7 +++++-- .../en/docs/building-operators/ansible/development-tips.md | 2 ++ .../en/docs/building-operators/ansible/quickstart.md | 2 ++ .../content/en/docs/building-operators/golang/migration.md | 2 ++ .../en/docs/building-operators/golang/quickstart.md | 2 ++ .../content/en/docs/building-operators/golang/testing.md | 3 ++- .../content/en/docs/building-operators/golang/tutorial.md | 2 +- .../content/en/docs/building-operators/helm/quickstart.md | 2 +- .../content/en/docs/building-operators/helm/tutorial.md | 2 +- website/content/en/docs/overview/cheat-sheet.md | 4 ++-- website/content/en/docs/overview/project-layout.md | 2 +- 13 files changed, 29 insertions(+), 13 deletions(-) diff --git a/internal/plugins/ansible/v1/scaffolds/internal/templates/makefile.go b/internal/plugins/ansible/v1/scaffolds/internal/templates/makefile.go index 7d027cddf88..3da676d8dc9 100644 --- a/internal/plugins/ansible/v1/scaffolds/internal/templates/makefile.go +++ b/internal/plugins/ansible/v1/scaffolds/internal/templates/makefile.go @@ -68,6 +68,8 @@ const makefileTemplate = ` # Image URL to use all building/pushing image targets IMG ?= {{ .Image }} +IMAGE_BUILDER ?= docker + .PHONY: all all: docker-build @@ -97,11 +99,11 @@ run: ansible-operator ## Run against the configured Kubernetes cluster in ~/.kub .PHONY: docker-build docker-build: ## Build docker image with the manager. - docker build -t ${IMG} . + ${IMAGE_BUILDER} build -t ${IMG} . .PHONY: docker-push docker-push: ## Push docker image with the manager. - docker push ${IMG} + ${IMAGE_BUILDER} push ${IMG} # PLATFORMS defines the target platforms for the manager image be build to provide support to multiple # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to: diff --git a/internal/plugins/helm/v1/scaffolds/internal/templates/makefile.go b/internal/plugins/helm/v1/scaffolds/internal/templates/makefile.go index 631eb32f33d..6c6c18cdb77 100644 --- a/internal/plugins/helm/v1/scaffolds/internal/templates/makefile.go +++ b/internal/plugins/helm/v1/scaffolds/internal/templates/makefile.go @@ -68,6 +68,8 @@ const makefileTemplate = ` # Image URL to use all building/pushing image targets IMG ?= {{ .Image }} +IMAGE_BUILDER ?= docker + .PHONY: all all: docker-build @@ -96,11 +98,11 @@ run: helm-operator ## Run against the configured Kubernetes cluster in ~/.kube/c .PHONY: docker-build docker-build: ## Build docker image with the manager. - docker build -t ${IMG} . + ${IMAGE_BUILDER} build -t ${IMG} . .PHONY: docker-push docker-push: ## Push docker image with the manager. - docker push ${IMG} + ${IMAGE_BUILDER} push ${IMG} # PLATFORMS defines the target platforms for the manager image be build to provide support to multiple # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to: diff --git a/internal/plugins/manifests/v2/init.go b/internal/plugins/manifests/v2/init.go index 772d00e90de..02d0b6edd4e 100644 --- a/internal/plugins/manifests/v2/init.go +++ b/internal/plugins/manifests/v2/init.go @@ -168,6 +168,9 @@ USE_IMAGE_DIGESTS ?= false ifeq ($(USE_IMAGE_DIGESTS), true) BUNDLE_GEN_FLAGS += --use-image-digests endif + +# IMAGE_BUILDER defines the engine to use for handling container images. +IMAGE_BUILDER ?= docker ` makefileBundleFragmentGo = ` @@ -191,7 +194,7 @@ bundle: kustomize ## Generate bundle manifests and metadata, then validate gener makefileBundleBuildPushFragment = ` .PHONY: bundle-build bundle-build: ## Build the bundle image. - docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . + ${IMAGE_BUILDER} build -f bundle.Dockerfile -t $(BUNDLE_IMG) . .PHONY: bundle-push bundle-push: ## Push the bundle image. @@ -253,7 +256,7 @@ endif # https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator .PHONY: catalog-build catalog-build: opm ## Build a catalog image. - $(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) + $(OPM) index add --container-tool ${IMAGE_BUILDER} --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) # Push the catalog image. .PHONY: catalog-push diff --git a/website/content/en/docs/building-operators/ansible/development-tips.md b/website/content/en/docs/building-operators/ansible/development-tips.md index 58187444f40..10a429f9aef 100644 --- a/website/content/en/docs/building-operators/ansible/development-tips.md +++ b/website/content/en/docs/building-operators/ansible/development-tips.md @@ -304,6 +304,8 @@ To build the `memcached-operator` image and push it to a registry: make docker-build docker-push IMG=example.com/memcached-operator:v0.0.1 ``` +Note: `IMAGE_BUILDER` can be used here to specify your container engine. default is `docker`. + Deploy the memcached-operator: ```sh diff --git a/website/content/en/docs/building-operators/ansible/quickstart.md b/website/content/en/docs/building-operators/ansible/quickstart.md index 3582e28703a..5a3cca1c890 100644 --- a/website/content/en/docs/building-operators/ansible/quickstart.md +++ b/website/content/en/docs/building-operators/ansible/quickstart.md @@ -40,6 +40,8 @@ This guide walks through an example of building a simple memcached-operator powe make docker-build docker-push IMG="example.com/memcached-operator:v0.0.1" ``` + Note: `IMAGE_BUILDER` can be used here to specify your container engine. default is `docker`. + ### OLM deployment 1. Install [OLM][doc-olm]: diff --git a/website/content/en/docs/building-operators/golang/migration.md b/website/content/en/docs/building-operators/golang/migration.md index 203e1b7c535..6098b1b6227 100644 --- a/website/content/en/docs/building-operators/golang/migration.md +++ b/website/content/en/docs/building-operators/golang/migration.md @@ -392,6 +392,8 @@ Note that: - `operator-sdk generate crds` is replaced with `make manifests`, which generates CRDs and RBAC rules. - `operator-sdk build` is replaced with `make docker-build IMG=/:`. +`IMAGE_BUILDER` can be used here to specify your container engine. default is `docker`. + In this way, run: ```sh diff --git a/website/content/en/docs/building-operators/golang/quickstart.md b/website/content/en/docs/building-operators/golang/quickstart.md index 3ad027b9e7b..da7bf4621c7 100644 --- a/website/content/en/docs/building-operators/golang/quickstart.md +++ b/website/content/en/docs/building-operators/golang/quickstart.md @@ -43,6 +43,8 @@ plugin which provides support for this platform by adding to the init subCommand make docker-build docker-push IMG="example.com/memcached-operator:v0.0.1" ``` +Note: `IMAGE_BUILDER` can be used here to specify your container engine. default is `docker`. + ### OLM deployment 1. Install [OLM][doc-olm]: diff --git a/website/content/en/docs/building-operators/golang/testing.md b/website/content/en/docs/building-operators/golang/testing.md index 3d7b2d1c79b..555160bd043 100644 --- a/website/content/en/docs/building-operators/golang/testing.md +++ b/website/content/en/docs/building-operators/golang/testing.md @@ -20,7 +20,8 @@ These tests are runnable as native Go tests: go test controllers/ -v -ginkgo.v ``` -The projects generated by using the SDK tool have a Makefile which contains the target tests which executes when you run `make test`. Note that this target will also execute when you run `make docker-build IMG=/:`. +The projects generated by using the SDK tool have a Makefile which contains the target tests which executes when you run `make test`. Note that this target will also execute when you run `make docker-build IMG=/:`. +`IMAGE_BUILDER` can be used here to specify your container engine. default is `docker`. Operator SDK adopted this stack to write tests for its operators. It might be useful to check [writing controller tests][writing-controller-tests] documentation and examples to learn how to better write tests for your operator. See, for example, that [controller-runtime](https://github.com/kubernetes-sigs/controller-runtime) is covered by tests using the same stack as well. diff --git a/website/content/en/docs/building-operators/golang/tutorial.md b/website/content/en/docs/building-operators/golang/tutorial.md index 4e8c5c0c0ff..347d226c8f0 100644 --- a/website/content/en/docs/building-operators/golang/tutorial.md +++ b/website/content/en/docs/building-operators/golang/tutorial.md @@ -331,7 +331,7 @@ build and push an operator image tagged as `example.com/memcached-operator:v0.0. ```console make docker-build docker-push ``` - +Note: `IMAGE_BUILDER` can be used here to specify your container engine. default is `docker`. ## Run the Operator diff --git a/website/content/en/docs/building-operators/helm/quickstart.md b/website/content/en/docs/building-operators/helm/quickstart.md index fa35864d530..6d1972a8c82 100644 --- a/website/content/en/docs/building-operators/helm/quickstart.md +++ b/website/content/en/docs/building-operators/helm/quickstart.md @@ -39,7 +39,7 @@ This guide walks through an example of building a simple nginx-operator powered ```sh make docker-build docker-push IMG="example.com/nginx-operator:v0.0.1" ``` - +Note: `IMAGE_BUILDER` can be used here to specify your container engine. default is `docker`. ### OLM deployment diff --git a/website/content/en/docs/building-operators/helm/tutorial.md b/website/content/en/docs/building-operators/helm/tutorial.md index ce456256a75..89581b0c5f8 100644 --- a/website/content/en/docs/building-operators/helm/tutorial.md +++ b/website/content/en/docs/building-operators/helm/tutorial.md @@ -188,7 +188,7 @@ build and push an operator image tagged as `example.com/nginx-operator:v0.0.1` t ```console make docker-build docker-push ``` - +Note: `IMAGE_BUILDER` can be used here to specify your container engine. default is `docker`. ## Run the operator diff --git a/website/content/en/docs/overview/cheat-sheet.md b/website/content/en/docs/overview/cheat-sheet.md index 24db235e187..5d086046320 100644 --- a/website/content/en/docs/overview/cheat-sheet.md +++ b/website/content/en/docs/overview/cheat-sheet.md @@ -16,8 +16,8 @@ Below you will find a cheat sheet with options and helpers for projects, which a | `operator-sdk init --plugins=` | To initialize an operator project in the current directory using a specific plugin. To check the available plugins you can run `operator-sdk --help`. E.g (`operator-sdk init --plugins=helm`).| | `operator-sdk create api [flags]` | Lets you create your own APIs with its [GKV][gkvs] by [Extending the Kubernetes API with CustomResourceDefinitions][extend-k8s-api], or lets you use external/core-types. Also generates their respective [controllers][controllers-k8s-doc].| | `operator-sdk create webhook [flags]` | To scaffold [Webhooks][webhooks-k8s-doc] for the APIs declared in the project. Currently, only the Go-based project supports this option. | -| `make docker-build IMG=/:` | Build the operator image. | -| `make docker-build docker-push IMG=/:` | Build and push the operator image for your registry. | +| `make docker-build IMG=/:` | Build the operator image. Note: `IMAGE_BUILDER` can be used here to specify your container engine. default is `docker`. | +| `make docker-build docker-push IMG=/:` | Build and push the operator image for your registry. Note: `IMAGE_BUILDER` can be used here to specify your container engine. default is `docker`. | | `make install` | Install the CRDs into the cluster. | | `make uninstall` | Uninstall the CRDs into the cluster. | | `make run` | Run your controller locally and outside of the cluster. Note that this will run in the foreground, so switch to a new terminal if you want to leave it running. | diff --git a/website/content/en/docs/overview/project-layout.md b/website/content/en/docs/overview/project-layout.md index a2f7e319190..902bc16592d 100644 --- a/website/content/en/docs/overview/project-layout.md +++ b/website/content/en/docs/overview/project-layout.md @@ -15,7 +15,7 @@ The common structure contains the following items: | File/Directory | Description | | ------ | ----- | -| `Dockerfile` | The Dockerfile of your operator project, used to build the image with `make docker-build`. | +| `Dockerfile` | The Dockerfile of your operator project, used to build the image with `make docker-build`. Note: `IMAGE_BUILDER` can be used here to specify your container engine. default is `docker`. | | `Makefile` | Build file with helper targets to help you work with your project. | | `PROJECT` | This file represents the project's configuration and is used to track useful information for the CLI and plugins. | | `bin/` | This directory contains useful binaries such as the `manager` which is used to run your project locally and the `kustomize` utility used for the project configuration. For other language types, it might have other binaries useful for developing your operator. |