Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add alternative names and wildcard support to lagoon.yml #25

Merged
merged 18 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions cmd/template_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,44 @@ func TestTemplateRoutes(t *testing.T) {
},
want: "../test-resources/template-ingress/test20-results",
},
{
name: "test21 alternative names",
args: args{
alertContact: "alertcontact",
statusPageID: "statuspageid",
projectName: "example-project",
environmentName: "main",
environmentType: "production",
buildType: "branch",
standbyEnvironment: "main2",
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/test21/lagoon.yml",
templatePath: "../test-resources/template-ingress/output",
},
want: "../test-resources/template-ingress/test21-results",
},
{
name: "test22 check wildcard",
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/test22/lagoon.yml",
templatePath: "../test-resources/template-ingress/output",
},
want: "../test-resources/template-ingress/test22-results",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
29 changes: 22 additions & 7 deletions internal/generator/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ func generateRoutes(
// generate the templates for these independently of any previously generated routes,
// this WILL overwrite previously created templates ensuring that anything defined in the `production_routes`
// section are created correctly ensuring active/standby will work
*activeStanbyRoutes = generateActiveStandbyRoutes(lagoonEnvVars, lYAML, buildValues)
*activeStanbyRoutes, err = generateActiveStandbyRoutes(lagoonEnvVars, lYAML, buildValues)
if err != nil {
return "", []string{}, []string{}, fmt.Errorf("couldn't generate and merge routes: %v", err)
}
// get the first route from the list of routes, replace the previous one if necessary
if len(activeStanbyRoutes.Routes) > 0 {
// if primary != "" {
Expand Down Expand Up @@ -244,14 +247,17 @@ func generateActiveStandbyRoutes(
envVars []lagoon.EnvironmentVariable,
lagoonYAML lagoon.YAML,
buildValues BuildValues,
) lagoon.RoutesV2 {
) (lagoon.RoutesV2, error) {
activeStanbyRoutes := &lagoon.RoutesV2{}
if lagoonYAML.ProductionRoutes != nil {
if buildValues.IsActiveEnvironment == true {
if lagoonYAML.ProductionRoutes.Active != nil {
if lagoonYAML.ProductionRoutes.Active.Routes != nil {
for _, routeMap := range lagoonYAML.ProductionRoutes.Active.Routes {
lagoon.GenerateRoutesV2(activeStanbyRoutes, routeMap, envVars, buildValues.IngressClass, buildValues.FastlyAPISecretPrefix, true)
err := lagoon.GenerateRoutesV2(activeStanbyRoutes, routeMap, envVars, buildValues.IngressClass, buildValues.FastlyAPISecretPrefix, true)
if err != nil {
return *activeStanbyRoutes, err
}
}
}
}
Expand All @@ -260,13 +266,16 @@ func generateActiveStandbyRoutes(
if lagoonYAML.ProductionRoutes.Standby != nil {
if lagoonYAML.ProductionRoutes.Standby.Routes != nil {
for _, routeMap := range lagoonYAML.ProductionRoutes.Standby.Routes {
lagoon.GenerateRoutesV2(activeStanbyRoutes, routeMap, envVars, buildValues.IngressClass, buildValues.FastlyAPISecretPrefix, true)
err := lagoon.GenerateRoutesV2(activeStanbyRoutes, routeMap, envVars, buildValues.IngressClass, buildValues.FastlyAPISecretPrefix, true)
if err != nil {
return *activeStanbyRoutes, err
}
}
}
}
}
}
return *activeStanbyRoutes
return *activeStanbyRoutes, nil
}

// getRoutesFromEnvVar will collect the value of the LAGOON_ROUTES_JSON
Expand Down Expand Up @@ -305,9 +314,15 @@ func generateAndMerge(

// otherwise it just uses the default environment name
for _, routeMap := range lagoonYAML.Environments[buildValues.Branch].Routes {
lagoon.GenerateRoutesV2(n, routeMap, envVars, buildValues.IngressClass, buildValues.FastlyAPISecretPrefix, false)
err := lagoon.GenerateRoutesV2(n, routeMap, envVars, buildValues.IngressClass, buildValues.FastlyAPISecretPrefix, false)
if err != nil {
return *n, err
}
}
// merge routes from the API on top of the routes from the `.lagoon.yml`
mainRoutes := lagoon.MergeRoutesV2(*n, api, envVars, buildValues.IngressClass, buildValues.FastlyAPISecretPrefix)
mainRoutes, err := lagoon.MergeRoutesV2(*n, api, envVars, buildValues.IngressClass, buildValues.FastlyAPISecretPrefix)
if err != nil {
return *n, err
}
return mainRoutes, nil
}
Loading
Loading