diff --git a/Makefile b/Makefile index dab69a58a..f5b328ecf 100644 --- a/Makefile +++ b/Makefile @@ -24,8 +24,7 @@ install-serverless-latest-release: ## Install serverless from latest release remove-serverless: ## Remove serverless-cr and serverless operator make -C ${OPERATOR_ROOT} remove-serverless undeploy -.PHONY: run -run: create-k3d install-serverless-main ## Create k3d cluster and install serverless from main +.PHONY: run-main +run-main: create-k3d install-serverless-main ## Create k3d cluster and install serverless from main check-var = $(if $(strip $($1)),,$(error "$1" is not defined)) - diff --git a/README.md b/README.md index 08003a5f7..c0bda0691 100644 --- a/README.md +++ b/README.md @@ -53,11 +53,12 @@ kubectl apply -f https://github.com/kyma-project/serverless-manager/releases/lat 2. Build Serverless Operator locally and run it in the k3d cluster. ```bash - make run + make run-main ``` > **NOTE:** To clean up the k3d cluster, use the `make delete-k3d` make target. +> **NOTE:** If you have k3d already running you can use `install-*` target to install Serverless in different flavors. ## Using Serverless Operator diff --git a/components/operator/Makefile b/components/operator/Makefile index b64d3d147..4b10aff1f 100644 --- a/components/operator/Makefile +++ b/components/operator/Makefile @@ -17,6 +17,7 @@ SHELL = /usr/bin/env bash -o pipefail ##@ Development CONFIG_OPERATOR = $(PROJECT_ROOT)/config/operator/base CONFIG_OPERATOR_DEV = $(PROJECT_ROOT)/config/operator/dev +CONFIG_OPERATOR_MAIN = https://github.com/kyma-project/serverless/config/operator/base?ref=main .PHONY: manifests manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. @@ -69,7 +70,7 @@ build-image-operator: ## Build serverless operator from local sources on k3d docker build -t $(OPERATOR_NAME) -f Dockerfile $(PROJECT_ROOT) .PHONY: install-operator-k3d -install-operator-k3d: build-image-operator ## Build and install serverless operator from local sources on k3d +install-operator-k3d: build-image-operator ## Build and replace serverless operator from local sources on k3d $(eval HASH_TAG=$(shell docker images $(OPERATOR_NAME):latest --quiet)) docker tag $(OPERATOR_NAME) $(OPERATOR_NAME):$(HASH_TAG) @@ -88,7 +89,7 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified .PHONY: deploy-main deploy-main: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. kubectl create namespace kyma-system || true - $(KUSTOMIZE) build $(CONFIG_OPERATOR) | kubectl apply -f - + $(KUSTOMIZE) build $(CONFIG_OPERATOR_MAIN) | kubectl apply -f - .PHONY: generate-kustomization-dev @@ -96,11 +97,19 @@ generate-kustomization-dev: cp $(CONFIG_OPERATOR_DEV)/kustomization.yaml.tpl $(CONFIG_OPERATOR_DEV)/kustomization.yaml .PHONY: deploy -deploy: manifests kustomize generate-kustomization-dev ## Deploy controller to the K8s cluster specified in ~/.kube/config with image from IMG env. +deploy: manifests kustomize generate-kustomization-dev ## Deploy operator to the K8s cluster specified in ~/.kube/config with image from IMG env. kubectl create namespace kyma-system || true cd $(CONFIG_OPERATOR_DEV) && $(KUSTOMIZE) edit set image europe-docker.pkg.dev/kyma-project/prod/serverless-operator=${IMG} $(KUSTOMIZE) build $(CONFIG_OPERATOR_DEV) | kubectl apply -f - +.PHONY: deploy-local +deploy-local: build-image-operator ## Deploy operator to the K8s cluster specified in ~/.kube/config with locally build image. + $(eval HASH_TAG=$(shell docker images $(OPERATOR_NAME):latest --quiet)) + docker tag $(OPERATOR_NAME) $(OPERATOR_NAME):$(HASH_TAG) + + $(eval IMG=$(OPERATOR_NAME):$(HASH_TAG)) + k3d image import $(IMG) -c kyma + IMG=$(IMG) make deploy .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. @@ -117,7 +126,7 @@ apply-default-serverless-cr: ## Apply the k3d serverless CR. kubectl apply \ -f ${PROJECT_ROOT}/config/samples/default-serverless-cr.yaml -.PHONY: remove-serverless +.PHONY: remove-default-serverless-cr remove-serverless: ## Remove Serverless CR kubectl delete serverless -n kyma-system default --timeout 2m || (kubectl get serverless -n kyma-system -oyaml && false) diff --git a/components/operator/README.md b/components/operator/README.md new file mode 100644 index 000000000..3e9279cbd --- /dev/null +++ b/components/operator/README.md @@ -0,0 +1,41 @@ +# Function Operator + +The Function Operator is a Kubernetes controller that install Serverless. + +## Prerequisites + +The Function Operator requires the following components to be installed: + +- [Go](https://go.dev/) + +## Development + +### Installing Locally Built Serverless Operator Image on k3d With Serverless +Prerequisite: +- installed Operator on a cluster + +To install `serverless-manager` from local sources on the k3d cluster run: + +```bash +make install-operator-k3d +``` + +This target: + +- builds local image with `serverless-operator` +- tags local the `serverless-operator` image with its hash to be sure the deployment is updated +- uploads local image to k3d +- updates the image in the `serverless-operator` deployment + +### Running/Debugging `serverless-operator` Locally + +To develop the component as a normal binary, set up environment variables. + +### Environment Variables + +#### The Function Operator Uses These Environment Variables: + +| Variable | Description | Default value | +|----------------------------|---------------------------------------------------------------------------------------------------------------------|-----------------| +| **CHART_PATH** | Location of the Serverless chart | `/module-chart` | +| **SERVERLESS_MANAGER_UID** | Unique ID of operator instance. Used to mark created resources to distinguish which version of the Operator created it. | `` | diff --git a/components/serverless/Makefile b/components/serverless/Makefile index 8543bcdc5..a3c5f7411 100644 --- a/components/serverless/Makefile +++ b/components/serverless/Makefile @@ -36,19 +36,19 @@ manifests: kustomize controller-gen ## Render CRDs install: manifests ## Install CRDS into the k8s cluster specified in ~/.kube/config kubectl apply -f ../../config/serverless/templates/crds.yaml -######## function manager -MANAGER_NAME = function-controller +######## function controller +CONTROLLER_NAME = function-controller .PHONY: build-image-function-controller build-image-function-controller: - docker build -t $(MANAGER_NAME) -f $(COMPONENT_ROOT)/deploy/manager/Dockerfile $(PROJECT_ROOT) + docker build -t $(CONTROLLER_NAME) -f $(COMPONENT_ROOT)/deploy/manager/Dockerfile $(PROJECT_ROOT) -install-manager-k3d: build-image-function-controller disable-operator ## Build and install serverless manager from local sources on k3d - $(eval HASH_TAG=$(shell docker images $(MANAGER_NAME):latest --quiet)) - docker tag $(MANAGER_NAME) $(MANAGER_NAME):$(HASH_TAG) +install-controller-k3d: build-image-function-controller disable-operator ## Build and replace serverless manager from local sources on k3d + $(eval HASH_TAG=$(shell docker images $(CONTROLLER_NAME):latest --quiet)) + docker tag $(CONTROLLER_NAME) $(CONTROLLER_NAME):$(HASH_TAG) - k3d image import $(MANAGER_NAME):$(HASH_TAG) -c kyma - kubectl set image deployment serverless-ctrl-mngr -n kyma-system manager=$(MANAGER_NAME):$(HASH_TAG) + k3d image import $(CONTROLLER_NAME):$(HASH_TAG) -c kyma + kubectl set image deployment serverless-ctrl-mngr -n kyma-system manager=$(CONTROLLER_NAME):$(HASH_TAG) ######## function webhook WEBHOOK_NAME = function-webhook @@ -57,7 +57,7 @@ WEBHOOK_NAME = function-webhook build-image-function-webhook: docker build -t $(WEBHOOK_NAME) -f $(COMPONENT_ROOT)/deploy/webhook/Dockerfile $(PROJECT_ROOT) -install-webhook-k3d: build-image-function-webhook disable-operator ## Build and install serverless webhook from local sources on k3d +install-webhook-k3d: build-image-function-webhook disable-operator ## Build and replace serverless webhook from local sources on k3d $(eval HASH_TAG=$(shell docker images $(WEBHOOK_NAME):latest --quiet)) docker tag $(WEBHOOK_NAME) $(WEBHOOK_NAME):$(HASH_TAG) diff --git a/components/serverless/README.md b/components/serverless/README.md index b34dc33b4..511715dfa 100644 --- a/components/serverless/README.md +++ b/components/serverless/README.md @@ -5,9 +5,7 @@ The Function Controller is a Kubernetes controller that enables Kyma to manage F ## Prerequisites The Function Controller requires the following components to be installed: - -- [Istio](https://github.com/istio/istio/releases) (v1.4.3) -- [Docker registry](https://github.com/docker/distribution) (v2.7.1) +- [Go](https://go.dev/) ## Development @@ -16,11 +14,25 @@ To develop the Function Controller, you need: - [controller-gen](https://github.com/kubernetes-sigs/controller-tools/releases/tag/v0.6.2) (v0.6.2) - [kustomize](https://github.com/kubernetes-sigs/kustomize/releases/tag/kustomize%2Fv4.5.7) (v4.5.7) -To develop the component, use the formulae declared in the [Makefile](./Makefile). +### Installing Locally Built Serverless Controller Image on k3d With Serverless +Prerequisite: +- installed Serverless on a cluster + +To install `serverless-controller` from local sources on the k3d cluster run: +```bash +make install-controller-k3d +``` -To run the manager and set up envs correctly, source [controller.env](./hack/controller.env). -You can customize the configuration by editing files in [hack](./hack) dir. +This target: +- scales down the Serverless Operator to prevent reverting further changes made to the `serverless-controller` deployment +- builds the local image with the `serverless-controller` image +- tags the local `serverless-controller` image with its hash to be sure the deployment is updated +- uploads the local image to k3d +- updates the image in the `serverless-ctrl-mngr` deployment +### Running/Debugging serverless-manager Locally +To develop the component as normal binary, set up envs correctly, example envs to use [controller.env](./hack/controller.env). +You can customize the configuration by editing files in [hack](./hack) dir. ### Environment Variables diff --git a/hack/makefile-strategy.md b/hack/makefile-strategy.md index 4560b4d02..943f3343b 100644 --- a/hack/makefile-strategy.md +++ b/hack/makefile-strategy.md @@ -9,7 +9,7 @@ Pros of the architecture: * extensibility ## Dependencies description -* `Makefile` - The main makefile that allows for installing and running the Serverless Operator. It's a high-level target to run the module without knowing its internals. It's the first contact point for the Serverless module users. +* `Makefile` - The main makefile that allows for installing and running the Serverless. It's a high-level target to run the module without knowing its internals. It's the first contact point for the Serverless module users. * `hack/Makefile` - High-level API that contains all targets that may be used by any CI/CD system. It has dependencies on the `hack/*.mk` makefiles. * `hack/*.mk` - Contains common targets that may be used by other makefiles (they are included and shouldn't be run directly). Targets are grouped by functionality. They should contain helpers' targets. * `components/operator/Makefile` - Contains all basic operations on Serverless Operator like builds, tests, etc., used during development. It's also used by `Makefile`. @@ -37,4 +37,4 @@ include ${PROJECT_ROOT}/hack/help.mk .PHONY: run run: create-k3d install-serverless-main ## Create k3d cluster and install serverless from main -``` \ No newline at end of file +```