Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve makefiles #845

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 13 additions & 4 deletions components/operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand All @@ -88,19 +89,27 @@ 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
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.
Expand All @@ -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)

Expand Down
41 changes: 41 additions & 0 deletions components/operator/README.md
Original file line number Diff line number Diff line change
@@ -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
anoipm marked this conversation as resolved.
Show resolved Hide resolved
```

This target:

dbadura marked this conversation as resolved.
Show resolved Hide resolved
- 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. | `` |
18 changes: 9 additions & 9 deletions components/serverless/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
24 changes: 18 additions & 6 deletions components/serverless/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
- <!-- markdown-link-check-disable-line -->[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
anoipm marked this conversation as resolved.
Show resolved Hide resolved
```

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

Expand Down
4 changes: 2 additions & 2 deletions hack/makefile-strategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you remove Operator? IMO main makefile run Serverless Operator.

Copy link
Contributor Author

@dbadura dbadura Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to stress it that this makefile works with serverless. Sure under the hood it's installed by operator, but this is the implementation detail.

* `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`.
Expand Down Expand Up @@ -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
```
```
Loading