diff --git a/.github/workflows/ci-e2e.yaml b/.github/workflows/ci-e2e.yaml index a84c357bd..6459ee09a 100644 --- a/.github/workflows/ci-e2e.yaml +++ b/.github/workflows/ci-e2e.yaml @@ -5,6 +5,7 @@ on: branches: - main - "release-*" + - remove_gateway_prefix tags: - "v[0-9]+.[0-9]+.[0-9]+" paths-ignore: @@ -68,7 +69,7 @@ jobs: make local-setup - name: Deploy run: | - make docker-build-gateway-controller kind-load-gateway-controller deploy-gateway-controller + make local-deploy kubectl --context kind-mgc-control-plane -n multicluster-gateway-controller-system get deployments/mgc-controller-manager -o yaml | yq .spec.template.spec.containers[0].image kubectl --context kind-mgc-control-plane -n multicluster-gateway-controller-system wait --timeout=300s --for=condition=Available deployment/mgc-controller-manager kubectl --context kind-mgc-control-plane logs --all-containers --ignore-errors deployment/mgc-controller-manager -n multicluster-gateway-controller-system diff --git a/.github/workflows/controller-image.yaml b/.github/workflows/controller-image.yaml index cd3555ff8..59d8a8702 100644 --- a/.github/workflows/controller-image.yaml +++ b/.github/workflows/controller-image.yaml @@ -5,6 +5,7 @@ on: branches: - main - "release-*" + - remove_gateway_prefix tags: - "v[0-9]+.[0-9]+.[0-9]+" @@ -56,7 +57,6 @@ jobs: with: push: true tags: ${{ env.IMG_TAGS }} - target: controller - name: Print Image URL run: | diff --git a/Dockerfile b/Dockerfile index 88d96a5c9..2225660cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ COPY go.sum go.sum RUN go mod download # Copy the go source -COPY cmd/ cmd/ +COPY cmd/main.go cmd/main.go COPY pkg/ pkg/ # Build @@ -20,14 +20,13 @@ COPY pkg/ pkg/ # was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO # the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore, # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform. -FROM builder as controller_builder -RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o controller cmd/gateway_controller/main.go +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details -FROM gcr.io/distroless/static:nonroot as controller +FROM gcr.io/distroless/static:nonroot WORKDIR / -COPY --from=controller_builder /workspace/controller . +COPY --from=builder /workspace/manager . USER 65532:65532 -ENTRYPOINT ["/controller"] \ No newline at end of file +ENTRYPOINT ["/manager"] diff --git a/Makefile b/Makefile index f57298f5b..e766f9c48 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,62 @@ +# VERSION defines the project version for the bundle. +# Update this value when you upgrade the version of your project. +# To re-generate a bundle for another specific version without changing the standard setup, you can: +# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2) +# - use environment variables to overwrite this value (e.g export VERSION=0.0.2) +VERSION ?= 0.0.0 + +ifeq (0.0.0,$(VERSION)) +IMAGE_TAG ?= latest +else +IMAGE_TAG ?= v$(VERSION) +endif -# Image URL to use all building/pushing image targets -TAG ?= latest +# CHANNELS define the bundle channels used in the bundle. +# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable") +# To re-generate a bundle for other specific channels without changing the standard setup, you can: +# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable) +# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable") +ifneq ($(origin CHANNELS), undefined) +BUNDLE_CHANNELS := --channels=$(CHANNELS) +endif + +# DEFAULT_CHANNEL defines the default channel used in the bundle. +# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable") +# To re-generate a bundle for any other default channel without changing the default setup, you can: +# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable) +# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable") +ifneq ($(origin DEFAULT_CHANNEL), undefined) +BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) +endif +BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) + +# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images. +# This variable is used to construct full image tags for bundle and catalog images. +# +# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both +# quay.io/kuadrant/multicluster-gateway-controller-bundle:$VERSION and quay.io/kuadrant/multicluster-gateway-controller-catalog:$VERSION. +IMAGE_TAG_BASE ?= quay.io/kuadrant/multicluster-gateway-controller + +# BUNDLE_IMG defines the image:tag used for the bundle. +# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=/:) +BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:$(IMAGE_TAG) + +# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command +BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) + +# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests +# You can enable this value if you would like to use SHA Based Digests +# To enable set flag to true +USE_IMAGE_DIGESTS ?= false +ifeq ($(USE_IMAGE_DIGESTS), true) + BUNDLE_GEN_FLAGS += --use-image-digests +endif +# Image URL to use all building/pushing image targets +DEFAULT_IMG ?= $(IMAGE_TAG_BASE):$(IMAGE_TAG) +IMG ?= $(DEFAULT_IMG) # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. -ENVTEST_K8S_VERSION = 1.25.0 +ENVTEST_K8S_VERSION = 1.27.1 # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) @@ -12,13 +65,17 @@ else GOBIN=$(shell go env GOBIN) endif +# CONTAINER_TOOL defines the container tool to be used for building images. +# Be aware that the target commands are only tested with Docker which is +# scaffolded by default. However, you might want to replace it to use other +# tools. (i.e. podman) +CONTAINER_TOOL ?= docker + # Setting SHELL to bash allows bash commands to be executed by recipes. # Options are set to exit when a recipe line exits non-zero or a piped command fails. SHELL = /usr/bin/env bash -o pipefail .SHELLFLAGS = -ec -include ./hack/make/*.make - .PHONY: all all: build @@ -47,13 +104,10 @@ clean: ## Clean up temporary files. -rm -rf ./tmp -rm -rf ./config/**/charts -.PHONY: gateway-manifests +.PHONY: manifests gateway-manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. $(CONTROLLER_GEN) rbac:roleName=manager-role paths="./pkg/controllers/gateway" output:rbac:artifacts:config=config/rbac -.PHONY: manifests -manifests: gateway-manifests - .PHONY: generate generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." @@ -74,6 +128,9 @@ lint: ## Run golangci-lint against code. imports: openshift-goimports ## Run openshift goimports against code. $(OPENSHIFT_GOIMPORTS) -m github.com/Kuadrant/multicluster-gateway-controller -i github.com/kuadrant +.PHONY: test +test: test-unit test-integration ## Run tests. + .PHONY: test-unit test-unit: manifests generate fmt vet envtest ## Run unit tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $(shell find ./pkg/_internal -mindepth 1 -type d) ./... -tags=unit -coverprofile cover-unit.out @@ -82,9 +139,6 @@ test-unit: manifests generate fmt vet envtest ## Run unit tests. test-integration: ginkgo manifests generate fmt vet envtest ## Run integration tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GINKGO) -tags=integration -v --focus "${FOCUS}" ./test/gateway_integration -.PHONY: test -test: test-unit test-integration ## Run tests. - .PHONY: test-e2e test-e2e: ginkgo $(GINKGO) -tags=e2e -v ./test/e2e @@ -111,10 +165,50 @@ local-cleanup: kind ## Cleanup kind clusters created by local-setup local-cleanup-mgc: ## Cleanup MGC from kind clusters ./hack/local-cleanup-mgc.sh +.PHONY: local-deploy +local-deploy: IMG := $(IMAGE_TAG_BASE):dev +local-deploy: docker-build kind-load-image deploy ## Deploy the operator into local kind cluster from the current code + +##@ Build + .PHONY: build -build: build-gateway-controller ## Build all binaries. +build: manifests generate fmt vet ## Build manager binary. + go build -o bin/manager cmd/main.go + +.PHONY: run +run: manifests generate fmt vet ## Run a controller from your host. + go run ./cmd/main.go + +# If you wish built 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. +# More info: https://docs.docker.com/develop/develop-images/build_enhancements/ +.PHONY: docker-build +docker-build: ## Build docker image with the manager. + $(CONTAINER_TOOL) build -t ${IMG} . + +.PHONY: docker-push +docker-push: ## Push docker image with the manager. + $(CONTAINER_TOOL) 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: +# - 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=> then 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 + - $(CONTAINER_TOOL) buildx create --name project-v3-builder + $(CONTAINER_TOOL) buildx use project-v3-builder + - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . + - $(CONTAINER_TOOL) buildx rm project-v3-builder + rm Dockerfile.cross ##@ Deployment + ifndef ignore-not-found ignore-not-found = false endif @@ -124,6 +218,95 @@ endif deploy-sample-applicationset: kubectl apply -f ./samples/argocd-applicationset/echo-applicationset.yaml +.PHONY: deploy +deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. + cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} + $(KUSTOMIZE) build config/deploy/local | kubectl apply -f - + @if [ "$(METRICS)" = "true" ]; then\ + $(KUSTOMIZE) build config/prometheus | kubectl apply -f -;\ + fi + +.PHONY: undeploy +undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. + @if [ "$(METRICS)" = "true" ]; then\ + $(KUSTOMIZE) build config/prometheus | kubectl delete --ignore-not-found=$(ignore-not-found) -f -;\ + fi + $(KUSTOMIZE) build config/deploy/local | kubectl delete --ignore-not-found=$(ignore-not-found) -f - + +##@ OLM + +.PHONY: bundle +bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files. + $(OPERATOR_SDK) generate kustomize manifests -q + cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) + $(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS) + $(OPERATOR_SDK) bundle validate ./bundle + $(MAKE) bundle-ignore-createdAt + +# Since operator-sdk 1.26.0, `make bundle` changes the `createdAt` field from the bundle +# even if it is patched: +# https://github.com/operator-framework/operator-sdk/pull/6136 +# This code checks if only the createdAt field. If is the only change, it is ignored. +# Else, it will do nothing. +# https://github.com/operator-framework/operator-sdk/issues/6285#issuecomment-1415350333 +# https://github.com/operator-framework/operator-sdk/issues/6285#issuecomment-1532150678 +.PHONY: bundle-ignore-createdAt +bundle-ignore-createdAt: + git diff --quiet -I'^ createdAt: ' ./bundle && git checkout ./bundle || true + +.PHONY: bundle-build +bundle-build: ## Build the bundle image. + docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . + +.PHONY: bundle-push +bundle-push: ## Push the bundle image. + $(MAKE) docker-push IMG=$(BUNDLE_IMG) + +.PHONY: opm +OPM = $(LOCALBIN)/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.23.0/$${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) + +# 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 + +# 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. + mkdir -p tmp/catalog + cd tmp/catalog && $(OPM) index add --container-tool docker --mode semver --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) --generate + cd tmp/catalog && docker build -t $(CATALOG_IMG) -f index.Dockerfile . + +# Push the catalog image. +.PHONY: catalog-push +catalog-push: ## Push a catalog image. + $(MAKE) docker-push IMG=$(CATALOG_IMG) + +##@ Misc + .PHONY: thanos-manifests thanos-manifests: ./hack/thanos/thanos_build.sh ./hack/thanos/thanos.jsonnet ./hack/thanos/thanos_build.sh @@ -144,4 +327,12 @@ clear-dev-tls: .PHONY: skupper-setup skupper-setup: - ./hack/skupper/skupper-setup.sh \ No newline at end of file + ./hack/skupper/skupper-setup.sh + +KIND_CLUSTER_NAME ?= mgc-control-plane +.PHONY: kind-load-image +kind-load-image: kind ## Load image to kind cluster. + $(KIND) load docker-image $(IMG) --name $(KIND_CLUSTER_NAME) + +# Include last to avoid changing MAKEFILE_LIST used above +include ./hack/make/*.make diff --git a/README.md b/README.md index 3cee9d8d0..b8ce5c0f7 100644 --- a/README.md +++ b/README.md @@ -40,20 +40,15 @@ When deploying the multicluster gateway controller using the make targets, the f ```sh make local-setup MGC_WORKLOAD_CLUSTERS_COUNT= ``` -1. Build the controller image and load it into the control plane +1. Build the controller image, load it into the control plane and deploy ```sh kubectl config use-context kind-mgc-control-plane - make kind-load-gateway-controller - ``` - -1. Deploy the controller(s) to the control plane cluster - ```sh - make deploy-gateway-controller + make local-deploy ``` 1. (Optional) View the logs of the deployed controller ```sh - kubectl logs -f $(kubectl get pods -n multi-cluster-gateways | grep "mgc-" | awk '{print $1}') -n multi-cluster-gateways + kubectl logs -f deployment/mgc-controller-manager -n multicluster-gateway-controller-system ``` ## 2. Running the controller locally: @@ -68,30 +63,9 @@ When deploying the multicluster gateway controller using the make targets, the f 1. Run the controller locally: ```sh kubectl config use-context kind-mgc-control-plane - make build-gateway-controller run-gateway-controller - ``` - -## 3. Running the agent in the cluster: -1. Build the agent image and load it into the workload cluster - ```sh - kubectl config use-context kind-mgc-workload-1 - make kind-load-agent + make build run ``` -1. Deploy the agent to the workload cluster - ```sh - make deploy-agent - ``` - -## 4. Running the agent locally -1. Target the workload cluster you wish to run on: -```sh -export KUBECONFIG=./tmp/kubeconfigs/mgc-workload-1.kubeconfig -``` -1. Run the agent locally: -```sh -make build-agent run-agent -``` ## 5. Clean up local environment In any terminal window target control plane cluster by: ```bash diff --git a/bundle/manifests/multicluster-gateway-controller.clusterserviceversion.yaml b/bundle/manifests/multicluster-gateway-controller.clusterserviceversion.yaml index 19e8a48c1..156eb7468 100644 --- a/bundle/manifests/multicluster-gateway-controller.clusterserviceversion.yaml +++ b/bundle/manifests/multicluster-gateway-controller.clusterserviceversion.yaml @@ -300,8 +300,8 @@ spec: - --metrics-bind-address=0.0.0.0:8080 - --leader-elect command: - - /controller - image: quay.io/kuadrant/multicluster-gateway-controller:main + - /manager + image: quay.io/kuadrant/multicluster-gateway-controller:latest imagePullPolicy: Always livenessProbe: httpGet: diff --git a/cmd/gateway_controller/main.go b/cmd/main.go similarity index 97% rename from cmd/gateway_controller/main.go rename to cmd/main.go index 5c56440fc..658adc9af 100644 --- a/cmd/gateway_controller/main.go +++ b/cmd/main.go @@ -40,8 +40,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/webhook" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" - "github.com/Kuadrant/multicluster-gateway-controller/cmd/gateway_controller/ocm" "github.com/Kuadrant/multicluster-gateway-controller/pkg/controllers/gateway" + ocmaddon "github.com/Kuadrant/multicluster-gateway-controller/pkg/ocm/addon" "github.com/Kuadrant/multicluster-gateway-controller/pkg/placement" "github.com/Kuadrant/multicluster-gateway-controller/pkg/policysync" //+kubebuilder:scaffold:imports @@ -141,7 +141,7 @@ func main() { } // add addon-manager - if err = mgr.Add(ocm.AddonRunnable{}); err != nil { + if err = mgr.Add(ocmaddon.AddonRunnable{}); err != nil { setupLog.Error(err, "unable to add addon manager runnable") os.Exit(1) } diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index cf5e1b32e..1a3e47742 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,7 +1,9 @@ resources: - manager.yaml +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization images: - name: controller newName: quay.io/kuadrant/multicluster-gateway-controller - newTag: main + newTag: latest diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 13fdb76e2..504b437b2 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -34,7 +34,7 @@ spec: runAsNonRoot: true containers: - command: - - /controller + - /manager args: - --leader-elect image: controller:latest diff --git a/docs/experimental/submariner-poc-2-gateways-resiliency-walkthrough.md b/docs/experimental/submariner-poc-2-gateways-resiliency-walkthrough.md index eeb5fe3aa..da937c335 100644 --- a/docs/experimental/submariner-poc-2-gateways-resiliency-walkthrough.md +++ b/docs/experimental/submariner-poc-2-gateways-resiliency-walkthrough.md @@ -107,7 +107,7 @@ kubectl create -f hack/ocm/gatewayclass.yaml In `T2` run the following to start the Gateway Controller: ```bash -make build-gateway-controller run-gateway-controller +make build run ``` ### Create a Gateway diff --git a/docs/experimental/submariner-poc-hub-gateway-walkthrough.md b/docs/experimental/submariner-poc-hub-gateway-walkthrough.md index 78801ccff..d7a754a40 100644 --- a/docs/experimental/submariner-poc-hub-gateway-walkthrough.md +++ b/docs/experimental/submariner-poc-hub-gateway-walkthrough.md @@ -111,7 +111,7 @@ In `T2` run the following to start the Gateway Controller: ```bash kind export kubeconfig --name=mgc-control-plane --kubeconfig=$(pwd)/local/kube/control-plane.yaml && export KUBECONFIG=$(pwd)/local/kube/control-plane.yaml -make build-gateway-controller install run-gateway-controller +make build install run ``` ### Create a Gateway diff --git a/hack/make/addon.make b/hack/make/addon.make deleted file mode 100644 index e69de29bb..000000000 diff --git a/hack/make/bundle.make b/hack/make/bundle.make deleted file mode 100644 index cec66b8f2..000000000 --- a/hack/make/bundle.make +++ /dev/null @@ -1,135 +0,0 @@ - -# VERSION defines the project version for the bundle. -# Update this value when you upgrade the version of your project. -# To re-generate a bundle for another specific version without changing the standard setup, you can: -# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2) -# - use environment variables to overwrite this value (e.g export VERSION=0.0.2) -VERSION ?= 0.0.0 - -# REGISTRY defines the image registry name for the bundle and catalog -# Update this value to what image registry -REGISTRY = quay.io - -# ORG defines the image registy organization name for the bundle and catalog image repos -ORG ?= kuadrant - -#IMAGE_TAG_BASE defines the image registry -IMAGE_TAG_BASE ?= $(REGISTRY)/$(ORG)/multicluster-gateway-controller - - -ifeq (0.0.0,$(VERSION)) -IMAGE_TAG ?= latest -else -IMAGE_TAG ?= v$(VERSION) -endif - -# Image URL to use all building/pushing image targets -IMG = ${IMAGE_TAG_BASE}:${IMAGE_TAG} - -# BUNDLE_IMG defines the image:tag used for the bundle. -# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=/:) -BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:$(IMAGE_TAG) - -# CHANNELS define the bundle channels used in the bundle. -# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable") -# To re-generate a bundle for other specific channels without changing the standard setup, you can: -# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable) -# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable") -ifneq ($(origin DEFAULT_CHANNEL), undefined) -BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) -endif -BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) - -# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command -BUNDLE_GEN_FLAGS ?= -q --overwrite --version --crds $(VERSION) $(BUNDLE_METADATA_OPTS) - -## Generate bundle manifests and metadata, then validate generated files. -.PHONY: bundle -bundle: manifests operator-sdk kustomize - - $(OPERATOR_SDK) generate kustomize manifests -q --apis-dir pkg/apis/v1alpha1 - $(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q $(BUNDLE_METADATA_OPTS) - $(OPERATOR_SDK) bundle validate ./bundle - $(MAKE) bundle-ignore-createdAt - -# Since operator-sdk 1.26.0, `make bundle` changes the `createdAt` field from the bundle -# even if it is patched: -# https://github.com/operator-framework/operator-sdk/pull/6136 -# This code checks if only the createdAt field. If is the only change, it is ignored. -# Else, it will do nothing. -# https://github.com/operator-framework/operator-sdk/issues/6285#issuecomment-1415350333 -# https://github.com/operator-framework/operator-sdk/issues/6285#issuecomment-1532150678 -.PHONY: bundle-ignore-createdAt -bundle-ignore-createdAt: - git diff --quiet -I'^ createdAt: ' ./bundle && git checkout ./bundle || true - -## Build the bundle image. -.PHONY: bundle-build -bundle-build: - docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . - -## Push the bundle image. -.PHONY: bundle-push -bundle-push: - docker push $(BUNDLE_IMG) - -.PHONY: bundle-build-push -bundle-build-push: bundle bundle-build bundle-push - -## Download opm locally if necessary. -.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.23.0/$${OS}-$${ARCH}-opm ;\ - chmod +x $(OPM) ;\ - } -else -OPM = $(shell which opm) -endif -endif - - -# 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 - -# 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_IMG) $(FROM_INDEX_OPT) - -# Push the catalog image. -.PHONY: catalog-push -catalog-push: ## Push a catalog image. - docker push $(CATALOG_IMG) - -# Build the docker image -.PHONY: docker-build -docker-build: - docker build --target controller . -t ${IMAGE_TAG_BASE:}${IMG} - -# Login to the registry -.PHONY: docker-login -docker-login: - echo "$(QUAY_TOKEN)" | docker --config="${DOCKER_CONFIG}" login -u "${QUAY_USER}" quay.io --password-stdin - -# Push the docker image -.PHONY: docker-push -docker-push: - docker push ${IMAGE_TAG_BASE:}${IMG} - -.PHONY: catalog-build-push -catalog-build-push: catalog-build catalog-push - diff --git a/hack/make/gateway_controller.make b/hack/make/gateway_controller.make deleted file mode 100644 index 057ed1c6f..000000000 --- a/hack/make/gateway_controller.make +++ /dev/null @@ -1,54 +0,0 @@ -##@ Controller - -CONTROLLER_IMG ?= controller:$(TAG) -LOG_LEVEL ?= 3 - -.PHONY: build-gateway-controller -build-gateway-controller: manifests generate fmt vet ## Build controller binary. - go build -o bin/controller ./cmd/gateway_controller/main.go - -.PHONY: run-gateway-controller -run-gateway-controller: manifests generate fmt vet - go run ./cmd/gateway_controller/main.go \ - --metrics-bind-address=:8080 \ - --health-probe-bind-address=:8081 \ - --zap-log-level=$(LOG_LEVEL) - -.PHONY: docker-build-gateway-controller -docker-build-gateway-controller: ## Build docker image with the controller. - docker build --target controller -t ${CONTROLLER_IMG} . - docker image prune -f --filter label=stage=mgc-builder - -.PHONY: kind-load-gateway-controller -kind-load-gateway-controller: docker-build-gateway-controller - kind load docker-image ${CONTROLLER_IMG} --name mgc-control-plane --nodes mgc-control-plane-control-plane - -.PHONY: docker-push-gateway-controller -docker-push-gateway-controller: ## Push docker image with the controller. - docker push ${CONTROLLER_IMG} - -.PHONY: update-gateway-controller-image -update-gateway-controller-image: kustomize ## Update gateway controller image to CONTROLLER_IMG. - cd config/manager && $(KUSTOMIZE) edit set image controller=${CONTROLLER_IMG} - -.PHONY: deploy-gateway-controller -deploy-gateway-controller: manifests kustomize update-gateway-controller-image ## Deploy controller to the K8s cluster specified in ~/.kube/config. - $(KUSTOMIZE) --load-restrictor LoadRestrictionsNone build config/deploy/local | kubectl apply -f - - @if [ "$(METRICS)" = "true" ]; then\ - $(KUSTOMIZE) build config/prometheus | kubectl apply -f -;\ - fi - -.PHONY: undeploy-gateway-controller -undeploy-gateway-controller: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. - @if [ $(METRICS) = "true" ]; then\ - $(KUSTOMIZE) build config/prometheus | kubectl delete --ignore-not-found=$(ignore-not-found) -f -;\ - fi - $(KUSTOMIZE) --load-restrictor LoadRestrictionsNone build config/deploy/local | kubectl delete --ignore-not-found=$(ignore-not-found) -f - - -.PHONY: restart-gateway-controller -restart-gateway-controller: - kubectl rollout restart deployment mgc-controller-manager -n multicluster-gateway-controller-system - -.PHONY: tail-gateway-controller-logs -tail-gateway-controller-logs: - kubectl logs -f deployment/mgc-controller-manager -n multicluster-gateway-controller-system \ No newline at end of file diff --git a/cmd/gateway_controller/ocm/addon-manager.go b/pkg/ocm/addon/addon-manager.go similarity index 99% rename from cmd/gateway_controller/ocm/addon-manager.go rename to pkg/ocm/addon/addon-manager.go index 5560da4a7..7100f3cdf 100644 --- a/cmd/gateway_controller/ocm/addon-manager.go +++ b/pkg/ocm/addon/addon-manager.go @@ -1,4 +1,4 @@ -package ocm +package addon import ( "context" diff --git a/cmd/gateway_controller/ocm/manifests/cluster-role-binding.yaml b/pkg/ocm/addon/manifests/cluster-role-binding.yaml similarity index 100% rename from cmd/gateway_controller/ocm/manifests/cluster-role-binding.yaml rename to pkg/ocm/addon/manifests/cluster-role-binding.yaml diff --git a/cmd/gateway_controller/ocm/manifests/cluster-role.yaml b/pkg/ocm/addon/manifests/cluster-role.yaml similarity index 100% rename from cmd/gateway_controller/ocm/manifests/cluster-role.yaml rename to pkg/ocm/addon/manifests/cluster-role.yaml diff --git a/cmd/gateway_controller/ocm/manifests/kuadrant-namespace.yaml b/pkg/ocm/addon/manifests/kuadrant-namespace.yaml similarity index 100% rename from cmd/gateway_controller/ocm/manifests/kuadrant-namespace.yaml rename to pkg/ocm/addon/manifests/kuadrant-namespace.yaml diff --git a/cmd/gateway_controller/ocm/manifests/kuadrant.yaml b/pkg/ocm/addon/manifests/kuadrant.yaml similarity index 100% rename from cmd/gateway_controller/ocm/manifests/kuadrant.yaml rename to pkg/ocm/addon/manifests/kuadrant.yaml diff --git a/cmd/gateway_controller/ocm/manifests/operator-group.yaml b/pkg/ocm/addon/manifests/operator-group.yaml similarity index 100% rename from cmd/gateway_controller/ocm/manifests/operator-group.yaml rename to pkg/ocm/addon/manifests/operator-group.yaml diff --git a/cmd/gateway_controller/ocm/manifests/subscription.yaml b/pkg/ocm/addon/manifests/subscription.yaml similarity index 100% rename from cmd/gateway_controller/ocm/manifests/subscription.yaml rename to pkg/ocm/addon/manifests/subscription.yaml