Skip to content

Commit

Permalink
[makefile] Adding target to setup olm kuadrant installation
Browse files Browse the repository at this point in the history
* Bumps opm version
* Creates tasks to load olm needed images to Kind for local testing
* Uses custom catalog Dockerfile

[catalog] Custom Dockerfile for building catalog

* In order to use instead of autogenerated index.Dockerfile
* To mitigate operator-framework/operator-registry#619

[gh] Using custom catalog.Dockerfile to build catalog images

[gh] Adding platforms for building images

[makefile] Adding platform param in custom docker build command
  • Loading branch information
didierofrivia authored and alexsnaps committed Dec 8, 2022
1 parent 8a789ed commit b98cdea
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 4 deletions.
90 changes: 86 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,19 @@ local-setup: $(KIND) ## Deploy locally kuadrant operator from the current code
local-cleanup: ## Delete local cluster
$(MAKE) kind-delete-cluster

# kuadrant is not deployed
.PHONY: local-env-setup
local-env-setup: ## Deploys all services and manifests required by kuadrant to run. Used to run kuadrant with "make run"
.PHONY: local-cluster-setup
local-cluster-setup: ## Sets up Kind cluster with GatewayAPI manifests and istio GW, nothing Kuadrant.
$(MAKE) kind-delete-cluster
$(MAKE) kind-create-cluster
$(MAKE) namespace
$(MAKE) gateway-api-install
$(MAKE) istio-install
$(MAKE) deploy-gateway

# kuadrant is not deployed
.PHONY: local-env-setup
local-env-setup: ## Deploys all services and manifests required by kuadrant to run. Used to run kuadrant with "make run"
$(MAKE) local-cluster-setup
$(MAKE) deploy-dependencies
$(MAKE) install

Expand All @@ -266,6 +270,20 @@ test-env-setup: ## Deploys all services and manifests required by kuadrant to ru
$(MAKE) deploy-dependencies
$(MAKE) install

.PHONY: local-olm-setup
local-olm-setup: ## Installs OLM and the Kuadrant operator catalog, then installs the operator with its dependencies.
$(MAKE) local-cluster-setup
$(MAKE) docker-build
$(MAKE) install-olm
$(MAKE) bundle
$(MAKE) bundle-build
$(MAKE) catalog-generate
$(MAKE) catalog-custom-build
$(MAKE) kind-load-catalog
$(MAKE) kind-load-image
$(MAKE) kind-load-bundle
$(MAKE) deploy-olm

##@ Build

build: generate fmt vet ## Build manager binary.
Expand All @@ -282,6 +300,15 @@ docker-build: ## Build docker image with the manager.
docker-push: ## Push docker image with the manager.
docker push $(IMG)

kind-load-catalog: ## Load catalog image to local cluster
$(KIND) load docker-image $(CATALOG_IMG) --name $(KIND_CLUSTER_NAME)

kind-load-image: ## Load image to local cluster
$(KIND) load docker-image $(IMG) --name $(KIND_CLUSTER_NAME)

kind-load-bundle: ## Load image to local cluster
$(KIND) load docker-image $(BUNDLE_IMG) --name $(KIND_CLUSTER_NAME)

##@ Deployment

install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
Expand Down Expand Up @@ -310,7 +337,7 @@ install-olm: $(OPERATOR_SDK)
uninstall-olm:
$(OPERATOR_SDK) olm uninstall

deploy-catalog: $(KUSTOMIZE) $(YQ) ## Deploy controller to the K8s cluster specified in ~/.kube/config using OLM catalog image.
deploy-catalog: $(KUSTOMIZE) $(YQ) ## Deploy operator to the K8s cluster specified in ~/.kube/config using OLM catalog image.
V="$(CATALOG_IMG)" $(YQ) eval '.spec.image = strenv(V)' -i config/deploy/olm/catalogsource.yaml
$(KUSTOMIZE) build config/deploy/olm | kubectl apply -f -

Expand Down Expand Up @@ -364,6 +391,61 @@ bundle-build: ## Build the bundle image.
bundle-push: ## Push the bundle image.
$(MAKE) docker-push IMG=$(BUNDLE_IMG)

.PHONY: opm
OPM = ./bin/opm
opm: ## Download opm locally if necessary.
ifeq (,$(wildcard $(OPM)))
ifeq (,$(shell which opm 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(OPM)) ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.26.2/$${OS}-$${ARCH}-opm ;\
chmod +x $(OPM) ;\
}
else
OPM = $(shell which opm)
endif
endif

# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
# These images MUST exist in a registry and be pull-able.
BUNDLE_IMGS ?= $(BUNDLE_IMG),$(LIMITADOR_OPERATOR_BUNDLE_IMG),$(AUTHORINO_OPERATOR_BUNDLE_IMG)

# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:$(IMAGE_TAG)

# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
ifneq ($(origin CATALOG_BASE_IMG), undefined)
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
endif

PLATFORM_PARAM =
ifeq ($(shell uname -sm),Darwin arm64)
PLATFORM_PARAM = --platform=linux/arm64
endif

# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
# 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)

.PHONY: catalog-custom-build
catalog-custom-build: ## Build the bundle image.
docker build $(PLATFORM_PARAM) -f catalog.Dockerfile -t $(CATALOG_IMG) .


.PHONY: catalog-generate
catalog-generate: opm ## Generate a catalog/index Dockerfile.
$(OPM) index add --generate --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)

# Push the catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)

##@ Code Style

GOLANGCI-LINT = $(PROJECT_PATH)/bin/golangci-lint
Expand Down
8 changes: 8 additions & 0 deletions catalog.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM quay.io/operator-framework/upstream-opm-builder
LABEL operators.operatorframework.io.index.database.v1=/database/index.db
ADD database/index.db /database/index.db
RUN mkdir /registry && chmod 775 /registry
EXPOSE 50051
WORKDIR /registry
ENTRYPOINT ["/bin/opm"]
CMD ["registry", "serve", "--database", "/database/index.db"]

0 comments on commit b98cdea

Please sign in to comment.