Skip to content

Commit

Permalink
fix: pullrequests with custom routes (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon authored Oct 4, 2022
1 parent 643b713 commit a0a2b34
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cmd/template_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,46 @@ func TestTemplateRoutes(t *testing.T) {
},
want: "../test-resources/template-ingress/test18-results",
},
{
name: "test19 pullrequest routes",
args: args{
alertContact: "alertcontact",
statusPageID: "statuspageid",
projectName: "example-project",
environmentName: "pr-4841",
environmentType: "development",
buildType: "pullrequest",
lagoonVersion: "v2.7.x",
prNumber: "4841",
prHeadBranch: "main",
prBaseBranch: "my-branch",
projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`,
envVars: `[]`,
lagoonYAML: "../test-resources/template-ingress/test19/lagoon.yml",
templatePath: "../test-resources/template-ingress/output",
},
want: "../test-resources/template-ingress/test19-results",
},
{
name: "test20 pullrequest routes polysite",
args: args{
alertContact: "alertcontact",
statusPageID: "statuspageid",
projectName: "example-project",
environmentName: "pr-4841",
environmentType: "development",
buildType: "pullrequest",
lagoonVersion: "v2.7.x",
prNumber: "4841",
prHeadBranch: "main",
prBaseBranch: "my-branch",
projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`,
envVars: `[]`,
lagoonYAML: "../test-resources/template-ingress/test20/lagoon.yml",
templatePath: "../test-resources/template-ingress/output",
},
want: "../test-resources/template-ingress/test20-results",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions internal/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func NewGenerator(
buildValues.PRTitle = prTitle
buildValues.PRHeadBranch = prHeadBranch
buildValues.PRBaseBranch = prBaseBranch
// since pullrequests don't have a branch
// we should set the branch to be `pr-PRNUMBER` so that it can be used for matching elsewhere where matching for `branch`
// using buildvalues is done
buildValues.Branch = fmt.Sprintf("pr-%v", prNumber)
}

// break out of the generator if these requirements are missing
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
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/prBaseBranch: my-branch
lagoon.sh/prHeadBranch: main
lagoon.sh/prNumber: "4841"
lagoon.sh/version: v2.7.x
nginx.ingress.kubernetes.io/server-snippet: |
add_header X-Robots-Tag "noindex, nofollow";
nginx.ingress.kubernetes.io/ssl-redirect: "true"
creationTimestamp: null
labels:
app.kubernetes.io/instance: performance.example.com
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: custom-ingress
helm.sh/chart: custom-ingress-0.1.0
lagoon.sh/autogenerated: "false"
lagoon.sh/buildType: pullrequest
lagoon.sh/environment: pr-4841
lagoon.sh/environmentType: development
lagoon.sh/project: example-project
lagoon.sh/service: performance.example.com
lagoon.sh/service-type: custom-ingress
name: performance.example.com
spec:
rules:
- host: performance.example.com
http:
paths:
- backend:
service:
name: nginx
port:
name: http
path: /
pathType: Prefix
tls:
- hosts:
- performance.example.com
secretName: performance.example.com-tls
status:
loadBalancer: {}
14 changes: 14 additions & 0 deletions test-resources/template-ingress/test19/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.2'
services:
node:
build:
context: .
dockerfile: Dockerfile
labels:
lagoon.type: node
nginx:
build:
context: .
dockerfile: .nginx/Dockerfile
labels:
lagoon.type: nginx
22 changes: 22 additions & 0 deletions test-resources/template-ingress/test19/lagoon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
docker-compose-yaml: ../test-resources/template-ingress/test19/docker-compose.yml

environment_variables:
git_sha: 'true'

tasks:
post-rollout:
- run:
name: Call
command: node /app/.lagoon/run-post.js || true
service: node

environments:
develop:
routes:
- nginx:
- develop.example.com
- app.develop.example.com
pr-4841:
routes:
- nginx:
- performance.example.com
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
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/prBaseBranch: my-branch
lagoon.sh/prHeadBranch: main
lagoon.sh/prNumber: "4841"
lagoon.sh/version: v2.7.x
nginx.ingress.kubernetes.io/server-snippet: |
add_header X-Robots-Tag "noindex, nofollow";
nginx.ingress.kubernetes.io/ssl-redirect: "true"
creationTimestamp: null
labels:
app.kubernetes.io/instance: performance.example.com
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: custom-ingress
helm.sh/chart: custom-ingress-0.1.0
lagoon.sh/autogenerated: "false"
lagoon.sh/buildType: pullrequest
lagoon.sh/environment: pr-4841
lagoon.sh/environmentType: development
lagoon.sh/project: example-project
lagoon.sh/service: performance.example.com
lagoon.sh/service-type: custom-ingress
name: performance.example.com
spec:
rules:
- host: performance.example.com
http:
paths:
- backend:
service:
name: nginx
port:
name: http
path: /
pathType: Prefix
tls:
- hosts:
- performance.example.com
secretName: performance.example.com-tls
status:
loadBalancer: {}
14 changes: 14 additions & 0 deletions test-resources/template-ingress/test20/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.2'
services:
node:
build:
context: .
dockerfile: Dockerfile
labels:
lagoon.type: node
nginx:
build:
context: .
dockerfile: .nginx/Dockerfile
labels:
lagoon.type: nginx
35 changes: 35 additions & 0 deletions test-resources/template-ingress/test20/lagoon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
docker-compose-yaml: ../test-resources/template-ingress/test20/docker-compose.yml

environment_variables:
git_sha: 'true'

tasks:
post-rollout:
- run:
name: Call
command: node /app/.lagoon/run-post.js || true
service: node

example-project:
environments:
develop:
routes:
- nginx:
- develop.example.com
- app.develop.example.com
pr-4841:
routes:
- nginx:
- performance.example.com

example-project2:
environments:
develop:
routes:
- nginx:
- develop2.example.com
- app.develop2.example.com
pr-4841:
routes:
- nginx:
- performance2.example.com

0 comments on commit a0a2b34

Please sign in to comment.