Skip to content

Commit

Permalink
add version checker script with documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
amritanshusikdar committed Dec 9, 2024
1 parent 89743f5 commit 2e26912
Show file tree
Hide file tree
Showing 18 changed files with 368 additions and 90 deletions.
8 changes: 4 additions & 4 deletions .run/Delete Test Clusters.run.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Delete Test Clusters" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="k3d cluster rm kcp skr" />
<option name="SCRIPT_TEXT" value="" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/scripts/tests/clusters_cleanup.sh" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="/bin/zsh" />
<option name="INTERPRETER_PATH" value="/bin/bash" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<option name="EXECUTE_SCRIPT_FILE" value="true" />
<envs />
<method v="2" />
</configuration>
Expand Down
11 changes: 4 additions & 7 deletions .run/Deploy KLM from registry.run.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Deploy KLM from registry" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="echo $KLM_IMAGE_REGISTRY; " />
<option name="SCRIPT_TEXT" value="echo &quot;Enter KLM image registry (dev, prod):&quot;; read input_img_reg; echo &quot;Enter KLM image tag (e.g.: latest):&quot;; read input_img_tag; $PROJECT_DIR$/scripts/tests/deploy_klm_from_registry.sh --image-registry $input_img_reg --image-tag $input_img_tag" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/scripts/tests/deploy_klm_from_registry.sh" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="/bin/bash" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="true" />
<envs>
<env name="IMG_REGISTRY_HOST" value="europe-docker.pkg.dev/kyma-project" />
<env name="IMG_NAME" value="lifecycle-manager" />
</envs>
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs />
<method v="2" />
</configuration>
</component>
11 changes: 4 additions & 7 deletions .run/Deploy KLM from sources.run.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Deploy KLM from sources" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="export KUBECONFIG=${HOME}/.k3d/kcp-local.yaml;TAG=\&quot;$(date +%Y%m%d%H%M%S)\&quot; &amp;&amp; make docker-build IMG=${LOCAL_IMG}:${TAG}; make docker-push IMG=${LOCAL_IMG}:${TAG}; make local-deploy-with-watcher IMG=${CLUSTER_IMG}:${TAG}" />
<option name="SCRIPT_TEXT" value="" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/scripts/tests/deploy_klm_from_sources.sh" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="/bin/zsh" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs>
<env name="LOCAL_IMG" value="localhost:5111/lifecycle-manager" />
<env name="CLUSTER_IMG" value="k3d-kcp-registry.localhost:5000/lifecycle-manager"/>
</envs>
<option name="EXECUTE_SCRIPT_FILE" value="true" />
<envs />
<method v="2" />
</configuration>
</component>
3 changes: 2 additions & 1 deletion .run/Deploy kyma.run.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Deploy kyma" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="echo Enter the skr host value \(host.k3d.internal or localhost\):; read SKR_HOST; export SKR_HOST; export KUBECONFIG=$HOME/.k3d/kcp-local.yaml; $PROJECT_DIR$/scripts/tests/deploy_kyma.sh" />
<option name="SCRIPT_TEXT" value="echo Enter the skr host value \(host.k3d.internal or localhost\):; read skr_host; $PROJECT_DIR$/scripts/tests/deploy_kyma.sh $skr_host" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
Expand All @@ -11,6 +11,7 @@
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs />
<method v="2" />
</configuration>
</component>
3 changes: 2 additions & 1 deletion .run/E2E Tests.run.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="E2E Tests" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="echo Enter the E2E test to run; read e2eTestName; export KCP_KUBECONFIG=$HOME/.k3d/kcp-local.yaml; export SKR_KUBECONFIG=$HOME/.k3d/skr-local.yaml; make -C $PROJECT_DIR$/tests/e2e $e2eTestName" />
<option name="SCRIPT_TEXT" value="echo Enter the E2E test to run:; read e2eTestName; $PROJECT_DIR$/scripts/tests/e2e.sh $e2eTestName" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
Expand All @@ -11,6 +11,7 @@
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs />
<method v="2" />
</configuration>
</component>
7 changes: 4 additions & 3 deletions .run/Install CRDs.run.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Install CRDs" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="export KUBECONFIG=$HOME/.k3d/kcp-local.yaml; make install" />
<option name="SCRIPT_TEXT" value="" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/scripts/tests/install_crds.sh" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="/bin/zsh" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<option name="EXECUTE_SCRIPT_FILE" value="true" />
<envs />
<method v="2" />
</configuration>
</component>
7 changes: 4 additions & 3 deletions .run/Un-Deploy kyma.run.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Un-Deploy kyma" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="export KUBECONFIG=$HOME/.k3d/kcp-local.yaml; kubectl -n kcp-system delete kyma kyma-sample; kubectl -n kcp-system delete secret kyma-sample" />
<option name="SCRIPT_TEXT" value="" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/scripts/tests/undeploy_kyma.sh" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="/bin/zsh" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<option name="EXECUTE_SCRIPT_FILE" value="true" />
<envs />
<method v="2" />
</configuration>
</component>
75 changes: 17 additions & 58 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,32 @@
"version": "2.0.0",
"tasks": [
{
"label": "Delete Test Clusters",
"label": "Create New Test Clusters",
"type": "shell",
"command": "k3d cluster rm kcp skr",
"command": "${cwd}/scripts/tests/create_test_clusters.sh",
"dependsOn": ["Delete Test Clusters"]
},
{
"label": "Ensure Test Clusters",
"label": "Delete Test Clusters",
"type": "shell",
"command": "${cwd}/scripts/tests/create_test_clusters.sh",
"command": "${cwd}/scripts/tests/clusters_cleanup.sh"
},
{
"label": "Create New Test Clusters",
"label": "Ensure Test Clusters",
"type": "shell",
"command": "${cwd}/scripts/tests/create_test_clusters.sh",
"dependsOn": [
"Delete Test Clusters"
]
"command": "${cwd}/scripts/tests/create_test_clusters.sh"
},
// 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-kcp-registry.localhost:5000/lifecycle-manager",
"KUBECONFIG": "${env:HOME}/.k3d/kcp-local.yaml"

}
}
"command": "${cwd}/scripts/tests/deploy_klm_from_sources.sh"
},
// 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",
}
}
"command": "${cwd}/scripts/tests/deploy_klm_from_registry.sh --image-registry ${input:klmImageRegistry} --image-tag ${input:klmImageTag}"
},
{
"label": "Deploy template-operator",
Expand All @@ -61,46 +44,25 @@
{
"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",
}
}
"command": "${cwd}/scripts/tests/deploy_kyma.sh ${input:skrHost}"
},
{
"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",
}
}
"command": "${cwd}/scripts/tests/undeploy_kyma.sh"
},
{
"label": "E2E Tests",
"type": "shell",
"command": "make -C ${cwd}/tests/e2e ${input:e2eTestTarget}",
"command": "${cwd}/scripts/tests/e2e.sh ${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",
}
}
"command": "${cwd}/scripts/tests/install_crds.sh"
}
],
"inputs": [
Expand Down Expand Up @@ -132,7 +94,7 @@
"mandatory-module",
"mandatory-module-metrics",
"misconfigured-kyma-secret",
"ocm-compatible-module-template",
"ocm-compatible-module-template"
]
},
{
Expand All @@ -152,15 +114,12 @@
"id": "klmImageRegistry",
"type": "pickString",
"description": "Registry of KLM image",
"options": [
"dev",
"prod"
]
"options": ["dev", "prod"]
},
{
"id": "klmImageTag",
"type": "promptString",
"description": "Tag of the KLM image, e.g. 'latest'",
"description": "Tag of the KLM image, e.g. 'latest'"
},
{
"id": "skrHost",
Expand All @@ -172,6 +131,6 @@
// use localhost when running KLM locally on the machine
"localhost"
]
},
}
]
}
60 changes: 60 additions & 0 deletions scripts/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Overview of All Scripts

## Version Checker: `version.sh`
The script checks if the Command Line Tools (CLI) for `kubectl`, `docker`, `GoLang`, `k3d`, and `istioctl` have the correct versions.
It ensures that the versions are in a valid format using [Semantic Versioning](https://semver.org/).
If the check detects outdated versions, it gives a warning and exits with success. For more information, see all the possible exit statuses:

* `0` - Success - the version is up-to-date or outdated and it uses the correct Semantic Versioning
* `1` - At least one of the CLI tools is not installed
* `2` - Invalid version found, for example, incorrect Semantic Versioning

### Current Versions
| CLI Tool | Version |
| --------- | ------- |
| `kubectl` | v1.31.3 |
| `go` | v1.23.3 |
| `k3d` | v5.6.0 |
| `docker` | v27.3.1 |
| `istioctl`| v1.24.1 |


## Create Test Clusters: `create_test_cluster.sh`
The script creates two test clusters using `k3d`:
- `kcp` for the control plane
- `skr` for the Kyma runtime
If the clusters already exist, the script exits with success.
If you get a notification, while running the script, saying that the Watcher CR is missing, re-run the script.
The script is accompanied by the `Ensure Test Clusters` task in the VSCode tasks, and by the corresponding run configuration for GoLand.

This script internally depends on `version.sh` to check the versions of the required tools. If you want to skip the version check, use the `--skip-version-check` flag.

## Cleaning the Clusters: `clusters_cleanup.sh`
The script deletes the `kcp` and `skr` test clusters using `k3d`.

## Deploying KLM from Sources: `deploy_klm_from_sources.sh`
The script deploys Lifecycle Manager using the current state of the locally cloned and developed repository.
It doesn't require any additional flags or parameters.

## Deploying KLM from the Registry: `deploy_klm_from_registry.sh`
The script deploys Lifecycle Manager from the given image registry and the given image tag.
It requires the following parameters:
- `--image-registry`: The accepted values are `prod` and `dev`.
- `--image-tag`: The tag of the image to be used. For example, `latest`.

## Deploy Kyma: `deploy_kyma.sh`
Use the script to deploy Kyma using one of the **required** parameters:
- `localhost`: To run Lifecycle Manager locally on your machine.
- `host.k3d.internal`: To deploy Lifecycle Manager to a cluster.

## Undeploy Kyma: `undeploy_kyma.sh`
The script undeploys Kyma from the cluster by deleting the Kyma and the corresponding Secret from the `kcp-system` namespace.

## End-To-End Tests: `e2e.sh`
The script runs end-to-end tests taking the test target as input.
The test targets are defined in the `tests` directory of the project root.
The script runs the test target and outputs the results to the console.
The errors that occurred during the test are handled directly by `make`.

## Installing CRDs: `install_crds.sh`
The script installs Custom Resource Definitions (CRDs) required for Lifecycle Manager. The CRDs' set is the same as in the `make install` of the Makefile in the project root directory.
6 changes: 6 additions & 0 deletions scripts/tests/clusters_cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# Remove the k3d cluster and the skr cluster
k3d cluster rm kcp skr

echo "[$(basename $0)] Cleanup completed"
Loading

0 comments on commit 2e26912

Please sign in to comment.