Skip to content

Commit d6f8be5

Browse files
committed
refactor: add api, yaml, and autogen routes to route logic
1 parent 6fa22aa commit d6f8be5

31 files changed

+368
-24
lines changed

cmd/template_autogen_ingress_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"encoding/base64"
45
"fmt"
56
"io/fs"
67
"os"
@@ -551,6 +552,44 @@ func TestAutogeneratedIngressGeneration(t *testing.T) {
551552
templatePath: "testdata/output",
552553
want: "internal/testdata/basic/autogen-templates/test29-autogenerated-pathroutes",
553554
},
555+
{
556+
name: "autogenerated-routes-api-config-against-existng-reuslt",
557+
args: testdata.GetSeedData(
558+
testdata.TestData{
559+
ProjectName: "example-project",
560+
EnvironmentName: "main",
561+
Branch: "main",
562+
LagoonYAML: "internal/testdata/node/lagoon.yml",
563+
ProjectVariables: []lagoon.EnvironmentVariable{
564+
{
565+
Name: "LAGOON_API_AUTOGENERATED_CONFIG",
566+
Value: base64.URLEncoding.EncodeToString([]byte(`{"autogenerate":{"enabled":true,"allowPullRequests":true,"insecure":"Redirect"},"environment":{"autogenerateRoutes":true}}`)),
567+
Scope: "internal_system",
568+
},
569+
},
570+
}, true),
571+
templatePath: "testoutput",
572+
want: "internal/testdata/node/autogen-templates/ingress-1",
573+
},
574+
{
575+
name: "autogenerated-routes-api-config",
576+
args: testdata.GetSeedData(
577+
testdata.TestData{
578+
ProjectName: "example-project",
579+
EnvironmentName: "main",
580+
Branch: "main",
581+
LagoonYAML: "internal/testdata/node/lagoon.yml",
582+
ProjectVariables: []lagoon.EnvironmentVariable{
583+
{
584+
Name: "LAGOON_API_AUTOGENERATED_CONFIG",
585+
Value: base64.URLEncoding.EncodeToString([]byte(`{"autogenerate":{"enabled":true,"allowPullRequests":true,"prefixes":["ie","de","abc"],"pathRoutes":[{"toService":"node","fromService":"node","path":"/"}],"insecure":"Redirect"},"environment":{"autogenerateRoutes":true,"autogeneratePathRoutes":[{"toService":"node","fromService":"node","path":"/"}]}}`)),
586+
Scope: "internal_system",
587+
},
588+
},
589+
}, true),
590+
templatePath: "testoutput",
591+
want: "internal/testdata/node/autogen-templates/autogenerated-routes-api-config",
592+
},
554593
}
555594
for _, tt := range tests {
556595
t.Run(tt.name, func(t *testing.T) {

cmd/template_ingress_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,78 @@ func TestTemplateRoutes(t *testing.T) {
432432
templatePath: "testoutput",
433433
want: "internal/testdata/node/ingress-templates/ingress-24",
434434
},
435+
{
436+
name: "active-standby-api-routes",
437+
args: testdata.GetSeedData(
438+
testdata.TestData{
439+
ProjectName: "example-project",
440+
EnvironmentName: "prod-left",
441+
Branch: "prod-left",
442+
LagoonYAML: "internal/testdata/node/lagoon.yml",
443+
ProjectVariables: []lagoon.EnvironmentVariable{
444+
{
445+
Name: "LAGOON_API_ROUTES",
446+
Value: base64.URLEncoding.EncodeToString([]byte(`{"routes":[
447+
{"type":"ACTIVE", "domain":"active.example.com","service":"node","alternativeNames":[],"annotations":{},"pathRoutes":[],"tlsAcme":true,"insecure":"Redirect","hstsEnabled":false,"hstsIncludeSubdomains":false,"hstsPreload":false,"hstsMaxAge":3153600,"primary":false,"source":"API"},
448+
{"domain":"other.example.com","service":"node","alternativeNames":[],"annotations":{},"pathRoutes":[],"tlsAcme":true,"insecure":"Redirect","hstsEnabled":false,"hstsIncludeSubdomains":false,"hstsPreload":false,"hstsMaxAge":3153600,"primary":false,"source":"API"},
449+
{"domain":"test.example.com","service":"node","alternativeNames":[],"annotations":{},"pathRoutes":[],"tlsAcme":true,"insecure":"Redirect","hstsEnabled":false,"hstsIncludeSubdomains":false,"hstsPreload":false,"hstsMaxAge":3153600,"primary":true,"source":"API"}
450+
]}`)),
451+
Scope: "internal_system",
452+
},
453+
},
454+
}, true),
455+
templatePath: "testoutput",
456+
want: "internal/testdata/node/ingress-templates/active-standby-api-routes",
457+
},
458+
{
459+
name: "api-defined-routes-with-lagoon-yml",
460+
args: testdata.GetSeedData(
461+
testdata.TestData{
462+
ProjectName: "example-project",
463+
EnvironmentName: "main",
464+
Branch: "main",
465+
LagoonYAML: "internal/testdata/node/lagoon.yml",
466+
ProjectVariables: []lagoon.EnvironmentVariable{
467+
{
468+
Name: "LAGOON_API_ROUTES",
469+
Value: base64.URLEncoding.EncodeToString([]byte(`{"routes":[
470+
{"domain":"other.example.com","service":"node","alternativeNames":[],"annotations":{},"pathRoutes":[],"tlsAcme":true,"insecure":"Redirect","hstsEnabled":false,"hstsIncludeSubdomains":false,"hstsPreload":false,"hstsMaxAge":3153600,"primary":false,"source":"API"},
471+
{"domain":"test.example.com","service":"node","alternativeNames":[],"annotations":{},"pathRoutes":[],"tlsAcme":true,"insecure":"Redirect","hstsEnabled":false,"hstsIncludeSubdomains":false,"hstsPreload":false,"hstsMaxAge":3153600,"primary":true,"source":"API"}
472+
]}`)),
473+
Scope: "internal_system",
474+
},
475+
},
476+
}, true),
477+
templatePath: "testoutput",
478+
want: "internal/testdata/node/ingress-templates/api-defined-routes-with-lagoon-yml",
479+
},
480+
{
481+
name: "api-defined-routes-with-lagoon-yml-fastly",
482+
args: testdata.GetSeedData(
483+
testdata.TestData{
484+
ProjectName: "example-project",
485+
EnvironmentName: "main",
486+
Branch: "main",
487+
LagoonYAML: "internal/testdata/node/lagoon.yml",
488+
ProjectVariables: []lagoon.EnvironmentVariable{
489+
{
490+
Name: "LAGOON_FASTLY_SERVICE_ID",
491+
Value: "service-id:true",
492+
Scope: "build",
493+
},
494+
{
495+
Name: "LAGOON_API_ROUTES",
496+
Value: base64.URLEncoding.EncodeToString([]byte(`{"routes":[
497+
{"domain":"other.example.com","service":"node","alternativeNames":[],"annotations":{},"pathRoutes":[],"tlsAcme":true,"insecure":"Redirect","hstsEnabled":false,"hstsIncludeSubdomains":false,"hstsPreload":false,"hstsMaxAge":3153600,"primary":false,"source":"API"},
498+
{"domain":"test.example.com","service":"node","alternativeNames":[],"annotations":{},"pathRoutes":[],"tlsAcme":true,"insecure":"Redirect","hstsEnabled":false,"hstsIncludeSubdomains":false,"hstsPreload":false,"hstsMaxAge":3153600,"primary":true,"source":"API"}
499+
]}`)),
500+
Scope: "internal_system",
501+
},
502+
},
503+
}, true),
504+
templatePath: "testoutput",
505+
want: "internal/testdata/node/ingress-templates/api-defined-routes-with-lagoon-yml-fastly",
506+
},
435507
}
436508
for _, tt := range tests {
437509
t.Run(tt.name, func(t *testing.T) {

internal/collector/testdata/json-result/result-1.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@
314314
"lagoon.sh/project": "example-project",
315315
"lagoon.sh/service": "example.com",
316316
"lagoon.sh/service-type": "custom-ingress",
317-
"lagoon.sh/template": "custom-ingress-0.1.0"
317+
"lagoon.sh/template": "custom-ingress-0.1.0",
318+
"route.lagoon.sh/source": "yaml"
318319
},
319320
"annotations": {
320321
"fastly.amazee.io/service-id": "service-id",
@@ -386,7 +387,8 @@
386387
"lagoon.sh/project": "example-project",
387388
"lagoon.sh/service": "node",
388389
"lagoon.sh/service-type": "node",
389-
"lagoon.sh/template": "autogenerated-ingress-0.1.0"
390+
"lagoon.sh/template": "autogenerated-ingress-0.1.0",
391+
"route.lagoon.sh/source": "autogenerated"
390392
},
391393
"annotations": {
392394
"fastly.amazee.io/watch": "false",

internal/collector/testdata/json-result/result-2.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@
189189
"lagoon.sh/project": "example-project",
190190
"lagoon.sh/service": "example.com",
191191
"lagoon.sh/service-type": "custom-ingress",
192-
"lagoon.sh/template": "custom-ingress-0.1.0"
192+
"lagoon.sh/template": "custom-ingress-0.1.0",
193+
"route.lagoon.sh/source": "yaml"
193194
},
194195
"annotations": {
195196
"fastly.amazee.io/service-id": "service-id",
@@ -261,7 +262,8 @@
261262
"lagoon.sh/project": "example-project",
262263
"lagoon.sh/service": "node",
263264
"lagoon.sh/service-type": "node",
264-
"lagoon.sh/template": "autogenerated-ingress-0.1.0"
265+
"lagoon.sh/template": "autogenerated-ingress-0.1.0",
266+
"route.lagoon.sh/source": "autogenerated"
265267
},
266268
"annotations": {
267269
"fastly.amazee.io/watch": "false",

internal/collector/testdata/result/result-1/lagoon-ingress.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ items:
3131
lagoon.sh/service: example.com
3232
lagoon.sh/service-type: custom-ingress
3333
lagoon.sh/template: custom-ingress-0.1.0
34+
route.lagoon.sh/source: yaml
3435
name: example.com
3536
namespace: example-project-main
3637
resourceVersion: "1"
@@ -79,6 +80,7 @@ items:
7980
lagoon.sh/service: node
8081
lagoon.sh/service-type: node
8182
lagoon.sh/template: autogenerated-ingress-0.1.0
83+
route.lagoon.sh/source: autogenerated
8284
name: node
8385
namespace: example-project-main
8486
resourceVersion: "1"

internal/collector/testdata/result/result-2/lagoon-ingress.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ items:
3131
lagoon.sh/service: example.com
3232
lagoon.sh/service-type: custom-ingress
3333
lagoon.sh/template: custom-ingress-0.1.0
34+
route.lagoon.sh/source: yaml
3435
name: example.com
3536
namespace: example-project-main
3637
resourceVersion: "1"
@@ -79,6 +80,7 @@ items:
7980
lagoon.sh/service: node
8081
lagoon.sh/service-type: node
8182
lagoon.sh/template: autogenerated-ingress-0.1.0
83+
route.lagoon.sh/source: autogenerated
8284
name: node
8385
namespace: example-project-main
8486
resourceVersion: "1"

internal/collector/testdata/seed/seed-1/ingress-example.com.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ metadata:
3131
lagoon.sh/service: example.com
3232
lagoon.sh/service-type: custom-ingress
3333
lagoon.sh/template: custom-ingress-0.1.0
34+
route.lagoon.sh/source: yaml
3435
name: example.com
3536
spec:
3637
rules:

internal/collector/testdata/seed/seed-1/ingress-node.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ metadata:
2626
lagoon.sh/service: node
2727
lagoon.sh/service-type: node
2828
lagoon.sh/template: autogenerated-ingress-0.1.0
29+
route.lagoon.sh/source: autogenerated
2930
name: node
3031
spec:
3132
rules:

internal/collector/testdata/seed/seed-2/ingress-example.com.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ metadata:
3131
lagoon.sh/service: example.com
3232
lagoon.sh/service-type: custom-ingress
3333
lagoon.sh/template: custom-ingress-0.1.0
34+
route.lagoon.sh/source: yaml
3435
name: example.com
3536
spec:
3637
rules:

internal/collector/testdata/seed/seed-2/ingress-node.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ metadata:
2626
lagoon.sh/service: node
2727
lagoon.sh/service-type: node
2828
lagoon.sh/template: autogenerated-ingress-0.1.0
29+
route.lagoon.sh/source: autogenerated
2930
name: node
3031
spec:
3132
rules:

0 commit comments

Comments
 (0)