Skip to content

Commit

Permalink
refactor: support mongo-mongodb type conversion and add tests for mon…
Browse files Browse the repository at this point in the history
…go to mongodb-dbaas conversion
  • Loading branch information
shreddedbacon committed Feb 28, 2024
1 parent 70b5279 commit 998d865
Show file tree
Hide file tree
Showing 8 changed files with 357 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cmd/template_dbaas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,33 @@ func TestDBaaSTemplateGeneration(t *testing.T) {
templatePath: "testdata/output",
want: "../internal/testdata/complex/dbaas-templates/dbaas-3",
},
{
name: "test4 - mongo",
args: testdata.GetSeedData(
testdata.TestData{
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "../internal/testdata/node/lagoon.mongo.yml",
}, true),
templatePath: "testdata/output",
want: "../internal/testdata/node/dbaas-templates/dbaas-1",
},
{
name: "test5 - mongo override (the mongo should not generate because it has a mongodb-single override)",
args: testdata.GetSeedData(
testdata.TestData{
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "../internal/testdata/node/lagoon.mongo.yml",
ProjectVariables: []lagoon.EnvironmentVariable{
{Name: "LAGOON_SERVICE_TYPES", Value: "mongo:mongodb-single", Scope: "build"},
},
}, true),
templatePath: "testdata/output",
want: "../internal/testdata/node/dbaas-templates/dbaas-2",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions internal/generator/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var oldServiceMap = map[string]string{
"postgres-shared": "postgres-dbaas",
"mongo-shared": "mongodb-dbaas",
"python-ckandatapusher": "python",
"mongo": "mongodb",
}

// these are lagoon types that support autogenerated routes
Expand Down
24 changes: 24 additions & 0 deletions internal/templating/dbaas/template_dbaas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,30 @@ func TestGenerateDBaaSTemplate(t *testing.T) {
},
want: "test-resources/result-postgres-1.yaml",
},
{
name: "test4 - mongo",
args: args{
lValues: generator.BuildValues{
Project: "example-project",
Environment: "environment-with-really-really-reall-3fdb",
EnvironmentType: "production",
Namespace: "myexample-project-environment-with-really-really-reall-3fdb",
BuildType: "branch",
LagoonVersion: "v2.x.x",
Kubernetes: "generator.local",
Branch: "environment-with-really-really-reall-3fdb",
Services: []generator.ServiceValues{
{
Name: "mongo",
OverrideName: "mongo",
Type: "mongodb-dbaas",
DBaaSEnvironment: "development",
},
},
},
},
want: "test-resources/result-mongodb-2.yaml",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
30 changes: 30 additions & 0 deletions internal/templating/dbaas/test-resources/result-mongodb-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
apiVersion: mongodb.amazee.io/v1
kind: MongoDBConsumer
metadata:
annotations:
lagoon.sh/branch: environment-with-really-really-reall-3fdb
lagoon.sh/version: v2.x.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: mongo
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: mongodb-dbaas
lagoon.sh/buildType: branch
lagoon.sh/environment: environment-with-really-really-reall-3fdb
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: mongo
lagoon.sh/service-type: mongodb-dbaas
lagoon.sh/template: mongodb-dbaas-0.1.0
name: mongo
spec:
consumer:
auth:
tls: false
services: {}
environment: development
provider:
auth:
tls: false
status: {}
90 changes: 90 additions & 0 deletions internal/testdata/node/dbaas-templates/dbaas-1/dbaas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
apiVersion: mongodb.amazee.io/v1
kind: MongoDBConsumer
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: mongo
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: mongodb-dbaas
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: mongo
lagoon.sh/service-type: mongodb-dbaas
lagoon.sh/template: mongodb-dbaas-0.1.0
name: mongo
spec:
consumer:
auth:
tls: false
services: {}
environment: production
provider:
auth:
tls: false
status: {}
---
apiVersion: mongodb.amazee.io/v1
kind: MongoDBConsumer
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: mongo2
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: mongodb-dbaas
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: mongo2
lagoon.sh/service-type: mongodb-dbaas
lagoon.sh/template: mongodb-dbaas-0.1.0
name: mongo2
spec:
consumer:
auth:
tls: false
services: {}
environment: production
provider:
auth:
tls: false
status: {}
---
apiVersion: mongodb.amazee.io/v1
kind: MongoDBConsumer
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: mongo3
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: mongodb-dbaas
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: mongo3
lagoon.sh/service-type: mongodb-dbaas
lagoon.sh/template: mongodb-dbaas-0.1.0
name: mongo3
spec:
consumer:
auth:
tls: false
services: {}
environment: production
provider:
auth:
tls: false
status: {}
60 changes: 60 additions & 0 deletions internal/testdata/node/dbaas-templates/dbaas-2/dbaas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
apiVersion: mongodb.amazee.io/v1
kind: MongoDBConsumer
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: mongo2
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: mongodb-dbaas
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: mongo2
lagoon.sh/service-type: mongodb-dbaas
lagoon.sh/template: mongodb-dbaas-0.1.0
name: mongo2
spec:
consumer:
auth:
tls: false
services: {}
environment: production
provider:
auth:
tls: false
status: {}
---
apiVersion: mongodb.amazee.io/v1
kind: MongoDBConsumer
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: mongo3
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: mongodb-dbaas
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: mongo3
lagoon.sh/service-type: mongodb-dbaas
lagoon.sh/template: mongodb-dbaas-0.1.0
name: mongo3
spec:
consumer:
auth:
tls: false
services: {}
environment: production
provider:
auth:
tls: false
status: {}
55 changes: 55 additions & 0 deletions internal/testdata/node/docker-compose.mongo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
version: '2'
services:
node:
networks:
- amazeeio-network
- default
build:
context: .
dockerfile: node.dockerfile
labels:
lagoon.type: node
volumes:
- .:/app:delegated
environment:
- LAGOON_LOCALDEV_HTTP_PORT=3000
- LAGOON_ROUTE=http://node.docker.amazee.io

mongo:
image: fake/mongo:latest
labels:
lagoon.type: mongo
ports:
- "27100" # exposes the port 9200 with a random local port, find it with `docker-compose port opensearch 9200`
volumes:
- data:/mongo/data

mongo2:
image: fake/mongo:latest
labels:
lagoon.type: mongodb
ports:
- "27100" # exposes the port 9200 with a random local port, find it with `docker-compose port opensearch 9200`
volumes:
- data2:/mongo/data

mongo3:
image: fake/mongo:latest
labels:
lagoon.type: mongo-shared
ports:
- "27100" # exposes the port 9200 with a random local port, find it with `docker-compose port opensearch 9200`
volumes:
- data3:/mongo/data

networks:
amazeeio-network:
external: true

volumes:
data:
{}
data2:
{}
data3:
{}
70 changes: 70 additions & 0 deletions internal/testdata/node/lagoon.mongo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
docker-compose-yaml: ../internal/testdata/node/docker-compose.mongo.yml


environment_variables:
git_sha: "true"

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

autogendisabled:
autogenerateRoutes: false
routes:
- node:
- example.com

tworoutes:
routes:
- node:
- example.com
- www.example.com

branch/routes:
routes:
- node:
- customdomain-will-be-main-domain.com
- customdomain-will-be-not-be-main-domain.com

ingressclass:
routes:
- node:
- example.com:
ingressClass: "custom-ingress"
hsts:
routes:
- node:
- example.com:
hstsEnabled: true
hstsMaxAge: 10000

hsts2:
routes:
- node:
- example.com:
hstsEnabled: true
hstsMaxAge: 10000
hstsIncludeSubdomains: true
hstsPreload: true

pr-4841:
routes:
- nginx:
- performance.example.com

alternativename:
routes:
- node:
- example.com:
alternativenames:
- www.example.com
- en.example.com

wildcard:
routes:
- node:
- example.com:
tls-acme: false
wildcard: true

0 comments on commit 998d865

Please sign in to comment.