Skip to content

Commit

Permalink
refactor: remove unused stakater annotations and add helper loop to c…
Browse files Browse the repository at this point in the history
…lean up old annotations
  • Loading branch information
shreddedbacon committed Nov 20, 2023
1 parent ab2e6d1 commit 08c75d6
Show file tree
Hide file tree
Showing 41 changed files with 99 additions and 164 deletions.
18 changes: 4 additions & 14 deletions internal/templating/ingress/templates_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,16 @@ func GenerateIngressTemplate(
}
if lValues.EnvironmentType == "production" {
// monitoring is only available in production environments
additionalAnnotations["monitor.stakater.com/enabled"] = "false"
primaryIngress, _ := url.Parse(lValues.Route)
// check if monitoring enabled, route isn't autogenerated, and the primary ingress from the .lagoon.yml is this processed routedomain
// and enable monitoring on the primary ingress only.
if lValues.Monitoring.Enabled && !route.Autogenerated && primaryIngress.Host == route.Domain {
additionalLabels["lagoon.sh/primaryIngress"] = "true"

// only add the monitring annotations if monitoring is enabled
additionalAnnotations["monitor.stakater.com/enabled"] = "true"
additionalAnnotations["uptimerobot.monitor.stakater.com/alert-contacts"] = "unconfigured"
if lValues.Monitoring.AlertContact != "" {
additionalAnnotations["uptimerobot.monitor.stakater.com/alert-contacts"] = lValues.Monitoring.AlertContact
}
if lValues.Monitoring.StatusPageID != "" {
additionalAnnotations["uptimerobot.monitor.stakater.com/status-pages"] = lValues.Monitoring.StatusPageID
}
additionalAnnotations["uptimerobot.monitor.stakater.com/interval"] = "60"
additionalLabels["route.lagoon.sh/primary"] = "true"
} else {
additionalLabels["route.lagoon.sh/primary"] = "false"
}
if route.MonitoringPath != "" {
additionalAnnotations["monitor.stakater.com/overridePath"] = route.MonitoringPath
additionalAnnotations["route.lagoon.sh/path-override"] = route.MonitoringPath
}
}
if route.Fastly.ServiceID != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: environment-with-really-really-reall-3fdb
lagoon.sh/version: v2.x.x
monitor.stakater.com/enabled: "true"
monitor.stakater.com/overridePath: /
nginx.ingress.kubernetes.io/ssl-redirect: "true"
uptimerobot.monitor.stakater.com/alert-contacts: abcdefg
uptimerobot.monitor.stakater.com/interval: "60"
uptimerobot.monitor.stakater.com/status-pages: "12345"
route.lagoon.sh/path-override: /
creationTimestamp: null
labels:
app.kubernetes.io/instance: extra-long-name-f6c8a
Expand All @@ -26,10 +22,10 @@ metadata:
lagoon.sh/buildType: branch
lagoon.sh/environment: environment-with-really-really-reall-3fdb
lagoon.sh/environmentType: production
lagoon.sh/primaryIngress: "true"
lagoon.sh/project: example-project
lagoon.sh/service: extra-long-name-f6c8a
lagoon.sh/service-type: custom-ingress
route.lagoon.sh/primary: "true"
name: extra-long-name.a-really-long-name-that-should-truncate.www.example.com
spec:
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: environment-with-really-really-reall-3fdb
lagoon.sh/version: v2.x.x
monitor.stakater.com/enabled: "true"
monitor.stakater.com/overridePath: /
nginx.ingress.kubernetes.io/ssl-redirect: "true"
uptimerobot.monitor.stakater.com/alert-contacts: abcdefg
uptimerobot.monitor.stakater.com/interval: "60"
uptimerobot.monitor.stakater.com/status-pages: "12345"
route.lagoon.sh/path-override: /
creationTimestamp: null
labels:
app.kubernetes.io/instance: extra-long-name-f6c8a
Expand All @@ -26,10 +22,10 @@ metadata:
lagoon.sh/buildType: branch
lagoon.sh/environment: environment-with-really-really-reall-3fdb
lagoon.sh/environmentType: production
lagoon.sh/primaryIngress: "true"
lagoon.sh/project: example-project
lagoon.sh/service: extra-long-name-f6c8a
lagoon.sh/service-type: custom-ingress
route.lagoon.sh/primary: "true"
name: extra-long-name.a-really-long-name-that-should-truncate.www.example.com
spec:
rules:
Expand Down
29 changes: 29 additions & 0 deletions legacy/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,35 @@ fi
# Load all routes with correct schema and comma separated
ROUTES=$(kubectl -n ${NAMESPACE} get ingress --sort-by='{.metadata.name}' -l "acme.openshift.io/exposer!=true" -o=go-template --template='{{range $indexItems, $ingress := .items}}{{if $indexItems}},{{end}}{{$tls := .spec.tls}}{{range $indexRule, $rule := .spec.rules}}{{if $indexRule}},{{end}}{{if $tls}}https://{{else}}http://{{end}}{{.host}}{{end}}{{end}}')

# remove stakater annotations, and fix primary label
for ingress in $(kubectl -n ${NAMESPACE} get ingress -o json | jq -r '.items[] | @base64'); do
_jq() {
echo ${ingress} | base64 --decode | jq -r ${1}
}
INGRESS_NAME=$(echo $(_jq '.') | jq -r '.metadata.name')
PRIMARY=$(echo $(_jq '.') | jq -r '.metadata.labels["lagoon.sh/primaryIngress"] // false ')
OVERRIDE=$(echo $(_jq '.') | jq -r '.metadata.annotations["monitor.stakater.com/overridePath"] // empty ')
PATCH='{
"metadata": {
"annotations": {
"monitor.stakater.com/enabled": null,
"monitor.stakater.com/overridePath": null,
"uptimerobot.monitor.stakater.com/alert-contacts": null,
"uptimerobot.monitor.stakater.com/interval": null,
"uptimerobot.monitor.stakater.com/status-pages": null
},
"labels": {
"route.lagoon.sh/primary": "'${PRIMARY}'"
}
}
}'
# if the ingress has a stakater override path annotation defined, change it to the new annotation
if [ ! -z "${OVERRIDE}" ]; then
PATCH=$(echo "${PATCH}" | jq '.metadata.annotations += {"route.lagoon.sh/path-override":"'${OVERRIDE}'"}')
fi
kubectl -n ${NAMESPACE} patch ingress ${INGRESS_NAME} -p "${PATCH}"
done

# Active / Standby routes
ACTIVE_ROUTES=""
STANDBY_ROUTES=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "false"
nginx.ingress.kubernetes.io/server-snippet: |
add_header X-Robots-Tag "noindex, nofollow";
nginx.ingress.kubernetes.io/ssl-redirect: "true"
Expand All @@ -26,6 +25,7 @@ metadata:
lagoon.sh/project: example-project
lagoon.sh/service: node
lagoon.sh/service-type: node
route.lagoon.sh/primary: "false"
name: node
spec:
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "false"
nginx.ingress.kubernetes.io/server-snippet: |
add_header X-Robots-Tag "noindex, nofollow";
nginx.ingress.kubernetes.io/ssl-redirect: "true"
Expand All @@ -28,6 +27,7 @@ metadata:
lagoon.sh/project: example-project
lagoon.sh/service: node
lagoon.sh/service-type: node
route.lagoon.sh/primary: "false"
name: node
spec:
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ metadata:
kubernetes.io/tls-acme: "false"
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "false"
nginx.ingress.kubernetes.io/server-snippet: |
add_header X-Robots-Tag "noindex, nofollow";
nginx.ingress.kubernetes.io/ssl-redirect: "true"
Expand All @@ -26,6 +25,7 @@ metadata:
lagoon.sh/project: example-project
lagoon.sh/service: node
lagoon.sh/service-type: node
route.lagoon.sh/primary: "false"
name: node
spec:
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ metadata:
kubernetes.io/tls-acme: "false"
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "false"
nginx.ingress.kubernetes.io/server-snippet: |
add_header X-Robots-Tag "noindex, nofollow";
nginx.ingress.kubernetes.io/ssl-redirect: "true"
Expand All @@ -26,6 +25,7 @@ metadata:
lagoon.sh/project: example-project
lagoon.sh/service: node
lagoon.sh/service-type: node
route.lagoon.sh/primary: "false"
name: node
spec:
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ metadata:
lagoon.sh/prHeadBranch: main
lagoon.sh/prNumber: "123"
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "false"
nginx.ingress.kubernetes.io/server-snippet: |
add_header X-Robots-Tag "noindex, nofollow";
nginx.ingress.kubernetes.io/ssl-redirect: "true"
Expand All @@ -28,6 +27,7 @@ metadata:
lagoon.sh/project: example-project
lagoon.sh/service: node
lagoon.sh/service-type: node
route.lagoon.sh/primary: "false"
name: node
spec:
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "false"
nginx.ingress.kubernetes.io/server-snippet: |
add_header X-Robots-Tag "noindex, nofollow";
nginx.ingress.kubernetes.io/ssl-redirect: "true"
Expand All @@ -26,6 +25,7 @@ metadata:
lagoon.sh/project: example-project
lagoon.sh/service: node
lagoon.sh/service-type: node
route.lagoon.sh/primary: "false"
name: node
spec:
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "false"
nginx.ingress.kubernetes.io/server-snippet: |
add_header X-Robots-Tag "noindex, nofollow";
nginx.ingress.kubernetes.io/ssl-redirect: "true"
Expand All @@ -26,6 +25,7 @@ metadata:
lagoon.sh/project: example-project
lagoon.sh/service: node
lagoon.sh/service-type: node
route.lagoon.sh/primary: "false"
name: node
spec:
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "false"
nginx.ingress.kubernetes.io/server-snippet: |
add_header X-Robots-Tag "noindex, nofollow";
nginx.ingress.kubernetes.io/ssl-redirect: "true"
Expand All @@ -26,6 +25,7 @@ metadata:
lagoon.sh/project: example-project
lagoon.sh/service: node
lagoon.sh/service-type: node
route.lagoon.sh/primary: "false"
name: node
spec:
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: short-router-url-from-a-very-long-environment-name-like-this
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "false"
nginx.ingress.kubernetes.io/server-snippet: |
add_header X-Robots-Tag "noindex, nofollow";
nginx.ingress.kubernetes.io/ssl-redirect: "true"
Expand All @@ -26,6 +25,7 @@ metadata:
lagoon.sh/project: ci-features-control-k8s
lagoon.sh/service: node
lagoon.sh/service-type: node
route.lagoon.sh/primary: "false"
name: node
spec:
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "false"
nginx.ingress.kubernetes.io/server-snippet: |
add_header X-Robots-Tag "noindex, nofollow";
nginx.ingress.kubernetes.io/ssl-redirect: "true"
Expand All @@ -26,6 +25,7 @@ metadata:
lagoon.sh/project: example-project
lagoon.sh/service: node
lagoon.sh/service-type: node
route.lagoon.sh/primary: "false"
name: node
spec:
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "false"
nginx.ingress.kubernetes.io/server-snippet: |
add_header X-Robots-Tag "noindex, nofollow";
nginx.ingress.kubernetes.io/ssl-redirect: "true"
Expand All @@ -27,6 +26,7 @@ metadata:
lagoon.sh/project: example-project
lagoon.sh/service: node
lagoon.sh/service-type: node
route.lagoon.sh/primary: "false"
name: node
spec:
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "false"
nginx.ingress.kubernetes.io/server-snippet: |
add_header X-Robots-Tag "noindex, nofollow";
nginx.ingress.kubernetes.io/ssl-redirect: "true"
Expand All @@ -27,6 +26,7 @@ metadata:
lagoon.sh/project: example-project
lagoon.sh/service: node
lagoon.sh/service-type: node
route.lagoon.sh/primary: "false"
name: node
spec:
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "true"
monitor.stakater.com/overridePath: /
nginx.ingress.kubernetes.io/ssl-redirect: "true"
uptimerobot.monitor.stakater.com/alert-contacts: alertcontact
uptimerobot.monitor.stakater.com/interval: "60"
uptimerobot.monitor.stakater.com/status-pages: statuspageid
route.lagoon.sh/path-override: /
creationTimestamp: null
labels:
app.kubernetes.io/instance: example.com
Expand All @@ -27,10 +23,10 @@ metadata:
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/primaryIngress: "true"
lagoon.sh/project: example-project
lagoon.sh/service: example.com
lagoon.sh/service-type: custom-ingress
route.lagoon.sh/primary: "true"
name: example.com
spec:
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main2
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "false"
monitor.stakater.com/overridePath: /
nginx.ingress.kubernetes.io/ssl-redirect: "true"
route.lagoon.sh/path-override: /
creationTimestamp: null
labels:
app.kubernetes.io/instance: main2.example.com
Expand All @@ -25,6 +24,7 @@ metadata:
lagoon.sh/project: example-project
lagoon.sh/service: main2.example.com
lagoon.sh/service-type: custom-ingress
route.lagoon.sh/primary: "false"
name: main2.example.com
spec:
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main2
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "true"
monitor.stakater.com/overridePath: /
nginx.ingress.kubernetes.io/ssl-redirect: "true"
uptimerobot.monitor.stakater.com/alert-contacts: alertcontact
uptimerobot.monitor.stakater.com/interval: "60"
uptimerobot.monitor.stakater.com/status-pages: statuspageid
route.lagoon.sh/path-override: /
creationTimestamp: null
labels:
app.kubernetes.io/instance: standby.example.com
Expand All @@ -25,10 +21,10 @@ metadata:
lagoon.sh/buildType: branch
lagoon.sh/environment: main2
lagoon.sh/environmentType: production
lagoon.sh/primaryIngress: "true"
lagoon.sh/project: example-project
lagoon.sh/service: standby.example.com
lagoon.sh/service-type: custom-ingress
route.lagoon.sh/primary: "true"
name: standby.example.com
spec:
rules:
Expand Down
Loading

0 comments on commit 08c75d6

Please sign in to comment.