-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
168 lines (151 loc) · 8.57 KB
/
update.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
163
164
165
166
167
168
#!/bin/bash
set -e pipefail
tempdir=$(mktemp -d)
### Helper
get_latest_release() {
curl --silent "https://api.github.com/repos/$1/releases" | # Get latest release from GitHub api
jq --raw-output 'map(select(.tag_name | test("^v.*"))) | map(select(.prerelease | not)) | map(select(.tag_name | test(".*beta.*")|not)) | map(select(.tag_name | test(".*alpha.*")|not)) | map(select(.tag_name | test(".*rc.*")|not)) | first | .tag_name' # get the tag from tag_name
}
helm repo add traefik https://traefik.github.io/charts
helm repo add external-secrets https://charts.external-secrets.io
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
argoCDVersion=$(get_latest_release "argoproj/argo-cd")
cd k8s/argocd
rm -rf resources/render/
mkdir -p resources/render
kubectl create ns argocd -o yaml --dry-run=client > resources/render/ns.yaml
curl -s https://raw.githubusercontent.com/argoproj/argo-cd/$argoCDVersion/manifests/install.yaml | yq -s '"resources/render/" + .metadata.name + "-" + .kind + ".yml"' -
cd resources/render/
kustomize create app --recursive --autodetect
cd ../../../..
echo "Upgraded argocd to $argoCDVersion"
cd k8s/tekton
rm -rf resources/render/
mkdir -p resources/render
curl -s https://storage.googleapis.com/tekton-releases/operator/latest/release.yaml | yq -s '"resources/render/" + .metadata.name + "-" + .kind + ".yml"' -
curl -s https://raw.githubusercontent.com/tektoncd/operator/main/config/crs/kubernetes/config/all/operator_v1alpha1_config_cr.yaml | yq -s '"resources/render/" + .metadata.name + "-" + .kind + ".yml"' -
rm .yml
cd resources/render/
kustomize create app --recursive --autodetect
kustomize edit set namespace tekton-operator
cd ../../../..
echo "Upgraded tekton"
certManagerVersion=$(get_latest_release "cert-manager/cert-manager")
cd k8s/certmanager
rm -rf resources/render/
mkdir -p resources/render
curl -sL https://github.com/cert-manager/cert-manager/releases/download/$certManagerVersion/cert-manager.yaml | yq -s '"resources/render/" + .metadata.name + "-" + .kind + ".yml"' -
cd resources/render/
kustomize create app --recursive --autodetect
cd ../../../..
echo "Upgraded certmanager to $certManagerVersion"
cd k8s/traefik
rm -rf resources/render/
mkdir -p resources/render
helm template traefik traefik/traefik \
-n traefik \
--set globalArguments= \
--set providers.kubernetesIngress.publishedService.enabled=true \
--set ingressRoute.dashboard.enabled=false \
| yq -s '"resources/render/" + .metadata.name + "-" + .kind + ".yml"' -
curl -sL https://raw.githubusercontent.com/traefik/traefik/master/docs/content/reference/dynamic-configuration/kubernetes-crd-definition-v1.yml | yq -s '"resources/render/" + .metadata.name + "-" + .kind + ".yml"' -
curl -sL https://raw.githubusercontent.com/traefik/traefik/master/docs/content/reference/dynamic-configuration/kubernetes-crd-rbac.yml | yq -s '"resources/render/" + .metadata.name + "-" + .kind + ".yml"' -
cd resources/render/
kustomize create app --recursive --autodetect
cd ../../../..
echo "Upgraded traefik"
mkdir -p k8s/prometheus-operator || true
cd k8s/prometheus-operator
rm -rf resources/render/ || true
mkdir -p resources/render
prometheusOperator=$(get_latest_release "prometheus-operator/prometheus-operator")
# curl -sL https://github.com/prometheus-operator/prometheus-operator/releases/download/${prometheusOperator}/bundle.yaml \
# | yq -s '"resources/render/" + .metadata.name + "-" + .kind + ".yml"' -
git clone -q --depth=1 https://github.com/prometheus-operator/prometheus-operator.git --branch $prometheusOperator $tempdir/prometheus-operator 2> /dev/null
cp $tempdir/prometheus-operator/example/prometheus-operator-crd/* resources/render
cp $tempdir/prometheus-operator/example/rbac/prometheus-operator/prometheus-operator-deployment.yaml resources/render
cp $tempdir/prometheus-operator/example/rbac/prometheus-operator/prometheus-operator-service.yaml resources/render
cp $tempdir/prometheus-operator/example/rbac/prometheus-operator/prometheus-operator-service-account.yaml resources/render
cp $tempdir/prometheus-operator/example/rbac/prometheus-operator/prometheus-operator-service-monitor.yaml resources/render
cp $tempdir/prometheus-operator/example/rbac/prometheus-operator/prometheus-operator-cluster-role.yaml resources/render
cp $tempdir/prometheus-operator/example/rbac/prometheus-operator/prometheus-operator-cluster-role-binding.yaml resources/render
cp $tempdir/prometheus-operator/example/rbac/prometheus-operator-crd/prometheus-operator-crd-cluster-roles.yaml resources/render
cd resources/render
kustomize create app --recursive --autodetect
cd ../../../..
echo "Upgraded prometheus-operator to $prometheusOperator"
mkdir -p k8s/monitoring || true
cd k8s/monitoring
rm -rf resources/render/ || true
mkdir -p resources/render
kubePrometheus=$(get_latest_release "prometheus-operator/kube-prometheus")
git clone -q --depth=1 https://github.com/prometheus-operator/kube-prometheus.git --branch $kubePrometheus $tempdir/kube-prometheus 2> /dev/null
mkdir -p resources/render/kube-state-metrics/ || true
mkdir -p resources/render/blackbox-exporter/ || true
mkdir -p resources/render/kubernetes/ || true
mkdir -p resources/render/node-exporter/ || true
mkdir -p resources/render/prometheus/ || true
mkdir -p resources/render/alertmanager/ || true
cp $tempdir/kube-prometheus/manifests/kubeStateMetrics-* resources/render/kube-state-metrics/
cp $tempdir/kube-prometheus/manifests/blackboxExporter-* resources/render/blackbox-exporter/
cp $tempdir/kube-prometheus/manifests/kubernetes* resources/render/kubernetes/
cp $tempdir/kube-prometheus/manifests/nodeExporter-* resources/render/node-exporter/
cp $tempdir/kube-prometheus/manifests/alertmanager-* resources/render/alertmanager/
thanosVersion=$(get_latest_release "thanos-io/thanos")
yq -i ".[0].value.version |= \"$thanosVersion\"" patches/prometheus-thanos.yaml
yq -i ".images[0].newTag |= \"$thanosVersion\"" kustomization.yaml
kubeThanosVersion=$(get_latest_release "thanos-io/kube-thanos")
git clone -q --depth=1 https://github.com/thanos-io/kube-thanos.git --branch $kubeThanosVersion $tempdir/kube-thanos 2> /dev/null
mkdir -p resources/render/thanos/ || true
cp $tempdir/kube-thanos/manifests/thanos-query* resources/render/thanos/
cp $tempdir/kube-thanos/manifests/thanos-store* resources/render/thanos/
# needed to be selective to take all namespaces easily
cp $tempdir/kube-prometheus/manifests/prometheus-* resources/render/prometheus/
cp $tempdir/prometheus-operator/example/rbac/prometheus/prometheus-cluster-role-binding.yaml resources/render/prometheus/prometheus-clusterRoleBinding.yaml
cp $tempdir/prometheus-operator/example/rbac/prometheus/prometheus-cluster-role.yaml resources/render/prometheus/prometheus-clusterRole.yaml
rm resources/render/prometheus/prometheus-*SpecificNamespaces.yaml
cd resources/render
kustomize create app --recursive --autodetect
cd ../../../..
echo "Upgraded kube-prometheus to $kubePrometheus"
echo "Upgraded kube-thanos to $kubeThanosVersion"
echo "Upgraded thanos to $thanosVersion"
grafanaOperator=$(get_latest_release "grafana-operator/grafana-operator")
mkdir -p k8s/grafana-operator || true
cd k8s/grafana-operator
rm -rf resources/render/
mkdir -p resources/render
kustomize build "https://github.com/grafana-operator/grafana-operator//deploy/kustomize/overlays/cluster_scoped?ref=$grafanaOperator" \
| yq -s '"resources/render/" + .metadata.name + "-" + .kind + ".yml"' -
cd resources/render
kustomize create app --recursive --autodetect
cd ../../../..
echo "Upgraded grafana-operator to $grafanaOperator"
mkdir -p k8s/dashboarding || true
cd k8s/dashboarding
rm -rf resources/render/
mkdir -p resources/render
helm template grafana-operator \
bitnami/grafana-operator \
-n grafana-operator \
--set namespaceOverride=grafana \
--set operator.enabled=false \
--set grafana.enabled=true | yq -s '"resources/render/" + .metadata.name + "-" + .kind + ".yml"' -
cd resources/render
kustomize create app --recursive --autodetect
cd ../../../..
echo "Upgraded dashboarding"
eckOperator=$(get_latest_release "elastic/cloud-on-k8s" | sed 's|v||' ) # hack to remove the v from the version
mkdir -p k8s/elastic-operator || true
cd k8s/elastic-operator
rm -rf resources/render/
mkdir -p resources/render
curl -s https://download.elastic.co/downloads/eck/$eckOperator/crds.yaml | yq -s '"resources/render/" + .metadata.name + "-" + .kind + ".yml"' -
curl -s https://download.elastic.co/downloads/eck/$eckOperator/operator.yaml | yq -s '"resources/render/" + .metadata.name + "-" + .kind + ".yml"' -
cd resources/render
kustomize create app --recursive --autodetect
cd ../../../..
echo "Upgraded elastic-operator to $eckOperator"
# # Cleanup
rm -rf $tempdir