Skip to content

Commit

Permalink
Merge pull request #50 from uselagoon/lagoon-name-types
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon authored Jun 15, 2022
2 parents 249999e + 46a1fad commit 7805ec3
Show file tree
Hide file tree
Showing 14 changed files with 751 additions and 12 deletions.
13 changes: 7 additions & 6 deletions cmd/helpers_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,17 @@ func composeToServiceValues(lYAML *lagoon.YAML, lagoonValues *lagoon.BuildValues
}
}
}
lagoonTypeName := lagoon.CheckServiceLagoonLabel(csValues.Labels, "lagoon.name")
if lagoonTypeName != "" {
if lagoonTypeName != csName {
// if there is a lagoon.name label on a service, then this service does not need an autogenerated route
// as it is likely an ancillary pod for another service (the one in the `lagoon.name` label :))
autogenEnabled = false
lagoonOverrideName := lagoon.CheckServiceLagoonLabel(csValues.Labels, "lagoon.name")
if lagoonOverrideName != "" {
for _, service := range lagoonValues.Services {
if service.OverrideName == lagoonOverrideName {
autogenEnabled = false
}
}
}
cService := lagoon.ServiceValues{
Name: csName,
OverrideName: lagoonOverrideName,
Type: lagoonType,
AutogeneratedRoutesEnabled: autogenEnabled,
AutogeneratedRoutesTLSAcme: autogenTLSAcmeEnabled,
Expand Down
22 changes: 22 additions & 0 deletions cmd/identify_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,28 @@ func TestIdentifyRoute(t *testing.T) {
wantautoGen: []string{"https://nginx-sales-customer-support-develop.ex1.example-web.com"},
wantJSON: `{"primary":"https://nginx-sales-customer-support-develop.ex1.example-web.com","secondary":["https://nginx-sales-customer-support-develop.ex1.example-web.com"],"autogenerated":["https://nginx-sales-customer-support-develop.ex1.example-web.com"]}`,
},
{
name: "test16 autogenerated routes where lagoon.name of service does not match service names",
args: args{
alertContact: "alertcontact",
statusPageID: "statuspageid",
projectName: "content-example-com",
environmentName: "feature-migration",
environmentType: "development",
buildType: "branch",
lagoonVersion: "v2.7.x",
branch: "feature/migration",
projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${environment}.${project}.example.com","scope":"internal_system"}]`,
envVars: `[]`,
secretPrefix: "fastly-api-",
lagoonYAML: "../test-resources/identify-ingress/test16/lagoon.yml",
templatePath: "../test-resources/output",
},
want: "https://nginx-php.feature-migration.content-example-com.example.com",
wantRemain: []string{"https://nginx-php.feature-migration.content-example-com.example.com"},
wantautoGen: []string{"https://nginx-php.feature-migration.content-example-com.example.com"},
wantJSON: `{"primary":"https://nginx-php.feature-migration.content-example-com.example.com","secondary":["https://nginx-php.feature-migration.content-example-com.example.com"],"autogenerated":["https://nginx-php.feature-migration.content-example-com.example.com"]}`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
16 changes: 11 additions & 5 deletions cmd/template_autogen_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ func generateAutogenRoutes(
// if autogenerated routes are enabled, generate them :)
if service.AutogeneratedRoutesEnabled {
if helpers.Contains(supportedAutogeneratedTypes, service.Type) {
domain, shortDomain := AutogeneratedDomainFromPattern(lagoonRouterPattern.Value, serviceName)
// use the service name as the servicetype name
serviceOverrideName := serviceName
if service.OverrideName != "" {
// but if a typename is provided by the service, use it instead
serviceOverrideName = service.OverrideName
}
domain, shortDomain := AutogeneratedDomainFromPattern(lagoonRouterPattern.Value, serviceOverrideName)
serviceValues := lagoon.ServiceValues{
AutogeneratedRouteDomain: domain,
ShortAutogeneratedRouteDomain: shortDomain,
Expand Down Expand Up @@ -112,12 +118,12 @@ func generateAutogenRoutes(
"lagoon.sh/autogenerated": "true",
"helm.sh/chart": fmt.Sprintf("%s-%s", "autogenerated-ingress", "0.1.0"),
"app.kubernetes.io/name": "autogenerated-ingress",
"app.kubernetes.io/instance": serviceName,
"lagoon.sh/service": serviceName,
"app.kubernetes.io/instance": serviceOverrideName,
"lagoon.sh/service": serviceOverrideName,
"lagoon.sh/service-type": service.Type,
},
Service: serviceName,
IngressName: serviceName,
Service: serviceOverrideName,
IngressName: serviceOverrideName,
Insecure: &insecure,
AlternativeNames: alternativeNames,
}
Expand Down
20 changes: 20 additions & 0 deletions cmd/template_autogen_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,26 @@ func TestAutogeneratedIngressGeneration(t *testing.T) {
emptyDir: false,
want: "../test-resources/template-autogenerated/test19-results",
},
{
name: "test20 autogenerated routes where lagoon.name of service does not match service names",
args: args{
alertContact: "alertcontact",
statusPageID: "statuspageid",
projectName: "content-example-com",
environmentName: "feature-migration",
environmentType: "development",
buildType: "branch",
lagoonVersion: "v2.7.x",
branch: "feature/migration",
projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${environment}.${project}.example.com","scope":"internal_system"}]`,
envVars: `[]`,
secretPrefix: "fastly-api-",
lagoonYAML: "../test-resources/template-autogenerated/test20/lagoon.yml",
templatePath: "../test-resources/template-autogenerated/output",
},
emptyDir: false,
want: "../test-resources/template-autogenerated/test20-results",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
19 changes: 19 additions & 0 deletions cmd/template_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,25 @@ func TestTemplateRoutes(t *testing.T) {
},
want: "../test-resources/template-ingress/test10-results",
},
{
name: "test10 standby no values",
args: args{
alertContact: "alertcontact",
statusPageID: "statuspageid",
projectName: "content-example-com",
environmentName: "production",
environmentType: "production",
buildType: "branch",
lagoonVersion: "v2.7.x",
branch: "production",
projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${environment}.${project}.example.com","scope":"internal_system"}]`,
envVars: `[]`,
secretPrefix: "fastly-api-",
lagoonYAML: "../test-resources/template-ingress/test11/lagoon.yml",
templatePath: "../test-resources/template-ingress/output",
},
want: "../test-resources/template-ingress/test11-results",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion internal/lagoon/buildvalues.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ type BuildValues struct {

// ServiceValues is the values for a specific service used by a lagoon build
type ServiceValues struct {
Name string `json:"name"`
Name string `json:"name"` // this is the actual compose service name
OverrideName string `json:"overrideName"` // if an override name is provided, use it
Type string `json:"type"`
AutogeneratedRoutesEnabled bool `json:"autogeneratedRoutesEnabled"`
AutogeneratedRoutesTLSAcme bool `json:"autogeneratedRoutesTLSAcme"`
Expand Down
146 changes: 146 additions & 0 deletions test-resources/identify-ingress/test16/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
version: '2.3'

x-example-image-version:
&example-image-version ${EXAMPLE_IMAGE_VERSION:-4.x}

x-project:
&project ${PROJECT_NAME:-mysite}

x-volumes:
&default-volumes
volumes:
- .:/app:${VOLUME_FLAGS:-delegated} ### Local overrides to mount host filesystem. Automatically removed in CI and PROD.
- ./docroot/sites/default/files:/app/docroot/sites/default/files:${VOLUME_FLAGS:-delegated} ### Local overrides to mount host filesystem. Automatically removed in CI and PROD.

x-environment:
&default-environment
LAGOON_PROJECT: *project
DRUPAL_HASH_SALT: fakehashsaltfakehashsaltfakehashsalt
LAGOON_LOCALDEV_URL: ${LOCALDEV_URL:-http://mysite.docker.amazee.io}
LAGOON_ROUTE: ${LOCALDEV_URL:-http://mysite.docker.amazee.io}
GITHUB_TOKEN: ${GITHUB_TOKEN:-}
EXAMPLE_KEY: ${EXAMPLE_KEY:-}
EXAMPLE_IMAGE_VERSION: ${EXAMPLE_IMAGE_VERSION:-latest}
LAGOON_ENVIRONMENT_TYPE: ${LAGOON_ENVIRONMENT_TYPE:-local}
DRUPAL_REFRESH_SEARCHAPI: ${DRUPAL_REFRESH_SEARCHAPI:-}
EXAMPLE_INGRESS_PSK: ${EXAMPLE_INGRESS_PSK:-}
EXAMPLE_INGRESS_HEADER: ${EXAMPLE_INGRESS_HEADER:-}
EXAMPLE_INGRESS_ENABLED: ${EXAMPLE_INGRESS_ENABLED:-}
REDIS_CACHE_PREFIX: "tide_"
DB_ALIAS: ${DB_ALIAS:-bay.production}


services:

cli:
build:
context: .
dockerfile: .docker/Dockerfile.cli
args:
COMPOSER: ${COMPOSER:-composer.json}
EXAMPLE_IMAGE_VERSION: *example-image-version
image: *project
environment:
<< : *default-environment
<< : *default-volumes
volumes_from: ### Local overrides to mount host SSH keys. Automatically removed in CI.
- container:amazeeio-ssh-agent ### Local overrides to mount host SSH keys. Automatically removed in CI.
labels:
lagoon.type: cli-persistent
lagoon.persistent: /app/docroot/sites/default/files/
lagoon.persistent.name: nginx-php
lagoon.persistent.size: 5Gi

nginx:
build:
context: .
dockerfile: .docker/Dockerfile.nginx-drupal
args:
CLI_IMAGE: *project
EXAMPLE_IMAGE_VERSION: *example-image-version
<< : *default-volumes
environment:
<< : *default-environment
depends_on:
- cli
networks:
- amazeeio-network
- default
labels:
lagoon.type: nginx-php-persistent
lagoon.persistent: /app/docroot/sites/default/files/
lagoon.persistent.size: 5Gi
lagoon.name: nginx-php
expose:
- "8080"
php:
build:
context: .
dockerfile: .docker/Dockerfile.php
args:
CLI_IMAGE: *project
EXAMPLE_IMAGE_VERSION: *example-image-version
environment:
<< : *default-environment
<< : *default-volumes
depends_on:
- cli
labels:
lagoon.type: nginx-php-persistent
lagoon.persistent: /app/docroot/sites/default/files/
lagoon.persistent.size: 5Gi
lagoon.name: nginx-php

mariadb:
image: amazeeio/mariadb-drupal
environment:
<< : *default-environment
ports:
- "3306" # Find port on host with `ahoy info` or `docker-compose port mariadb 3306`
labels:
lagoon.type: mariadb-shared

redis:
image: amazeeio/redis
labels:
lagoon.type: redis

elasticsearch:
build:
context: .
dockerfile: .docker/Dockerfile.elasticsearch
args:
- ES_TPL=${ES_TPL:-elasticsearch.yml}
environment:
- discovery.type=single-node
labels:
lagoon.type: none

chrome:
image: selenium/standalone-chrome:3.141.59-oxygen
shm_size: '1gb'
environment:
<< : *default-environment
<< : *default-volumes
depends_on:
- cli
labels:
lagoon.type: none

clamav:
image: clamav/clamav:${EXAMPLE_IMAGE_VERSION:-4.x}
environment:
<< : *default-environment
ports:
- "3310"
labels:
lagoon.type: none


networks:
amazeeio-network:
external: true

volumes:
app: {}
files: {}
46 changes: 46 additions & 0 deletions test-resources/identify-ingress/test16/lagoon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
docker-compose-yaml: ../test-resources/template-autogenerated/test20/docker-compose.yml

project: content-example-com

environments:
production:
cronjobs:
- name: drush cron
schedule: "*/15 * * * *"
command: 'drush cron'
service: cli

routes:
- nginx-php:
- "content.example.com":
monitoring-path: "/api/v1"
tls-acme: 'false'
insecure: Allow
hsts: max-age=31536000
master:
cronjobs:
- name: drush cron
schedule: "0 1,4 * * *"
command: 'drush cron'
service: cli

routes:
- nginx-php:
- "master.content.example.com":
tls-acme: 'false'
insecure: Allow
hsts: max-age=31536000
develop:
cronjobs:
- name: drush cron
schedule: "0 1,4 * * *"
command: 'drush cron'
service: cli

routes:
- nginx-php:
- "develop.content.example.com":
tls-acme: 'false'
insecure: Allow
hsts: max-age=31536000
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
fastly.amazee.io/watch: "false"
ingress.kubernetes.io/ssl-redirect: "false"
kubernetes.io/tls-acme: "true"
lagoon.sh/branch: feature/migration
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: "false"
creationTimestamp: null
labels:
app.kubernetes.io/instance: nginx-php
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: autogenerated-ingress
helm.sh/chart: autogenerated-ingress-0.1.0
lagoon.sh/autogenerated: "true"
lagoon.sh/buildType: branch
lagoon.sh/environment: feature-migration
lagoon.sh/environmentType: development
lagoon.sh/project: content-example-com
lagoon.sh/service: nginx-php
lagoon.sh/service-type: nginx-php-persistent
name: nginx-php
spec:
rules:
- host: nginx-php.feature-migration.content-example-com.example.com
http:
paths:
- backend:
service:
name: nginx-php
port:
name: http
path: /
pathType: Prefix
tls:
- hosts:
- nginx-php.feature-migration.content-example-com.example.com
secretName: nginx-php-tls
status:
loadBalancer: {}
Loading

0 comments on commit 7805ec3

Please sign in to comment.