diff --git a/cmd/identify_ingress.go b/cmd/identify_ingress.go index 50d1e424..65dd2c9d 100644 --- a/cmd/identify_ingress.go +++ b/cmd/identify_ingress.go @@ -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])) @@ -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])) } @@ -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])) } diff --git a/cmd/identify_ingress_test.go b/cmd/identify_ingress_test.go index e83c50aa..4f9bd33d 100644 --- a/cmd/identify_ingress_test.go +++ b/cmd/identify_ingress_test.go @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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 { diff --git a/cmd/test-resources/template-ingress/single-lagoon-noautogen.yml b/cmd/test-resources/template-ingress/single-lagoon-noautogen.yml new file mode 100644 index 00000000..e282518c --- /dev/null +++ b/cmd/test-resources/template-ingress/single-lagoon-noautogen.yml @@ -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