diff --git a/cmd/identify_lagoonservices.go b/cmd/identify_lagoonservices.go index d17b8ad9..a81e7c85 100644 --- a/cmd/identify_lagoonservices.go +++ b/cmd/identify_lagoonservices.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/cobra" generator "github.com/uselagoon/build-deploy-tool/internal/generator" - servicestemplates "github.com/uselagoon/build-deploy-tool/internal/templating/services" + servicestemplates "github.com/uselagoon/build-deploy-tool/internal/templating" ) type identifyServices struct { diff --git a/cmd/template_autogen_ingress.go b/cmd/template_autogen_ingress.go index 5ab47649..eda356a5 100644 --- a/cmd/template_autogen_ingress.go +++ b/cmd/template_autogen_ingress.go @@ -6,7 +6,8 @@ import ( "github.com/spf13/cobra" generator "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/helpers" - ingresstemplate "github.com/uselagoon/build-deploy-tool/internal/templating/ingress" + servicestemplates "github.com/uselagoon/build-deploy-tool/internal/templating" + "sigs.k8s.io/yaml" ) var autogenRouteGeneration = &cobra.Command{ @@ -31,17 +32,22 @@ func AutogeneratedIngressGeneration(g generator.GeneratorInput) error { return err } savedTemplates := g.SavedTemplatesPath - + separator := []byte("---\n") // generate the templates for _, route := range lagoonBuild.AutogeneratedRoutes.Routes { // autogenerated routes use the `servicename` as the name of the ingress resource, use `IngressName` in routev2 to handle this if g.Debug { fmt.Printf("Templating autogenerated ingress manifest for %s to %s\n", route.Domain, fmt.Sprintf("%s/%s.yaml", savedTemplates, route.LagoonService)) } - templateYAML, err := ingresstemplate.GenerateIngressTemplate(route, *lagoonBuild.BuildValues) + ingress, err := servicestemplates.GenerateIngressTemplate(route, *lagoonBuild.BuildValues) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + iBytes, err := yaml.Marshal(ingress) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } + templateYAML := append(separator[:], iBytes[:]...) helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, route.LagoonService), templateYAML) } diff --git a/cmd/template_backups.go b/cmd/template_backups.go index 33ff8ef9..a24f9ae9 100644 --- a/cmd/template_backups.go +++ b/cmd/template_backups.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/cobra" generator "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/helpers" - backuptemplate "github.com/uselagoon/build-deploy-tool/internal/templating/backups" + servicestemplates "github.com/uselagoon/build-deploy-tool/internal/templating" "sigs.k8s.io/yaml" ) @@ -69,16 +69,24 @@ func BackupTemplateGeneration(g generator.GeneratorInput, lagoonBuild.BuildValues.Services = repServices // generate the backup schedule templates - templateYAML, err := backuptemplate.GenerateBackupSchedule(*lagoonBuild.BuildValues) + schedules, err := servicestemplates.GenerateBackupSchedule(*lagoonBuild.BuildValues) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + templateYAML, err := servicestemplates.TemplateSchedules(schedules) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } if len(templateYAML) > 0 { helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "k8up-lagoon-backup-schedule"), templateYAML) } - + templateYAML = nil // generate any prebackuppod templates - templateYAML, err = backuptemplate.GeneratePreBackupPod(*lagoonBuild.BuildValues) + pbps, err := servicestemplates.GeneratePreBackupPod(*lagoonBuild.BuildValues) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + templateYAML, err = servicestemplates.TemplatePreBackupPods(pbps) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } diff --git a/cmd/template_backups_test.go b/cmd/template_backups_test.go index bf9658de..0ae74a96 100644 --- a/cmd/template_backups_test.go +++ b/cmd/template_backups_test.go @@ -6,6 +6,7 @@ import ( "reflect" "testing" + "github.com/andreyvit/diff" "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/lagoon" @@ -328,8 +329,7 @@ func TestBackupTemplateGeneration(t *testing.T) { t.Errorf("couldn't read file %v: %v", tt.want, err) } if !reflect.DeepEqual(f1, r1) { - fmt.Println(string(f1)) - t.Errorf("resulting templates do not match") + t.Errorf("BackupTemplateGeneration() = \n%v", diff.LineDiff(string(r1), string(f1))) } } } diff --git a/cmd/template_dbaas.go b/cmd/template_dbaas.go index ad304602..9b34a2da 100644 --- a/cmd/template_dbaas.go +++ b/cmd/template_dbaas.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" generator "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/helpers" - dbaasTemplater "github.com/uselagoon/build-deploy-tool/internal/templating/dbaas" + servicestemplates "github.com/uselagoon/build-deploy-tool/internal/templating" ) var dbaasGeneration = &cobra.Command{ @@ -33,7 +33,11 @@ func DBaaSTemplateGeneration(g generator.GeneratorInput, } savedTemplates := g.SavedTemplatesPath - templateYAML, err := dbaasTemplater.GenerateDBaaSTemplate(*lagoonBuild.BuildValues) + dbaas, err := servicestemplates.GenerateDBaaSTemplate(*lagoonBuild.BuildValues) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + templateYAML, err := servicestemplates.TemplateConsumers(dbaas) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } diff --git a/cmd/template_dbaas_test.go b/cmd/template_dbaas_test.go index 026845cf..aa8bbc37 100644 --- a/cmd/template_dbaas_test.go +++ b/cmd/template_dbaas_test.go @@ -7,6 +7,7 @@ import ( "reflect" "testing" + "github.com/andreyvit/diff" "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/lagoon" @@ -184,8 +185,7 @@ func TestDBaaSTemplateGeneration(t *testing.T) { t.Errorf("couldn't read file %v: %v", tt.want, err) } if !reflect.DeepEqual(f1, r1) { - fmt.Println(string(f1)) - t.Errorf("resulting templates do not match") + t.Errorf("DBaaSTemplateGeneration() = \n%v", diff.LineDiff(string(r1), string(f1))) } } } diff --git a/cmd/template_ingress.go b/cmd/template_ingress.go index 19afe880..311cf09c 100644 --- a/cmd/template_ingress.go +++ b/cmd/template_ingress.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" generator "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/helpers" - ingresstemplate "github.com/uselagoon/build-deploy-tool/internal/templating/ingress" + servicestemplates "github.com/uselagoon/build-deploy-tool/internal/templating" ) var routeGeneration = &cobra.Command{ @@ -31,13 +31,16 @@ func IngressTemplateGeneration(g generator.GeneratorInput) error { return err } savedTemplates := g.SavedTemplatesPath - // generate the templates for _, route := range lagoonBuild.MainRoutes.Routes { if g.Debug { fmt.Printf("Templating ingress manifest for %s to %s\n", route.Domain, fmt.Sprintf("%s/%s.yaml", savedTemplates, route.Domain)) } - templateYAML, err := ingresstemplate.GenerateIngressTemplate(route, *lagoonBuild.BuildValues) + ingress, err := servicestemplates.GenerateIngressTemplate(route, *lagoonBuild.BuildValues) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + templateYAML, err := servicestemplates.TemplateIngress(ingress) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } @@ -53,7 +56,11 @@ func IngressTemplateGeneration(g generator.GeneratorInput) error { if g.Debug { fmt.Printf("Templating active/standby ingress manifest for %s to %s\n", route.Domain, fmt.Sprintf("%s/%s.yaml", savedTemplates, route.Domain)) } - templateYAML, err := ingresstemplate.GenerateIngressTemplate(route, *lagoonBuild.BuildValues) + ingress, err := servicestemplates.GenerateIngressTemplate(route, *lagoonBuild.BuildValues) + if err != nil { + return fmt.Errorf("couldn't generate template: %v", err) + } + templateYAML, err := servicestemplates.TemplateIngress(ingress) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } diff --git a/cmd/template_lagoonservices.go b/cmd/template_lagoonservices.go index 2efc7df4..6851ecbf 100644 --- a/cmd/template_lagoonservices.go +++ b/cmd/template_lagoonservices.go @@ -7,9 +7,7 @@ import ( "github.com/spf13/cobra" generator "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/helpers" - "github.com/uselagoon/build-deploy-tool/internal/templating/networkpolicy" - "github.com/uselagoon/build-deploy-tool/internal/templating/registrysecret" - servicestemplates "github.com/uselagoon/build-deploy-tool/internal/templating/services" + servicestemplates "github.com/uselagoon/build-deploy-tool/internal/templating" "sigs.k8s.io/yaml" ) @@ -62,102 +60,90 @@ func LagoonServiceTemplateGeneration(g generator.GeneratorInput) error { savedTemplates := g.SavedTemplatesPath // generate the templates - secrets, err := registrysecret.GenerateRegistrySecretTemplate(*lagoonBuild.BuildValues) + secrets, err := servicestemplates.GenerateRegistrySecretTemplate(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } for _, secret := range secrets { - serviceBytes, err := yaml.Marshal(secret) + templateBytes, err := servicestemplates.TemplateSecret(secret) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - separator := []byte("---\n") - restoreResult := append(separator[:], serviceBytes[:]...) if g.Debug { fmt.Printf("Templating registry secret manifests %s\n", fmt.Sprintf("%s/%s.yaml", savedTemplates, secret.Name)) } - helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, secret.Name), restoreResult) + helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, secret.Name), templateBytes) } services, err := servicestemplates.GenerateServiceTemplate(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } for _, d := range services { - serviceBytes, err := yaml.Marshal(d) + templateBytes, err := servicestemplates.TemplateService(d) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - separator := []byte("---\n") - restoreResult := append(separator[:], serviceBytes[:]...) if g.Debug { fmt.Printf("Templating service manifests %s\n", fmt.Sprintf("%s/service-%s.yaml", savedTemplates, d.Name)) } - helpers.WriteTemplateFile(fmt.Sprintf("%s/service-%s.yaml", savedTemplates, d.Name), restoreResult) + helpers.WriteTemplateFile(fmt.Sprintf("%s/service-%s.yaml", savedTemplates, d.Name), templateBytes) } pvcs, err := servicestemplates.GeneratePVCTemplate(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } for _, d := range pvcs { - serviceBytes, err := yaml.Marshal(d) + templateBytes, err := servicestemplates.TemplatePVC(d) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - separator := []byte("---\n") - restoreResult := append(separator[:], serviceBytes[:]...) if g.Debug { fmt.Printf("Templating pvc manifests %s\n", fmt.Sprintf("%s/pvc-%s.yaml", savedTemplates, d.Name)) } - helpers.WriteTemplateFile(fmt.Sprintf("%s/pvc-%s.yaml", savedTemplates, d.Name), restoreResult) + helpers.WriteTemplateFile(fmt.Sprintf("%s/pvc-%s.yaml", savedTemplates, d.Name), templateBytes) } deployments, err := servicestemplates.GenerateDeploymentTemplate(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } for _, d := range deployments { - deploymentBytes, err := yaml.Marshal(d) + templateBytes, err := servicestemplates.TemplateDeployment(d) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - separator := []byte("---\n") - restoreResult := append(separator[:], deploymentBytes[:]...) if g.Debug { fmt.Printf("Templating deployment manifests %s\n", fmt.Sprintf("%s/deployment-%s.yaml", savedTemplates, d.Name)) } - helpers.WriteTemplateFile(fmt.Sprintf("%s/deployment-%s.yaml", savedTemplates, d.Name), restoreResult) + helpers.WriteTemplateFile(fmt.Sprintf("%s/deployment-%s.yaml", savedTemplates, d.Name), templateBytes) } cronjobs, err := servicestemplates.GenerateCronjobTemplate(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } for _, d := range cronjobs { - deploymentBytes, err := yaml.Marshal(d) + templateBytes, err := servicestemplates.TemplateCronjobs(d) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - separator := []byte("---\n") - restoreResult := append(separator[:], deploymentBytes[:]...) if g.Debug { fmt.Printf("Templating cronjob manifests %s\n", fmt.Sprintf("%s/cronjob-%s.yaml", savedTemplates, d.Name)) } - helpers.WriteTemplateFile(fmt.Sprintf("%s/cronjob-%s.yaml", savedTemplates, d.Name), restoreResult) + helpers.WriteTemplateFile(fmt.Sprintf("%s/cronjob-%s.yaml", savedTemplates, d.Name), templateBytes) } if lagoonBuild.BuildValues.IsolationNetworkPolicy { // if isolation network policies are enabled, template that here - np, err := networkpolicy.GenerateNetworkPolicy(*lagoonBuild.BuildValues) + np, err := servicestemplates.GenerateNetworkPolicy(*lagoonBuild.BuildValues) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - npBytes, err := yaml.Marshal(np) + templateBytes, err := servicestemplates.TemplateNetworkPolicy(np) if err != nil { return fmt.Errorf("couldn't generate template: %v", err) } - separator := []byte("---\n") - restoreResult := append(separator[:], npBytes[:]...) if g.Debug { fmt.Printf("Templating networkpolicy manifest %s\n", fmt.Sprintf("%s/isolation-network-policy.yaml", savedTemplates)) } - helpers.WriteTemplateFile(fmt.Sprintf("%s/isolation-network-policy.yaml", savedTemplates), restoreResult) + helpers.WriteTemplateFile(fmt.Sprintf("%s/isolation-network-policy.yaml", savedTemplates), templateBytes) } return nil } diff --git a/internal/templating/dbaas/template_dbaas.go b/internal/templating/template_dbaas.go similarity index 70% rename from internal/templating/dbaas/template_dbaas.go rename to internal/templating/template_dbaas.go index 74325022..7c87b78f 100644 --- a/internal/templating/dbaas/template_dbaas.go +++ b/internal/templating/template_dbaas.go @@ -1,4 +1,4 @@ -package dbaas +package services import ( "fmt" @@ -8,10 +8,11 @@ import ( postgresv1 "github.com/amazeeio/dbaas-operator/apis/postgres/v1" "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/helpers" + "sigs.k8s.io/yaml" + apivalidation "k8s.io/apimachinery/pkg/api/validation" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" - "sigs.k8s.io/yaml" ) var dbaasTypes = []string{ @@ -20,12 +21,19 @@ var dbaasTypes = []string{ "postgres-dbaas", } +type DBaaSTemplates struct { + MariaDB []mariadbv1.MariaDBConsumer + MongoDB []mongodbv1.MongoDBConsumer + PostgreSQL []postgresv1.PostgreSQLConsumer +} + // GenerateDBaaSTemplate generates the lagoon template to apply. func GenerateDBaaSTemplate( lValues generator.BuildValues, -) ([]byte, error) { - separator := []byte("---\n") - var result []byte +) (*DBaaSTemplates, error) { + // separator := []byte("---\n") + // var result []byte + var dbaasTemplates DBaaSTemplates // add the default labels labels := map[string]string{ @@ -55,7 +63,6 @@ func GenerateDBaaSTemplate( for _, serviceValues := range lValues.Services { if helpers.Contains(dbaasTypes, serviceValues.Type) { - var consumerBytes []byte additionalLabels["app.kubernetes.io/name"] = serviceValues.Type additionalLabels["app.kubernetes.io/instance"] = serviceValues.Name additionalLabels["lagoon.sh/template"] = fmt.Sprintf("%s-%s", serviceValues.Type, "0.1.0") @@ -64,7 +71,7 @@ func GenerateDBaaSTemplate( switch serviceValues.Type { case "mariadb-dbaas": { - mariaDBConsumer := &mariadbv1.MariaDBConsumer{ + mariaDBConsumer := mariadbv1.MariaDBConsumer{ TypeMeta: metav1.TypeMeta{ Kind: "MariaDBConsumer", APIVersion: mariadbv1.GroupVersion.String(), @@ -76,12 +83,17 @@ func GenerateDBaaSTemplate( Environment: serviceValues.DBaaSEnvironment, }, } - mariaDBConsumer.ObjectMeta.Labels = labels - mariaDBConsumer.ObjectMeta.Annotations = annotations + mariaDBConsumer.ObjectMeta.Labels = map[string]string{} + mariaDBConsumer.ObjectMeta.Annotations = map[string]string{} + for key, value := range labels { + mariaDBConsumer.ObjectMeta.Labels[key] = value + } + for key, value := range annotations { + mariaDBConsumer.ObjectMeta.Annotations[key] = value + } for key, value := range additionalLabels { mariaDBConsumer.ObjectMeta.Labels[key] = value } - // add any additional annotations for key, value := range additionalAnnotations { mariaDBConsumer.ObjectMeta.Annotations[key] = value } @@ -103,10 +115,7 @@ func GenerateDBaaSTemplate( if err != nil { return nil, err } - consumerBytes, err = yaml.Marshal(mariaDBConsumer) - if err != nil { - return nil, err - } + dbaasTemplates.MariaDB = append(dbaasTemplates.MariaDB, mariaDBConsumer) } case "mongodb-dbaas": { @@ -122,12 +131,17 @@ func GenerateDBaaSTemplate( Environment: serviceValues.DBaaSEnvironment, }, } - mongodbConsumer.ObjectMeta.Labels = labels - mongodbConsumer.ObjectMeta.Annotations = annotations + mongodbConsumer.ObjectMeta.Labels = map[string]string{} + mongodbConsumer.ObjectMeta.Annotations = map[string]string{} + for key, value := range labels { + mongodbConsumer.ObjectMeta.Labels[key] = value + } + for key, value := range annotations { + mongodbConsumer.ObjectMeta.Annotations[key] = value + } for key, value := range additionalLabels { mongodbConsumer.ObjectMeta.Labels[key] = value } - // add any additional annotations for key, value := range additionalAnnotations { mongodbConsumer.ObjectMeta.Annotations[key] = value } @@ -148,10 +162,7 @@ func GenerateDBaaSTemplate( if err != nil { return nil, err } - consumerBytes, err = yaml.Marshal(mongodbConsumer) - if err != nil { - return nil, err - } + dbaasTemplates.MongoDB = append(dbaasTemplates.MongoDB, *mongodbConsumer) } case "postgres-dbaas": { @@ -167,12 +178,17 @@ func GenerateDBaaSTemplate( Environment: serviceValues.DBaaSEnvironment, }, } - postgresqlConsumer.ObjectMeta.Labels = labels - postgresqlConsumer.ObjectMeta.Annotations = annotations + postgresqlConsumer.ObjectMeta.Labels = map[string]string{} + postgresqlConsumer.ObjectMeta.Annotations = map[string]string{} + for key, value := range labels { + postgresqlConsumer.ObjectMeta.Labels[key] = value + } + for key, value := range annotations { + postgresqlConsumer.ObjectMeta.Annotations[key] = value + } for key, value := range additionalLabels { postgresqlConsumer.ObjectMeta.Labels[key] = value } - // add any additional annotations for key, value := range additionalAnnotations { postgresqlConsumer.ObjectMeta.Annotations[key] = value } @@ -194,20 +210,40 @@ func GenerateDBaaSTemplate( if err != nil { return nil, err } - consumerBytes, err = yaml.Marshal(postgresqlConsumer) - if err != nil { - return nil, err - } + dbaasTemplates.PostgreSQL = append(dbaasTemplates.PostgreSQL, *postgresqlConsumer) } - } - // @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[:]...) } } - return result, nil + return &dbaasTemplates, nil +} + +func TemplateConsumers(dbaas *DBaaSTemplates) ([]byte, error) { + separator := []byte("---\n") + var templateYAML []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[:]...) + } + 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[:]...) + } + 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[:]...) + } + return templateYAML, nil } diff --git a/internal/templating/dbaas/template_dbaas_test.go b/internal/templating/template_dbaas_test.go similarity index 73% rename from internal/templating/dbaas/template_dbaas_test.go rename to internal/templating/template_dbaas_test.go index 8213a3f1..063570c6 100644 --- a/internal/templating/dbaas/template_dbaas_test.go +++ b/internal/templating/template_dbaas_test.go @@ -1,4 +1,4 @@ -package dbaas +package services import ( "os" @@ -43,7 +43,7 @@ func TestGenerateDBaaSTemplate(t *testing.T) { }, }, }, - want: "test-resources/result-mariadb-1.yaml", + want: "test-resources/dbaas/result-mariadb-1.yaml", }, { name: "test2 - mongodb", @@ -67,7 +67,7 @@ func TestGenerateDBaaSTemplate(t *testing.T) { }, }, }, - want: "test-resources/result-mongodb-1.yaml", + want: "test-resources/dbaas/result-mongodb-1.yaml", }, { name: "test3 - postgres", @@ -91,7 +91,7 @@ func TestGenerateDBaaSTemplate(t *testing.T) { }, }, }, - want: "test-resources/result-postgres-1.yaml", + want: "test-resources/dbaas/result-postgres-1.yaml", }, { name: "test4 - mongo", @@ -115,7 +115,37 @@ func TestGenerateDBaaSTemplate(t *testing.T) { }, }, }, - want: "test-resources/result-mongodb-2.yaml", + want: "test-resources/dbaas/result-mongodb-2.yaml", + }, + { + name: "test5 - multi mariadb", + 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: "mariadb", + OverrideName: "mariadb", + Type: "mariadb-dbaas", + DBaaSEnvironment: "development", + }, + { + Name: "mariadb2", + OverrideName: "mariadb2", + Type: "mariadb-dbaas", + DBaaSEnvironment: "development", + }, + }, + }, + }, + want: "test-resources/dbaas/result-mariadb-2.yaml", }, } for _, tt := range tests { @@ -135,8 +165,12 @@ func TestGenerateDBaaSTemplate(t *testing.T) { 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))) + templateYAML, err := TemplateConsumers(got) + 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))) } }) } diff --git a/internal/templating/services/template_helpers.go b/internal/templating/template_helpers.go similarity index 100% rename from internal/templating/services/template_helpers.go rename to internal/templating/template_helpers.go diff --git a/internal/templating/networkpolicy/template_networkpolicy.go b/internal/templating/template_networkpolicy.go similarity index 82% rename from internal/templating/networkpolicy/template_networkpolicy.go rename to internal/templating/template_networkpolicy.go index bc3ffb64..9502911e 100644 --- a/internal/templating/networkpolicy/template_networkpolicy.go +++ b/internal/templating/template_networkpolicy.go @@ -1,15 +1,18 @@ -package networkpolicy +package services import ( + "fmt" + "github.com/uselagoon/build-deploy-tool/internal/generator" networkv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/yaml" ) // GenerateNetworkPolicy generates the lagoon template to apply. func GenerateNetworkPolicy( buildValues generator.BuildValues, -) (networkv1.NetworkPolicy, error) { +) (*networkv1.NetworkPolicy, error) { // add the default labels labels := map[string]string{ "app.kubernetes.io/managed-by": "build-deploy-tool", @@ -70,5 +73,17 @@ func GenerateNetworkPolicy( }, }, } - return np, nil + return &np, nil +} + +func TemplateNetworkPolicy(ingress *networkv1.NetworkPolicy) ([]byte, error) { + separator := []byte("---\n") + var templateYAML []byte + iBytes, err := yaml.Marshal(ingress) + if err != nil { + return nil, fmt.Errorf("couldn't generate template: %v", err) + } + restoreResult := append(separator[:], iBytes[:]...) + templateYAML = append(templateYAML, restoreResult[:]...) + return templateYAML, nil } diff --git a/internal/templating/networkpolicy/template_networkpolicy_test.go b/internal/templating/template_networkpolicy_test.go similarity index 93% rename from internal/templating/networkpolicy/template_networkpolicy_test.go rename to internal/templating/template_networkpolicy_test.go index 6598c254..cced032b 100644 --- a/internal/templating/networkpolicy/template_networkpolicy_test.go +++ b/internal/templating/template_networkpolicy_test.go @@ -1,4 +1,4 @@ -package networkpolicy +package services import ( "os" @@ -8,7 +8,6 @@ import ( "github.com/andreyvit/diff" "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/lagoon" - "sigs.k8s.io/yaml" ) func TestGenerateNetworkPolicy(t *testing.T) { @@ -109,7 +108,7 @@ func TestGenerateNetworkPolicy(t *testing.T) { }, }, }, - want: "test-resources/result-np-1.yaml", + want: "test-resources/netpol/result-np-1.yaml", }, } for _, tt := range tests { @@ -123,14 +122,10 @@ func TestGenerateNetworkPolicy(t *testing.T) { if err != nil { t.Errorf("couldn't read file %v: %v", tt.want, err) } - separator := []byte("---\n") - var result []byte - deploymentBytes, err := yaml.Marshal(got) + result, err := TemplateNetworkPolicy(got) if err != nil { t.Errorf("couldn't generate template %v", err) } - restoreResult := append(separator[:], deploymentBytes[:]...) - result = append(result, restoreResult[:]...) if !reflect.DeepEqual(string(result), string(r1)) { t.Errorf("GenerateDeploymentTemplate() = \n%v", diff.LineDiff(string(r1), string(result))) } diff --git a/internal/templating/backups/template_prebackuppod.go b/internal/templating/template_prebackuppod.go similarity index 86% rename from internal/templating/backups/template_prebackuppod.go rename to internal/templating/template_prebackuppod.go index 43ce0c9c..0f863581 100644 --- a/internal/templating/backups/template_prebackuppod.go +++ b/internal/templating/template_prebackuppod.go @@ -1,4 +1,4 @@ -package backups +package services import ( "bytes" @@ -24,13 +24,17 @@ type PreBackupPodTmpl struct { Namespace string } +type PreBackupPod struct { + K8upV1 []k8upv1.PreBackupPod + K8upV1alpha1 []k8upv1alpha1.PreBackupPod +} + func GeneratePreBackupPod( lValues generator.BuildValues, -) ([]byte, error) { +) (*PreBackupPod, error) { // generate the template spec - var result []byte - separator := []byte("---\n") + var result PreBackupPod // add the default labels labels := map[string]string{ @@ -75,9 +79,20 @@ func GeneratePreBackupPod( }, Spec: k8upv1alpha1.PreBackupPodSpec{}, } - - prebackuppod.ObjectMeta.Labels = labels - prebackuppod.ObjectMeta.Annotations = annotations + prebackuppod.ObjectMeta.Labels = map[string]string{} + prebackuppod.ObjectMeta.Annotations = map[string]string{} + for key, value := range labels { + prebackuppod.ObjectMeta.Labels[key] = value + } + for key, value := range annotations { + prebackuppod.ObjectMeta.Annotations[key] = value + } + for key, value := range additionalLabels { + prebackuppod.ObjectMeta.Labels[key] = value + } + for key, value := range additionalAnnotations { + prebackuppod.ObjectMeta.Annotations[key] = value + } prebackuppod.ObjectMeta.Labels["prebackuppod"] = serviceValues.Name var pbp bytes.Buffer @@ -142,18 +157,7 @@ func GeneratePreBackupPod( if err != nil { return nil, err } - // @TODO: we should review this in the future when we stop doing `kubectl apply` in the builds :) - // marshal the resulting ingress - prebackuppodBytes, err := yaml.Marshal(prebackuppod) - if err != nil { - return nil, err - } - - pbpBytes, _ := RemoveYAML(prebackuppodBytes) - // add the seperator to the template so that it can be `kubectl apply` in bulk as part - // of the current build process - restoreResult := append(separator[:], pbpBytes[:]...) - result = append(result, restoreResult[:]...) + result.K8upV1alpha1 = append(result.K8upV1alpha1, *prebackuppod) case "v2": prebackuppod := &k8upv1.PreBackupPod{ TypeMeta: metav1.TypeMeta{ @@ -165,9 +169,20 @@ func GeneratePreBackupPod( }, Spec: k8upv1.PreBackupPodSpec{}, } - - prebackuppod.ObjectMeta.Labels = labels - prebackuppod.ObjectMeta.Annotations = annotations + prebackuppod.ObjectMeta.Labels = map[string]string{} + prebackuppod.ObjectMeta.Annotations = map[string]string{} + for key, value := range labels { + prebackuppod.ObjectMeta.Labels[key] = value + } + for key, value := range annotations { + prebackuppod.ObjectMeta.Annotations[key] = value + } + for key, value := range additionalLabels { + prebackuppod.ObjectMeta.Labels[key] = value + } + for key, value := range additionalAnnotations { + prebackuppod.ObjectMeta.Annotations[key] = value + } prebackuppod.ObjectMeta.Labels["prebackuppod"] = serviceValues.Name var pbp bytes.Buffer @@ -232,21 +247,35 @@ func GeneratePreBackupPod( if err != nil { return nil, err } - // @TODO: we should review this in the future when we stop doing `kubectl apply` in the builds :) - // marshal the resulting ingress - prebackuppodBytes, err := yaml.Marshal(prebackuppod) - if err != nil { - return nil, err - } - pbpBytes, _ := RemoveYAML(prebackuppodBytes) - // add the seperator to the template so that it can be `kubectl apply` in bulk as part - // of the current build process - restoreResult := append(separator[:], pbpBytes[:]...) - result = append(result, restoreResult[:]...) + result.K8upV1 = append(result.K8upV1, *prebackuppod) } } } - return result, nil + return &result, nil +} + +func TemplatePreBackupPods(pbps *PreBackupPod) ([]byte, error) { + separator := []byte("---\n") + var templateYAML []byte + for _, pbp := range pbps.K8upV1 { + pbpBytes, err := yaml.Marshal(pbp) + if err != nil { + return nil, fmt.Errorf("couldn't generate template: %v", err) + } + pbpBytes, _ = RemoveYAML(pbpBytes) + restoreResult := append(separator[:], pbpBytes[:]...) + templateYAML = append(templateYAML, restoreResult[:]...) + } + for _, pbp := range pbps.K8upV1alpha1 { + pbpBytes, err := yaml.Marshal(pbp) + if err != nil { + return nil, fmt.Errorf("couldn't generate template: %v", err) + } + pbpBytes, _ = RemoveYAML(pbpBytes) + restoreResult := append(separator[:], pbpBytes[:]...) + templateYAML = append(templateYAML, restoreResult[:]...) + } + return templateYAML, nil } // helper function to remove the creationtimestamp from the prebackuppod pod spec so that kubectl will apply without validation errors @@ -267,7 +296,7 @@ var funcMap = template.FuncMap{ // varfix just uppercases and replaces - with _ for variable names func varFix(s string) string { - return fmt.Sprintf("%s", strings.ToUpper(strings.Replace(s, "-", "_", -1))) + return strings.ToUpper(strings.Replace(s, "-", "_", -1)) } // this is just the first run at doing this, once the service template generator is introduced, this will need to be re-evaluated diff --git a/internal/templating/backups/template_prebackuppod_test.go b/internal/templating/template_prebackuppod_test.go similarity index 89% rename from internal/templating/backups/template_prebackuppod_test.go rename to internal/templating/template_prebackuppod_test.go index 47698464..0d4dce1c 100644 --- a/internal/templating/backups/template_prebackuppod_test.go +++ b/internal/templating/template_prebackuppod_test.go @@ -1,4 +1,4 @@ -package backups +package services import ( "os" @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/andreyvit/diff" "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/generator" ) @@ -46,7 +47,7 @@ func TestGeneratePreBackupPod(t *testing.T) { }, }, }, - want: "test-resources/result-prebackuppod1.yaml", + want: "test-resources/backups/result-prebackuppod1.yaml", }, { name: "test2 - k8up/v1alpha1", @@ -74,7 +75,7 @@ func TestGeneratePreBackupPod(t *testing.T) { }, }, }, - want: "test-resources/result-prebackuppod2.yaml", + want: "test-resources/backups/result-prebackuppod2.yaml", }, { name: "test3 - k8up/v1alpha1", @@ -102,7 +103,7 @@ func TestGeneratePreBackupPod(t *testing.T) { }, }, }, - want: "test-resources/result-prebackuppod3.yaml", + want: "test-resources/backups/result-prebackuppod3.yaml", }, { name: "test4 - k8up/v1", @@ -130,7 +131,7 @@ func TestGeneratePreBackupPod(t *testing.T) { }, }, }, - want: "test-resources/result-prebackuppod4.yaml", + want: "test-resources/backups/result-prebackuppod4.yaml", }, { name: "test5 - multiple k8up/v1", @@ -165,7 +166,7 @@ func TestGeneratePreBackupPod(t *testing.T) { }, }, }, - want: "test-resources/result-prebackuppod5.yaml", + want: "test-resources/backups/result-prebackuppod5.yaml", }, } for _, tt := range tests { @@ -184,8 +185,12 @@ func TestGeneratePreBackupPod(t *testing.T) { if err != nil { t.Errorf("couldn't read file %v: %v", tt.want, err) } - if !reflect.DeepEqual(string(got), string(r1)) { - t.Errorf("GeneratePreBackupPod() = %v, want %v", string(got), string(r1)) + templateYAML, err := TemplatePreBackupPods(got) + if err != nil { + t.Errorf("couldn't generate template: %v", err) + } + if !reflect.DeepEqual(string(templateYAML), string(r1)) { + t.Errorf("GeneratePreBackupPod() = \n%v", diff.LineDiff(string(r1), string(templateYAML))) } }) } diff --git a/internal/templating/registrysecret/registrysecret.go b/internal/templating/template_registrysecret.go similarity index 91% rename from internal/templating/registrysecret/registrysecret.go rename to internal/templating/template_registrysecret.go index d02c96ce..881652ce 100644 --- a/internal/templating/registrysecret/registrysecret.go +++ b/internal/templating/template_registrysecret.go @@ -1,4 +1,4 @@ -package registrysecret +package services import ( "encoding/base64" @@ -10,6 +10,7 @@ import ( apivalidation "k8s.io/apimachinery/pkg/api/validation" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" + "sigs.k8s.io/yaml" ) // GenerateRegistrySecretTemplate generates the lagoon template to apply. @@ -104,3 +105,13 @@ func GenerateRegistrySecretTemplate( } return result, nil } + +func TemplateSecret(item corev1.Secret) ([]byte, error) { + separator := []byte("---\n") + iBytes, err := yaml.Marshal(item) + if err != nil { + return nil, fmt.Errorf("couldn't generate template: %v", err) + } + templateYAML := append(separator[:], iBytes[:]...) + return templateYAML, nil +} diff --git a/internal/templating/registrysecret/registrysecret_test.go b/internal/templating/template_registrysecret_test.go similarity index 88% rename from internal/templating/registrysecret/registrysecret_test.go rename to internal/templating/template_registrysecret_test.go index b8b39294..9f86a497 100644 --- a/internal/templating/registrysecret/registrysecret_test.go +++ b/internal/templating/template_registrysecret_test.go @@ -1,4 +1,4 @@ -package registrysecret +package services import ( "os" @@ -7,7 +7,6 @@ import ( "github.com/andreyvit/diff" "github.com/uselagoon/build-deploy-tool/internal/generator" - "sigs.k8s.io/yaml" ) func TestGenerateRegistrySecretTemplate(t *testing.T) { @@ -58,7 +57,7 @@ func TestGenerateRegistrySecretTemplate(t *testing.T) { }, }, }, - want: "test-resources/registry-secret1.yaml", + want: "test-resources/regsecret/registry-secret1.yaml", }, } for _, tt := range tests { @@ -72,15 +71,13 @@ func TestGenerateRegistrySecretTemplate(t *testing.T) { if err != nil { t.Errorf("couldn't read file %v: %v", tt.want, err) } - separator := []byte("---\n") var result []byte for _, d := range got { - secretBytes, err := yaml.Marshal(d) + templateBytes, err := TemplateSecret(d) if err != nil { t.Errorf("couldn't generate template %v", err) } - restoreResult := append(separator[:], secretBytes[:]...) - result = append(result, restoreResult[:]...) + result = append(result, templateBytes[:]...) } if !reflect.DeepEqual(string(result), string(r1)) { t.Errorf("GenerateRegistrySecretTemplate() = \n%v", diff.LineDiff(string(r1), string(result))) diff --git a/internal/templating/backups/template_schedule.go b/internal/templating/template_schedule.go similarity index 88% rename from internal/templating/backups/template_schedule.go rename to internal/templating/template_schedule.go index d37bfd75..dc30293b 100644 --- a/internal/templating/backups/template_schedule.go +++ b/internal/templating/template_schedule.go @@ -1,10 +1,11 @@ -package backups +package services import ( "fmt" "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/helpers" + "sigs.k8s.io/yaml" k8upv1 "github.com/k8up-io/k8up/v2/api/v1" k8upv1alpha1 "github.com/vshn/k8up/api/v1alpha1" @@ -12,17 +13,20 @@ import ( apivalidation "k8s.io/apimachinery/pkg/api/validation" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" - - "sigs.k8s.io/yaml" ) +type BackupSchedule struct { + K8upV1 []k8upv1.Schedule + K8upV1alpha1 []k8upv1alpha1.Schedule + Secrets []corev1.Secret +} + func GenerateBackupSchedule( lValues generator.BuildValues, -) ([]byte, error) { +) (*BackupSchedule, error) { // generate the template spec - var result []byte - separator := []byte("---\n") + var result BackupSchedule // create the schedule if lValues.BackupsEnabled { @@ -147,15 +151,7 @@ func GenerateBackupSchedule( if err != nil { return nil, err } - // @TODO: we should review this in the future when we stop doing `kubectl apply` in the builds :) - // marshal the resulting ingress - scheduleBytes, err := yaml.Marshal(schedule) - if err != nil { - return nil, err - } - // add the seperator to the template so that it can be `kubectl apply` in bulk as part - // of the current build process - result = append(separator[:], scheduleBytes[:]...) + result.K8upV1alpha1 = append(result.K8upV1alpha1, *schedule) case "v2": s3Spec := &k8upv1.S3Spec{} if lValues.Backup.S3Endpoint != "" { @@ -278,13 +274,7 @@ func GenerateBackupSchedule( } // @TODO: we should review this in the future when we stop doing `kubectl apply` in the builds :) // marshal the resulting ingress - scheduleBytes, err := yaml.Marshal(schedule) - if err != nil { - return nil, err - } - // add the seperator to the template so that it can be `kubectl apply` in bulk as part - // of the current build process - result = append(separator[:], scheduleBytes[:]...) + result.K8upV1 = append(result.K8upV1, *schedule) } if lValues.Backup.CustomLocation.BackupLocationAccessKey != "" && lValues.Backup.CustomLocation.BackupLocationSecretKey != "" { backupSecret := &corev1.Secret{ @@ -300,12 +290,7 @@ func GenerateBackupSchedule( "secret-key": lValues.Backup.CustomLocation.BackupLocationSecretKey, }, } - backupSecretBytes, err := yaml.Marshal(backupSecret) - if err != nil { - return nil, err - } - backupResult := append(separator[:], backupSecretBytes[:]...) - result = append(result, backupResult[:]...) + result.Secrets = append(result.Secrets, *backupSecret) } if lValues.Backup.CustomLocation.RestoreLocationAccessKey != "" && lValues.Backup.CustomLocation.RestoreLocationSecretKey != "" { restoreSecret := &corev1.Secret{ @@ -321,13 +306,38 @@ func GenerateBackupSchedule( "secret-key": lValues.Backup.CustomLocation.RestoreLocationSecretKey, }, } - restoreSecretBytes, err := yaml.Marshal(restoreSecret) - if err != nil { - return nil, err - } - restoreResult := append(separator[:], restoreSecretBytes[:]...) - result = append(result, restoreResult[:]...) + result.Secrets = append(result.Secrets, *restoreSecret) + } + } + return &result, nil +} + +func TemplateSchedules(schedules *BackupSchedule) ([]byte, error) { + separator := []byte("---\n") + var templateYAML []byte + for _, schedule := range schedules.K8upV1 { + sBytes, err := yaml.Marshal(schedule) + if err != nil { + return nil, fmt.Errorf("couldn't generate template: %v", err) + } + restoreResult := append(separator[:], sBytes[:]...) + templateYAML = append(templateYAML, restoreResult[:]...) + } + for _, schedule := range schedules.K8upV1alpha1 { + sBytes, err := yaml.Marshal(schedule) + if err != nil { + return nil, fmt.Errorf("couldn't generate template: %v", err) + } + restoreResult := append(separator[:], sBytes[:]...) + templateYAML = append(templateYAML, restoreResult[:]...) + } + for _, secret := range schedules.Secrets { + sBytes, err := yaml.Marshal(secret) + if err != nil { + return nil, fmt.Errorf("couldn't generate template: %v", err) } + restoreResult := append(separator[:], sBytes[:]...) + templateYAML = append(templateYAML, restoreResult[:]...) } - return result, nil + return templateYAML, nil } diff --git a/internal/templating/backups/template_schedule_test.go b/internal/templating/template_schedule_test.go similarity index 92% rename from internal/templating/backups/template_schedule_test.go rename to internal/templating/template_schedule_test.go index 700a5f98..118bfd53 100644 --- a/internal/templating/backups/template_schedule_test.go +++ b/internal/templating/template_schedule_test.go @@ -1,4 +1,4 @@ -package backups +package services import ( "os" @@ -51,7 +51,7 @@ func TestGenerateBackupSchedule(t *testing.T) { }, }, }, - want: "test-resources/result-schedule1.yaml", + want: "test-resources/backups/result-schedule1.yaml", }, { name: "test2 - k8up/v1alpha1", @@ -81,7 +81,7 @@ func TestGenerateBackupSchedule(t *testing.T) { }, }, }, - want: "test-resources/result-schedule2.yaml", + want: "test-resources/backups/result-schedule2.yaml", }, { name: "test3 - k8up/v1alpha1", @@ -117,7 +117,7 @@ func TestGenerateBackupSchedule(t *testing.T) { }, }, }, - want: "test-resources/result-schedule3.yaml", + want: "test-resources/backups/result-schedule3.yaml", }, { name: "test4 - k8up/v1alpha1", @@ -153,7 +153,7 @@ func TestGenerateBackupSchedule(t *testing.T) { }, }, }, - want: "test-resources/result-schedule4.yaml", + want: "test-resources/backups/result-schedule4.yaml", }, { name: "test5 - k8up/v1alpha1", @@ -191,7 +191,7 @@ func TestGenerateBackupSchedule(t *testing.T) { }, }, }, - want: "test-resources/result-schedule5.yaml", + want: "test-resources/backups/result-schedule5.yaml", }, { name: "test6 - k8up/v1", @@ -223,7 +223,7 @@ func TestGenerateBackupSchedule(t *testing.T) { }, }, }, - want: "test-resources/result-schedule6.yaml", + want: "test-resources/backups/result-schedule6.yaml", }, } for _, tt := range tests { @@ -242,8 +242,12 @@ func TestGenerateBackupSchedule(t *testing.T) { if err != nil { t.Errorf("couldn't read file %v: %v", tt.want, err) } - if !reflect.DeepEqual(string(got), string(r1)) { - t.Errorf("GenerateBackupSchedule() = \n%v", diff.LineDiff(string(r1), string(got))) + templateYAML, err := TemplateSchedules(got) + if err != nil { + t.Errorf("couldn't generate template: %v", err) + } + if !reflect.DeepEqual(string(templateYAML), string(r1)) { + t.Errorf("GenerateBackupSchedule() = \n%v", diff.LineDiff(string(r1), string(templateYAML))) } }) } diff --git a/internal/templating/services/templates_cronjob.go b/internal/templating/templates_cronjob.go similarity index 98% rename from internal/templating/services/templates_cronjob.go rename to internal/templating/templates_cronjob.go index f885b93b..14a2ae2c 100644 --- a/internal/templating/services/templates_cronjob.go +++ b/internal/templating/templates_cronjob.go @@ -12,6 +12,7 @@ import ( apivalidation "k8s.io/apimachinery/pkg/api/validation" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" + "sigs.k8s.io/yaml" ) // GenerateCronjobTemplate generates the lagoon template to apply. @@ -432,3 +433,13 @@ func GenerateCronjobTemplate( } return result, nil } + +func TemplateCronjobs(item batchv1.CronJob) ([]byte, error) { + separator := []byte("---\n") + iBytes, err := yaml.Marshal(item) + if err != nil { + return nil, fmt.Errorf("couldn't generate template: %v", err) + } + templateYAML := append(separator[:], iBytes[:]...) + return templateYAML, nil +} diff --git a/internal/templating/services/templates_cronjob_test.go b/internal/templating/templates_cronjob_test.go similarity index 96% rename from internal/templating/services/templates_cronjob_test.go rename to internal/templating/templates_cronjob_test.go index 43ed203e..86f95632 100644 --- a/internal/templating/services/templates_cronjob_test.go +++ b/internal/templating/templates_cronjob_test.go @@ -8,7 +8,6 @@ import ( "github.com/andreyvit/diff" "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/lagoon" - "sigs.k8s.io/yaml" ) func TestGenerateCronjobTemplate(t *testing.T) { @@ -159,15 +158,13 @@ func TestGenerateCronjobTemplate(t *testing.T) { if err != nil { t.Errorf("couldn't read file %v: %v", tt.want, err) } - separator := []byte("---\n") var result []byte for _, d := range got { - deploymentBytes, err := yaml.Marshal(d) + templateBytes, err := TemplateCronjobs(d) if err != nil { t.Errorf("couldn't generate template %v", err) } - restoreResult := append(separator[:], deploymentBytes[:]...) - result = append(result, restoreResult[:]...) + result = append(result, templateBytes[:]...) } if !reflect.DeepEqual(string(result), string(r1)) { t.Errorf("GenerateCronjobTemplate() = \n%v", diff.LineDiff(string(r1), string(result))) diff --git a/internal/templating/services/templates_deployment.go b/internal/templating/templates_deployment.go similarity index 98% rename from internal/templating/services/templates_deployment.go rename to internal/templating/templates_deployment.go index 151bdc7a..72675fb9 100644 --- a/internal/templating/services/templates_deployment.go +++ b/internal/templating/templates_deployment.go @@ -15,6 +15,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" "k8s.io/apimachinery/pkg/util/intstr" + "sigs.k8s.io/yaml" ) // GenerateDeploymentTemplate generates the lagoon template to apply. @@ -681,3 +682,13 @@ func GenerateDeploymentTemplate( } return deployments, nil } + +func TemplateDeployment(item appsv1.Deployment) ([]byte, error) { + separator := []byte("---\n") + iBytes, err := yaml.Marshal(item) + if err != nil { + return nil, fmt.Errorf("couldn't generate template: %v", err) + } + templateYAML := append(separator[:], iBytes[:]...) + return templateYAML, nil +} diff --git a/internal/templating/services/templates_deployment_test.go b/internal/templating/templates_deployment_test.go similarity index 99% rename from internal/templating/services/templates_deployment_test.go rename to internal/templating/templates_deployment_test.go index ad1a0ffb..98a0c9a3 100644 --- a/internal/templating/services/templates_deployment_test.go +++ b/internal/templating/templates_deployment_test.go @@ -10,7 +10,6 @@ import ( "github.com/compose-spec/compose-go/types" "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/lagoon" - "sigs.k8s.io/yaml" ) func TestGenerateDeploymentTemplate(t *testing.T) { @@ -1004,15 +1003,13 @@ func TestGenerateDeploymentTemplate(t *testing.T) { if err != nil { t.Errorf("couldn't read file %v: %v", tt.want, err) } - separator := []byte("---\n") var result []byte for _, d := range got { - deploymentBytes, err := yaml.Marshal(d) + templateBytes, err := TemplateDeployment(d) if err != nil { t.Errorf("couldn't generate template %v", err) } - restoreResult := append(separator[:], deploymentBytes[:]...) - result = append(result, restoreResult[:]...) + result = append(result, templateBytes[:]...) } if !reflect.DeepEqual(string(result), string(r1)) { t.Errorf("GenerateDeploymentTemplate() = \n%v", diff.LineDiff(string(r1), string(result))) diff --git a/internal/templating/ingress/templates_ingress.go b/internal/templating/templates_ingress.go similarity index 94% rename from internal/templating/ingress/templates_ingress.go rename to internal/templating/templates_ingress.go index cb584297..1d2c0641 100644 --- a/internal/templating/ingress/templates_ingress.go +++ b/internal/templating/templates_ingress.go @@ -1,4 +1,4 @@ -package routes +package services import ( "fmt" @@ -9,13 +9,11 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/generator" "github.com/uselagoon/build-deploy-tool/internal/helpers" "github.com/uselagoon/build-deploy-tool/internal/lagoon" - "github.com/uselagoon/build-deploy-tool/internal/templating/services" networkv1 "k8s.io/api/networking/v1" apivalidation "k8s.io/apimachinery/pkg/api/validation" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" utilvalidation "k8s.io/apimachinery/pkg/util/validation" - "sigs.k8s.io/yaml" ) @@ -23,7 +21,7 @@ import ( func GenerateIngressTemplate( route lagoon.RouteV2, lValues generator.BuildValues, -) ([]byte, error) { +) (*networkv1.Ingress, error) { // truncate the route for use in labels and secretname truncatedRouteDomain := route.Domain @@ -255,13 +253,13 @@ func GenerateIngressTemplate( for _, service := range lValues.Services { for idx, addPort := range service.AdditionalServicePorts { if addPort.ServiceName == route.LagoonService { - servicePort = services.GenerateServiceBackendPort(addPort) + servicePort = GenerateServiceBackendPort(addPort) backendService = service.OverrideName } // if this service is for the default named lagoonservice if service.OverrideName == route.LagoonService && idx == 0 { // and set the portname to the name of the first service in the list - servicePort = services.GenerateServiceBackendPort(addPort) + servicePort = GenerateServiceBackendPort(addPort) } } } @@ -299,13 +297,13 @@ func GenerateIngressTemplate( if pr.ToService == service.OverrideName && len(service.AdditionalServicePorts) > 0 { // extract the first port from the additional ports to use as the path port // as the first port in the list is the "default" port - pathPort = services.GenerateServiceBackendPort(service.AdditionalServicePorts[0]) + pathPort = GenerateServiceBackendPort(service.AdditionalServicePorts[0]) } // otherwise if the user has specified a specific 'servicename-port' in their toService // look that up instead and serve the backend as requested for _, addPort := range service.AdditionalServicePorts { if addPort.ServiceName == pr.ToService { - pathPort = services.GenerateServiceBackendPort(addPort) + pathPort = GenerateServiceBackendPort(addPort) backendServiceName = addPort.ServiceOverrideName } } @@ -357,16 +355,17 @@ func GenerateIngressTemplate( } ingress.Spec.Rules = append(ingress.Spec.Rules, altName) } + return ingress, nil +} - // @TODO: we should review this in the future when we stop doing `kubectl apply` in the builds :) - // marshal the resulting ingress - ingressBytes, err := yaml.Marshal(ingress) +func TemplateIngress(ingress *networkv1.Ingress) ([]byte, error) { + separator := []byte("---\n") + var templateYAML []byte + iBytes, err := yaml.Marshal(ingress) if err != nil { - return nil, err + return nil, fmt.Errorf("couldn't generate template: %v", err) } - // add the seperator to the template so that it can be `kubectl apply` in bulk as part - // of the current build process - separator := []byte("---\n") - result := append(separator[:], ingressBytes[:]...) - return result, nil + restoreResult := append(separator[:], iBytes[:]...) + templateYAML = append(templateYAML, restoreResult[:]...) + return templateYAML, nil } diff --git a/internal/templating/ingress/templates_ingress_test.go b/internal/templating/templates_ingress_test.go similarity index 95% rename from internal/templating/ingress/templates_ingress_test.go rename to internal/templating/templates_ingress_test.go index adcda7e5..9fa1f62b 100644 --- a/internal/templating/ingress/templates_ingress_test.go +++ b/internal/templating/templates_ingress_test.go @@ -1,4 +1,4 @@ -package routes +package services import ( "os" @@ -14,7 +14,7 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/lagoon" ) -func TestGenerateKubeTemplate(t *testing.T) { +func TestGenerateIngressTemplate(t *testing.T) { type args struct { route lagoon.RouteV2 values generator.BuildValues @@ -69,7 +69,7 @@ func TestGenerateKubeTemplate(t *testing.T) { }, activeStandby: true, }, - want: "test-resources/result-active-standby1.yaml", + want: "test-resources/ingress/result-active-standby1.yaml", }, { name: "custom-ingress1", @@ -114,7 +114,7 @@ func TestGenerateKubeTemplate(t *testing.T) { }, activeStandby: false, }, - want: "test-resources/result-custom-ingress1.yaml", + want: "test-resources/ingress/result-custom-ingress1.yaml", }, { name: "custom-ingress2", @@ -159,7 +159,7 @@ func TestGenerateKubeTemplate(t *testing.T) { }, activeStandby: false, }, - want: "test-resources/result-custom-ingress2.yaml", + want: "test-resources/ingress/result-custom-ingress2.yaml", }, { name: "test3 - custom ingress with ingress class", @@ -205,7 +205,7 @@ func TestGenerateKubeTemplate(t *testing.T) { }, activeStandby: false, }, - want: "test-resources/result-custom-ingress3.yaml", + want: "test-resources/ingress/result-custom-ingress3.yaml", }, { name: "test4 - custom ingress with ingress class and hsts", @@ -253,7 +253,7 @@ func TestGenerateKubeTemplate(t *testing.T) { }, activeStandby: false, }, - want: "test-resources/result-custom-ingress4.yaml", + want: "test-resources/ingress/result-custom-ingress4.yaml", }, { name: "test5 - custom ingress with ingress class and hsts and existing config snippet", @@ -304,7 +304,7 @@ func TestGenerateKubeTemplate(t *testing.T) { }, activeStandby: false, }, - want: "test-resources/result-custom-ingress5.yaml", + want: "test-resources/ingress/result-custom-ingress5.yaml", }, { name: "test6 - invalid annotation", @@ -436,7 +436,7 @@ func TestGenerateKubeTemplate(t *testing.T) { }, activeStandby: false, }, - want: "test-resources/result-custom-ingress6.yaml", + want: "test-resources/ingress/result-custom-ingress6.yaml", }, { name: "test9 - wildcard ingress", @@ -482,7 +482,7 @@ func TestGenerateKubeTemplate(t *testing.T) { }, activeStandby: false, }, - want: "test-resources/result-wildcard-ingress1.yaml", + want: "test-resources/ingress/result-wildcard-ingress1.yaml", }, { name: "test10 - wildcard ingress", @@ -528,7 +528,7 @@ func TestGenerateKubeTemplate(t *testing.T) { }, activeStandby: false, }, - want: "test-resources/result-wildcard-ingress2.yaml", + want: "test-resources/ingress/result-wildcard-ingress2.yaml", }, { name: "custom-ingress1 with specific port service", @@ -590,7 +590,7 @@ func TestGenerateKubeTemplate(t *testing.T) { }, activeStandby: false, }, - want: "test-resources/result-custom-ingress7.yaml", + want: "test-resources/ingress/result-custom-ingress7.yaml", }, { name: "custom-ingress1 with specific port service 2", @@ -652,7 +652,7 @@ func TestGenerateKubeTemplate(t *testing.T) { }, activeStandby: false, }, - want: "test-resources/result-custom-ingress8.yaml", + want: "test-resources/ingress/result-custom-ingress8.yaml", }, { name: "custom-ingress9", @@ -698,7 +698,7 @@ func TestGenerateKubeTemplate(t *testing.T) { }, activeStandby: false, }, - want: "test-resources/result-custom-ingress9.yaml", + want: "test-resources/ingress/result-custom-ingress9.yaml", }, } for _, tt := range tests { @@ -723,8 +723,12 @@ func TestGenerateKubeTemplate(t *testing.T) { if err != nil { t.Errorf("couldn't read file %v: %v", tt.want, err) } - if !reflect.DeepEqual(string(got), string(r1)) { - t.Errorf("GenerateIngressTemplate() = \n%v", diff.LineDiff(string(r1), string(got))) + gotR, err := TemplateIngress(got) + if err != nil { + t.Errorf("couldn't generate template %v", err) + } + if !reflect.DeepEqual(string(gotR), string(r1)) { + t.Errorf("GenerateIngressTemplate() = \n%v", diff.LineDiff(string(r1), string(gotR))) } } }) diff --git a/internal/templating/services/templates_pvc.go b/internal/templating/templates_pvc.go similarity index 96% rename from internal/templating/services/templates_pvc.go rename to internal/templating/templates_pvc.go index 83fcd14e..3103fe9f 100644 --- a/internal/templating/services/templates_pvc.go +++ b/internal/templating/templates_pvc.go @@ -13,6 +13,7 @@ import ( apivalidation "k8s.io/apimachinery/pkg/api/validation" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" + "sigs.k8s.io/yaml" ) // GeneratePVCTemplate generates the lagoon template to apply. @@ -257,3 +258,13 @@ func updatePVC( } return nil } + +func TemplatePVC(item corev1.PersistentVolumeClaim) ([]byte, error) { + separator := []byte("---\n") + iBytes, err := yaml.Marshal(item) + if err != nil { + return nil, fmt.Errorf("couldn't generate template: %v", err) + } + templateYAML := append(separator[:], iBytes[:]...) + return templateYAML, nil +} diff --git a/internal/templating/services/templates_pvc_test.go b/internal/templating/templates_pvc_test.go similarity index 97% rename from internal/templating/services/templates_pvc_test.go rename to internal/templating/templates_pvc_test.go index 1aaa4f57..ee0b4e5a 100644 --- a/internal/templating/services/templates_pvc_test.go +++ b/internal/templating/templates_pvc_test.go @@ -7,7 +7,6 @@ import ( "github.com/andreyvit/diff" "github.com/uselagoon/build-deploy-tool/internal/generator" - "sigs.k8s.io/yaml" ) func TestGeneratePVCTemplate(t *testing.T) { @@ -277,15 +276,13 @@ func TestGeneratePVCTemplate(t *testing.T) { if err != nil { t.Errorf("couldn't read file %v: %v", tt.want, err) } - separator := []byte("---\n") var result []byte for _, d := range got { - deploymentBytes, err := yaml.Marshal(d) + templateBytes, err := TemplatePVC(d) if err != nil { t.Errorf("couldn't generate template %v", err) } - restoreResult := append(separator[:], deploymentBytes[:]...) - result = append(result, restoreResult[:]...) + result = append(result, templateBytes[:]...) } if !reflect.DeepEqual(string(result), string(r1)) { t.Errorf("GeneratePVCTemplate() = \n%v", diff.LineDiff(string(r1), string(result))) diff --git a/internal/templating/services/templates_service.go b/internal/templating/templates_service.go similarity index 95% rename from internal/templating/services/templates_service.go rename to internal/templating/templates_service.go index cae60856..8260a837 100644 --- a/internal/templating/services/templates_service.go +++ b/internal/templating/templates_service.go @@ -12,6 +12,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" "k8s.io/apimachinery/pkg/util/intstr" + "sigs.k8s.io/yaml" ) // GenerateServiceTemplate generates the lagoon template to apply. @@ -181,3 +182,13 @@ func GenerateServiceBackendPort(addPort generator.AdditionalServicePort) network } } } + +func TemplateService(item corev1.Service) ([]byte, error) { + separator := []byte("---\n") + iBytes, err := yaml.Marshal(item) + if err != nil { + return nil, fmt.Errorf("couldn't generate template: %v", err) + } + templateYAML := append(separator[:], iBytes[:]...) + return templateYAML, nil +} diff --git a/internal/templating/services/templates_service_test.go b/internal/templating/templates_service_test.go similarity index 97% rename from internal/templating/services/templates_service_test.go rename to internal/templating/templates_service_test.go index 86a452ef..c1af2f4c 100644 --- a/internal/templating/services/templates_service_test.go +++ b/internal/templating/templates_service_test.go @@ -8,7 +8,6 @@ import ( "github.com/andreyvit/diff" "github.com/compose-spec/compose-go/types" "github.com/uselagoon/build-deploy-tool/internal/generator" - "sigs.k8s.io/yaml" ) func TestGenerateServiceTemplate(t *testing.T) { @@ -280,15 +279,13 @@ func TestGenerateServiceTemplate(t *testing.T) { if err != nil { t.Errorf("couldn't read file %v: %v", tt.want, err) } - separator := []byte("---\n") var result []byte for _, d := range got { - sBytes, err := yaml.Marshal(d) + templateBytes, err := TemplateService(d) if err != nil { t.Errorf("couldn't generate template %v", err) } - restoreResult := append(separator[:], sBytes[:]...) - result = append(result, restoreResult[:]...) + result = append(result, templateBytes[:]...) } if !reflect.DeepEqual(string(result), string(r1)) { t.Errorf("GenerateServiceTemplate() = \n%v", diff.LineDiff(string(r1), string(result))) diff --git a/internal/templating/backups/test-resources/result-prebackuppod1.yaml b/internal/templating/test-resources/backups/result-prebackuppod1.yaml similarity index 100% rename from internal/templating/backups/test-resources/result-prebackuppod1.yaml rename to internal/templating/test-resources/backups/result-prebackuppod1.yaml diff --git a/internal/templating/backups/test-resources/result-prebackuppod2.yaml b/internal/templating/test-resources/backups/result-prebackuppod2.yaml similarity index 100% rename from internal/templating/backups/test-resources/result-prebackuppod2.yaml rename to internal/templating/test-resources/backups/result-prebackuppod2.yaml diff --git a/internal/templating/backups/test-resources/result-prebackuppod3.yaml b/internal/templating/test-resources/backups/result-prebackuppod3.yaml similarity index 100% rename from internal/templating/backups/test-resources/result-prebackuppod3.yaml rename to internal/templating/test-resources/backups/result-prebackuppod3.yaml diff --git a/internal/templating/backups/test-resources/result-prebackuppod4.yaml b/internal/templating/test-resources/backups/result-prebackuppod4.yaml similarity index 100% rename from internal/templating/backups/test-resources/result-prebackuppod4.yaml rename to internal/templating/test-resources/backups/result-prebackuppod4.yaml diff --git a/internal/templating/backups/test-resources/result-prebackuppod5.yaml b/internal/templating/test-resources/backups/result-prebackuppod5.yaml similarity index 100% rename from internal/templating/backups/test-resources/result-prebackuppod5.yaml rename to internal/templating/test-resources/backups/result-prebackuppod5.yaml diff --git a/internal/templating/backups/test-resources/result-schedule1.yaml b/internal/templating/test-resources/backups/result-schedule1.yaml similarity index 100% rename from internal/templating/backups/test-resources/result-schedule1.yaml rename to internal/templating/test-resources/backups/result-schedule1.yaml diff --git a/internal/templating/backups/test-resources/result-schedule2.yaml b/internal/templating/test-resources/backups/result-schedule2.yaml similarity index 100% rename from internal/templating/backups/test-resources/result-schedule2.yaml rename to internal/templating/test-resources/backups/result-schedule2.yaml diff --git a/internal/templating/backups/test-resources/result-schedule3.yaml b/internal/templating/test-resources/backups/result-schedule3.yaml similarity index 100% rename from internal/templating/backups/test-resources/result-schedule3.yaml rename to internal/templating/test-resources/backups/result-schedule3.yaml diff --git a/internal/templating/backups/test-resources/result-schedule4.yaml b/internal/templating/test-resources/backups/result-schedule4.yaml similarity index 100% rename from internal/templating/backups/test-resources/result-schedule4.yaml rename to internal/templating/test-resources/backups/result-schedule4.yaml diff --git a/internal/templating/backups/test-resources/result-schedule5.yaml b/internal/templating/test-resources/backups/result-schedule5.yaml similarity index 100% rename from internal/templating/backups/test-resources/result-schedule5.yaml rename to internal/templating/test-resources/backups/result-schedule5.yaml diff --git a/internal/templating/backups/test-resources/result-schedule6.yaml b/internal/templating/test-resources/backups/result-schedule6.yaml similarity index 100% rename from internal/templating/backups/test-resources/result-schedule6.yaml rename to internal/templating/test-resources/backups/result-schedule6.yaml diff --git a/internal/templating/services/test-resources/cronjob/result-cli-1.yaml b/internal/templating/test-resources/cronjob/result-cli-1.yaml similarity index 100% rename from internal/templating/services/test-resources/cronjob/result-cli-1.yaml rename to internal/templating/test-resources/cronjob/result-cli-1.yaml diff --git a/internal/templating/services/test-resources/cronjob/result-cli-2.yaml b/internal/templating/test-resources/cronjob/result-cli-2.yaml similarity index 100% rename from internal/templating/services/test-resources/cronjob/result-cli-2.yaml rename to internal/templating/test-resources/cronjob/result-cli-2.yaml diff --git a/internal/templating/dbaas/test-resources/result-mariadb-1.yaml b/internal/templating/test-resources/dbaas/result-mariadb-1.yaml similarity index 100% rename from internal/templating/dbaas/test-resources/result-mariadb-1.yaml rename to internal/templating/test-resources/dbaas/result-mariadb-1.yaml diff --git a/internal/templating/test-resources/dbaas/result-mariadb-2.yaml b/internal/templating/test-resources/dbaas/result-mariadb-2.yaml new file mode 100644 index 00000000..66968754 --- /dev/null +++ b/internal/templating/test-resources/dbaas/result-mariadb-2.yaml @@ -0,0 +1,52 @@ +--- +apiVersion: mariadb.amazee.io/v1 +kind: MariaDBConsumer +metadata: + annotations: + lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/version: v2.x.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: environment-with-really-really-reall-3fdb + 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: development + provider: {} +status: {} +--- +apiVersion: mariadb.amazee.io/v1 +kind: MariaDBConsumer +metadata: + annotations: + lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mariadb2 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mariadb-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: mariadb2 + lagoon.sh/service-type: mariadb-dbaas + lagoon.sh/template: mariadb-dbaas-0.1.0 + name: mariadb2 +spec: + consumer: + services: {} + environment: development + provider: {} +status: {} diff --git a/internal/templating/dbaas/test-resources/result-mongodb-1.yaml b/internal/templating/test-resources/dbaas/result-mongodb-1.yaml similarity index 100% rename from internal/templating/dbaas/test-resources/result-mongodb-1.yaml rename to internal/templating/test-resources/dbaas/result-mongodb-1.yaml diff --git a/internal/templating/dbaas/test-resources/result-mongodb-2.yaml b/internal/templating/test-resources/dbaas/result-mongodb-2.yaml similarity index 100% rename from internal/templating/dbaas/test-resources/result-mongodb-2.yaml rename to internal/templating/test-resources/dbaas/result-mongodb-2.yaml diff --git a/internal/templating/dbaas/test-resources/result-postgres-1.yaml b/internal/templating/test-resources/dbaas/result-postgres-1.yaml similarity index 100% rename from internal/templating/dbaas/test-resources/result-postgres-1.yaml rename to internal/templating/test-resources/dbaas/result-postgres-1.yaml diff --git a/internal/templating/services/test-resources/deployment/result-basic-1.yaml b/internal/templating/test-resources/deployment/result-basic-1.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-basic-1.yaml rename to internal/templating/test-resources/deployment/result-basic-1.yaml diff --git a/internal/templating/services/test-resources/deployment/result-basic-2.yaml b/internal/templating/test-resources/deployment/result-basic-2.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-basic-2.yaml rename to internal/templating/test-resources/deployment/result-basic-2.yaml diff --git a/internal/templating/services/test-resources/deployment/result-basic-3.yaml b/internal/templating/test-resources/deployment/result-basic-3.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-basic-3.yaml rename to internal/templating/test-resources/deployment/result-basic-3.yaml diff --git a/internal/templating/services/test-resources/deployment/result-basic-4.yaml b/internal/templating/test-resources/deployment/result-basic-4.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-basic-4.yaml rename to internal/templating/test-resources/deployment/result-basic-4.yaml diff --git a/internal/templating/services/test-resources/deployment/result-basic-5.yaml b/internal/templating/test-resources/deployment/result-basic-5.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-basic-5.yaml rename to internal/templating/test-resources/deployment/result-basic-5.yaml diff --git a/internal/templating/services/test-resources/deployment/result-cli-1.yaml b/internal/templating/test-resources/deployment/result-cli-1.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-cli-1.yaml rename to internal/templating/test-resources/deployment/result-cli-1.yaml diff --git a/internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml b/internal/templating/test-resources/deployment/result-elasticsearch-1.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-elasticsearch-1.yaml rename to internal/templating/test-resources/deployment/result-elasticsearch-1.yaml diff --git a/internal/templating/services/test-resources/deployment/result-mariadb-1.yaml b/internal/templating/test-resources/deployment/result-mariadb-1.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-mariadb-1.yaml rename to internal/templating/test-resources/deployment/result-mariadb-1.yaml diff --git a/internal/templating/services/test-resources/deployment/result-mariadb-2.yaml b/internal/templating/test-resources/deployment/result-mariadb-2.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-mariadb-2.yaml rename to internal/templating/test-resources/deployment/result-mariadb-2.yaml diff --git a/internal/templating/services/test-resources/deployment/result-mongodb-1.yaml b/internal/templating/test-resources/deployment/result-mongodb-1.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-mongodb-1.yaml rename to internal/templating/test-resources/deployment/result-mongodb-1.yaml diff --git a/internal/templating/services/test-resources/deployment/result-nginx-1.yaml b/internal/templating/test-resources/deployment/result-nginx-1.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-nginx-1.yaml rename to internal/templating/test-resources/deployment/result-nginx-1.yaml diff --git a/internal/templating/services/test-resources/deployment/result-nginx-2.yaml b/internal/templating/test-resources/deployment/result-nginx-2.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-nginx-2.yaml rename to internal/templating/test-resources/deployment/result-nginx-2.yaml diff --git a/internal/templating/services/test-resources/deployment/result-node-1.yaml b/internal/templating/test-resources/deployment/result-node-1.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-node-1.yaml rename to internal/templating/test-resources/deployment/result-node-1.yaml diff --git a/internal/templating/services/test-resources/deployment/result-opensearch-1.yaml b/internal/templating/test-resources/deployment/result-opensearch-1.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-opensearch-1.yaml rename to internal/templating/test-resources/deployment/result-opensearch-1.yaml diff --git a/internal/templating/services/test-resources/deployment/result-postgres-1.yaml b/internal/templating/test-resources/deployment/result-postgres-1.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-postgres-1.yaml rename to internal/templating/test-resources/deployment/result-postgres-1.yaml diff --git a/internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml b/internal/templating/test-resources/deployment/result-postgres-single-1.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-postgres-single-1.yaml rename to internal/templating/test-resources/deployment/result-postgres-single-1.yaml diff --git a/internal/templating/services/test-resources/deployment/result-python-1.yaml b/internal/templating/test-resources/deployment/result-python-1.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-python-1.yaml rename to internal/templating/test-resources/deployment/result-python-1.yaml diff --git a/internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml b/internal/templating/test-resources/deployment/result-rabbitmq-1.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-rabbitmq-1.yaml rename to internal/templating/test-resources/deployment/result-rabbitmq-1.yaml diff --git a/internal/templating/services/test-resources/deployment/result-redis-1.yaml b/internal/templating/test-resources/deployment/result-redis-1.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-redis-1.yaml rename to internal/templating/test-resources/deployment/result-redis-1.yaml diff --git a/internal/templating/services/test-resources/deployment/result-solr-1.yaml b/internal/templating/test-resources/deployment/result-solr-1.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-solr-1.yaml rename to internal/templating/test-resources/deployment/result-solr-1.yaml diff --git a/internal/templating/services/test-resources/deployment/result-valkey-1.yaml b/internal/templating/test-resources/deployment/result-valkey-1.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-valkey-1.yaml rename to internal/templating/test-resources/deployment/result-valkey-1.yaml diff --git a/internal/templating/services/test-resources/deployment/result-varnish-1.yaml b/internal/templating/test-resources/deployment/result-varnish-1.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-varnish-1.yaml rename to internal/templating/test-resources/deployment/result-varnish-1.yaml diff --git a/internal/templating/services/test-resources/deployment/result-worker-1.yaml b/internal/templating/test-resources/deployment/result-worker-1.yaml similarity index 100% rename from internal/templating/services/test-resources/deployment/result-worker-1.yaml rename to internal/templating/test-resources/deployment/result-worker-1.yaml diff --git a/internal/templating/ingress/test-resources/result-active-standby1.yaml b/internal/templating/test-resources/ingress/result-active-standby1.yaml similarity index 100% rename from internal/templating/ingress/test-resources/result-active-standby1.yaml rename to internal/templating/test-resources/ingress/result-active-standby1.yaml diff --git a/internal/templating/ingress/test-resources/result-custom-ingress1.yaml b/internal/templating/test-resources/ingress/result-custom-ingress1.yaml similarity index 100% rename from internal/templating/ingress/test-resources/result-custom-ingress1.yaml rename to internal/templating/test-resources/ingress/result-custom-ingress1.yaml diff --git a/internal/templating/ingress/test-resources/result-custom-ingress2.yaml b/internal/templating/test-resources/ingress/result-custom-ingress2.yaml similarity index 100% rename from internal/templating/ingress/test-resources/result-custom-ingress2.yaml rename to internal/templating/test-resources/ingress/result-custom-ingress2.yaml diff --git a/internal/templating/ingress/test-resources/result-custom-ingress3.yaml b/internal/templating/test-resources/ingress/result-custom-ingress3.yaml similarity index 100% rename from internal/templating/ingress/test-resources/result-custom-ingress3.yaml rename to internal/templating/test-resources/ingress/result-custom-ingress3.yaml diff --git a/internal/templating/ingress/test-resources/result-custom-ingress4.yaml b/internal/templating/test-resources/ingress/result-custom-ingress4.yaml similarity index 100% rename from internal/templating/ingress/test-resources/result-custom-ingress4.yaml rename to internal/templating/test-resources/ingress/result-custom-ingress4.yaml diff --git a/internal/templating/ingress/test-resources/result-custom-ingress5.yaml b/internal/templating/test-resources/ingress/result-custom-ingress5.yaml similarity index 100% rename from internal/templating/ingress/test-resources/result-custom-ingress5.yaml rename to internal/templating/test-resources/ingress/result-custom-ingress5.yaml diff --git a/internal/templating/ingress/test-resources/result-custom-ingress6.yaml b/internal/templating/test-resources/ingress/result-custom-ingress6.yaml similarity index 100% rename from internal/templating/ingress/test-resources/result-custom-ingress6.yaml rename to internal/templating/test-resources/ingress/result-custom-ingress6.yaml diff --git a/internal/templating/ingress/test-resources/result-custom-ingress7.yaml b/internal/templating/test-resources/ingress/result-custom-ingress7.yaml similarity index 100% rename from internal/templating/ingress/test-resources/result-custom-ingress7.yaml rename to internal/templating/test-resources/ingress/result-custom-ingress7.yaml diff --git a/internal/templating/ingress/test-resources/result-custom-ingress8.yaml b/internal/templating/test-resources/ingress/result-custom-ingress8.yaml similarity index 100% rename from internal/templating/ingress/test-resources/result-custom-ingress8.yaml rename to internal/templating/test-resources/ingress/result-custom-ingress8.yaml diff --git a/internal/templating/ingress/test-resources/result-custom-ingress9.yaml b/internal/templating/test-resources/ingress/result-custom-ingress9.yaml similarity index 100% rename from internal/templating/ingress/test-resources/result-custom-ingress9.yaml rename to internal/templating/test-resources/ingress/result-custom-ingress9.yaml diff --git a/internal/templating/ingress/test-resources/result-wildcard-ingress1.yaml b/internal/templating/test-resources/ingress/result-wildcard-ingress1.yaml similarity index 100% rename from internal/templating/ingress/test-resources/result-wildcard-ingress1.yaml rename to internal/templating/test-resources/ingress/result-wildcard-ingress1.yaml diff --git a/internal/templating/ingress/test-resources/result-wildcard-ingress2.yaml b/internal/templating/test-resources/ingress/result-wildcard-ingress2.yaml similarity index 100% rename from internal/templating/ingress/test-resources/result-wildcard-ingress2.yaml rename to internal/templating/test-resources/ingress/result-wildcard-ingress2.yaml diff --git a/internal/templating/networkpolicy/test-resources/result-np-1.yaml b/internal/templating/test-resources/netpol/result-np-1.yaml similarity index 100% rename from internal/templating/networkpolicy/test-resources/result-np-1.yaml rename to internal/templating/test-resources/netpol/result-np-1.yaml diff --git a/internal/templating/services/test-resources/pvc/result-basic-1.yaml b/internal/templating/test-resources/pvc/result-basic-1.yaml similarity index 100% rename from internal/templating/services/test-resources/pvc/result-basic-1.yaml rename to internal/templating/test-resources/pvc/result-basic-1.yaml diff --git a/internal/templating/services/test-resources/pvc/result-basic-2.yaml b/internal/templating/test-resources/pvc/result-basic-2.yaml similarity index 100% rename from internal/templating/services/test-resources/pvc/result-basic-2.yaml rename to internal/templating/test-resources/pvc/result-basic-2.yaml diff --git a/internal/templating/services/test-resources/pvc/result-basic-3.yaml b/internal/templating/test-resources/pvc/result-basic-3.yaml similarity index 100% rename from internal/templating/services/test-resources/pvc/result-basic-3.yaml rename to internal/templating/test-resources/pvc/result-basic-3.yaml diff --git a/internal/templating/services/test-resources/pvc/result-basic-4.yaml b/internal/templating/test-resources/pvc/result-basic-4.yaml similarity index 100% rename from internal/templating/services/test-resources/pvc/result-basic-4.yaml rename to internal/templating/test-resources/pvc/result-basic-4.yaml diff --git a/internal/templating/services/test-resources/pvc/result-cli-1.yaml b/internal/templating/test-resources/pvc/result-cli-1.yaml similarity index 100% rename from internal/templating/services/test-resources/pvc/result-cli-1.yaml rename to internal/templating/test-resources/pvc/result-cli-1.yaml diff --git a/internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml b/internal/templating/test-resources/pvc/result-elasticsearch-1.yaml similarity index 100% rename from internal/templating/services/test-resources/pvc/result-elasticsearch-1.yaml rename to internal/templating/test-resources/pvc/result-elasticsearch-1.yaml diff --git a/internal/templating/services/test-resources/pvc/result-opensearch-1.yaml b/internal/templating/test-resources/pvc/result-opensearch-1.yaml similarity index 100% rename from internal/templating/services/test-resources/pvc/result-opensearch-1.yaml rename to internal/templating/test-resources/pvc/result-opensearch-1.yaml diff --git a/internal/templating/services/test-resources/pvc/result-postgres-single-1.yaml b/internal/templating/test-resources/pvc/result-postgres-single-1.yaml similarity index 100% rename from internal/templating/services/test-resources/pvc/result-postgres-single-1.yaml rename to internal/templating/test-resources/pvc/result-postgres-single-1.yaml diff --git a/internal/templating/registrysecret/test-resources/registry-secret1.yaml b/internal/templating/test-resources/regsecret/registry-secret1.yaml similarity index 100% rename from internal/templating/registrysecret/test-resources/registry-secret1.yaml rename to internal/templating/test-resources/regsecret/registry-secret1.yaml diff --git a/internal/templating/services/test-resources/service/result-basic-1.yaml b/internal/templating/test-resources/service/result-basic-1.yaml similarity index 100% rename from internal/templating/services/test-resources/service/result-basic-1.yaml rename to internal/templating/test-resources/service/result-basic-1.yaml diff --git a/internal/templating/services/test-resources/service/result-basic-2.yaml b/internal/templating/test-resources/service/result-basic-2.yaml similarity index 100% rename from internal/templating/services/test-resources/service/result-basic-2.yaml rename to internal/templating/test-resources/service/result-basic-2.yaml diff --git a/internal/templating/services/test-resources/service/result-basic-3.yaml b/internal/templating/test-resources/service/result-basic-3.yaml similarity index 100% rename from internal/templating/services/test-resources/service/result-basic-3.yaml rename to internal/templating/test-resources/service/result-basic-3.yaml diff --git a/internal/templating/services/test-resources/service/result-cli-1.yaml b/internal/templating/test-resources/service/result-cli-1.yaml similarity index 100% rename from internal/templating/services/test-resources/service/result-cli-1.yaml rename to internal/templating/test-resources/service/result-cli-1.yaml diff --git a/internal/templating/services/test-resources/service/result-elasticsearch-1.yaml b/internal/templating/test-resources/service/result-elasticsearch-1.yaml similarity index 100% rename from internal/templating/services/test-resources/service/result-elasticsearch-1.yaml rename to internal/templating/test-resources/service/result-elasticsearch-1.yaml diff --git a/internal/templating/services/test-resources/service/result-nginx-php-1.yaml b/internal/templating/test-resources/service/result-nginx-php-1.yaml similarity index 100% rename from internal/templating/services/test-resources/service/result-nginx-php-1.yaml rename to internal/templating/test-resources/service/result-nginx-php-1.yaml diff --git a/internal/templating/services/test-resources/service/result-opensearch-1.yaml b/internal/templating/test-resources/service/result-opensearch-1.yaml similarity index 100% rename from internal/templating/services/test-resources/service/result-opensearch-1.yaml rename to internal/templating/test-resources/service/result-opensearch-1.yaml