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

refactor: dont update dbaas crds after they are provisioned #370

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
6 changes: 3 additions & 3 deletions cmd/template_dbaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ func DBaaSTemplateGeneration(g generator.GeneratorInput,
if err != nil {
return fmt.Errorf("couldn't generate template: %v", err)
}
if len(templateYAML) > 0 {
helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "dbaas"), templateYAML)
for db, tpl := range templateYAML {
helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, db), tpl)
if g.Debug {
fmt.Printf("Templating dbaas consumers to %s\n", fmt.Sprintf("%s/%s.yaml", savedTemplates, "dbaas"))
fmt.Printf("Templating dbaas consumers to %s\n", fmt.Sprintf("%s/%s.yaml", savedTemplates, db))
}
}
return nil
Expand Down
10 changes: 5 additions & 5 deletions internal/templating/template_dbaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,32 +218,32 @@ func GenerateDBaaSTemplate(
return &dbaasTemplates, nil
}

func TemplateConsumers(dbaas *DBaaSTemplates) ([]byte, error) {
func TemplateConsumers(dbaas *DBaaSTemplates) (map[string][]byte, error) {
separator := []byte("---\n")
var templateYAML []byte
templateYAML := map[string][]byte{}
for _, db := range dbaas.MariaDB {
dbBytes, err := yaml.Marshal(db)
if err != nil {
return nil, fmt.Errorf("couldn't generate template: %v", err)
}
restoreResult := append(separator[:], dbBytes[:]...)
templateYAML = append(templateYAML, restoreResult[:]...)
templateYAML[db.Name] = append(templateYAML[db.Name], restoreResult[:]...)
}
for _, db := range dbaas.MongoDB {
dbBytes, err := yaml.Marshal(db)
if err != nil {
return nil, fmt.Errorf("couldn't generate template: %v", err)
}
restoreResult := append(separator[:], dbBytes[:]...)
templateYAML = append(templateYAML, restoreResult[:]...)
templateYAML[db.Name] = append(templateYAML[db.Name], restoreResult[:]...)
}
for _, db := range dbaas.PostgreSQL {
dbBytes, err := yaml.Marshal(db)
if err != nil {
return nil, fmt.Errorf("couldn't generate template: %v", err)
}
restoreResult := append(separator[:], dbBytes[:]...)
templateYAML = append(templateYAML, restoreResult[:]...)
templateYAML[db.Name] = append(templateYAML[db.Name], restoreResult[:]...)
}
return templateYAML, nil
}
9 changes: 7 additions & 2 deletions internal/templating/template_dbaas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func TestGenerateDBaaSTemplate(t *testing.T) {
t.Errorf("GenerateDBaaSTemplate() error = %v, wantErr %v", err, tt.wantErr)
return
}

r1, err := os.ReadFile(tt.want)
if err != nil {
t.Errorf("couldn't read file %v: %v", tt.want, err)
Expand All @@ -169,8 +170,12 @@ func TestGenerateDBaaSTemplate(t *testing.T) {
if err != nil {
t.Errorf("couldn't generate template: %v", err)
}
if !reflect.DeepEqual(string(templateYAML), string(r1)) {
t.Errorf("GenerateDBaaSTemplate() = \n%v", diff.LineDiff(string(r1), string(templateYAML)))
var tplYAML []byte
for _, tpl := range templateYAML {
tplYAML = append(tplYAML, tpl...)
}
if !reflect.DeepEqual(string(tplYAML), string(r1)) {
t.Errorf("GenerateDBaaSTemplate() = \n%v", diff.LineDiff(string(r1), string(tplYAML)))
}
})
}
Expand Down
26 changes: 26 additions & 0 deletions internal/testdata/complex/dbaas-templates/dbaas-3/mariadb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
apiVersion: mariadb.amazee.io/v1
kind: MariaDBConsumer
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: mariadb
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: mariadb-dbaas
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: mariadb
lagoon.sh/service-type: mariadb-dbaas
lagoon.sh/template: mariadb-dbaas-0.1.0
name: mariadb
spec:
consumer:
services: {}
environment: production
provider: {}
status: {}
Original file line number Diff line number Diff line change
@@ -1,32 +1,6 @@
---
apiVersion: mariadb.amazee.io/v1
kind: MariaDBConsumer
metadata:
annotations:
lagoon.sh/branch: main
lagoon.sh/version: v2.7.x
creationTimestamp: null
labels:
app.kubernetes.io/instance: mariadb
app.kubernetes.io/managed-by: build-deploy-tool
app.kubernetes.io/name: mariadb-dbaas
lagoon.sh/buildType: branch
lagoon.sh/environment: main
lagoon.sh/environmentType: production
lagoon.sh/project: example-project
lagoon.sh/service: mariadb
lagoon.sh/service-type: mariadb-dbaas
lagoon.sh/template: mariadb-dbaas-0.1.0
name: mariadb
spec:
consumer:
services: {}
environment: production
provider: {}
status: {}
---
apiVersion: mariadb.amazee.io/v1
kind: MariaDBConsumer
metadata:
annotations:
lagoon.sh/branch: main
Expand Down
90 changes: 0 additions & 90 deletions internal/testdata/node/dbaas-templates/dbaas-1/dbaas.yaml

This file was deleted.

30 changes: 30 additions & 0 deletions internal/testdata/node/dbaas-templates/dbaas-1/mongo.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: 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: {}
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,3 @@ spec:
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: {}
30 changes: 30 additions & 0 deletions internal/testdata/node/dbaas-templates/dbaas-1/mongo3.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: 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: {}
30 changes: 30 additions & 0 deletions internal/testdata/node/dbaas-templates/dbaas-2/mongo2.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: 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: {}
30 changes: 30 additions & 0 deletions internal/testdata/node/dbaas-templates/dbaas-2/mongo3.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: 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: {}
Loading
Loading