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

Add real local target #928

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
.idea
bin
4 changes: 2 additions & 2 deletions Makefile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ 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.
$(eval IMG_VERSION=local-$(shell date +'%Y%m%d-%H%M%S'))
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
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,15 +51,15 @@ 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
pPrecel marked this conversation as resolved.
Show resolved Hide resolved

```bash
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.
> **NOTE:** If you have k3d already running you can use `install-*` targets to install Serverless in different flavors.
pPrecel marked this conversation as resolved.
Show resolved Hide resolved

## Using Serverless Operator

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion config/serverless/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/serverless/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions hack/build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions hack/docker-compose.yaml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
services:
# serverless
function_controller:
image: europe-docker.pkg.dev/kyma-project/dev/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: europe-docker.pkg.dev/kyma-project/dev/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: europe-docker.pkg.dev/kyma-project/dev/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: europe-docker.pkg.dev/kyma-project/dev/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: europe-docker.pkg.dev/kyma-project/dev/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: europe-docker.pkg.dev/kyma-project/dev/function-runtime-python312:local
image: localhost:5000/kyma-project/function-runtime-python312:local
platform: "linux/amd64"
build:
context: ../components/runtimes/python
Expand Down
8 changes: 4 additions & 4 deletions hack/k3d.mk
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The kyma cli used to delete old k3d and registry, As I used plain k3d cli I added delete-k3d as dependency to create-k3d target

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
Expand Down
16 changes: 11 additions & 5 deletions hack/replace_serverless_chart_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest to install yq in bin if it doesn't exist. We don't need to generate another requirement for every developer/user

echo "==== End of Local Changes ===="
Loading