Skip to content

Commit

Permalink
chore: Add VSCode tasks and launch config for local setup (#1898)
Browse files Browse the repository at this point in the history
* chore: VSCode tasks for local test setup

* add KUBECONFIG env var to be on the save side

* use timestamp as tag for local sources deploy

* add task that creates the test clusters from scratch

* add launch config

* create script exactly matching "skr"/"kcp"
  • Loading branch information
c-pius committed Sep 30, 2024
1 parent adce201 commit 2fed199
Show file tree
Hide file tree
Showing 5 changed files with 278 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
atlassian-ide-plugin.xml

## VSCode
**/*.vscode
**/*.devcontainer*

### OSX template
Expand Down
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
// use task "Deploy Kyma" with "localhost" option
"name": "Launch KLM",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${cwd}/cmd/main.go",
"args": ["--in-kcp-mode"],
"env": {
"KUBECONFIG": "${env:HOME}/.k3d/kcp-local.yaml",
"ENABLE_WEBHOOKS": "false"
},
"preLaunchTask": "Install CRDs"
}
]
}
181 changes: 181 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Delete Test Clusters",
"type": "shell",
"command": "k3d cluster rm kcp skr",
},
{
"label": "Ensure Test Clusters",
"type": "shell",
"command": "${cwd}/scripts/tests/create_test_clusters.sh",
},
{
"label": "Create New Test Clusters",
"type": "shell",
"command": "${cwd}/scripts/tests/create_test_clusters.sh",
"dependsOn": [
"Delete Test Clusters"
]
},
// re-run if encountering error that the watcher CRD is missing
{
"label": "Deploy KLM from sources",
"type": "shell",
"command": "TAG=\"$(date +%Y%m%d%H%M%S)\" && make docker-build IMG=${LOCAL_IMG}:${TAG}; make docker-push IMG=${LOCAL_IMG}:${TAG}; make local-deploy-with-watcher IMG=${CLUSTER_IMG}:${TAG}",
"options": {
"env": {
"LOCAL_IMG": "localhost:5111/lifecycle-manager",
"CLUSTER_IMG": "k3d-myregistry.localhost:5000/lifecycle-manager",
"KUBECONFIG": "${env:HOME}/.k3d/kcp-local.yaml",

}
}
},
// re-run if encountering error that the watcher CRD is missing
{
"label": "Deploy KLM from registry",
"type": "shell",
"command": "make local-deploy-with-watcher IMG=${IMG_REGISTRY_HOST}/${input:klmImageRegistry}/${IMG_NAME}:${input:klmImageTag}",
"options": {
"env": {
"IMG_REGISTRY_HOST": "europe-docker.pkg.dev/kyma-project",
"IMG_NAME": "lifecycle-manager",
"KUBECONFIG": "${env:HOME}/.k3d/kcp-local.yaml",
}
}
},
{
"label": "Deploy template-operator",
"type": "shell",
"command": "kubectl apply -f ${cwd}/tests/moduletemplates/${input:templateOperatorVersion}",
"options": {
"env": {
"KUBECONFIG": "${env:HOME}/.k3d/kcp-local.yaml",
}
}
},
{
"label": "Deploy kyma",
"type": "shell",
"command": "export SKR_HOST=${input:skrHost} && ${cwd}/scripts/tests/deploy_kyma.sh",
"options": {
"env": {
"KUBECONFIG": "${env:HOME}/.k3d/kcp-local.yaml",
}
}
},
{
"label": "Un-Deploy kyma",
"type": "shell",
"command": "kubectl -n kcp-system delete kyma kyma-sample; kubectl -n kcp-system delete secret kyma-sample",
"options": {
"env": {
"KUBECONFIG": "${env:HOME}/.k3d/kcp-local.yaml",
}
}
},
{
"label": "E2E Tests",
"type": "shell",
"command": "make -C ${cwd}/tests/e2e ${input:e2eTestTarget}",
"group": {
"kind": "test"
},
"options": {
"env": {
"KCP_KUBECONFIG": "${env:HOME}/.k3d/kcp-local.yaml",
"SKR_KUBECONFIG": "${env:HOME}/.k3d/skr-local.yaml"
}
}
},
{
"label": "Install CRDs",
"type": "shell",
"command": "make install",
"options": {
"env": {
"KUBECONFIG": "${env:HOME}/.k3d/kcp-local.yaml",
}
}
}
],
"inputs": [
{
// not all of the options work OOTB, see deploy-lifecycle-manager-e2e action.yaml for specific patches
"id": "e2eTestTarget",
"type": "pickString",
"description": "E2E test target",
"options": [
"watcher-enqueue",
"rbac-privileges",
"kyma-deprovision-with-foreground-propagation",
"kyma-deprovision-with-background-propagation",
"module-status-decoupling-with-statefulset",
"module-status-decoupling-with-deployment",
"kyma-metrics",
"module-without-default-cr",
"module-consistency",
"non-blocking-deletion",
"upgrade-under-deletion",
"purge-controller",
"purge-metrics",
"module-upgrade-channel-switch",
"module-upgrade-new-version",
"unmanage-module",
"skip-manifest-reconciliation",
"ca-certificate-rotation",
"self-signed-certificate-rotation",
"mandatory-module",
"mandatory-module-metrics",
"misconfigured-kyma-secret",
"ocm-compatible-module-template",
]
},
{
"id": "templateOperatorVersion",
"type": "pickString",
"description": "Template-operator manifest",
"options": [
"mandatory_moduletemplate_template_operator_v1.yaml",
"mandatory_moduletemplate_template_operator_v2.yaml",
"moduletemplate_template_operator_regular_new_ocm.yaml",
"moduletemplate_template_operator_v1_regular.yaml",
"moduletemplate_template_operator_v2_fast.yaml",
"moduletemplate_template_operator_v2_regular_new_version.yaml",
"operator_v1beta2_moduletemplate_kcp-module_updated.yaml",
"operator_v1beta2_moduletemplate_kcp-module-cred-label.yaml",
"operator_v1beta2_moduletemplate_kcp-module.yaml",
"operator_v1beta2_moduletemplate_ocm.software.v3alpha1.yaml"
]
},
{
"id": "klmImageRegistry",
"type": "pickString",
"description": "Registry of KLM image",
"options": [
"dev",
"prod"
]
},
{
"id": "klmImageTag",
"type": "promptString",
"description": "Tag of the KLM image, e.g. 'latest'",
},
{
"id": "skrHost",
"type": "pickString",
"description": "Host of the SKR",
"options": [
// use host.k3d.internal when deploying KLM into the cluster
"host.k3d.internal",
// use localhost when running KLM locally on the machine
"localhost"
]
},
]
}
51 changes: 51 additions & 0 deletions scripts/tests/create_test_clusters.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

# Change to the directory where the script is located
cd "$(dirname "$0")"

# create SKR cluster
if k3d cluster list | grep -q "^skr\s"; then
echo "Reusing existing SKR cluster..."
else
k3d cluster create skr \
-p 10080:80@loadbalancer \
-p 10443:443@loadbalancer \
--k3s-arg --tls-san="skr.cluster.local@server:*" \
--image rancher/k3s:v1.28.7-k3s1 \
--k3s-arg --disable="traefik@server:*" \
--k3s-arg --tls-san="host.k3d.internal@server:*"
fi

# create KCP cluster
if k3d cluster list | grep -q "^kcp\s"; then
echo "Reusing existing KCP cluster..."
else
k3d cluster create kcp \
-p 9443:443@loadbalancer \
-p 9080:80@loadbalancer \
-p 9081:8080@loadbalancer \
--registry-create k3d-myregistry.localhost:5111 \
--image rancher/k3s:v1.28.7-k3s1 \
--k3s-arg --disable="traefik@server:*" \
--k3s-arg --tls-san="host.k3d.internal@server:*"

kubectl config use-context k3d-kcp

# install istio
istioctl install --set profile=demo -y

# install cert-manager
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.3/cert-manager.yaml

./add_skr_host_to_coredns.sh

# create kcp-system namespace
kubectl create namespace kcp-system

# label node
kubectl label nodes k3d-kcp-server-0 iam.gke.io/gke-metadata-server-enabled="true" pool-type=mgmt
fi

# export kubeconfigs
k3d kubeconfig get skr > ~/.k3d/skr-local.yaml
k3d kubeconfig get kcp > ~/.k3d/kcp-local.yaml
24 changes: 24 additions & 0 deletions scripts/tests/deploy_kyma.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
name: kyma-sample
namespace: kcp-system
labels:
"operator.kyma-project.io/kyma-name": "kyma-sample"
"operator.kyma-project.io/managed-by": "lifecycle-manager"
data:
config: $(k3d kubeconfig get skr | sed "s/0\.0\.0\.0/${SKR_HOST}/" | base64 | tr -d '\n')
---
apiVersion: operator.kyma-project.io/v1beta2
kind: Kyma
metadata:
annotations:
skr-domain: "example.domain.com"
name: kyma-sample
namespace: kcp-system
spec:
channel: regular
EOF

0 comments on commit 2fed199

Please sign in to comment.