Skip to content

Commit

Permalink
fix: monitoring only on primary route (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon authored Sep 20, 2022
1 parent bcac570 commit 3f9bbad
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 18 deletions.
18 changes: 18 additions & 0 deletions cmd/template_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,24 @@ func TestTemplateRoutes(t *testing.T) {
},
want: "../test-resources/template-ingress/test17-results",
},
{
name: "test18 check first route has monitoring only",
args: args{
alertContact: "alertcontact",
statusPageID: "statuspageid",
projectName: "example-project",
environmentName: "main",
environmentType: "production",
buildType: "branch",
lagoonVersion: "v2.7.x",
branch: "main",
projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`,
envVars: `[]`,
lagoonYAML: "../test-resources/template-ingress/test18/lagoon.yml",
templatePath: "../test-resources/template-ingress/output",
},
want: "../test-resources/template-ingress/test18-results",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
6 changes: 5 additions & 1 deletion internal/templating/ingress/templates_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package routes

import (
"fmt"
"net/url"
"strconv"
"strings"

Expand Down Expand Up @@ -85,7 +86,10 @@ func GenerateIngressTemplate(
if lValues.EnvironmentType == "production" {
// monitoring is only available in production environments
additionalAnnotations["monitor.stakater.com/enabled"] = "false"
if lValues.Monitoring.Enabled && !route.Autogenerated {
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 == routeDomain {
// only add the monitring annotations if monitoring is enabled
additionalAnnotations["monitor.stakater.com/enabled"] = "true"
additionalAnnotations["uptimerobot.monitor.stakater.com/alert-contacts"] = "unconfigured"
Expand Down
8 changes: 7 additions & 1 deletion internal/templating/ingress/templates_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func TestGenerateKubeTemplate(t *testing.T) {
StatusPageID: "12345",
Enabled: true,
},
Route: "https://extra-long-name.a-really-long-name-that-should-truncate.www.example.com/",
},
activeStandby: true,
},
Expand Down Expand Up @@ -91,6 +92,7 @@ func TestGenerateKubeTemplate(t *testing.T) {
StatusPageID: "12345",
Enabled: true,
},
Route: "https://extra-long-name.a-really-long-name-that-should-truncate.www.example.com/",
},
activeStandby: false,
},
Expand Down Expand Up @@ -127,6 +129,7 @@ func TestGenerateKubeTemplate(t *testing.T) {
StatusPageID: "12345",
Enabled: true,
},
Route: "https://extra-long-name.a-really-long-name-that-should-truncate.www.example.com/",
},
activeStandby: false,
},
Expand Down Expand Up @@ -164,6 +167,7 @@ func TestGenerateKubeTemplate(t *testing.T) {
StatusPageID: "12345",
Enabled: true,
},
Route: "https://extra-long-name.a-really-long-name-that-should-truncate.www.example.com/",
},
activeStandby: false,
},
Expand Down Expand Up @@ -203,6 +207,7 @@ func TestGenerateKubeTemplate(t *testing.T) {
StatusPageID: "12345",
Enabled: true,
},
Route: "https://extra-long-name.a-really-long-name-that-should-truncate.www.example.com/",
},
activeStandby: false,
},
Expand Down Expand Up @@ -245,6 +250,7 @@ func TestGenerateKubeTemplate(t *testing.T) {
StatusPageID: "12345",
Enabled: true,
},
Route: "https://extra-long-name.a-really-long-name-that-should-truncate.www.example.com/",
},
activeStandby: false,
},
Expand Down Expand Up @@ -403,7 +409,7 @@ func TestGenerateKubeTemplate(t *testing.T) {
wantErr: true,
},
{
name: "test10 - custom ingress with exceptionally log subdomain",
name: "test10 - custom ingress with exceptionally long subdomain",
args: args{
route: lagoon.RouteV2{
Domain: "hmm-this-is-a-really-long-branch-name-designed-to-test-a-specific-feature.www.example.com",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main2
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "true"
monitor.stakater.com/enabled: "false"
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
creationTimestamp: null
labels:
app.kubernetes.io/instance: main2.example.com
Expand Down
49 changes: 49 additions & 0 deletions test-resources/template-ingress/test18-results/example.com.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
ingress.kubernetes.io/ssl-redirect: "true"
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
creationTimestamp: null
labels:
app.kubernetes.io/instance: example.com
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: custom-ingress
dioscuri.amazee.io/migrate: "false"
helm.sh/chart: custom-ingress-0.1.0
lagoon.sh/autogenerated: "false"
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: example.com
lagoon.sh/service-type: custom-ingress
name: example.com
spec:
rules:
- host: example.com
http:
paths:
- backend:
service:
name: node
port:
name: http
path: /
pathType: Prefix
tls:
- hosts:
- example.com
secretName: example.com-tls
status:
loadBalancer: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "false"
monitor.stakater.com/overridePath: /
nginx.ingress.kubernetes.io/ssl-redirect: "true"
creationTimestamp: null
labels:
app.kubernetes.io/instance: www.example.com
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: custom-ingress
dioscuri.amazee.io/migrate: "false"
helm.sh/chart: custom-ingress-0.1.0
lagoon.sh/autogenerated: "false"
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: www.example.com
lagoon.sh/service-type: custom-ingress
name: www.example.com
spec:
rules:
- host: www.example.com
http:
paths:
- backend:
service:
name: node
port:
name: http
path: /
pathType: Prefix
tls:
- hosts:
- www.example.com
secretName: www.example.com-tls
status:
loadBalancer: {}
20 changes: 20 additions & 0 deletions test-resources/template-ingress/test18/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '2'
services:
node:
networks:
- amazeeio-network
- default
build:
context: .
dockerfile: node.dockerfile
labels:
lagoon.type: node
volumes:
- .:/app:delegated
environment:
- LAGOON_LOCALDEV_HTTP_PORT=3000
- LAGOON_ROUTE=http://node.docker.amazee.io

networks:
amazeeio-network:
external: true
11 changes: 11 additions & 0 deletions test-resources/template-ingress/test18/lagoon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
docker-compose-yaml: ../test-resources/template-ingress/test18/docker-compose.yml

environment_variables:
git_sha: "true"

environments:
main:
routes:
- node:
- example.com
- www.example.com
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "true"
monitor.stakater.com/enabled: "false"
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
creationTimestamp: null
labels:
app.kubernetes.io/instance: www.example.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: branch/routes
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "true"
monitor.stakater.com/enabled: "false"
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
creationTimestamp: null
labels:
app.kubernetes.io/instance: customdomain-will-be-not-be-main-domain.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ metadata:
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
monitor.stakater.com/enabled: "true"
monitor.stakater.com/enabled: "false"
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
creationTimestamp: null
labels:
app.kubernetes.io/instance: main.example.com
Expand Down

0 comments on commit 3f9bbad

Please sign in to comment.