Skip to content

Commit

Permalink
Dockerfile: Migrate ansible-operator image to v1.28.1
Browse files Browse the repository at this point in the history
Following migration guide from v1.22.0 to v1.28.1
https://sdk.operatorframework.io/docs/upgrading-sdk-version/

- v1.23.0
  - Upgrade kustomize versions from v3.8.7 to v4.5.5
  - In the `molecule/default`, replace `--load_restrictor none .` with `--load-restrictor LoadRestrictionsNone`

- v1.24.0
  In Ansible & Helm-based operators, if you need to support arm64, add the following
  `| sed 's/aarch64/arm64/'`

  on the following line

  `ARCH := $(shell uname -m | sed 's/x86_64/amd64/')`

  The resulting line should look like this

  `ARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')`

- v1.25.0
  Add docker-buildx target

- v1.26.0
  update ansible operator Makefile’s run target

- v1.28.0
  Upgrade kubernetes.core collection to v2.4.0

Signed-off-by: Tiger Kaovilai <[email protected]>
  • Loading branch information
kaovilai committed May 11, 2023
1 parent f8d1654 commit 43313b1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM quay.io/operator-framework/ansible-operator:v1.22.0
ARG OPERATOR_SDK_VERSION=v1.28.1
FROM quay.io/operator-framework/ansible-operator:$OPERATOR_SDK_VERSION

COPY requirements.yml ${HOME}/requirements.yml
RUN ansible-galaxy collection install -r ${HOME}/requirements.yml \
Expand Down
39 changes: 27 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ help: ## Display this help.
##@ Build

.PHONY: run
ANSIBLE_ROLES_PATH?="$(shell pwd)/roles"
run: ansible-operator ## Run against the configured Kubernetes cluster in ~/.kube/config
ANSIBLE_ROLES_PATH="$(ANSIBLE_ROLES_PATH):$(shell pwd)/roles" $(ANSIBLE_OPERATOR) run
$(ANSIBLE_OPERATOR) run

TARGET_PLATFORMS ?= linux/${TARGET_ARCH}
CONTAINER_BUILDARGS ?= --build-arg OPERATOR_SDK_VERSION=v1.28.1
.PHONY: docker-build
docker-build: ## Build docker image with the manager.
ifeq ($(CONTAINER_RUNTIME), podman)
Expand All @@ -95,6 +97,23 @@ else
$(CONTAINER_RUNTIME) build --platform ${TARGET_PLATFORMS} -t ${IMG} .
endif

# 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:
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> than the export will fail)
# To properly provided solutions that supports more than one platform you should use this option.
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
.PHONY: docker-buildx
docker-buildx: test ## 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
- docker buildx create --name project-v3-builder
docker buildx use project-v3-builder
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross
- docker buildx rm project-v3-builder
rm Dockerfile.cross

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
$(CONTAINER_RUNTIME) push ${IMG}
Expand Down Expand Up @@ -139,24 +158,19 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
$(KUSTOMIZE) build config/default | kubectl delete -f -

OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m | sed 's/x86_64/amd64/')
ARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')

.PHONY: kustomize
KUSTOMIZE = $(shell pwd)/bin/kustomize
KUSTOMIZE_ARCH=$(ARCH)
ifeq ($(OS),darwin)
# Kustomize does not provide a Darwin/arm64 binary for v3.8.7
KUSTOMIZE_ARCH="amd64"
endif
KUSTOMIZE_VERSION = v4.5.5
kustomize: ## Download kustomize locally if necessary.
ifeq (,$(wildcard $(KUSTOMIZE)))
ifeq (,$(shell which kustomize 2>/dev/null))
@{ \
set -e &&\
echo "$(KUSTOMIZE_ARCH)" &&\
mkdir -p $(dir $(KUSTOMIZE)) &&\
echo https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v3.8.7/kustomize_v3.8.7_$(OS)_$(KUSTOMIZE_ARCH).tar.gz &&\
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v3.8.7/kustomize_v3.8.7_$(OS)_$(KUSTOMIZE_ARCH).tar.gz | \
echo https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/$(KUSTOMIZE_VERSION)/kustomize_$(KUSTOMIZE_VERSION)_$(OS)_$(ARCH).tar.gz &&\
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/$(KUSTOMIZE_VERSION)/kustomize_$(KUSTOMIZE_VERSION)_$(OS)_$(ARCH).tar.gz | \
tar xzf - -C bin/ ;\
}
else
Expand All @@ -172,7 +186,7 @@ ifeq (,$(shell which ansible-operator 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(ANSIBLE_OPERATOR)) ;\
curl -sSLo $(ANSIBLE_OPERATOR) https://github.com/operator-framework/operator-sdk/releases/download/v1.22.0/ansible-operator_$(OS)_$(ARCH) ;\
curl -sSLo $(ANSIBLE_OPERATOR) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/ansible-operator_$(OS)_$(ARCH) ;\
chmod +x $(ANSIBLE_OPERATOR) ;\
}
else
Expand All @@ -181,12 +195,13 @@ endif
endif

OPERATOR_SDK = $(shell pwd)/bin/operator-sdk
OPERATOR_SDK_VERSION ?= v1.28.1
.PHONY: operator-sdk
operator-sdk: $(OPERATOR_SDK)

$(OPERATOR_SDK):
mkdir -p $(dir $(OPERATOR_SDK)) && \
curl -Lo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/v1.28.1/operator-sdk_$(shell go env GOOS)_$(shell go env GOARCH) && \
curl -Lo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$(shell go env GOOS)_$(shell go env GOARCH) && \
chmod +x $(OPERATOR_SDK);

.PHONY: bundle
Expand Down
2 changes: 1 addition & 1 deletion molecule/default/kustomize.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Build kustomize testing overlay
# load_restrictor must be set to none so we can load patch files from the default overlay
command: '{{ kustomize }} build --load_restrictor none .'
command: '{{ kustomize }} build --load-restrictor LoadRestrictionsNone'
args:
chdir: '{{ config_dir }}/testing'
register: resources
Expand Down
2 changes: 1 addition & 1 deletion requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ collections:
- name: operator_sdk.util
version: "0.4.0"
- name: kubernetes.core
version: "2.3.1"
version: "2.4.0"
- name: cloud.common
version: "2.1.1"

0 comments on commit 43313b1

Please sign in to comment.