-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
Β·138 lines (128 loc) Β· 3.94 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
Β·138 lines (128 loc) Β· 3.94 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
#!/bin/bash
# WebApp Operator Quick Setup Script
# This script helps you get started with the operator example
set -e
echo "π WebApp Operator Setup"
echo "========================"
echo ""
# Check prerequisites
echo "Checking prerequisites..."
if ! command -v kubectl &> /dev/null; then
echo "β kubectl not found. Please install kubectl first."
exit 1
fi
echo "β
kubectl found"
if ! command -v go &> /dev/null; then
echo "β Go not found. Please install Go 1.21+ first."
exit 1
fi
echo "β
Go found ($(go version))"
# Check if connected to a cluster
if ! kubectl cluster-info &> /dev/null; then
echo "β Not connected to a Kubernetes cluster."
echo " Please configure kubectl to connect to a cluster (minikube, kind, etc.)"
exit 1
fi
echo "β
Connected to cluster: $(kubectl config current-context)"
echo ""
# Ask user what they want to do
echo "What would you like to do?"
echo "1) Install CRD only"
echo "2) Install CRD and run operator locally"
echo "3) Install CRD and deploy example WebApp"
echo "4) Full demo (install everything)"
echo "5) Clean up (remove all resources)"
echo ""
read -p "Enter choice [1-5]: " choice
case $choice in
1)
echo ""
echo "π¦ Installing CRD..."
kubectl apply -f crd/webapp-crd.yaml
echo "β
CRD installed successfully!"
echo ""
echo "Verify with: kubectl get crd webapps.example.com"
;;
2)
echo ""
echo "π¦ Installing CRD..."
kubectl apply -f crd/webapp-crd.yaml
echo "β
CRD installed!"
echo ""
echo "π₯ Downloading Go dependencies..."
go mod download
echo "β
Dependencies ready!"
echo ""
echo "π Starting operator..."
echo " (Press Ctrl+C to stop)"
echo ""
go run main.go
;;
3)
echo ""
echo "π¦ Installing CRD..."
kubectl apply -f crd/webapp-crd.yaml
echo "β
CRD installed!"
echo ""
echo "β³ Waiting 2 seconds for CRD to be ready..."
sleep 2
echo ""
echo "π Creating example WebApp (nginx-app)..."
kubectl apply -f examples/nginx-webapp.yaml
echo "β
WebApp created!"
echo ""
echo "π Current resources:"
kubectl get webapps,deployments,services -l managed-by=webapp-operator
echo ""
echo "β οΈ Note: You need to run the operator for it to work!"
echo " Run: go run main.go"
;;
4)
echo ""
echo "π¬ Starting full demo..."
echo ""
echo "π¦ Installing CRD..."
kubectl apply -f crd/webapp-crd.yaml
echo "β
CRD installed!"
echo ""
echo "π₯ Downloading Go dependencies..."
go mod download
echo "β
Dependencies ready!"
echo ""
echo "β³ Waiting 2 seconds for CRD to be ready..."
sleep 2
echo ""
echo "π Creating example WebApp..."
kubectl apply -f examples/nginx-webapp.yaml
echo "β
WebApp created!"
echo ""
echo "π Initial state:"
kubectl get webapps
echo ""
echo "π Starting operator..."
echo " Watch it create Deployment and Service automatically!"
echo " (Press Ctrl+C to stop)"
echo ""
go run main.go
;;
5)
echo ""
echo "π§Ή Cleaning up..."
echo ""
echo "Deleting WebApp resources..."
kubectl delete -f examples/ --ignore-not-found=true
echo ""
echo "Deleting CRD (this also deletes all WebApp custom resources)..."
kubectl delete -f crd/webapp-crd.yaml --ignore-not-found=true
echo ""
echo "β
Cleanup complete!"
echo ""
echo "Remaining deployments and services will be garbage collected by Kubernetes."
;;
*)
echo "Invalid choice. Exiting."
exit 1
;;
esac
echo ""
echo "π For more information, see README.md"