Skip to content

Commit

Permalink
configurable engine for container images
Browse files Browse the repository at this point in the history
  • Loading branch information
itroyano committed Jul 22, 2023
1 parent 888ea7f commit 3f8e0e3
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions internal/plugins/manifests/v2/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ 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
# Set the Operator SDK version to use. By default, what is installed on the system is used.
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
OPERATOR_SDK_VERSION ?= %[3]s
Expand Down Expand Up @@ -241,7 +244,7 @@ bundle: kustomize operator-sdk ## Generate bundle manifests and metadata, then v
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.
Expand Down Expand Up @@ -303,7 +306,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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=<some-registry>/<project-name>:<tag>`.

`IMAGE_BUILDER` can be used here to specify your container engine. default is `docker`.

In this way, run:

```sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
3 changes: 2 additions & 1 deletion website/content/en/docs/building-operators/golang/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<some-registry>/<project-name>:<tag>`.
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=<some-registry>/<project-name>:<tag>`.
`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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions website/content/en/docs/overview/cheat-sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Below you will find a cheat sheet with options and helpers for projects, which a
| `operator-sdk init --plugins=<plugin-key>` | 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=<some-registry>/<project-name>:<tag>` | Build the operator image. |
| `make docker-build docker-push IMG=<some-registry>/<project-name>:<tag>` | Build and push the operator image for your registry. |
| `make docker-build IMG=<some-registry>/<project-name>:<tag>` | 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=<some-registry>/<project-name>:<tag>` | 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. |
Expand Down
2 changes: 1 addition & 1 deletion website/content/en/docs/overview/project-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down

0 comments on commit 3f8e0e3

Please sign in to comment.