From db858c777ea564aac9c22f9e86ddf08a5cc15a8b Mon Sep 17 00:00:00 2001 From: Damian Badura Date: Thu, 25 Apr 2024 12:23:51 +0200 Subject: [PATCH 1/4] ad real local target --- .dockerignore | 3 +++ Makefile | 2 +- .../docker-registry/templates/deployment.yaml | 4 ++-- config/serverless/templates/deployment.yaml | 2 +- config/serverless/values.yaml | 2 ++ hack/build_all.sh | 4 ++-- hack/docker-compose.yaml | 12 ++++++------ hack/k3d.mk | 8 ++++---- hack/replace_serverless_chart_images.sh | 16 +++++++++++----- 9 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 .dockerignore mode change 100644 => 100755 Makefile mode change 100644 => 100755 hack/docker-compose.yaml mode change 100644 => 100755 hack/k3d.mk diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..04dc2e0d4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git +.idea +bin diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index 20ca199c1..08068e544 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ install-serverless-local-sources: ## Install serverless from local sources IMG_VERSION=${IMG_VERSION} ./hack/build_all.sh $(eval IMG=europe-docker.pkg.dev/kyma-project/dev/serverless-operator:${IMG_VERSION}) - IMG_DIRECTORY="dev" IMG_VERSION=${IMG_VERSION} IMG=${IMG} make -C ${OPERATOR_ROOT} docker-build-local + IMG_DIRECTORY="kyma-project" IMG_VERSION=${IMG_VERSION} IMG=${IMG} make -C ${OPERATOR_ROOT} docker-build-local k3d image import "${IMG}" -c kyma IMG=${IMG} make install-serverless-custom-operator diff --git a/config/serverless/charts/docker-registry/templates/deployment.yaml b/config/serverless/charts/docker-registry/templates/deployment.yaml index 2ee14955f..2a1410efe 100644 --- a/config/serverless/charts/docker-registry/templates/deployment.yaml +++ b/config/serverless/charts/docker-registry/templates/deployment.yaml @@ -47,7 +47,7 @@ spec: hostIPC: false # Optional. The default is false if the entry is not there. initContainers: - name: generate-htpasswd - image: "{{ include "imageurl" (dict "reg" .Values.global.containerRegistry "img" .Values.global.images.registry) }}" + image: "{{ include "imageurl" (dict "reg" .Values.global.tpiContainerRegistry "img" .Values.global.images.registry) }}" {{- if .Values.initContainers.securityContext }} securityContext: {{- include "tplValue" ( dict "value" .Values.initContainers.securityContext "context" . ) | nindent 12 }} @@ -75,7 +75,7 @@ spec: containers: - name: {{ .Chart.Name }} - image: "{{ include "imageurl" (dict "reg" .Values.global.containerRegistry "img" .Values.global.images.registry) }}" + image: "{{ include "imageurl" (dict "reg" .Values.global.tpiContainerRegistry "img" .Values.global.images.registry) }}" imagePullPolicy: {{ .Values.image.pullPolicy }} {{- if .Values.containers.securityContext }} securityContext: diff --git a/config/serverless/templates/deployment.yaml b/config/serverless/templates/deployment.yaml index a505f82df..7e318ef14 100644 --- a/config/serverless/templates/deployment.yaml +++ b/config/serverless/templates/deployment.yaml @@ -140,7 +140,7 @@ spec: - name: APP_FUNCTION_BUILD_EXECUTOR_ARGS value: "{{.Values.containers.manager.configuration.data.functionBuildExecutorArgs }}" - name: APP_FUNCTION_BUILD_EXECUTOR_IMAGE - value: "{{ include "imageurl" (dict "reg" .Values.global.containerRegistry "img" .Values.global.images.kaniko_executor) }}" + value: "{{ include "imageurl" (dict "reg" .Values.global.tpiContainerRegistry "img" .Values.global.images.kaniko_executor) }}" - name: APP_FUNCTION_TARGET_CPU_UTILIZATION_PERCENTAGE value: "{{.Values.containers.manager.configuration.data.targetCPUUtilizationPercentage }}" - name: APP_FUNCTION_BUILD_REPO_FETCHER_IMAGE diff --git a/config/serverless/values.yaml b/config/serverless/values.yaml index 384a6e9f1..968ca4600 100644 --- a/config/serverless/values.yaml +++ b/config/serverless/values.yaml @@ -69,6 +69,8 @@ global: domainName: containerRegistry: path: europe-docker.pkg.dev/kyma-project + tpiContainerRegistry: + path: europe-docker.pkg.dev/kyma-project images: function_controller: name: "function-controller" diff --git a/hack/build_all.sh b/hack/build_all.sh index 3a0f5c92b..99172ceb8 100755 --- a/hack/build_all.sh +++ b/hack/build_all.sh @@ -6,10 +6,10 @@ echo "New tag: $IMG_VERSION" (cd "${HACK_DIR}" && pwd && docker compose build) for i in $(yq '.services[].image' ${HACK_DIR}/docker-compose.yaml); do - IMAGE_NAME=$(echo "${i}" | cut -d ":" -f 1) + IMAGE_NAME=$(echo "${i}" | cut -d ":" -f 1,2) NEW_IMAGE_NAME="${IMAGE_NAME}:${IMG_VERSION}" docker tag "${i}" "${NEW_IMAGE_NAME}" set -x - k3d image import "${NEW_IMAGE_NAME}" -c kyma + docker push "${NEW_IMAGE_NAME}" set +x done diff --git a/hack/docker-compose.yaml b/hack/docker-compose.yaml old mode 100644 new mode 100755 index 367fb6630..d4d1d15a1 --- a/hack/docker-compose.yaml +++ b/hack/docker-compose.yaml @@ -1,38 +1,38 @@ services: # serverless function_controller: - image: europe-docker.pkg.dev/kyma-project/dev/function-controller:local + image: k3d-kyma-registry.localhost:5000/kyma-project/function-controller:local platform: "linux/amd64" build: context: ../ dockerfile: components/serverless/deploy/manager/Dockerfile function_build_init: - image: europe-docker.pkg.dev/kyma-project/dev/function-build-init:local + image: k3d-kyma-registry.localhost:5000/kyma-project/function-build-init:local platform: "linux/amd64" build: context: ../ dockerfile: components/serverless/deploy/jobinit/Dockerfile # runtimes function_runtime_nodejs18: - image: europe-docker.pkg.dev/kyma-project/dev/function-runtime-nodejs18:local + image: k3d-kyma-registry.localhost:5000/kyma-project/function-runtime-nodejs18:local platform: "linux/amd64" build: context: ../components/runtimes/nodejs dockerfile: nodejs18/Dockerfile function_runtime_nodejs20: - image: europe-docker.pkg.dev/kyma-project/dev/function-runtime-nodejs20:local + image: k3d-kyma-registry.localhost:5000/kyma-project/function-runtime-nodejs20:local platform: "linux/amd64" build: context: ../components/runtimes/nodejs dockerfile: nodejs20/Dockerfile function_runtime_python39: - image: europe-docker.pkg.dev/kyma-project/dev/function-runtime-python39:local + image: k3d-kyma-registry.localhost:5000/kyma-project/function-runtime-python39:local platform: "linux/amd64" build: context: ../components/runtimes/python dockerfile: python39/Dockerfile function_runtime_python312: - image: europe-docker.pkg.dev/kyma-project/dev/function-runtime-python312:local + image: k3d-kyma-registry.localhost:5000/kyma-project/function-runtime-python312:local platform: "linux/amd64" build: context: ../components/runtimes/python diff --git a/hack/k3d.mk b/hack/k3d.mk old mode 100644 new mode 100755 index 7eab3ad02..eaec9da47 --- a/hack/k3d.mk +++ b/hack/k3d.mk @@ -1,17 +1,17 @@ CLUSTER_NAME ?= kyma REGISTRY_PORT ?= 5001 -REGISTRY_NAME ?= ${CLUSTER_NAME}-registry +REGISTRY_NAME ?= ${CLUSTER_NAME}-registry.localhost ifndef PROJECT_ROOT $(error PROJECT_ROOT is undefined) endif -include $(PROJECT_ROOT)/hack/tools.mk ##@ K3D .PHONY: create-k3d -create-k3d: kyma ## Create k3d with kyma CRDs. - ${KYMA} provision k3d --registry-port ${REGISTRY_PORT} --name ${CLUSTER_NAME} --ci -p 6080:8080@loadbalancer -p 6433:8433@loadbalancer +create-k3d: delete-k3d ## Delete old k3d registry and cluster. Create preconfigured k3d with registry + k3d registry create ${REGISTRY_NAME} --port 5000 + k3d cluster create ${CLUSTER_NAME} --registry-use "k3d-${REGISTRY_NAME}:5000" kubectl create namespace kyma-system .PHONY: delete-k3d diff --git a/hack/replace_serverless_chart_images.sh b/hack/replace_serverless_chart_images.sh index 73bad3932..5f8eefdc7 100755 --- a/hack/replace_serverless_chart_images.sh +++ b/hack/replace_serverless_chart_images.sh @@ -2,6 +2,7 @@ # if you only need replace images with version set to "main" specify "main-only" argument REPLACE_SCOPE=$1 +VALUES_FILE=${PROJECT_ROOT}/config/serverless/values.yaml REQUIRED_ENV_VARIABLES=('IMG_DIRECTORY' 'IMG_VERSION' 'PROJECT_ROOT') for VAR in "${REQUIRED_ENV_VARIABLES[@]}"; do @@ -16,11 +17,16 @@ if [[ ${REPLACE_SCOPE} == "main-only" ]]; then MAIN_ONLY_SELECTOR="| select(.version == \"main\")" fi -IMAGES_SELECTOR=".global.images[] | select(key == \"function_*\") ${MAIN_ONLY_SELECTOR}" -VALUES_FILE=${PROJECT_ROOT}/config/serverless/values.yaml -yq -i "(${IMAGES_SELECTOR} | .directory) = \"${IMG_DIRECTORY}\"" ${VALUES_FILE} -yq -i "(${IMAGES_SELECTOR} | .version) = \"${IMG_VERSION}\"" ${VALUES_FILE} +if [[ ${PURPOSE} == "local" ]]; then + echo "Changing container registry" + yq -i '.global.containerRegistry.path="k3d-kyma-registry.localhost:5000"' "${VALUES_FILE}" +fi + +IMAGES_SELECTOR=".global.images[] | select(key == \"function_*\") ${MAIN_ONLY_SELECTOR}" +yq --inplace "(${IMAGES_SELECTOR} | .directory) = \"${IMG_DIRECTORY}\"" ${VALUES_FILE} +yq --inplace "(${IMAGES_SELECTOR} | .version) = \"${IMG_VERSION}\"" ${VALUES_FILE} echo "==== Local Changes ====" -yq '.global.images' ${VALUES_FILE} +yq '.global.images' "${VALUES_FILE}" +yq '.global.containerRegistry' "${VALUES_FILE}" echo "==== End of Local Changes ====" From c7e86c4e4ef03899f8abd4aeb0f159b4a6dbd4fc Mon Sep 17 00:00:00 2001 From: Damian Badura Date: Fri, 26 Apr 2024 12:31:19 +0200 Subject: [PATCH 2/4] add more docs --- Makefile | 2 +- README.md | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 08068e544..c3927b5f1 100755 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ install-serverless-latest-release:## Install serverless from latest release make -C ${OPERATOR_ROOT} check-serverless-installation .PHONY: install-serverless-local-sources -install-serverless-local-sources: ## Install serverless from local sources +install-serverless-local-sources: ## Install serverless from local sources. Tip: On some OSes it won't work without preconfiguration. See Readme.md rroubleshooting section. $(eval IMG_VERSION=local-$(shell date +'%Y%m%d-%H%M%S')) IMG_VERSION=${IMG_VERSION} ./hack/build_all.sh diff --git a/README.md b/README.md index e4d4f3e36..21ea297f1 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ kubectl apply -f https://github.com/kyma-project/serverless/releases/latest/down - [Docker](https://www.docker.com/) - [kubectl](https://kubernetes.io/docs/tasks/tools/) - [Kubebuilder](https://book.kubebuilder.io/) +- [yq](https://mikefarah.gitbook.io/yq) ## Installation in the k3d Cluster Using Make Targets @@ -50,7 +51,7 @@ kubectl apply -f https://github.com/kyma-project/serverless/releases/latest/down git clone https://github.com/kyma-project/serverless.git && cd serverless/ ``` -2. Build Serverless Operator locally and run it in the k3d cluster. +2. Run serverless from main with new k3d cluster ```bash make run-main @@ -58,7 +59,7 @@ kubectl apply -f https://github.com/kyma-project/serverless/releases/latest/down > **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. +> **NOTE:** If you have k3d already running you can use `install-*` targets to install Serverless in different flavors. ## Using Serverless Operator @@ -104,3 +105,18 @@ kubectl apply -f https://github.com/kyma-project/serverless/releases/latest/down secretName: my-secret EOF ``` +## Troubleshooting + +### Target install-serverless-local-sources - lookup k3d-kyma-registry.localhost: no such host + +On some OSes there is a problem with pushing to k3d registry. +The error log may look similar: +``` ++ docker push k3d-kyma-registry.localhost:5000/kyma-project/function-controller:local-20240426-111856 +The push refers to repository [k3d-kyma-registry.localhost:5000/kyma-project/function-controller] +Get "https://k3d-kyma-registry.localhost:5000/v2/": dialing k3d-kyma-registry.localhost:5000 with direct connection: resolving host k3d-kyma-registry.localhost: lookup k3d-kyma-registry.localhost: no such host +make: *** [install-serverless-local-sources] Error 1 +``` + +You have to add `127.0.0.1 k3d-kyma-registry.locahost` to your `etc/hosts`. +More details: https://k3d.io/v5.3.0/usage/registries/#preface-referencing-local-registries From e4b0f1fc2a2f4bbd7bd782b39eb9b2a49efbd5f3 Mon Sep 17 00:00:00 2001 From: Damian Badura Date: Fri, 26 Apr 2024 16:39:38 +0200 Subject: [PATCH 3/4] fix macos localhost problem --- Makefile | 2 +- README.md | 15 --------------- hack/docker-compose.yaml | 12 ++++++------ 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index c3927b5f1..1d18a3e4d 100755 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ install-serverless-latest-release:## Install serverless from latest release make -C ${OPERATOR_ROOT} check-serverless-installation .PHONY: install-serverless-local-sources -install-serverless-local-sources: ## Install serverless from local sources. Tip: On some OSes it won't work without preconfiguration. See Readme.md rroubleshooting section. +install-serverless-local-sources: ## Install serverless from local sources. $(eval IMG_VERSION=local-$(shell date +'%Y%m%d-%H%M%S')) IMG_VERSION=${IMG_VERSION} ./hack/build_all.sh diff --git a/README.md b/README.md index 21ea297f1..476440e0c 100644 --- a/README.md +++ b/README.md @@ -105,18 +105,3 @@ kubectl apply -f https://github.com/kyma-project/serverless/releases/latest/down secretName: my-secret EOF ``` -## Troubleshooting - -### Target install-serverless-local-sources - lookup k3d-kyma-registry.localhost: no such host - -On some OSes there is a problem with pushing to k3d registry. -The error log may look similar: -``` -+ docker push k3d-kyma-registry.localhost:5000/kyma-project/function-controller:local-20240426-111856 -The push refers to repository [k3d-kyma-registry.localhost:5000/kyma-project/function-controller] -Get "https://k3d-kyma-registry.localhost:5000/v2/": dialing k3d-kyma-registry.localhost:5000 with direct connection: resolving host k3d-kyma-registry.localhost: lookup k3d-kyma-registry.localhost: no such host -make: *** [install-serverless-local-sources] Error 1 -``` - -You have to add `127.0.0.1 k3d-kyma-registry.locahost` to your `etc/hosts`. -More details: https://k3d.io/v5.3.0/usage/registries/#preface-referencing-local-registries diff --git a/hack/docker-compose.yaml b/hack/docker-compose.yaml index d4d1d15a1..7094ce6b6 100755 --- a/hack/docker-compose.yaml +++ b/hack/docker-compose.yaml @@ -1,38 +1,38 @@ services: # serverless function_controller: - image: k3d-kyma-registry.localhost:5000/kyma-project/function-controller:local + image: localhost:5000/kyma-project/function-controller:local platform: "linux/amd64" build: context: ../ dockerfile: components/serverless/deploy/manager/Dockerfile function_build_init: - image: k3d-kyma-registry.localhost:5000/kyma-project/function-build-init:local + image: localhost:5000/kyma-project/function-build-init:local platform: "linux/amd64" build: context: ../ dockerfile: components/serverless/deploy/jobinit/Dockerfile # runtimes function_runtime_nodejs18: - image: k3d-kyma-registry.localhost:5000/kyma-project/function-runtime-nodejs18:local + image: localhost:5000/kyma-project/function-runtime-nodejs18:local platform: "linux/amd64" build: context: ../components/runtimes/nodejs dockerfile: nodejs18/Dockerfile function_runtime_nodejs20: - image: k3d-kyma-registry.localhost:5000/kyma-project/function-runtime-nodejs20:local + image: localhost:5000/kyma-project/function-runtime-nodejs20:local platform: "linux/amd64" build: context: ../components/runtimes/nodejs dockerfile: nodejs20/Dockerfile function_runtime_python39: - image: k3d-kyma-registry.localhost:5000/kyma-project/function-runtime-python39:local + image: localhost:5000/kyma-project/function-runtime-python39:local platform: "linux/amd64" build: context: ../components/runtimes/python dockerfile: python39/Dockerfile function_runtime_python312: - image: k3d-kyma-registry.localhost:5000/kyma-project/function-runtime-python312:local + image: localhost:5000/kyma-project/function-runtime-python312:local platform: "linux/amd64" build: context: ../components/runtimes/python From 7e0b317060b4b920d0c87bec583f0b7a570d70c8 Mon Sep 17 00:00:00 2001 From: Filip Strozik Date: Mon, 29 Apr 2024 14:04:41 +0200 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Natalia Sitko <80401180+nataliasitko@users.noreply.github.com> --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 476440e0c..1d083fb3b 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ kubectl apply -f https://github.com/kyma-project/serverless/releases/latest/down git clone https://github.com/kyma-project/serverless.git && cd serverless/ ``` -2. Run serverless from main with new k3d cluster +2. Create a new k3d cluster and run Serverless from the main branch: ```bash make run-main @@ -59,7 +59,7 @@ kubectl apply -f https://github.com/kyma-project/serverless/releases/latest/down > **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-*` targets to install Serverless in different flavors. +> **NOTE:** If you have k3d already running, you can use the `install-*` targets to install Serverless in different flavors. ## Using Serverless Operator