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
10 changes: 6 additions & 4 deletions cmd/template_dbaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ func DBaaSTemplateGeneration(g generator.GeneratorInput,
}
savedTemplates := g.SavedTemplatesPath

templateYAML, err := dbaasTemplater.GenerateDBaaSTemplate(*lagoonBuild.BuildValues)
dbaas, err := dbaasTemplater.GenerateDBaaSTemplate(*lagoonBuild.BuildValues)
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 dn, d := range dbaas {
separator := []byte("---\n")
restoreResult := append(separator[:], d[:]...)
if g.Debug {
fmt.Printf("Templating dbaas consumers to %s\n", fmt.Sprintf("%s/%s.yaml", savedTemplates, "dbaas"))
fmt.Printf("Templating deployment manifests %s\n", fmt.Sprintf("%s/%s.yaml", savedTemplates, dn))
}
helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, dn), restoreResult)
}
return nil
}
Expand Down
12 changes: 4 additions & 8 deletions internal/templating/dbaas/template_dbaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ var dbaasTypes = []string{
// GenerateDBaaSTemplate generates the lagoon template to apply.
func GenerateDBaaSTemplate(
lValues generator.BuildValues,
) ([]byte, error) {
separator := []byte("---\n")
var result []byte
) (map[string][]byte, error) {
result := make(map[string][]byte)

// add the default labels
labels := map[string]string{
Expand Down Expand Up @@ -202,11 +201,8 @@ func GenerateDBaaSTemplate(

}
// @TODO: we should review this in the future when we stop doing `kubectl apply` in the builds :)
// add the seperator to the template so that it can be `kubectl apply` in bulk as part
// of the current build process
// join all dbaas-consumer templates together
restoreResult := append(separator[:], consumerBytes[:]...)
result = append(result, restoreResult[:]...)
// add to the map so that it can be templated out and `kubectl apply` as part of the current build process
result[serviceValues.Name] = consumerBytes
}
}
return result, nil
Expand Down
11 changes: 9 additions & 2 deletions internal/templating/dbaas/template_dbaas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,19 @@ 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)
}
if !reflect.DeepEqual(string(got), string(r1)) {
t.Errorf("GenerateDBaaSTemplate() = \n%v", diff.LineDiff(string(r1), string(got)))
separator := []byte("---\n")
var result []byte
for _, d := range got {
restoreResult := append(separator[:], d[:]...)
result = append(result, restoreResult[:]...)
}
if !reflect.DeepEqual(string(result), string(r1)) {
t.Errorf("GenerateServiceTemplate() = \n%v", diff.LineDiff(string(r1), string(result)))
}
})
}
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