-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgitops.sh
executable file
·162 lines (134 loc) · 2.76 KB
/
gitops.sh
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
#!/usr/bin/env bash
set -e
# CONSTANTS
readonly DNSMASQ_DOMAIN=kind.cluster
# FUNCTIONS
log(){
echo "---------------------------------------------------------------------------------------"
echo $1
echo "---------------------------------------------------------------------------------------"
}
get_subnet(){
docker network inspect -f '{{(index .IPAM.Config 0).Subnet}}' $1
}
subnet_to_ip(){
echo $1 | sed "[email protected]/16@$2@"
}
cleanup(){
log "CLEANUP ..."
rm -rf .gitops
}
init(){
log "INIT ..."
mkdir .gitops
git init .gitops
git -C .gitops remote add origin http://gitea_admin:[email protected]/gitea_admin/gitops.git
git -C .gitops fetch --all || true
git -C .gitops pull origin master || true
}
install(){
log "INSTALL ..."
rm -rf .gitops/helm
cp -r helm/ .gitops/
cat <<EOF > .gitops/config.yaml
prometheus:
operator:
enabled: false
dns:
private: $DNSMASQ_DOMAIN
metallb:
start: $METALLB_START
end: $METALLB_END
applications:
argocd:
enabled: true
certManager:
enabled: true
cilium:
enabled: true
gitea:
enabled: true
ingressNginx:
enabled: true
keycloak:
enabled: true
kubeview:
enabled: true
kyverno:
enabled: true
kyvernoPolicies:
enabled: true
metallb:
enabled: true
metricsServer:
enabled: true
nodeProblemDetector:
enabled: true
policyReporter:
enabled: true
rbacManager:
enabled: true
EOF
}
push(){
log "PUSH ..."
git -C .gitops add .
git -C .gitops commit -m "gitops" --allow-empty
git -C .gitops push -u origin master
}
bootstrap(){
log "BOOTSTRAP ..."
local KIND_SUBNET=$(get_subnet kind)
local METALLB_START=$(subnet_to_ip $KIND_SUBNET 255.200)
local METALLB_END=$(subnet_to_ip $KIND_SUBNET 255.250)
kubectl apply -n argocd -f - <<EOF
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: gitops
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: default
source:
repoURL: http://gitea.kind.cluster/gitea_admin/gitops
path: helm/gitops
targetRevision: HEAD
helm:
values: |
prometheus:
operator:
enabled: false
dns:
private: $DNSMASQ_DOMAIN
metallb:
start: $METALLB_START
end: $METALLB_END
destination:
server: https://kubernetes.default.svc
namespace: argocd
revisionHistoryLimit: 3
syncPolicy:
syncOptions:
- ApplyOutOfSyncOnly=true
- CreateNamespace=true
- FailOnSharedResource=true
- PruneLast=true
automated:
prune: true
selfHeal: true
EOF
}
unhelm(){
log "REMOVE HELM SECRETS ..."
kubectl delete secret -A -l owner=helm
}
# RUN
cleanup
init
install
push
bootstrap
unhelm
# DONE
log "GITOPS READY !"