Skip to content

Commit

Permalink
Update setup scripts.
Browse files Browse the repository at this point in the history
Signed-off-by: Vitaliy Guschin <[email protected]>
  • Loading branch information
Vitaliy Guschin committed May 23, 2024
1 parent 84206c4 commit 3272f17
Show file tree
Hide file tree
Showing 163 changed files with 26,502 additions and 124 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cluster-setup/aws-create-1.sh → cluster-setup/aws/aws-create-1.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ parent_path=$( cd "$(dirname "$0")" ; pwd -P ) || exit

source "$parent_path"/private/aws-login.sh || exit

kube_config_dir=/tmp/kind-configs
kube_config_dir=/tmp/kube-configs
mkdir -p "$kube_config_dir" || exit

aws_kubeconfig="$kube_config_dir"/kubeconfig-aws-1
Expand Down
2 changes: 1 addition & 1 deletion cluster-setup/aws-create-2.sh → cluster-setup/aws/aws-create-2.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ parent_path=$( cd "$(dirname "$0")" ; pwd -P ) || exit

source "$parent_path"/private/aws-login.sh || exit

kube_config_dir=/tmp/kind-configs
kube_config_dir=/tmp/kube-configs
mkdir -p "$kube_config_dir" || exit

aws_kubeconfig="$kube_config_dir"/kubeconfig-aws-2
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions cluster-setup/env-aws-aws.sh → cluster-setup/aws/env-aws-aws.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env false "This script should be sourced in a shell, not executed directly"
#!/usr/bin/env bash

# ===== get script folder =====
shellname=$(ps -cp "$$" -o command="")
Expand All @@ -16,12 +16,13 @@ parent_path=$( cd "$(dirname "$script_path")" && pwd -P ) || return || exit
kube_config_dir=/tmp/kube-configs

echo '#!/usr/bin/env false "This script should be sourced in a shell, not executed directly"
unset USE_KIND_NODE
unset CLUSTER1_CIDR
unset CLUSTER2_CIDR
export KUBECONFIG1="'"$kube_config_dir"'"/kubeconfig-aws-1
export KUBECONFIG2="'"$kube_config_dir"'"/kubeconfig-aws-2
export K8S_ENV_NAME=aws_aws
source "$1"/aws-login.sh
source "$parent_path"/private/aws-login.sh
' > "$parent_path"/private/current-env.sh
chmod +x "$parent_path"/private/current-env.sh

Expand Down
File renamed without changes.
73 changes: 73 additions & 0 deletions cluster-setup/aws/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

# AWS cluster setup

This folder contains scripts to set up AWS clusters for testing.

# Authentication

Create file `cluster-setup/aws/private/aws-login.sh` with the following content:

```bash
#!/usr/bin/env false

export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
```

Put your values into variables.

No additional actions are needed.

# Install CLI

Run `aws-install-` script to install CLI

# Prepare clusters

After you set up required authentication you can just use `aws-create` scripts:

```bash
./cluster-setup/aws/aws-create-1.sh
./cluster-setup/aws/aws-create-2.sh
```

List clusters:

```bash
./cluster-setup/aws/aws-list.sh
```

Setup test environment

Run `env-aws-aws.sh` for initial setup, to create kubeconfig files.

Taint nodes:

```bash
k1 taint node -l node-role.kubernetes.io/control-plane node-role.kubernetes.io/master:NoSchedule
k2 taint node -l node-role.kubernetes.io/control-plane node-role.kubernetes.io/master:NoSchedule
```

Metallb setup:

```bash
k1 create ns metallb-system
k1 apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/metallb.yaml
k1 -n metallb-system create cm config
k2 create ns metallb-system
k2 apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/metallb.yaml
k2 -n metallb-system create cm config
```

# Execute tests

```bash
./scripts/test_suite.sh
```

# Cleanup

```bash
./cluster-setup/aws/aws-delete-1.sh
./cluster-setup/aws/aws-delete-2.sh
```
23 changes: 23 additions & 0 deletions cluster-setup/kind-local/env-kind-kind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

# ===== get script folder =====
shellname=$(ps -cp "$$" -o command="")
if [ "$shellname" = "bash" ]; then
script_path="${BASH_SOURCE[0]}"
elif [ "$shellname" = "zsh" ]; then
script_path="${(%):-%x}"
else
echo "unsupported shell $shellname"
return 1 || exit 1
fi
parent_path=$( cd "$(dirname "$script_path")" && pwd -P ) || return || exit
# ===== ===== =====

kind get kubeconfig --name kind-1 > "$parent_path"/kubeconfig/config1
kind get kubeconfig --name kind-2 > "$parent_path"/kubeconfig/config2
export KUBECONFIG1="$parent_path"/kubeconfig/config1
export KUBECONFIG2="$parent_path"/kubeconfig/config2
export CLUSTER1_CIDR=172.21.0.0/24
export CLUSTER2_CIDR=172.21.1.0/24
export K8S_ENV_NAME=kind_kind
export USE_KIND_NODE=true
8 changes: 8 additions & 0 deletions cluster-setup/kind-local/kind-create-1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

echo "
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker" | kind create cluster --config - --name kind-1
8 changes: 8 additions & 0 deletions cluster-setup/kind-local/kind-create-2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

echo "
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker" | kind create cluster --config - --name kind-2
35 changes: 35 additions & 0 deletions cluster-setup/kind-local/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

# Kind cluster setup for local testing

Create clusters:

```bash
./cluster-setup/kind-local/kind-create-1.sh
./cluster-setup/kind-local/kind-create-2.sh
```

Setup test environment:

```bash
source ./cluster-setup/kind-local/env-kind-kind.sh
```

Taint nodes:

```bash
k1 taint node -l node-role.kubernetes.io/control-plane node-role.kubernetes.io/master:NoSchedule
k2 taint node -l node-role.kubernetes.io/control-plane node-role.kubernetes.io/master:NoSchedule
```

# Execute tests

```bash
./scripts/test_suite.sh
```

# Cleanup

```bash
kind delete cluster --name kind-1
kind delete cluster --name kind-2
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
function install_clusterctl() {
clusterctl version && return

curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.5.2/clusterctl-linux-amd64 -o clusterctl || exit
curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.6.2/clusterctl-linux-amd64 -o clusterctl || exit
sudo install -o root -g root -m 0755 clusterctl /usr/local/bin/clusterctl
clusterctl version || exit
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
function install_clusterctl() {
clusterctl version && return

curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.5.2/clusterctl-darwin-amd64 -o clusterctl || exit
curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.6.2/clusterctl-darwin-amd64 -o clusterctl || exit
chmod +x ./clusterctl || exit
sudo mv ./clusterctl /usr/local/bin/clusterctl || exit
clusterctl version || exit
Expand Down
18 changes: 18 additions & 0 deletions cluster-setup/packet/env--autocomplete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env false "This script should be sourced in a shell, not executed directly"

alias "k1=kubectl --kubeconfig=$KUBECONFIG1"
alias "k2=kubectl --kubeconfig=$KUBECONFIG2"

shellname=$(ps -cp "$$" -o command="")
if [ "$shellname" = "bash" ]; then
echo "set autocompletion for bash"
source <(kubectl completion bash) || return || exit
complete -o default -F __start_kubectl k1 || return || exit
complete -o default -F __start_kubectl k2 || return || exit
elif [ "$shellname" = "zsh" ]; then
echo "set autocompletion for zsh"
source <(kubectl completion zsh) || return || exit
else
echo "unsupported shell $shellname"
return 1
fi
File renamed without changes.
3 changes: 2 additions & 1 deletion cluster-setup/env-packet.sh → cluster-setup/packet/env-packet.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env false "This script should be sourced in a shell, not executed directly"
#!/usr/bin/env bash

# ===== get script folder =====
shellname=$(ps -cp "$$" -o command="")
Expand Down Expand Up @@ -26,6 +26,7 @@ skip_fetch=${3:-}
kube_config_path=$parent_path/private/kubeconfig/packet_$remote_cluster_index.yaml

echo '#!/usr/bin/env false "This script should be sourced in a shell, not executed directly"
unset USE_KIND_NODE
unset CLUSTER'$local_cluster_index'_CIDR
export KUBECONFIG'$local_cluster_index'="'"$kube_config_path"'"
export K8S_ENV_NAME'$local_cluster_index'=packet
Expand Down
21 changes: 21 additions & 0 deletions cluster-setup/packet/env-restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env false "This script should be sourced in a shell, not executed directly"

# ===== get script folder =====
shellname=$(ps -cp "$$" -o command="")
if [ "$shellname" = "bash" ]; then
script_path="${BASH_SOURCE[0]}"
elif [ "$shellname" = "zsh" ]; then
script_path="${(%):-%x}"
else
echo "unsupported shell $shellname"
return 1 || exit 1
fi
parent_path=$( cd "$(dirname "$script_path")" && pwd -P ) || return || exit
# ===== ===== =====

split_configs=${1:-}

[ "$split_configs" = 'split' ] || source "$parent_path"/private/current-env.sh "$parent_path"/private
[ ! "$split_configs" = 'split' ] || source "$parent_path"/private/current-env-1.sh "$parent_path"/private
[ ! "$split_configs" = 'split' ] || source "$parent_path"/private/current-env-2.sh "$parent_path"/private
source "$parent_path"/env--autocomplete.sh
8 changes: 8 additions & 0 deletions cluster-setup/packet/kind-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

echo "
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker" | kind create cluster --config - --name kind-management
File renamed without changes.
2 changes: 1 addition & 1 deletion cluster-setup/packet-create-2.sh → cluster-setup/packet/packet-create-2.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ clusterctl generate cluster msm-perf-test-2 \
| sed 's/"eipTag"/"metro": "'"$METRO"'", "loadbalancer": "metallb:\/\/\/", "eipTag"/' \
> "$parent_path"/private/packet-cluster-2.yaml || exit

kubectl apply -f "$parent_path"/private/packet-cluster-1.yaml
kubectl apply -f "$parent_path"/private/packet-cluster-2.yaml
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions cluster-setup/packet-init-env.sh → cluster-setup/packet/packet-init-env.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env false "This script should be sourced in a shell, not executed directly"
#!/usr/bin/env bash

# ===== get script folder =====
shellname=$(ps -cp "$$" -o command="")
Expand All @@ -24,4 +24,4 @@ export KUBECONFIG="$config"

. "$parent_path"/private/packet-login.sh || return 1

clusterctl init --core cluster-api:v1.5.2 --infrastructure packet:v0.7.2
clusterctl init --infrastructure packet:v0.8.0
File renamed without changes.
File renamed without changes.
File renamed without changes.
108 changes: 108 additions & 0 deletions cluster-setup/packet/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@

# Equinix Metal cluster setup

This folder contains scripts to set up Equinix metal clusters for testing.

# Authentication

Create file `./cluster-setup/packet/private/packet-login.sh` with the following content:

```bash
#!/usr/bin/env false

export PROJECT_ID=
# METAL_AUTH_TOKEN and PACKET_API_KEY should have the same value
# METAL_AUTH_TOKEN is for metal cli
# PACKET_API_KEY is for clusterctl
export METAL_AUTH_TOKEN=
export PACKET_API_KEY=
# usually METRO=da
export METRO=
# your public key (get it using 'cat ~/.ssh/id_rsa.pub' or generate another one), like SSH_KEY="ssh-rsa AAAAC3NzaC1lZDI1NTE5AAAAIjAqaYj9nmCkgr4PdK username@computer"
export SSH_KEY=
```

# Install CLI

Run `clusterctl-install-` script to install CLI

# Prepare clusters

Initialize a Kind cluster for management

```bash
./cluster-setup/packet/kind-create.sh
kind get kubeconfig --name kind-management > /tmp/kubeconfigs/config-management
source ./cluster-setup/packet/packet-init-env.sh /tmp/kubeconfigs/config-management
```

Generate workload clusters

```bash
source ./cluster-setup/packet/packet-create-1.sh
source ./cluster-setup/packet/packet-create-2.sh
```

List clusters

```bash
./cluster-setup/packet/packet-list.sh
clusterctl describe --show-conditions all cluster msm-perf-test-1
clusterctl describe --show-conditions all cluster msm-perf-test-2
```

Setup test environment

```bash
source ./cluster-setup/packet/env-packet.sh 1 1
source ./cluster-setup/packet/env-packet.sh 2 2
```

When using a pre-configured packet cluster, place kubeconfig files here:

- `./cluster-setup/packet/private/kubeconfig/packet_1.yaml`
- `./cluster-setup/packet/private/kubeconfig/packet_2.yaml`

Taint nodes:

```bash
k1 taint node -l node-role.kubernetes.io/control-plane node-role.kubernetes.io/master:NoSchedule
k2 taint node -l node-role.kubernetes.io/control-plane node-role.kubernetes.io/master:NoSchedule
```

Install CNI

```bash
k1 apply -k https://github.com/networkservicemesh/integration-k8s-packet/scripts/defaultCNI
k2 apply -k https://github.com/networkservicemesh/integration-k8s-packet/scripts/defaultCNI
```

SPIRE server requires StorageClass
```bash
k1 apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/v0.0.24/deploy/local-path-storage.yaml
k1 patch storageclass local-path -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

k2 apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/v0.0.24/deploy/local-path-storage.yaml
k2 patch storageclass local-path -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
```

Metallb setup:

```bash
./cluster-setup/packet/packet-lb-1.sh
./cluster-setup/packet/packet-lb-2.sh
```

# Execute tests

```bash
./scripts/test_suite.sh
```

# Cleanup

```bash
./cluster-setup/packet/packet-delete-1.sh
./cluster-setup/packet/packet-delete-2.sh
kind delete cluster --name kind-management
```
Loading

0 comments on commit 3272f17

Please sign in to comment.