Skip to content

Commit

Permalink
Merge pull request #37 from uselagoon/secondary-routes
Browse files Browse the repository at this point in the history
chore: fix secondary routes to also contain the primary routes
  • Loading branch information
shreddedbacon authored May 23, 2022
2 parents 3d89a39 + 26f3c5e commit dc60c7e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 35 deletions.
28 changes: 16 additions & 12 deletions cmd/identify_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ func generateRoutes(lagoonEnvVars []lagoon.EnvironmentVariable,
autogen = append(autogen, fmt.Sprintf("%s%s", prefix, autogenRoutes.Routes[i].Domain))
if i == 0 {
primary = fmt.Sprintf("%s%s", prefix, autogenRoutes.Routes[i].Domain)
} else {
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, autogenRoutes.Routes[i].Domain))
// } else {
// remainders = append(remainders, fmt.Sprintf("%s%s", prefix, autogenRoutes.Routes[i].Domain))
}
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, autogenRoutes.Routes[i].Domain))
for a := 0; a < len(autogenRoutes.Routes[i].AlternativeNames); a++ {
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, autogenRoutes.Routes[i].AlternativeNames[a]))
autogen = append(autogen, fmt.Sprintf("%s%s", prefix, autogenRoutes.Routes[i].AlternativeNames[a]))
Expand All @@ -109,15 +110,16 @@ func generateRoutes(lagoonEnvVars []lagoon.EnvironmentVariable,

// get the first route from the list of routes, replace the previous one if necessary
if len(mainRoutes.Routes) > 0 {
if primary != "" {
remainders = append(remainders, primary)
}
// if primary != "" {
// remainders = append(remainders, primary)
// }
for i := 0; i < len(mainRoutes.Routes); i++ {
if i == 0 {
primary = fmt.Sprintf("%s%s", prefix, mainRoutes.Routes[i].Domain)
} else {
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, mainRoutes.Routes[i].Domain))
// } else {
// remainders = append(remainders, fmt.Sprintf("%s%s", prefix, mainRoutes.Routes[i].Domain))
}
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, mainRoutes.Routes[i].Domain))
for a := 0; a < len(mainRoutes.Routes[i].AlternativeNames); a++ {
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, mainRoutes.Routes[i].AlternativeNames[a]))
}
Expand All @@ -132,15 +134,17 @@ func generateRoutes(lagoonEnvVars []lagoon.EnvironmentVariable,
*activeStanbyRoutes = generateActiveStandby(activeEnv, standbyEnv, lagoonEnvVars, lYAML)
// get the first route from the list of routes, replace the previous one if necessary
if len(activeStanbyRoutes.Routes) > 0 {
if primary != "" {
remainders = append(remainders, primary)
}
// if primary != "" {
// remainders = append(remainders, primary)
// }
for i := 0; i < len(activeStanbyRoutes.Routes); i++ {
if i == 0 {
primary = fmt.Sprintf("%s%s", prefix, activeStanbyRoutes.Routes[i].Domain)
} else {
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, activeStanbyRoutes.Routes[i].Domain))
// } else {
// remainders = append(remainders, fmt.Sprintf("%s%s", prefix, activeStanbyRoutes.Routes[i].Domain))
}
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, activeStanbyRoutes.Routes[i].Domain))
// remainders = append(remainders, fmt.Sprintf("%s%s", prefix, activeStanbyRoutes.Routes[i].Domain))
for a := 0; a < len(activeStanbyRoutes.Routes[i].AlternativeNames); a++ {
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, activeStanbyRoutes.Routes[i].AlternativeNames[a]))
}
Expand Down
69 changes: 46 additions & 23 deletions cmd/identify_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func TestIdentifyRoute(t *testing.T) {
templatePath: "test-resources/template-ingress/output",
},
want: "https://example.com",
wantRemain: []string{"https://node-example-project-main.example.com"},
wantRemain: []string{"https://node-example-project-main.example.com", "https://example.com"},
wantautoGen: []string{"https://node-example-project-main.example.com"},
wantJSON: `{"primary":"https://example.com","secondary":["https://node-example-project-main.example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`,
wantJSON: `{"primary":"https://example.com","secondary":["https://node-example-project-main.example.com","https://example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`,
},
{
name: "test2 check LAGOON_FASTLY_SERVICE_IDS no secret and no values",
Expand All @@ -79,9 +79,9 @@ func TestIdentifyRoute(t *testing.T) {
templatePath: "test-resources/template-ingress/output",
},
want: "https://example.com",
wantRemain: []string{"https://node-example-project-main.example.com"},
wantRemain: []string{"https://node-example-project-main.example.com", "https://example.com"},
wantautoGen: []string{"https://node-example-project-main.example.com"},
wantJSON: `{"primary":"https://example.com","secondary":["https://node-example-project-main.example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`,
wantJSON: `{"primary":"https://example.com","secondary":["https://node-example-project-main.example.com","https://example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`,
},
{
name: "test3 check LAGOON_FASTLY_SERVICE_ID no secret and no values",
Expand All @@ -101,9 +101,9 @@ func TestIdentifyRoute(t *testing.T) {
templatePath: "test-resources/template-ingress/output",
},
want: "https://example.com",
wantRemain: []string{"https://node-example-project-main.example.com"},
wantRemain: []string{"https://node-example-project-main.example.com", "https://example.com"},
wantautoGen: []string{"https://node-example-project-main.example.com"},
wantJSON: `{"primary":"https://example.com","secondary":["https://node-example-project-main.example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`,
wantJSON: `{"primary":"https://example.com","secondary":["https://node-example-project-main.example.com","https://example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`,
},
{
name: "test4 check no fastly and no values",
Expand All @@ -123,9 +123,9 @@ func TestIdentifyRoute(t *testing.T) {
templatePath: "test-resources/template-ingress/output",
},
want: "https://example.com",
wantRemain: []string{"https://node-example-project-main.example.com"},
wantRemain: []string{"https://node-example-project-main.example.com", "https://example.com"},
wantautoGen: []string{"https://node-example-project-main.example.com"},
wantJSON: `{"primary":"https://example.com","secondary":["https://node-example-project-main.example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`,
wantJSON: `{"primary":"https://example.com","secondary":["https://node-example-project-main.example.com","https://example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`,
},
{
name: "test5 multiproject1 no values",
Expand All @@ -145,9 +145,9 @@ func TestIdentifyRoute(t *testing.T) {
templatePath: "test-resources/template-ingress/output",
},
want: "https://multiproject1.com",
wantRemain: []string{"https://node-multiproject1-multiproject.example.com"},
wantRemain: []string{"https://node-multiproject1-multiproject.example.com", "https://multiproject1.com"},
wantautoGen: []string{"https://node-multiproject1-multiproject.example.com"},
wantJSON: `{"primary":"https://multiproject1.com","secondary":["https://node-multiproject1-multiproject.example.com"],"autogenerated":["https://node-multiproject1-multiproject.example.com"]}`,
wantJSON: `{"primary":"https://multiproject1.com","secondary":["https://node-multiproject1-multiproject.example.com","https://multiproject1.com"],"autogenerated":["https://node-multiproject1-multiproject.example.com"]}`,
},
{
name: "test6 multiproject2 no values",
Expand All @@ -167,9 +167,9 @@ func TestIdentifyRoute(t *testing.T) {
templatePath: "test-resources/template-ingress/output",
},
want: "https://multiproject2.com",
wantRemain: []string{"https://node-multiproject2-multiproject.example.com"},
wantRemain: []string{"https://node-multiproject2-multiproject.example.com", "https://multiproject2.com"},
wantautoGen: []string{"https://node-multiproject2-multiproject.example.com"},
wantJSON: `{"primary":"https://multiproject2.com","secondary":["https://node-multiproject2-multiproject.example.com"],"autogenerated":["https://node-multiproject2-multiproject.example.com"]}`,
wantJSON: `{"primary":"https://multiproject2.com","secondary":["https://node-multiproject2-multiproject.example.com","https://multiproject2.com"],"autogenerated":["https://node-multiproject2-multiproject.example.com"]}`,
},
{
name: "test7 multidomain no values",
Expand All @@ -189,9 +189,9 @@ func TestIdentifyRoute(t *testing.T) {
templatePath: "test-resources/template-ingress/output",
},
want: "https://example.com",
wantRemain: []string{"https://node-example-project-main.example.com", "https://www.example.com"},
wantRemain: []string{"https://node-example-project-main.example.com", "https://example.com", "https://www.example.com"},
wantautoGen: []string{"https://node-example-project-main.example.com"},
wantJSON: `{"primary":"https://example.com","secondary":["https://node-example-project-main.example.com","https://www.example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`,
wantJSON: `{"primary":"https://example.com","secondary":["https://node-example-project-main.example.com","https://example.com","https://www.example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`,
},
{
name: "test8 multidomain no values",
Expand All @@ -211,9 +211,9 @@ func TestIdentifyRoute(t *testing.T) {
templatePath: "test-resources/template-ingress/output",
},
want: "https://customdomain-will-be-main-domain.com",
wantRemain: []string{"https://node-example-project-branch-routes.example.com", "https://customdomain-will-be-not-be-main-domain.com"},
wantRemain: []string{"https://node-example-project-branch-routes.example.com", "https://customdomain-will-be-main-domain.com", "https://customdomain-will-be-not-be-main-domain.com"},
wantautoGen: []string{"https://node-example-project-branch-routes.example.com"},
wantJSON: `{"primary":"https://customdomain-will-be-main-domain.com","secondary":["https://node-example-project-branch-routes.example.com","https://customdomain-will-be-not-be-main-domain.com"],"autogenerated":["https://node-example-project-branch-routes.example.com"]}`,
wantJSON: `{"primary":"https://customdomain-will-be-main-domain.com","secondary":["https://node-example-project-branch-routes.example.com","https://customdomain-will-be-main-domain.com","https://customdomain-will-be-not-be-main-domain.com"],"autogenerated":["https://node-example-project-branch-routes.example.com"]}`,
},
{
name: "test9 active no values",
Expand All @@ -234,9 +234,9 @@ func TestIdentifyRoute(t *testing.T) {
templatePath: "test-resources/template-ingress/output",
},
want: "https://active.example.com",
wantRemain: []string{"https://node-example-project-main.example.com", "https://main.example.com"},
wantRemain: []string{"https://node-example-project-main.example.com", "https://main.example.com", "https://active.example.com"},
wantautoGen: []string{"https://node-example-project-main.example.com"},
wantJSON: `{"primary":"https://active.example.com","secondary":["https://node-example-project-main.example.com","https://main.example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`,
wantJSON: `{"primary":"https://active.example.com","secondary":["https://node-example-project-main.example.com","https://main.example.com","https://active.example.com"],"autogenerated":["https://node-example-project-main.example.com"]}`,
},
{
name: "test10 standby no values",
Expand All @@ -257,9 +257,9 @@ func TestIdentifyRoute(t *testing.T) {
templatePath: "test-resources/template-ingress/output",
},
want: "https://standby.example.com",
wantRemain: []string{"https://node-example-project-main2.example.com", "https://main2.example.com"},
wantRemain: []string{"https://node-example-project-main2.example.com", "https://main2.example.com", "https://standby.example.com"},
wantautoGen: []string{"https://node-example-project-main2.example.com"},
wantJSON: `{"primary":"https://standby.example.com","secondary":["https://node-example-project-main2.example.com","https://main2.example.com"],"autogenerated":["https://node-example-project-main2.example.com"]}`,
wantJSON: `{"primary":"https://standby.example.com","secondary":["https://node-example-project-main2.example.com","https://main2.example.com","https://standby.example.com"],"autogenerated":["https://node-example-project-main2.example.com"]}`,
},
{
name: "test11 no custom ingress",
Expand All @@ -280,9 +280,9 @@ func TestIdentifyRoute(t *testing.T) {
templatePath: "test-resources/template-ingress/output",
},
want: "https://node-example-project-no-ingress.example.com",
wantRemain: []string{},
wantRemain: []string{"https://node-example-project-no-ingress.example.com"},
wantautoGen: []string{"https://node-example-project-no-ingress.example.com"},
wantJSON: `{"primary":"https://node-example-project-no-ingress.example.com","secondary":[],"autogenerated":["https://node-example-project-no-ingress.example.com"]}`,
wantJSON: `{"primary":"https://node-example-project-no-ingress.example.com","secondary":["https://node-example-project-no-ingress.example.com"],"autogenerated":["https://node-example-project-no-ingress.example.com"]}`,
},
{
name: "test12 no custom ingress",
Expand All @@ -304,6 +304,7 @@ func TestIdentifyRoute(t *testing.T) {
},
want: "https://node-example-project-no-ingress.example.com",
wantRemain: []string{
"https://node-example-project-no-ingress.example.com",
"https://www.node-example-project-no-ingress.example.com",
"https://en.node-example-project-no-ingress.example.com",
"https://de.node-example-project-no-ingress.example.com",
Expand All @@ -316,7 +317,29 @@ func TestIdentifyRoute(t *testing.T) {
"https://de.node-example-project-no-ingress.example.com",
"https://fi.node-example-project-no-ingress.example.com",
},
wantJSON: `{"primary":"https://node-example-project-no-ingress.example.com","secondary":["https://www.node-example-project-no-ingress.example.com","https://en.node-example-project-no-ingress.example.com","https://de.node-example-project-no-ingress.example.com","https://fi.node-example-project-no-ingress.example.com"],"autogenerated":["https://node-example-project-no-ingress.example.com","https://www.node-example-project-no-ingress.example.com","https://en.node-example-project-no-ingress.example.com","https://de.node-example-project-no-ingress.example.com","https://fi.node-example-project-no-ingress.example.com"]}`,
wantJSON: `{"primary":"https://node-example-project-no-ingress.example.com","secondary":["https://node-example-project-no-ingress.example.com","https://www.node-example-project-no-ingress.example.com","https://en.node-example-project-no-ingress.example.com","https://de.node-example-project-no-ingress.example.com","https://fi.node-example-project-no-ingress.example.com"],"autogenerated":["https://node-example-project-no-ingress.example.com","https://www.node-example-project-no-ingress.example.com","https://en.node-example-project-no-ingress.example.com","https://de.node-example-project-no-ingress.example.com","https://fi.node-example-project-no-ingress.example.com"]}`,
},
{
name: "test12 no autogenerated routes",
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: `[]`,
secretPrefix: "fastly-api-",
lagoonYAML: "test-resources/template-ingress/single-lagoon-noautogen.yml",
templatePath: "test-resources/template-ingress/output",
},
want: "https://example.com",
wantRemain: []string{"https://example.com"},
wantautoGen: []string{},
wantJSON: `{"primary":"https://example.com","secondary":["https://example.com"],"autogenerated":[]}`,
},
}
for _, tt := range tests {
Expand Down
14 changes: 14 additions & 0 deletions cmd/test-resources/template-ingress/single-lagoon-noautogen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
docker-compose-yaml: test-resources/template-ingress/docker-compose.yml

routes:
autogenerate:
enabled: false

environment_variables:
git_sha: "true"

environments:
main:
routes:
- node:
- example.com

0 comments on commit dc60c7e

Please sign in to comment.