Skip to content

Commit de080f4

Browse files
committed
Install monitoring-satellite with obs-installer
1 parent 3743c60 commit de080f4

File tree

3 files changed

+97
-90
lines changed

3 files changed

+97
-90
lines changed
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
SCRIPT_PATH=$(realpath "$(dirname "$0")")
6+
7+
if [[ -z "${PREVIEW_NAME}" ]]; then
8+
echo "Must set PREVIEW_NAME variable" 1>&2
9+
exit 1
10+
fi
11+
12+
if [[ -z "${KUBE_PATH}" ]]; then
13+
echo "Must set KUBE_PATH variable" 1>&2
14+
exit 1
15+
fi
16+
17+
# exports all vars
18+
shopt -os allexport
19+
20+
kubectl --kubeconfig "${KUBE_PATH}" create ns monitoring-satellite || true
21+
kubectl --kubeconfig "${KUBE_PATH}" create ns certmanager || true
22+
23+
if ! command -v envsubst; then
24+
go install github.com/a8m/envsubst/cmd/envsubst@latest
25+
fi
26+
27+
obsDir="${SCRIPT_PATH}/observability"
28+
mkdir -p "${obsDir}"
29+
git clone https://roboquat:"$(cat /mnt/secrets/monitoring-satellite-preview-token/token)"@github.com/gitpod-io/observability.git "${obsDir}"
30+
cd "${obsDir}/installer"
31+
32+
tmpdir=$(mktemp -d)
33+
34+
envsubst <"${SCRIPT_PATH}/manifests/monitoring-satellite.yaml" | go run main.go render --output-split-files "${tmpdir}" --config -
35+
36+
pushd "${tmpdir}"
37+
38+
# we have to apply the CRDs first and wait until they are available before we can apply the rest
39+
find . -name "*CustomResourceDefinition*" -exec kubectl --kubeconfig "${KUBE_PATH}" apply -f {} --server-side \;
40+
41+
# wait for the CRDs
42+
kubectl --kubeconfig "${KUBE_PATH}" -n monitoring-satellite wait --for condition=established --timeout=60s crd/servicemonitors.monitoring.coreos.com
43+
44+
kubectl --kubeconfig "${KUBE_PATH}" apply --server-side -f .
45+
46+
kubectl --kubeconfig "${KUBE_PATH}" patch deployments.apps -n monitoring-satellite grafana --type=json -p="[{'op': 'remove', 'path': '/spec/template/spec/nodeSelector'}]"
47+
48+
popd
49+
popd
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace: monitoring-satellite
2+
certmanager:
3+
installServiceMonitors: true
4+
pyrra:
5+
install: true
6+
prometheus:
7+
externalLabels:
8+
cluster: ${PREVIEW_NAME}
9+
environment: preview-environments
10+
resources:
11+
requests:
12+
cpu: 50m
13+
memory: 200Mi
14+
remoteWrite:
15+
- username: ${PROM_REMOTE_WRITE_USER}
16+
password: ${PROM_REMOTE_WRITE_PASSWORD}
17+
url: "https://victoriametrics.gitpod.io/api/v1/write"
18+
writeRelabelConfigs:
19+
- action: keep
20+
regex: "rest_client_requests_total.*|http_prober_.*"
21+
separator: ";"
22+
sourceLabels:
23+
- __name__
24+
- job
25+
imports:
26+
yaml:
27+
- gitURL: https://github.com/gitpod-io/observability
28+
path: monitoring-satellite/manifests/kube-prometheus-rules
29+
- gitURL: https://github.com/gitpod-io/observability
30+
path: monitoring-satellite/manifests/crds
31+
- gitURL: https://github.com/gitpod-io/observability
32+
path: monitoring-satellite/manifests/kubescape
33+
- gitURL: https://github.com/gitpod-io/observability
34+
path: monitoring-satellite/manifests/grafana
35+
- gitURL: https://github.com/gitpod-io/observability
36+
path: monitoring-satellite/manifests/probers
+12-90
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { exec } from "../util/shell";
2-
import { Werft } from "../util/werft";
3-
import * as fs from "fs";
1+
import {exec} from "../util/shell";
2+
import {Werft} from "../util/werft";
43

54
type MonitoringSatelliteInstallerOptions = {
65
werft: Werft;
@@ -20,7 +19,8 @@ const sliceName = "observability";
2019
* Installs monitoring-satellite, while updating its dependencies to the latest commit in the branch it is running.
2120
*/
2221
export class MonitoringSatelliteInstaller {
23-
constructor(private readonly options: MonitoringSatelliteInstallerOptions) {}
22+
constructor(private readonly options: MonitoringSatelliteInstallerOptions) {
23+
}
2424

2525
public async install() {
2626
const {
@@ -31,94 +31,16 @@ export class MonitoringSatelliteInstaller {
3131

3232
werft.log(
3333
sliceName,
34-
`Cloning observability repository - Branch: ${branch}`,
35-
);
36-
exec(
37-
`git clone --branch ${branch} https://roboquat:$(cat /mnt/secrets/monitoring-satellite-preview-token/token)@github.com/gitpod-io/observability.git`,
38-
{ silent: true },
39-
);
40-
let currentCommit = exec(`git rev-parse HEAD`, { silent: true }).stdout.trim();
41-
let pwd = exec(`pwd`, { silent: true }).stdout.trim();
42-
werft.log(
43-
sliceName,
44-
`Updating Gitpod's mixin in monitoring-satellite's jsonnetfile.json to latest commit SHA: ${currentCommit}`,
34+
`Installing observability stack - Branch: ${branch}`,
4535
);
4636

47-
let jsonnetFile = JSON.parse(fs.readFileSync(`${pwd}/observability/jsonnetfile.json`, "utf8"));
48-
jsonnetFile.dependencies.forEach((dep) => {
49-
if (dep.name == "gitpod") {
50-
dep.version = currentCommit;
51-
}
52-
});
53-
fs.writeFileSync(`${pwd}/observability/jsonnetfile.json`, JSON.stringify(jsonnetFile));
54-
exec(`cd observability && jb update`, { slice: sliceName });
55-
56-
// As YAML is indentation sensitive we're using json instead so we don't have to worry about
57-
// getting the indentation right when formatting the code in TypeScript.
58-
const observabilityInstallerRenderCmd = `cd observability && \
59-
make generate && \
60-
./hack/deploy-crds.sh --kubeconfig ${this.options.kubeconfigPath} && \
61-
kubectl create ns monitoring-satellite --kubeconfig ${this.options.kubeconfigPath} || true && \
62-
cd installer && echo '
63-
{
64-
"gitpod": {
65-
"installServiceMonitors": true
66-
},
67-
"pyrra": {
68-
"install": true
69-
},
70-
"prometheus": {
71-
"externalLabels": {
72-
"cluster": "${previewName}",
73-
"environment": "preview-environments",
74-
},
75-
"resources": {
76-
"requests": {
77-
"memory": "200Mi",
78-
"cpu": "50m",
79-
},
80-
},
81-
"remoteWrite": [{
82-
"username": "${process.env.PROM_REMOTE_WRITE_USER}",
83-
"password": "${process.env.PROM_REMOTE_WRITE_PASSWORD}",
84-
"url": "https://victoriametrics.gitpod.io/api/v1/write",
85-
"writeRelabelConfigs": [{
86-
"sourceLabels": ["__name__", "job"],
87-
"separator": ";",
88-
"regex": "rest_client_requests_total.*|http_prober_.*",
89-
"action": "keep",
90-
}],
91-
}],
92-
},
93-
"imports": {
94-
"yaml": [{
95-
"gitURL": "https://github.com/gitpod-io/observability",
96-
"path": "monitoring-satellite/manifests/kube-prometheus-rules",
97-
},
98-
{
99-
"gitURL": "https://github.com/gitpod-io/observability",
100-
"path": "monitoring-satellite/manifests/kubescape",
101-
},
102-
{
103-
"gitURL": "https://github.com/gitpod-io/observability",
104-
"path": "monitoring-satellite/manifests/grafana",
105-
},
106-
{
107-
"gitURL": "https://github.com/gitpod-io/observability",
108-
"path": "monitoring-satellite/manifests/probers",
109-
}],
110-
},
111-
}' | go run main.go render --config - | kubectl --kubeconfig ${this.options.kubeconfigPath} apply -f -`;
112-
const renderingResult = exec(observabilityInstallerRenderCmd, { silent: false, dontCheckRc: true});
113-
if (renderingResult.code > 0) {
114-
const err = new Error(`Failed rendering YAML with exit code ${renderingResult.code}`)
115-
renderingResult.stderr.split('\n').forEach(stderrLine => werft.log(sliceName, stderrLine))
116-
werft.failSlice(sliceName, err)
117-
return
118-
}
37+
const installSatellite = exec(`KUBE_PATH=${this.options.kubeconfigPath} PREVIEW_NAME=${previewName} .werft/observability/install-satellite.sh`, {slice: sliceName});
11938

120-
// The grafana YAML files we're importing have nodeSelector tied to a nodepool that don't exist in previews
121-
// We're hot-patching the removal os such nodeSelector to make sure Grafana starts
122-
exec(`kubectl patch deployments.apps -n monitoring-satellite grafana --type=json -p="[{'op': 'remove', 'path': '/spec/template/spec/nodeSelector'}]"`)
39+
if (installSatellite.code > 0) {
40+
const err = new Error(`Failed installing monitoring-satellite`)
41+
installSatellite.stderr.split('\n').forEach(stderrLine => werft.log(sliceName, stderrLine))
42+
werft.failSlice(sliceName, err)
43+
return
44+
}
12345
}
12446
}

0 commit comments

Comments
 (0)