-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto-demo-existing-kind.sh
More file actions
executable file
·164 lines (137 loc) · 4.95 KB
/
auto-demo-existing-kind.sh
File metadata and controls
executable file
·164 lines (137 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env bash
# Check to see if the repo exists already
# NOTE: this is a duplicate in case this script is run directly
if [ -d ./test ]; then
echo "The test repo directory exists already. Delete it and start again"
exit 1
fi
# Create keys for admin user
# mkdir keys
# ssh-keygen -f keys/admin
# Add chart repos we are going to use
pei "helm repo add gitea-charts https://dl.gitea.com/charts/"
pei "helm repo add fleet https://rancher.github.io/fleet-helm-charts/"
pei "helm repo add capi-operator https://kubernetes-sigs.github.io/cluster-api-operator"
pe "helm repo update"
# get settings required for fleet
kubectl config view -o json --raw | jq -r '.clusters[].cluster["certificate-authority-data"]' | base64 -d >ca.pem
API_SERVER_URL=$(kubectl config view -o json --raw | jq -r '.clusters[] | select(.name=="kind-k8sug").cluster["server"]')
API_SERVER_CA="ca.pem"
# Install Fleet
pe "helm -n cattle-fleet-system install --create-namespace --wait fleet-crd fleet/fleet-crd"
pe "helm install --create-namespace -n cattle-fleet-system --set apiServerURL=\"$API_SERVER_URL\" --set-file apiServerCA=\"$API_SERVER_CA\" fleet fleet/fleet --wait"
# Install Gitea
pe "helm install gitea gitea-charts/gitea --values gitea_values.yaml --wait"
# For later use
export USERNAME=gitea_admin
export PASSWORD=admin
export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services gitea-http)
export REPO_NAME=test
# Add SSH key to Gitea user
PUB_KEY=$(cat keys/admin.pub)
curl \
-X POST "http://$NODE_IP:$NODE_PORT/api/v1/user/keys" \
-H "accept: application/json" \
-u $USERNAME:$PASSWORD \
-H "Content-Type: application/json" \
-d "{\"key\": \"$PUB_KEY\", \"read_only\": false, \"title\": \"key1\" }" \
-i
# Setup gitea user
curl \
-X POST "http://$NODE_IP:$NODE_PORT/api/v1/user/repos" \
-H "accept: application/json" \
-u $USERNAME:$PASSWORD \
-H "Content-Type: application/json" \
-d "{\"name\": \"$REPO_NAME\", \"auto_init\": true}" \
-i
# Add git auth secret
pe "kubectl create secret generic basic-auth-secret -n fleet-local --type=kubernetes.io/basic-auth --from-literal=username=$USERNAME --from-literal=password=$PASSWORD"
# Add our git repo
cat <<EOF >>./repo.yaml
kind: GitRepo
apiVersion: fleet.cattle.io/v1alpha1
metadata:
name: fleet-repo
spec:
repo: http://$NODE_IP:$NODE_PORT/$USERNAME/$REPO_NAME.git
branch: main
forceSyncGeneration: 1
clientSecretName: basic-auth-secret
EOF
pe "$EDITOR repo.yaml"
pe "kubectl apply -n fleet-local -f repo.yaml"
# Install CAPI operator
pe "helm install capi-operator capi-operator/cluster-api-operator --create-namespace -n capi-operator-system --set cert-manager.enabled=true --wait"
export GITEA_URL="http://$USERNAME:$PASSWORD@$NODE_IP:$NODE_PORT"
pe "xdg-open $GITEA_URL"
export GIT_URL="http://$USERNAME:$PASSWORD@$NODE_IP:$NODE_PORT/$USERNAME/$REPO_NAME.git"
# Clone the test repo
pe "git clone $GIT_URL"
pei "cd test"
# Install CAPI providers
# equivalent of doing clusterctl init
pe "mkdir mgmt"
pe "cp ../data/providers.yaml mgmt/"
pei "git add ."
pei "git commit -m \"Add CAPI providers\""
pe "git push"
# Create a child cluster
pe "mkdir clusters"
pe "cp ../data/cluster.yaml clusters/"
pei "git add ."
pei "git commit -m \"Add cluster definition\""
pe "git push"
pei "echo \"Explore child cluster\""
# Add kindnet CNI using CRS
pe "mkdir crs"
pe "cp ../data/crs.yaml crs/"
pei "git add ."
pei "git commit -m \"Add kindet crs\""
pe "git push"
pei "echo \"Explore child cluster\""
# Deploy CAPI Helm addon provider
pe "cp ../data/addon_provider.yaml mgmt/"
pei "git add ."
pei "git commit -m \"Add helm addon provider\""
pe "git push"
# Deploy app to child cluster based on label
pe "mkdir apps"
pe "cp ../data/addon_app.yaml apps/"
pei "git add ."
pei "git commit -m \"Add app to bde deployed via label\""
pe "git push"
pei "echo \"Explore child cluster\""
# Register child cluster with fleet
pe "cp ../data/fleet_cluster.yaml clusters/"
pei "git add ."
pei "git commit -m \"Register child cluster with fleet\""
pe "git push"
# Create "dev cluster group
pe "cp ../data/dev_cluster_group.yaml mgmt/"
pei "git add ."
pei "git commit -m \"Create dev cluster group\""
pe "git push"
# Deploy nginx to all dev clusters
pe "cp ../data/nginx_bundle.yaml apps/"
pei "git add ."
pei "git commit -m \"Add ngnix to dev clusters\""
pe "git push"
# scale the workers to 3
pe "echo \"Scale workers to 3\""
pe "$EDITOR clusters/cluster.yaml"
pei "git add ."
pei "git commit -m \"Scale workers to 3\""
pe "git push"
# Upgrade the control plane to v1.28.6
pe "echo \"Upgrade Control Plane v1.28.6\""
pe "$EDITOR clusters/cluster.yaml"
pei "git add ."
pei "git commit -m \"Upgrade k8s version\""
pe "git push"
# Add second cluster and watch everything get deployed
pe "cp ../data/cluster2.yaml clusters/"
pei "git add ."
pei "git commit -m \"Add 2nd cluster definition\""
pe "git push"
pei "echo \"Explore child cluster\""