Skip to content

Commit

Permalink
refactor: dont update dbaas crds after they are provisioned
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Dec 15, 2024
1 parent e9f8dc4 commit b655c49
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 159 deletions.
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

0 comments on commit b655c49

Please sign in to comment.