From 12c6c3a17fc3d8abf65cd0906f14bd910ac2de8d Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 12 Sep 2022 13:17:55 +1000 Subject: [PATCH 01/13] refactor: use build-tool for generating dbaas consumers in builds --- cmd/identify_dbaas.go | 46 ++++ cmd/identify_dbaas_test.go | 251 ++++++++++++++++++ cmd/template_dbaas_test.go | 38 ++- internal/generator/buildvalues.go | 3 +- internal/generator/services.go | 17 +- internal/generator/services_test.go | 2 + legacy/build-deploy-docker-compose.sh | 174 +----------- .../template-dbaas/test2-results/dbaas.yaml | 26 ++ .../template-dbaas/test2/docker-compose.yml | 121 +++++++++ .../template-dbaas/test2/lagoon.yml | 10 + .../template-dbaas/test3-results/dbaas.yaml | 52 ++++ .../template-dbaas/test3/docker-compose.yml | 132 +++++++++ .../template-dbaas/test3/lagoon.yml | 10 + 13 files changed, 711 insertions(+), 171 deletions(-) create mode 100644 cmd/identify_dbaas.go create mode 100644 cmd/identify_dbaas_test.go create mode 100644 test-resources/template-dbaas/test2-results/dbaas.yaml create mode 100644 test-resources/template-dbaas/test2/docker-compose.yml create mode 100644 test-resources/template-dbaas/test2/lagoon.yml create mode 100644 test-resources/template-dbaas/test3-results/dbaas.yaml create mode 100644 test-resources/template-dbaas/test3/docker-compose.yml create mode 100644 test-resources/template-dbaas/test3/lagoon.yml diff --git a/cmd/identify_dbaas.go b/cmd/identify_dbaas.go new file mode 100644 index 00000000..44c7f6dd --- /dev/null +++ b/cmd/identify_dbaas.go @@ -0,0 +1,46 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" + generator "github.com/uselagoon/build-deploy-tool/internal/generator" +) + +// this is an intermediate helper command while transitioning from bash to go +// eventually this won't be required +var dbaasIdentify = &cobra.Command{ + Use: "dbaas", + Aliases: []string{"db", "d"}, + Short: "Identify if any dbaas consumers are created", + RunE: func(cmd *cobra.Command, args []string) error { + generator, err := generatorInput(true) + if err != nil { + return err + } + dbaasConsumers, err := IdentifyDBaaSConsumers(generator) + if err != nil { + return err + } + for _, dbc := range dbaasConsumers { + fmt.Println(dbc) + } + return nil + }, +} + +func IdentifyDBaaSConsumers(g generator.GeneratorInput) ([]string, error) { + lagoonBuild, err := generator.NewGenerator( + g, + ) + if err != nil { + return nil, err + } + ret := []string{} + for _, svc := range lagoonBuild.BuildValues.Services { + if svc.IsDBaaS { + ret = append(ret, fmt.Sprintf("%s:%s", svc.Name, svc.Type)) + } + } + return ret, nil +} diff --git a/cmd/identify_dbaas_test.go b/cmd/identify_dbaas_test.go new file mode 100644 index 00000000..a1448b8c --- /dev/null +++ b/cmd/identify_dbaas_test.go @@ -0,0 +1,251 @@ +package cmd + +import ( + "os" + "reflect" + "testing" + "time" + + "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" + "github.com/uselagoon/build-deploy-tool/internal/helpers" +) + +// these tests uses the same files as the dbaas templates +func TestIdentifyDBaaSConsumers(t *testing.T) { + type args struct { + name string + alertContact string + statusPageID string + projectName string + environmentName string + branch string + prNumber string + prHeadBranch string + prBaseBranch string + environmentType string + buildType string + activeEnvironment string + standbyEnvironment string + cacheNoCache string + serviceID string + secretPrefix string + projectVars string + envVars string + lagoonVersion string + lagoonYAML string + valuesFilePath string + templatePath string + } + tests := []struct { + name string + args args + vars []helpers.EnvironmentVariable + want []string + wantErr bool + }{ + { + name: "test1 - mariadb to mariadb-dbaas only", + args: args{ + name: "ROOTLESS_WORKLOAD", + alertContact: "alertcontact", + statusPageID: "statuspageid", + projectName: "example-project", + environmentName: "main", + environmentType: "production", + buildType: "branch", + lagoonVersion: "v2.7.x", + branch: "main", + projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, + envVars: `[]`, + lagoonYAML: "../test-resources/template-dbaas/test1/lagoon.yml", + templatePath: "../test-resources/output", + }, + want: []string{ + "mariadb:mariadb-dbaas", + }, + }, + { + name: "test2 - mariadb to mariadb-shared which converts to mariadb-dbaas", + args: args{ + name: "ROOTLESS_WORKLOAD", + alertContact: "alertcontact", + statusPageID: "statuspageid", + projectName: "example-project", + environmentName: "main", + environmentType: "production", + buildType: "branch", + lagoonVersion: "v2.7.x", + branch: "main", + projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_SERVICE_TYPES","value":"mariadb:mariadb-shared","scope":"build"}]`, + envVars: `[]`, + lagoonYAML: "../test-resources/template-dbaas/test1/lagoon.yml", + templatePath: "../test-resources/output", + }, + want: []string{ + "mariadb:mariadb-dbaas", + }, + }, + { + name: "test3 - override provider to non-existent should result in failing dbaas check and a single pod no dbaas found", + args: args{ + name: "ROOTLESS_WORKLOAD", + alertContact: "alertcontact", + statusPageID: "statuspageid", + projectName: "example-project", + environmentName: "main", + environmentType: "production", + buildType: "branch", + lagoonVersion: "v2.7.x", + branch: "main", + projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_DBAAS_ENVIRONMENT_TYPES","value":"mariadb:development2","scope":"build"}]`, + envVars: `[]`, + lagoonYAML: "../test-resources/template-dbaas/test1/lagoon.yml", + templatePath: "../test-resources/output", + }, + want: []string{}, + }, + { + name: "test4 - mariadb-single to mariadb-dbaas (using mariadb-shared to mariadb-dbaas conversion)", + args: args{ + name: "ROOTLESS_WORKLOAD", + alertContact: "alertcontact", + statusPageID: "statuspageid", + projectName: "example-project", + environmentName: "main", + environmentType: "production", + buildType: "branch", + lagoonVersion: "v2.7.x", + branch: "main", + projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_SERVICE_TYPES","value":"mariadb:mariadb-shared","scope":"build"}]`, + envVars: `[]`, + lagoonYAML: "../test-resources/template-dbaas/test2/lagoon.yml", + templatePath: "../test-resources/output", + }, + want: []string{ + "mariadb:mariadb-dbaas", + }, + }, + { + name: "test5 - multiple mariadb", + args: args{ + name: "ROOTLESS_WORKLOAD", + alertContact: "alertcontact", + statusPageID: "statuspageid", + projectName: "example-project", + environmentName: "main", + environmentType: "production", + buildType: "branch", + lagoonVersion: "v2.7.x", + branch: "main", + projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_SERVICE_TYPES","value":"mariadb:mariadb-shared","scope":"build"}]`, + envVars: `[]`, + lagoonYAML: "../test-resources/template-dbaas/test3/lagoon.yml", + templatePath: "../test-resources/output", + }, + want: []string{ + "mariadb:mariadb-dbaas", + "mariadb2:mariadb-dbaas", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // set the environment variables from args + err := os.Setenv("MONITORING_ALERTCONTACT", tt.args.alertContact) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("MONITORING_STATUSPAGEID", tt.args.statusPageID) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("PROJECT", tt.args.projectName) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("ENVIRONMENT", tt.args.environmentName) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("BRANCH", tt.args.branch) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("PR_NUMBER", tt.args.prNumber) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("PR_HEAD_BRANCH", tt.args.prHeadBranch) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("PR_BASE_BRANCH", tt.args.prBaseBranch) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("ENVIRONMENT_TYPE", tt.args.environmentType) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("BUILD_TYPE", tt.args.buildType) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("ACTIVE_ENVIRONMENT", tt.args.activeEnvironment) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("STANDBY_ENVIRONMENT", tt.args.standbyEnvironment) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("LAGOON_FASTLY_NOCACHE_SERVICE_ID", tt.args.cacheNoCache) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("LAGOON_PROJECT_VARIABLES", tt.args.projectVars) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("LAGOON_ENVIRONMENT_VARIABLES", tt.args.envVars) + if err != nil { + t.Errorf("%v", err) + } + err = os.Setenv("LAGOON_VERSION", tt.args.lagoonVersion) + if err != nil { + t.Errorf("%v", err) + } + generator, err := generatorInput(false) + if err != nil { + t.Errorf("%v", err) + } + generator.LagoonYAML = tt.args.lagoonYAML + // add dbaasclient overrides for tests + generator.DBaaSClient = dbaasclient.NewClient(dbaasclient.Client{ + RetryMax: 5, + RetryWaitMin: time.Duration(10) * time.Millisecond, + RetryWaitMax: time.Duration(50) * time.Millisecond, + }) + + // setup the fake dbaas server + ts := dbaasclient.TestDBaaSHTTPServer() + defer ts.Close() + err = os.Setenv("DBAAS_OPERATOR_HTTP", ts.URL) + if err != nil { + t.Errorf("%v", err) + } + + got, err := IdentifyDBaaSConsumers(generator) + if (err != nil) != tt.wantErr { + t.Errorf("IdentifyDBaaSConsumers() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("IdentifyDBaaSConsumers() = %v, want %v", got, tt.want) + } + t.Cleanup(func() { + helpers.UnsetEnvVars(tt.vars) + }) + }) + } +} diff --git a/cmd/template_dbaas_test.go b/cmd/template_dbaas_test.go index bf205e0e..9dd89812 100644 --- a/cmd/template_dbaas_test.go +++ b/cmd/template_dbaas_test.go @@ -54,13 +54,49 @@ func TestDBaaSTemplateGeneration(t *testing.T) { buildType: "branch", lagoonVersion: "v2.7.x", branch: "main", - projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_FASTLY_SERVICE_IDS","value":"example.com:service-id:true:annotationscom","scope":"build"}]`, + projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, envVars: `[]`, lagoonYAML: "../test-resources/template-dbaas/test1/lagoon.yml", templatePath: "../test-resources/template-dbaas/output", }, want: "../test-resources/template-dbaas/test1-results", }, + { + name: "test2 - mariadb-single to mariadb-dbaas (using mariadb-shared to mariadb-dbaas conversion)", + args: args{ + alertContact: "alertcontact", + statusPageID: "statuspageid", + projectName: "example-project", + environmentName: "main", + environmentType: "production", + buildType: "branch", + lagoonVersion: "v2.7.x", + branch: "main", + projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_SERVICE_TYPES","value":"mariadb:mariadb-shared","scope":"build"}]`, + envVars: `[]`, + lagoonYAML: "../test-resources/template-dbaas/test2/lagoon.yml", + templatePath: "../test-resources/template-dbaas/output", + }, + want: "../test-resources/template-dbaas/test2-results", + }, + { + name: "test3 - multiple mariadb", + args: args{ + alertContact: "alertcontact", + statusPageID: "statuspageid", + projectName: "example-project", + environmentName: "main", + environmentType: "production", + buildType: "branch", + lagoonVersion: "v2.7.x", + branch: "main", + projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, + envVars: `[]`, + lagoonYAML: "../test-resources/template-dbaas/test3/lagoon.yml", + templatePath: "../test-resources/template-dbaas/output", + }, + want: "../test-resources/template-dbaas/test3-results", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/generator/buildvalues.go b/internal/generator/buildvalues.go index 6efd4b97..8a0ae6e0 100644 --- a/internal/generator/buildvalues.go +++ b/internal/generator/buildvalues.go @@ -73,11 +73,12 @@ type ServiceValues struct { AutogeneratedRoutesTLSAcme bool `json:"autogeneratedRoutesTLSAcme"` AutogeneratedRouteDomain string `json:"autogeneratedRouteDomain"` ShortAutogeneratedRouteDomain string `json:"shortAutogeneratedRouteDomain"` - DBaaSEnvironment string `json:"dbaasEnvironment"` NativeCronjobs map[string]CronjobValues `json:"nativeCronjobs"` InPodCronjobs string `json:"inPodCronjobs"` ImageName string `json:"imageName"` DeploymentServiceType string `json:"deploymentServiecType"` + DBaaSEnvironment string `json:"dbaasEnvironment"` + IsDBaaS bool `json:"isDBaaS"` } // CronjobValues is the values for cronjobs diff --git a/internal/generator/services.go b/internal/generator/services.go index e7f57d19..708fb32a 100644 --- a/internal/generator/services.go +++ b/internal/generator/services.go @@ -35,6 +35,16 @@ var supportedAutogeneratedTypes = []string{ "python", } +// these are lagoon types that support autogenerated routes +var supportedDBTypes = []string{ + "mariadb", + "mariadb-dbaas", + "postgres", + "postgres-dbaas", + "mongodb", + "mongodb-dbaas", +} + // generateServicesFromDockerCompose unmarshals the docker-compose file and processes the services using composeToServiceValues func generateServicesFromDockerCompose( buildValues *BuildValues, @@ -191,7 +201,10 @@ func composeToServiceValues( // handle dbaas operator checks here dbaasEnvironment := buildValues.EnvironmentType - if lagoonType == "mariadb" || lagoonType == "postgres" || lagoonType == "mongodb" { + svcIsDBaaS := false + if helpers.Contains(supportedDBTypes, lagoonType) { + // strip the dbaas off the supplied type for checking against providers, it gets added again later + lagoonType = strings.Split(lagoonType, "-dbaas")[0] err := buildValues.DBaaSClient.CheckHealth(buildValues.DBaaSOperatorEndpoint) if err != nil { // @TODO eventually this error should be handled and fail a build, with a flag to override https://github.com/uselagoon/build-deploy-tool/issues/56 @@ -238,6 +251,7 @@ func composeToServiceValues( // if the requested dbaas environment exists, then set the type to be the requested type with `-dbaas` if exists { lagoonType = fmt.Sprintf("%s-dbaas", lagoonType) + svcIsDBaaS = true } else { // otherwise fallback to -single (if DBaaSFallbackSingle is enabled, otherwise it will error out prior) lagoonType = fmt.Sprintf("%s-single", lagoonType) @@ -259,6 +273,7 @@ func composeToServiceValues( AutogeneratedRoutesEnabled: autogenEnabled, AutogeneratedRoutesTLSAcme: autogenTLSAcmeEnabled, DBaaSEnvironment: dbaasEnvironment, + IsDBaaS: svcIsDBaaS, } return cService, nil } diff --git a/internal/generator/services_test.go b/internal/generator/services_test.go index 87a0c2df..c9471bb6 100644 --- a/internal/generator/services_test.go +++ b/internal/generator/services_test.go @@ -347,6 +347,7 @@ func Test_composeToServiceValues(t *testing.T) { AutogeneratedRoutesEnabled: false, AutogeneratedRoutesTLSAcme: false, DBaaSEnvironment: "development", + IsDBaaS: true, }, }, { @@ -428,6 +429,7 @@ func Test_composeToServiceValues(t *testing.T) { AutogeneratedRoutesEnabled: false, AutogeneratedRoutesTLSAcme: false, DBaaSEnvironment: "development", + IsDBaaS: true, }, }, { diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index bda1a121..9cd281c8 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -241,7 +241,6 @@ MONGODB_SHARED_DEFAULT_CLASS="lagoon-maas-mongodb-apb" SERVICE_TYPES=() IMAGES=() NATIVE_CRONJOB_CLEANUP_ARRAY=() -DBAAS=() declare -A MAP_DEPLOYMENT_SERVICETYPE_TO_IMAGENAME declare -A MAP_SERVICE_TYPE_TO_COMPOSE_SERVICE declare -A MAP_SERVICE_NAME_TO_IMAGENAME @@ -319,168 +318,11 @@ do done fi - # functions used to check dbaas providers - #### - function checkDBaaSHealth() { - response_code=$(curl --write-out "%{http_code}\n" --silent --output /dev/null "${DBAAS_OPERATOR_HTTP}/healthz") - if [ "$response_code" == "200" ]; then - return 0 - else - return 1 - fi - } - - function checkDBaaSProvider() { - response_json=$(curl --silent "${DBAAS_OPERATOR_HTTP}/$1/$2") - response_found=$(echo ${response_json} | jq -r '.result.found') - response_error=$(echo ${response_json} | jq -r '.error') - if [ "${response_error}" == "null" ]; then - return 0 - else - echo $response_error 1>&2 - return 1 - fi - } - - function getDBaaSEnvironment() { - dbaas_environment=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$COMPOSE_SERVICE.labels.lagoon\\.$1\\.environment "${ENVIRONMENT_TYPE}") - # Allow the dbaas shared servicebroker plan to be overriden by environment in .lagoon.yml - environment_dbaas_override=$(cat .lagoon.yml | shyaml get-value environments.${BRANCH//./\\.}.overrides.$SERVICE_NAME.$1\\.environment false) - if [ ! $environment_dbaas_override == "false" ]; then - dbaas_environment=$environment_dbaas_override - fi - # If we have a dbaas environment type override in the api, consume it here - if [ ! -z "$LAGOON_DBAAS_ENVIRONMENT_TYPES" ]; then - IFS=',' read -ra LAGOON_DBAAS_ENVIRONMENT_TYPES_SPLIT <<< "$LAGOON_DBAAS_ENVIRONMENT_TYPES" - for LAGOON_DBAAS_ENVIRONMENT_TYPE in "${LAGOON_DBAAS_ENVIRONMENT_TYPES_SPLIT[@]}" - do - IFS=':' read -ra LAGOON_DBAAS_ENVIRONMENT_TYPE_SPLIT <<< "$LAGOON_DBAAS_ENVIRONMENT_TYPE" - if [ "${LAGOON_DBAAS_ENVIRONMENT_TYPE_SPLIT[0]}" == "$SERVICE_NAME" ]; then - dbaas_environment=${LAGOON_DBAAS_ENVIRONMENT_TYPE_SPLIT[1]} - fi - done - fi - echo $dbaas_environment - } - #### - # Previous versions of Lagoon used "python-ckandatapusher", this should be mapped to "python" if [[ "$SERVICE_TYPE" == "python-ckandatapusher" ]]; then SERVICE_TYPE="python" fi - # "mariadb" is a meta service, which allows lagoon to decide itself which of the services to use: - # - mariadb-single (a single mariadb pod) - # - mariadb-dbaas (use the dbaas shared operator) - if [ "$SERVICE_TYPE" == "mariadb" ]; then - # if there is already a service existing with the service_name we assume that for this project there has been a - # mariadb-single deployed (probably from the past where there was no mariadb-shared yet, or mariadb-dbaas) and use that one - if kubectl -n ${NAMESPACE} get service "$SERVICE_NAME" &> /dev/null; then - SERVICE_TYPE="mariadb-single" - elif checkDBaaSHealth; then - # check if the dbaas operator responds to a health check - # if it does, then check if the dbaas operator has a provider matching the provider type that is expected - if checkDBaaSProvider mariadb $(getDBaaSEnvironment mariadb-dbaas); then - SERVICE_TYPE="mariadb-dbaas" - else - SERVICE_TYPE="mariadb-single" - fi - elif [[ "${CAPABILITIES[@]}" =~ "mariadb.amazee.io/v1/MariaDBConsumer" ]] && ! checkDBaaSHealth ; then - # check if this cluster supports the default one, if not we assume that this cluster is not capable of shared mariadbs and we use a mariadb-single - # real basic check to see if the mariadbconsumer exists as a kind - SERVICE_TYPE="mariadb-dbaas" - else - SERVICE_TYPE="mariadb-single" - fi - - fi - - # Previous versions of Lagoon supported "mariadb-shared", this has been superseeded by "mariadb-dbaas" - if [[ "$SERVICE_TYPE" == "mariadb-shared" ]]; then - SERVICE_TYPE="mariadb-dbaas" - fi - - if [[ "$SERVICE_TYPE" == "mariadb-dbaas" ]]; then - # Default plan is the enviroment type - DBAAS_ENVIRONMENT=$(getDBaaSEnvironment mariadb-dbaas) - - MAP_SERVICE_NAME_TO_DBAAS_ENVIRONMENT["${SERVICE_NAME}"]="${DBAAS_ENVIRONMENT}" - fi - - # "postgres" is a meta service, which allows lagoon to decide itself which of the services to use: - # - postgres-single (a single postgres pod) - # - postgres-dbaas (use the dbaas shared operator) - if [ "$SERVICE_TYPE" == "postgres" ]; then - # if there is already a service existing with the service_name we assume that for this project there has been a - # postgres-single deployed (probably from the past where there was no postgres-shared yet, or postgres-dbaas) and use that one - if kubectl -n ${NAMESPACE} get service "$SERVICE_NAME" &> /dev/null; then - SERVICE_TYPE="postgres-single" - elif checkDBaaSHealth; then - # check if the dbaas operator responds to a health check - # if it does, then check if the dbaas operator has a provider matching the provider type that is expected - if checkDBaaSProvider postgres $(getDBaaSEnvironment postgres-dbaas); then - SERVICE_TYPE="postgres-dbaas" - else - SERVICE_TYPE="postgres-single" - fi - # heck if this cluster supports the default one, if not we assume that this cluster is not capable of shared PostgreSQL and we use a postgres-single - # real basic check to see if the postgreSQLConsumer exists as a kind - elif [[ "${CAPABILITIES[@]}" =~ "postgres.amazee.io/v1/PostgreSQLConsumer" ]] && ! checkDBaaSHealth; then - SERVICE_TYPE="postgres-dbaas" - else - SERVICE_TYPE="postgres-single" - fi - - fi - - # Previous versions of Lagoon supported "postgres-shared", this has been superseeded by "postgres-dbaas" - if [[ "$SERVICE_TYPE" == "postgres-shared" ]]; then - SERVICE_TYPE="postgres-dbaas" - fi - - if [[ "$SERVICE_TYPE" == "postgres-dbaas" ]]; then - # Default plan is the enviroment type - DBAAS_ENVIRONMENT=$(getDBaaSEnvironment postgres-dbaas) - - MAP_SERVICE_NAME_TO_DBAAS_ENVIRONMENT["${SERVICE_NAME}"]="${DBAAS_ENVIRONMENT}" - fi - - # "mongo" is a meta service, which allows lagoon to decide itself which of the services to use: - # - mongodb-single (a single mongodb pod) - # - mongodb-dbaas (use the dbaas shared operator) - if [ "$SERVICE_TYPE" == "mongo" ]; then - # if there is already a service existing with the service_name we assume that for this project there has been a - # mongodb-single deployed (probably from the past where there was no mongodb-shared yet, or mongodb-dbaas) and use that one - if kubectl -n ${NAMESPACE} get service "$SERVICE_NAME" &> /dev/null; then - SERVICE_TYPE="mongodb-single" - elif checkDBaaSHealth; then - # check if the dbaas operator responds to a health check - # if it does, then check if the dbaas operator has a provider matching the provider type that is expected - if checkDBaaSProvider mongodb $(getDBaaSEnvironment mongodb-dbaas); then - SERVICE_TYPE="mongodb-dbaas" - else - SERVICE_TYPE="mongodb-single" - fi - # heck if this cluster supports the default one, if not we assume that this cluster is not capable of shared MongoDB and we use a mongodb-single - # real basic check to see if the MongoDBConsumer exists as a kind - elif [[ "${CAPABILITIES[@]}" =~ "mongodb.amazee.io/v1/MongoDBConsumer" ]] && ! checkDBaaSHealth; then - SERVICE_TYPE="mongodb-dbaas" - else - SERVICE_TYPE="mongodb-single" - fi - - fi - - # Previous versions of Lagoon supported "mongo-shared", this has been superseeded by "mongodb-dbaas" - if [[ "$SERVICE_TYPE" == "mongo-shared" ]]; then - SERVICE_TYPE="mongodb-dbaas" - fi - - if [[ "$SERVICE_TYPE" == "mongodb-dbaas" ]]; then - DBAAS_ENVIRONMENT=$(getDBaaSEnvironment mongodb-dbaas) - - MAP_SERVICE_NAME_TO_DBAAS_ENVIRONMENT["${SERVICE_NAME}"]="${DBAAS_ENVIRONMENT}" - fi if [ "$SERVICE_TYPE" == "none" ]; then continue @@ -973,8 +815,12 @@ set -x ### CREATE SERVICES, AUTOGENERATED ROUTES AND DBAAS CONFIG ############################################## +# generate the autogenerated ingress build-deploy-tool template autogenerated-ingress +# generate the dbaas templates if any +build-deploy-tool template dbaas + for SERVICE_TYPES_ENTRY in "${SERVICE_TYPES[@]}" do echo "=== BEGIN route processing for service ${SERVICE_TYPES_ENTRY} ===" @@ -992,15 +838,6 @@ do cat /kubectl-build-deploy/values.yaml helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -s $HELM_SERVICE_TEMPLATE -f /kubectl-build-deploy/values.yaml "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/service-${SERVICE_NAME}.yaml fi - - HELM_DBAAS_TEMPLATE="templates/dbaas.yaml" - if [ -f /kubectl-build-deploy/helmcharts/${SERVICE_TYPE}/$HELM_DBAAS_TEMPLATE ]; then - # Load the requested class and plan for this service - DBAAS_ENVIRONMENT="${MAP_SERVICE_NAME_TO_DBAAS_ENVIRONMENT["${SERVICE_NAME}"]}" - yq3 write -i -- /kubectl-build-deploy/${SERVICE_NAME}-values.yaml 'environment' $DBAAS_ENVIRONMENT - helm template ${SERVICE_NAME} /kubectl-build-deploy/helmcharts/${SERVICE_TYPE} -s $HELM_DBAAS_TEMPLATE -f /kubectl-build-deploy/values.yaml -f /kubectl-build-deploy/${SERVICE_NAME}-values.yaml "${HELM_ARGUMENTS[@]}" > $YAML_FOLDER/service-${SERVICE_NAME}.yaml - DBAAS+=("${SERVICE_NAME}:${SERVICE_TYPE}") - fi done set +x @@ -1124,7 +961,8 @@ if [ "$BUILD_TYPE" == "pullrequest" ]; then -p "{\"data\":{\"LAGOON_PR_HEAD_BRANCH\":\"${PR_HEAD_BRANCH}\", \"LAGOON_PR_BASE_BRANCH\":\"${PR_BASE_BRANCH}\", \"LAGOON_PR_TITLE\":$(echo $PR_TITLE | jq -R)}}" fi -# loop through created DBAAS +# loop through created DBAAS templates +DBAAS=($(build-deploy-tool identify dbaas)) for DBAAS_ENTRY in "${DBAAS[@]}" do IFS=':' read -ra DBAAS_ENTRY_SPLIT <<< "$DBAAS_ENTRY" diff --git a/test-resources/template-dbaas/test2-results/dbaas.yaml b/test-resources/template-dbaas/test2-results/dbaas.yaml new file mode 100644 index 00000000..7c206c80 --- /dev/null +++ b/test-resources/template-dbaas/test2-results/dbaas.yaml @@ -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: {} diff --git a/test-resources/template-dbaas/test2/docker-compose.yml b/test-resources/template-dbaas/test2/docker-compose.yml new file mode 100644 index 00000000..2c8445b0 --- /dev/null +++ b/test-resources/template-dbaas/test2/docker-compose.yml @@ -0,0 +1,121 @@ +version: '2.3' + +x-volumes: + &default-volumes + # Define all volumes you would like to have real-time mounted into the docker containers + volumes: + - .:/app:delegated ### Local overrides to mount host filesystem. Automatically removed in CI and PROD. + - files:/app/web/sites/default/files + +x-environment: + &default-environment + # Route that should be used locally, if you are using pygmy, this route *must* end with .docker.amazee.io + LAGOON_ROUTE: &default-url http://${COMPOSE_PROJECT_NAME:-drupal9-example-advanced}.docker.amazee.io + # Uncomment if you like to have the system behave like in production + #LAGOON_ENVIRONMENT_TYPE: production + # Uncomment to enable xdebug and then restart via `docker-compose up -d` + #XDEBUG_ENABLE: "true" + +x-user: + &default-user + # The default user under which the containers should run. Change this if you are on linux and run with another user than id `1000` + user: '1000' + +volumes: + files: + {} + +services: + + cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.) + build: + context: . + dockerfile: lagoon/cli.dockerfile + image: &cli-image ${COMPOSE_PROJECT_NAME:-drupal9-example-advanced}-cli # this image will be reused as `CLI_IMAGE` in subsequent Docker builds + labels: + # Lagoon Labels + lagoon.type: cli-persistent + lagoon.persistent.name: nginx # mount the persistent storage of nginx into this container + lagoon.persistent: /app/web/sites/default/files/ # location where the persistent storage should be mounted + lando.type: php-cli-drupal + << : *default-volumes # loads the defined volumes from the top + user: root + volumes_from: ### mount the ssh-agent from the pygmy or cachalot ssh-agent. Automatically removed in CI. + - container:amazeeio-ssh-agent ### Local overrides to mount host SSH keys. Automatically removed in CI. + environment: + << : *default-environment # loads the defined environment variables from the top + + nginx: + build: + context: . + dockerfile: lagoon/nginx.dockerfile + args: + CLI_IMAGE: *cli-image # Inject the name of the cli image + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: /app/web/sites/default/files/ # define where the persistent storage should be mounted too + lando.type: nginx-drupal + << : *default-volumes # loads the defined volumes from the top + << : *default-user # uses the defined user from top + depends_on: + - cli # basically just tells docker-compose to build the cli first + environment: + << : *default-environment # loads the defined environment variables from the top + LAGOON_LOCALDEV_URL: *default-url + networks: + - amazeeio-network + - default + + php: + build: + context: . + dockerfile: lagoon/php.dockerfile + args: + CLI_IMAGE: *cli-image + labels: + lagoon.type: nginx-php-persistent + lagoon.name: nginx # we want this service be part of the nginx pod in Lagoon + lagoon.persistent: /app/web/sites/default/files/ # define where the persistent storage should be mounted too + lando.type: php-fpm + << : *default-volumes # loads the defined volumes from the top + << : *default-user # uses the defined user from top + depends_on: + - cli # basically just tells docker-compose to build the cli first + environment: + << : *default-environment # loads the defined environment variables from the top + + mariadb: + image: uselagoon/mariadb-10.5-drupal:latest + labels: + lagoon.type: mariadb-single + lando.type: mariadb-drupal + ports: + - "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306` + << : *default-user # uses the defined user from top + environment: + << : *default-environment + + redis: + image: uselagoon/redis-5:latest + labels: + lagoon.type: redis + lando.type: redis + ports: + - "6379" # exposes the port 6379 with a random local port, find it with `docker-compose port redis 6379` + << : *default-user # uses the defined user from top + environment: + << : *default-environment + + solr: + image: uselagoon/solr-7.7-drupal:latest + labels: + lagoon.type: solr + lando.type: solr-drupal + ports: + - "8983" # exposes the port 8983 with a random local port, find it with `docker-compose port solr 8983` + environment: + << : *default-environment + +networks: + amazeeio-network: + external: true \ No newline at end of file diff --git a/test-resources/template-dbaas/test2/lagoon.yml b/test-resources/template-dbaas/test2/lagoon.yml new file mode 100644 index 00000000..fa563027 --- /dev/null +++ b/test-resources/template-dbaas/test2/lagoon.yml @@ -0,0 +1,10 @@ +docker-compose-yaml: ../test-resources/template-dbaas/test2/docker-compose.yml + +environment_variables: + git_sha: "true" + +environments: + main: + routes: + - node: + - example.com diff --git a/test-resources/template-dbaas/test3-results/dbaas.yaml b/test-resources/template-dbaas/test3-results/dbaas.yaml new file mode 100644 index 00000000..b16ae4d4 --- /dev/null +++ b/test-resources/template-dbaas/test3-results/dbaas.yaml @@ -0,0 +1,52 @@ +--- +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 + lagoon.sh/version: v2.7.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: main + 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: production + provider: {} +status: {} diff --git a/test-resources/template-dbaas/test3/docker-compose.yml b/test-resources/template-dbaas/test3/docker-compose.yml new file mode 100644 index 00000000..afd3fcf6 --- /dev/null +++ b/test-resources/template-dbaas/test3/docker-compose.yml @@ -0,0 +1,132 @@ +version: '2.3' + +x-volumes: + &default-volumes + # Define all volumes you would like to have real-time mounted into the docker containers + volumes: + - .:/app:delegated ### Local overrides to mount host filesystem. Automatically removed in CI and PROD. + - files:/app/web/sites/default/files + +x-environment: + &default-environment + # Route that should be used locally, if you are using pygmy, this route *must* end with .docker.amazee.io + LAGOON_ROUTE: &default-url http://${COMPOSE_PROJECT_NAME:-drupal9-example-advanced}.docker.amazee.io + # Uncomment if you like to have the system behave like in production + #LAGOON_ENVIRONMENT_TYPE: production + # Uncomment to enable xdebug and then restart via `docker-compose up -d` + #XDEBUG_ENABLE: "true" + +x-user: + &default-user + # The default user under which the containers should run. Change this if you are on linux and run with another user than id `1000` + user: '1000' + +volumes: + files: + {} + +services: + + cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.) + build: + context: . + dockerfile: lagoon/cli.dockerfile + image: &cli-image ${COMPOSE_PROJECT_NAME:-drupal9-example-advanced}-cli # this image will be reused as `CLI_IMAGE` in subsequent Docker builds + labels: + # Lagoon Labels + lagoon.type: cli-persistent + lagoon.persistent.name: nginx # mount the persistent storage of nginx into this container + lagoon.persistent: /app/web/sites/default/files/ # location where the persistent storage should be mounted + lando.type: php-cli-drupal + << : *default-volumes # loads the defined volumes from the top + user: root + volumes_from: ### mount the ssh-agent from the pygmy or cachalot ssh-agent. Automatically removed in CI. + - container:amazeeio-ssh-agent ### Local overrides to mount host SSH keys. Automatically removed in CI. + environment: + << : *default-environment # loads the defined environment variables from the top + + nginx: + build: + context: . + dockerfile: lagoon/nginx.dockerfile + args: + CLI_IMAGE: *cli-image # Inject the name of the cli image + labels: + lagoon.type: nginx-php-persistent + lagoon.persistent: /app/web/sites/default/files/ # define where the persistent storage should be mounted too + lando.type: nginx-drupal + << : *default-volumes # loads the defined volumes from the top + << : *default-user # uses the defined user from top + depends_on: + - cli # basically just tells docker-compose to build the cli first + environment: + << : *default-environment # loads the defined environment variables from the top + LAGOON_LOCALDEV_URL: *default-url + networks: + - amazeeio-network + - default + + php: + build: + context: . + dockerfile: lagoon/php.dockerfile + args: + CLI_IMAGE: *cli-image + labels: + lagoon.type: nginx-php-persistent + lagoon.name: nginx # we want this service be part of the nginx pod in Lagoon + lagoon.persistent: /app/web/sites/default/files/ # define where the persistent storage should be mounted too + lando.type: php-fpm + << : *default-volumes # loads the defined volumes from the top + << : *default-user # uses the defined user from top + depends_on: + - cli # basically just tells docker-compose to build the cli first + environment: + << : *default-environment # loads the defined environment variables from the top + + mariadb: + image: uselagoon/mariadb-10.5-drupal:latest + labels: + lagoon.type: mariadb + lando.type: mariadb-drupal + ports: + - "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306` + << : *default-user # uses the defined user from top + environment: + << : *default-environment + + mariadb2: + image: uselagoon/mariadb-10.5-drupal:latest + labels: + lagoon.type: mariadb + lando.type: mariadb-drupal + ports: + - "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306` + << : *default-user # uses the defined user from top + environment: + << : *default-environment + + redis: + image: uselagoon/redis-5:latest + labels: + lagoon.type: redis + lando.type: redis + ports: + - "6379" # exposes the port 6379 with a random local port, find it with `docker-compose port redis 6379` + << : *default-user # uses the defined user from top + environment: + << : *default-environment + + solr: + image: uselagoon/solr-7.7-drupal:latest + labels: + lagoon.type: solr + lando.type: solr-drupal + ports: + - "8983" # exposes the port 8983 with a random local port, find it with `docker-compose port solr 8983` + environment: + << : *default-environment + +networks: + amazeeio-network: + external: true \ No newline at end of file diff --git a/test-resources/template-dbaas/test3/lagoon.yml b/test-resources/template-dbaas/test3/lagoon.yml new file mode 100644 index 00000000..5f92cb78 --- /dev/null +++ b/test-resources/template-dbaas/test3/lagoon.yml @@ -0,0 +1,10 @@ +docker-compose-yaml: ../test-resources/template-dbaas/test3/docker-compose.yml + +environment_variables: + git_sha: "true" + +environments: + main: + routes: + - node: + - example.com From 87cd3971a579263e280583a1429252611f6e69b8 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 12 Sep 2022 15:17:36 +1000 Subject: [PATCH 02/13] chore: remove unused classes --- legacy/build-deploy-docker-compose.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 9cd281c8..bd6fbaf8 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -233,9 +233,6 @@ DEPLOY_TYPE=$(cat .lagoon.yml | shyaml get-value environments.${BRANCH//./\\.}.d # Load all Services that are defined COMPOSE_SERVICES=($(cat $DOCKER_COMPOSE_YAML | shyaml keys services)) -# Default shared mariadb service broker -MARIADB_SHARED_DEFAULT_CLASS="lagoon-dbaas-mariadb-apb" -MONGODB_SHARED_DEFAULT_CLASS="lagoon-maas-mongodb-apb" # Figure out which services should we handle SERVICE_TYPES=() From cdb7465879ead91adbcabcd8cae8f1c635f22cd7 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 12 Sep 2022 15:50:40 +1000 Subject: [PATCH 03/13] chore: add debug message for templating result --- cmd/template_dbaas.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/template_dbaas.go b/cmd/template_dbaas.go index 3365a729..a756227b 100644 --- a/cmd/template_dbaas.go +++ b/cmd/template_dbaas.go @@ -38,6 +38,9 @@ func DBaaSTemplateGeneration(g generator.GeneratorInput, return fmt.Errorf("couldn't generate template: %v", err) } helpers.WriteTemplateFile(fmt.Sprintf("%s/%s.yaml", savedTemplates, "dbaas"), templateYAML) + if g.Debug { + fmt.Println(fmt.Sprintf("Templating dbaas consumers to %s", fmt.Sprintf("%s/%s.yaml", savedTemplates, "dbaas"))) + } return nil } From 7e9ebb62cafe2892d95b50d2d6a95ba9b6f007d0 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 12 Sep 2022 15:52:14 +1000 Subject: [PATCH 04/13] chore: disable debug for ingress identification --- cmd/identify_ingress.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/identify_ingress.go b/cmd/identify_ingress.go index 8595aee9..f2adea47 100644 --- a/cmd/identify_ingress.go +++ b/cmd/identify_ingress.go @@ -37,7 +37,7 @@ var ingressIdentify = &cobra.Command{ Aliases: []string{"i"}, Short: "Identify all ingress for a specific environment", RunE: func(cmd *cobra.Command, args []string) error { - generator, err := generatorInput(true) + generator, err := generatorInput(false) if err != nil { return err } From fbe1977698749f262db98583e948292c6761e7c3 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 12 Sep 2022 16:01:20 +1000 Subject: [PATCH 05/13] chore: disable debug for ingress identification --- cmd/identify_ingress.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/identify_ingress.go b/cmd/identify_ingress.go index f2adea47..35cb9e38 100644 --- a/cmd/identify_ingress.go +++ b/cmd/identify_ingress.go @@ -19,7 +19,7 @@ var primaryIngressIdentify = &cobra.Command{ Aliases: []string{"pi"}, Short: "Identify the primary ingress for a specific environment", RunE: func(cmd *cobra.Command, args []string) error { - generator, err := generatorInput(true) + generator, err := generatorInput(false) if err != nil { return err } From 0bc4b5060225adc34d3d28c6941d7d91503eeb1d Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 12 Sep 2022 16:12:12 +1000 Subject: [PATCH 06/13] chore: disable debug for dbaas identification --- cmd/identify_dbaas.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/identify_dbaas.go b/cmd/identify_dbaas.go index 44c7f6dd..837591ee 100644 --- a/cmd/identify_dbaas.go +++ b/cmd/identify_dbaas.go @@ -14,7 +14,7 @@ var dbaasIdentify = &cobra.Command{ Aliases: []string{"db", "d"}, Short: "Identify if any dbaas consumers are created", RunE: func(cmd *cobra.Command, args []string) error { - generator, err := generatorInput(true) + generator, err := generatorInput(false) if err != nil { return err } From 165bd800c88d095325e6c0545f19b134ff6b5852 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 12 Sep 2022 16:44:31 +1000 Subject: [PATCH 07/13] chore: add dbaas command to identify --- cmd/identify_ingress.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/identify_ingress.go b/cmd/identify_ingress.go index 35cb9e38..f4d3495c 100644 --- a/cmd/identify_ingress.go +++ b/cmd/identify_ingress.go @@ -71,4 +71,5 @@ func IdentifyPrimaryIngress(g generator.GeneratorInput) (string, []string, []str func init() { identifyCmd.AddCommand(primaryIngressIdentify) identifyCmd.AddCommand(ingressIdentify) + identifyCmd.AddCommand(dbaasIdentify) } From 952950e4e60008bdce5d5a822e85e88cea6a675e Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 12 Sep 2022 17:39:31 +1000 Subject: [PATCH 08/13] chore: add dbaas support to exec-monitor since existing code that transformed types changed --- legacy/build-deploy-docker-compose.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index bd6fbaf8..b1cce5a6 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -1257,6 +1257,17 @@ do SERVICE_ROLLOUT_TYPE=$ENVIRONMENT_SERVICE_ROLLOUT_TYPE fi + # check if this service is a dbaas service and transform the service_type accordingly + for DBAAS_ENTRY in "${DBAAS[@]}" + do + IFS=':' read -ra DBAAS_ENTRY_SPLIT <<< "$DBAAS_ENTRY" + DB_SERVICE_NAME=${DBAAS_ENTRY_SPLIT[0]} + DB_SERVICE_TYPE=${DBAAS_ENTRY_SPLIT[1]} + if [ $SERVICE_NAME == $DB_SERVICE_NAME ]; then + SERVICE_TYPE=$DB_SERVICE_TYPE + fi + done + if [ $SERVICE_TYPE == "mariadb-dbaas" ]; then echo "nothing to monitor for $SERVICE_TYPE" From 95727e90965c8bd27a5f00258f2894a641048b11 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Mon, 15 Jan 2024 16:17:06 +1100 Subject: [PATCH 09/13] test: fix dbaas tests with new changes --- cmd/identify_dbaas.go | 2 +- cmd/identify_dbaas_test.go | 219 ++++++------------ cmd/template_dbaas_test.go | 64 +++-- .../dbaas-templates/dbaas-2}/dbaas.yaml | 0 .../dbaas-templates/dbaas-3}/dbaas.yaml | 0 .../complex/docker-compose.multi-db.yml | 0 .../testdata/complex/lagoon.multidb.yml | 2 +- .../template-dbaas/test2/docker-compose.yml | 121 ---------- .../template-dbaas/test3/lagoon.yml | 10 - 9 files changed, 95 insertions(+), 323 deletions(-) rename {test-resources/template-dbaas/test2-results => internal/testdata/complex/dbaas-templates/dbaas-2}/dbaas.yaml (100%) rename {test-resources/template-dbaas/test3-results => internal/testdata/complex/dbaas-templates/dbaas-3}/dbaas.yaml (100%) rename test-resources/template-dbaas/test3/docker-compose.yml => internal/testdata/complex/docker-compose.multi-db.yml (100%) rename test-resources/template-dbaas/test2/lagoon.yml => internal/testdata/complex/lagoon.multidb.yml (59%) delete mode 100644 test-resources/template-dbaas/test2/docker-compose.yml delete mode 100644 test-resources/template-dbaas/test3/lagoon.yml diff --git a/cmd/identify_dbaas.go b/cmd/identify_dbaas.go index 837591ee..26009d1c 100644 --- a/cmd/identify_dbaas.go +++ b/cmd/identify_dbaas.go @@ -14,7 +14,7 @@ var dbaasIdentify = &cobra.Command{ Aliases: []string{"db", "d"}, Short: "Identify if any dbaas consumers are created", RunE: func(cmd *cobra.Command, args []string) error { - generator, err := generatorInput(false) + generator, err := generator.GenerateInput(*rootCmd, false) if err != nil { return err } diff --git a/cmd/identify_dbaas_test.go b/cmd/identify_dbaas_test.go index a1448b8c..932d4a77 100644 --- a/cmd/identify_dbaas_test.go +++ b/cmd/identify_dbaas_test.go @@ -4,10 +4,11 @@ import ( "os" "reflect" "testing" - "time" "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/helpers" + "github.com/uselagoon/build-deploy-tool/internal/lagoon" + "github.com/uselagoon/build-deploy-tool/internal/testdata" ) // these tests uses the same files as the dbaas templates @@ -37,111 +38,86 @@ func TestIdentifyDBaaSConsumers(t *testing.T) { templatePath string } tests := []struct { - name string - args args - vars []helpers.EnvironmentVariable - want []string - wantErr bool + name string + args testdata.TestData + vars []helpers.EnvironmentVariable + templatePath string + want []string + wantErr bool }{ { name: "test1 - mariadb to mariadb-dbaas only", - args: args{ - name: "ROOTLESS_WORKLOAD", - alertContact: "alertcontact", - statusPageID: "statuspageid", - projectName: "example-project", - environmentName: "main", - environmentType: "production", - buildType: "branch", - lagoonVersion: "v2.7.x", - branch: "main", - projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, - envVars: `[]`, - lagoonYAML: "../test-resources/template-dbaas/test1/lagoon.yml", - templatePath: "../test-resources/output", - }, + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/complex/lagoon.yml", + }, true), + templatePath: "testdata/output", want: []string{ "mariadb:mariadb-dbaas", }, }, { name: "test2 - mariadb to mariadb-shared which converts to mariadb-dbaas", - args: args{ - name: "ROOTLESS_WORKLOAD", - alertContact: "alertcontact", - statusPageID: "statuspageid", - projectName: "example-project", - environmentName: "main", - environmentType: "production", - buildType: "branch", - lagoonVersion: "v2.7.x", - branch: "main", - projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_SERVICE_TYPES","value":"mariadb:mariadb-shared","scope":"build"}]`, - envVars: `[]`, - lagoonYAML: "../test-resources/template-dbaas/test1/lagoon.yml", - templatePath: "../test-resources/output", - }, + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/complex/lagoon.yml", + ProjectVariables: []lagoon.EnvironmentVariable{ + {Name: "LAGOON_SERVICE_TYPES", Value: "mariadb:mariadb-shared", Scope: "build"}, + }, + }, true), + templatePath: "testdata/output", want: []string{ "mariadb:mariadb-dbaas", }, }, { name: "test3 - override provider to non-existent should result in failing dbaas check and a single pod no dbaas found", - args: args{ - name: "ROOTLESS_WORKLOAD", - alertContact: "alertcontact", - statusPageID: "statuspageid", - projectName: "example-project", - environmentName: "main", - environmentType: "production", - buildType: "branch", - lagoonVersion: "v2.7.x", - branch: "main", - projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_DBAAS_ENVIRONMENT_TYPES","value":"mariadb:development2","scope":"build"}]`, - envVars: `[]`, - lagoonYAML: "../test-resources/template-dbaas/test1/lagoon.yml", - templatePath: "../test-resources/output", - }, - want: []string{}, + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/complex/lagoon.yml", + ProjectVariables: []lagoon.EnvironmentVariable{ + {Name: "LAGOON_DBAAS_ENVIRONMENT_TYPES", Value: "mariadb:development2", Scope: "build"}, + }, + }, true), + templatePath: "testdata/output", + want: []string{}, }, { name: "test4 - mariadb-single to mariadb-dbaas (using mariadb-shared to mariadb-dbaas conversion)", - args: args{ - name: "ROOTLESS_WORKLOAD", - alertContact: "alertcontact", - statusPageID: "statuspageid", - projectName: "example-project", - environmentName: "main", - environmentType: "production", - buildType: "branch", - lagoonVersion: "v2.7.x", - branch: "main", - projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_SERVICE_TYPES","value":"mariadb:mariadb-shared","scope":"build"}]`, - envVars: `[]`, - lagoonYAML: "../test-resources/template-dbaas/test2/lagoon.yml", - templatePath: "../test-resources/output", - }, + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/complex/lagoon.yml", + ProjectVariables: []lagoon.EnvironmentVariable{ + {Name: "LAGOON_SERVICE_TYPES", Value: "mariadb:mariadb-shared", Scope: "build"}, + }, + }, true), + templatePath: "testdata/output", want: []string{ "mariadb:mariadb-dbaas", }, }, { name: "test5 - multiple mariadb", - args: args{ - name: "ROOTLESS_WORKLOAD", - alertContact: "alertcontact", - statusPageID: "statuspageid", - projectName: "example-project", - environmentName: "main", - environmentType: "production", - buildType: "branch", - lagoonVersion: "v2.7.x", - branch: "main", - projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_SERVICE_TYPES","value":"mariadb:mariadb-shared","scope":"build"}]`, - envVars: `[]`, - lagoonYAML: "../test-resources/template-dbaas/test3/lagoon.yml", - templatePath: "../test-resources/output", - }, + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/complex/lagoon.multidb.yml", + }, true), + templatePath: "testdata/output", want: []string{ "mariadb:mariadb-dbaas", "mariadb2:mariadb-dbaas", @@ -150,82 +126,17 @@ func TestIdentifyDBaaSConsumers(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - // set the environment variables from args - err := os.Setenv("MONITORING_ALERTCONTACT", tt.args.alertContact) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("MONITORING_STATUSPAGEID", tt.args.statusPageID) + savedTemplates := tt.templatePath + generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args) if err != nil { t.Errorf("%v", err) } - err = os.Setenv("PROJECT", tt.args.projectName) - if err != nil { - t.Errorf("%v", err) + for _, envVar := range tt.vars { + err = os.Setenv(envVar.Name, envVar.Value) + if err != nil { + t.Errorf("%v", err) + } } - err = os.Setenv("ENVIRONMENT", tt.args.environmentName) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("BRANCH", tt.args.branch) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("PR_NUMBER", tt.args.prNumber) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("PR_HEAD_BRANCH", tt.args.prHeadBranch) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("PR_BASE_BRANCH", tt.args.prBaseBranch) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("ENVIRONMENT_TYPE", tt.args.environmentType) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("BUILD_TYPE", tt.args.buildType) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("ACTIVE_ENVIRONMENT", tt.args.activeEnvironment) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("STANDBY_ENVIRONMENT", tt.args.standbyEnvironment) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("LAGOON_FASTLY_NOCACHE_SERVICE_ID", tt.args.cacheNoCache) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("LAGOON_PROJECT_VARIABLES", tt.args.projectVars) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("LAGOON_ENVIRONMENT_VARIABLES", tt.args.envVars) - if err != nil { - t.Errorf("%v", err) - } - err = os.Setenv("LAGOON_VERSION", tt.args.lagoonVersion) - if err != nil { - t.Errorf("%v", err) - } - generator, err := generatorInput(false) - if err != nil { - t.Errorf("%v", err) - } - generator.LagoonYAML = tt.args.lagoonYAML - // add dbaasclient overrides for tests - generator.DBaaSClient = dbaasclient.NewClient(dbaasclient.Client{ - RetryMax: 5, - RetryWaitMin: time.Duration(10) * time.Millisecond, - RetryWaitMax: time.Duration(50) * time.Millisecond, - }) // setup the fake dbaas server ts := dbaasclient.TestDBaaSHTTPServer() diff --git a/cmd/template_dbaas_test.go b/cmd/template_dbaas_test.go index 12f7f671..e54bb159 100644 --- a/cmd/template_dbaas_test.go +++ b/cmd/template_dbaas_test.go @@ -9,6 +9,7 @@ import ( "github.com/uselagoon/build-deploy-tool/internal/dbaasclient" "github.com/uselagoon/build-deploy-tool/internal/helpers" + "github.com/uselagoon/build-deploy-tool/internal/lagoon" "github.com/uselagoon/build-deploy-tool/internal/testdata" ) @@ -32,42 +33,33 @@ func TestDBaaSTemplateGeneration(t *testing.T) { templatePath: "testdata/output", want: "../internal/testdata/complex/dbaas-templates/dbaas-1", }, - // { - // name: "test2 - mariadb-single to mariadb-dbaas (using mariadb-shared to mariadb-dbaas conversion)", - // args: args{ - // alertContact: "alertcontact", - // statusPageID: "statuspageid", - // projectName: "example-project", - // environmentName: "main", - // environmentType: "production", - // buildType: "branch", - // lagoonVersion: "v2.7.x", - // branch: "main", - // projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_SERVICE_TYPES","value":"mariadb:mariadb-shared","scope":"build"}]`, - // envVars: `[]`, - // lagoonYAML: "../test-resources/template-dbaas/test2/lagoon.yml", - // templatePath: "../test-resources/template-dbaas/output", - // }, - // want: "../test-resources/template-dbaas/test2-results", - // }, - // { - // name: "test3 - multiple mariadb", - // args: args{ - // alertContact: "alertcontact", - // statusPageID: "statuspageid", - // projectName: "example-project", - // environmentName: "main", - // environmentType: "production", - // buildType: "branch", - // lagoonVersion: "v2.7.x", - // branch: "main", - // projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`, - // envVars: `[]`, - // lagoonYAML: "../test-resources/template-dbaas/test3/lagoon.yml", - // templatePath: "../test-resources/template-dbaas/output", - // }, - // want: "../test-resources/template-dbaas/test3-results", - // }, + { + name: "test2 - mariadb-single to mariadb-dbaas (using mariadb-shared to mariadb-dbaas conversion)", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/complex/lagoon.yml", + ProjectVariables: []lagoon.EnvironmentVariable{ + {Name: "LAGOON_SERVICE_TYPES", Value: "mariadb:mariadb-shared", Scope: "build"}, + }, + }, true), + templatePath: "testdata/output", + want: "../internal/testdata/complex/dbaas-templates/dbaas-2", + }, + { + name: "test3 - multiple mariadb", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/complex/lagoon.multidb.yml", + }, true), + templatePath: "testdata/output", + want: "../internal/testdata/complex/dbaas-templates/dbaas-3", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/test-resources/template-dbaas/test2-results/dbaas.yaml b/internal/testdata/complex/dbaas-templates/dbaas-2/dbaas.yaml similarity index 100% rename from test-resources/template-dbaas/test2-results/dbaas.yaml rename to internal/testdata/complex/dbaas-templates/dbaas-2/dbaas.yaml diff --git a/test-resources/template-dbaas/test3-results/dbaas.yaml b/internal/testdata/complex/dbaas-templates/dbaas-3/dbaas.yaml similarity index 100% rename from test-resources/template-dbaas/test3-results/dbaas.yaml rename to internal/testdata/complex/dbaas-templates/dbaas-3/dbaas.yaml diff --git a/test-resources/template-dbaas/test3/docker-compose.yml b/internal/testdata/complex/docker-compose.multi-db.yml similarity index 100% rename from test-resources/template-dbaas/test3/docker-compose.yml rename to internal/testdata/complex/docker-compose.multi-db.yml diff --git a/test-resources/template-dbaas/test2/lagoon.yml b/internal/testdata/complex/lagoon.multidb.yml similarity index 59% rename from test-resources/template-dbaas/test2/lagoon.yml rename to internal/testdata/complex/lagoon.multidb.yml index fa563027..0bbc4ee3 100644 --- a/test-resources/template-dbaas/test2/lagoon.yml +++ b/internal/testdata/complex/lagoon.multidb.yml @@ -1,4 +1,4 @@ -docker-compose-yaml: ../test-resources/template-dbaas/test2/docker-compose.yml +docker-compose-yaml: ../internal/testdata/complex/docker-compose.multi-db.yml environment_variables: git_sha: "true" diff --git a/test-resources/template-dbaas/test2/docker-compose.yml b/test-resources/template-dbaas/test2/docker-compose.yml deleted file mode 100644 index 2c8445b0..00000000 --- a/test-resources/template-dbaas/test2/docker-compose.yml +++ /dev/null @@ -1,121 +0,0 @@ -version: '2.3' - -x-volumes: - &default-volumes - # Define all volumes you would like to have real-time mounted into the docker containers - volumes: - - .:/app:delegated ### Local overrides to mount host filesystem. Automatically removed in CI and PROD. - - files:/app/web/sites/default/files - -x-environment: - &default-environment - # Route that should be used locally, if you are using pygmy, this route *must* end with .docker.amazee.io - LAGOON_ROUTE: &default-url http://${COMPOSE_PROJECT_NAME:-drupal9-example-advanced}.docker.amazee.io - # Uncomment if you like to have the system behave like in production - #LAGOON_ENVIRONMENT_TYPE: production - # Uncomment to enable xdebug and then restart via `docker-compose up -d` - #XDEBUG_ENABLE: "true" - -x-user: - &default-user - # The default user under which the containers should run. Change this if you are on linux and run with another user than id `1000` - user: '1000' - -volumes: - files: - {} - -services: - - cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.) - build: - context: . - dockerfile: lagoon/cli.dockerfile - image: &cli-image ${COMPOSE_PROJECT_NAME:-drupal9-example-advanced}-cli # this image will be reused as `CLI_IMAGE` in subsequent Docker builds - labels: - # Lagoon Labels - lagoon.type: cli-persistent - lagoon.persistent.name: nginx # mount the persistent storage of nginx into this container - lagoon.persistent: /app/web/sites/default/files/ # location where the persistent storage should be mounted - lando.type: php-cli-drupal - << : *default-volumes # loads the defined volumes from the top - user: root - volumes_from: ### mount the ssh-agent from the pygmy or cachalot ssh-agent. Automatically removed in CI. - - container:amazeeio-ssh-agent ### Local overrides to mount host SSH keys. Automatically removed in CI. - environment: - << : *default-environment # loads the defined environment variables from the top - - nginx: - build: - context: . - dockerfile: lagoon/nginx.dockerfile - args: - CLI_IMAGE: *cli-image # Inject the name of the cli image - labels: - lagoon.type: nginx-php-persistent - lagoon.persistent: /app/web/sites/default/files/ # define where the persistent storage should be mounted too - lando.type: nginx-drupal - << : *default-volumes # loads the defined volumes from the top - << : *default-user # uses the defined user from top - depends_on: - - cli # basically just tells docker-compose to build the cli first - environment: - << : *default-environment # loads the defined environment variables from the top - LAGOON_LOCALDEV_URL: *default-url - networks: - - amazeeio-network - - default - - php: - build: - context: . - dockerfile: lagoon/php.dockerfile - args: - CLI_IMAGE: *cli-image - labels: - lagoon.type: nginx-php-persistent - lagoon.name: nginx # we want this service be part of the nginx pod in Lagoon - lagoon.persistent: /app/web/sites/default/files/ # define where the persistent storage should be mounted too - lando.type: php-fpm - << : *default-volumes # loads the defined volumes from the top - << : *default-user # uses the defined user from top - depends_on: - - cli # basically just tells docker-compose to build the cli first - environment: - << : *default-environment # loads the defined environment variables from the top - - mariadb: - image: uselagoon/mariadb-10.5-drupal:latest - labels: - lagoon.type: mariadb-single - lando.type: mariadb-drupal - ports: - - "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306` - << : *default-user # uses the defined user from top - environment: - << : *default-environment - - redis: - image: uselagoon/redis-5:latest - labels: - lagoon.type: redis - lando.type: redis - ports: - - "6379" # exposes the port 6379 with a random local port, find it with `docker-compose port redis 6379` - << : *default-user # uses the defined user from top - environment: - << : *default-environment - - solr: - image: uselagoon/solr-7.7-drupal:latest - labels: - lagoon.type: solr - lando.type: solr-drupal - ports: - - "8983" # exposes the port 8983 with a random local port, find it with `docker-compose port solr 8983` - environment: - << : *default-environment - -networks: - amazeeio-network: - external: true \ No newline at end of file diff --git a/test-resources/template-dbaas/test3/lagoon.yml b/test-resources/template-dbaas/test3/lagoon.yml deleted file mode 100644 index 5f92cb78..00000000 --- a/test-resources/template-dbaas/test3/lagoon.yml +++ /dev/null @@ -1,10 +0,0 @@ -docker-compose-yaml: ../test-resources/template-dbaas/test3/docker-compose.yml - -environment_variables: - git_sha: "true" - -environments: - main: - routes: - - node: - - example.com From 62e85b620a7fdbc47958c2d009d760fad520186e Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Tue, 13 Feb 2024 18:21:54 +1100 Subject: [PATCH 10/13] chore: remove redundant types --- internal/generator/services.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/generator/services.go b/internal/generator/services.go index 7c033502..27d24913 100644 --- a/internal/generator/services.go +++ b/internal/generator/services.go @@ -67,35 +67,35 @@ var typesWithBackups = []string{ // just some default values for services var defaultServiceValues = map[string]map[string]string{ - "elasticsearch": map[string]string{ + "elasticsearch": { "persistentPath": "/usr/share/elasticsearch/data", "persistentSize": "5Gi", }, - "opensearch": map[string]string{ + "opensearch": { "persistentPath": "/usr/share/opensearch/data", "persistentSize": "5Gi", }, - "mariadb-single": map[string]string{ + "mariadb-single": { "persistentPath": "/var/lib/mysql", "persistentSize": "5Gi", }, - "postgres-single": map[string]string{ + "postgres-single": { "persistentPath": "/var/lib/postgresql/data", "persistentSize": "5Gi", }, - "mongodb-single": map[string]string{ + "mongodb-single": { "persistentPath": "/data/db", "persistentSize": "5Gi", }, - "varnish-persistent": map[string]string{ + "varnish-persistent": { "persistentPath": "/var/cache/varnish", "persistentSize": "5Gi", }, - "rabbitmq": map[string]string{ + "rabbitmq": { "persistentPath": "/var/lib/rabbitmq", "persistentSize": "5Gi", }, - "redis-persistent": map[string]string{ + "redis-persistent": { "persistentPath": "/data", "persistentSize": "5Gi", }, From 70b52794c2a8658e63fe1f3c87790c23a7736d47 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 28 Feb 2024 15:45:11 +1100 Subject: [PATCH 11/13] chore: remove legacy dbaas charts --- legacy/helmcharts/mariadb-dbaas/.helmignore | 22 ----- legacy/helmcharts/mariadb-dbaas/Chart.yaml | 17 ---- .../mariadb-dbaas/templates/_helpers.tpl | 79 ----------------- .../mariadb-dbaas/templates/dbaas.yaml | 11 --- legacy/helmcharts/mariadb-dbaas/values.yaml | 9 -- legacy/helmcharts/mongodb-dbaas/.helmignore | 22 ----- legacy/helmcharts/mongodb-dbaas/Chart.yaml | 17 ---- .../mongodb-dbaas/templates/_helpers.tpl | 79 ----------------- .../mongodb-dbaas/templates/dbaas.yaml | 11 --- legacy/helmcharts/mongodb-dbaas/values.yaml | 7 -- legacy/helmcharts/postgres-dbaas/.helmignore | 22 ----- legacy/helmcharts/postgres-dbaas/Chart.yaml | 21 ----- .../postgres-dbaas/templates/_helpers.tpl | 87 ------------------- .../postgres-dbaas/templates/dbaas.yaml | 11 --- legacy/helmcharts/postgres-dbaas/values.yaml | 9 -- 15 files changed, 424 deletions(-) delete mode 100644 legacy/helmcharts/mariadb-dbaas/.helmignore delete mode 100644 legacy/helmcharts/mariadb-dbaas/Chart.yaml delete mode 100644 legacy/helmcharts/mariadb-dbaas/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/mariadb-dbaas/templates/dbaas.yaml delete mode 100644 legacy/helmcharts/mariadb-dbaas/values.yaml delete mode 100644 legacy/helmcharts/mongodb-dbaas/.helmignore delete mode 100644 legacy/helmcharts/mongodb-dbaas/Chart.yaml delete mode 100644 legacy/helmcharts/mongodb-dbaas/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/mongodb-dbaas/templates/dbaas.yaml delete mode 100644 legacy/helmcharts/mongodb-dbaas/values.yaml delete mode 100644 legacy/helmcharts/postgres-dbaas/.helmignore delete mode 100644 legacy/helmcharts/postgres-dbaas/Chart.yaml delete mode 100644 legacy/helmcharts/postgres-dbaas/templates/_helpers.tpl delete mode 100644 legacy/helmcharts/postgres-dbaas/templates/dbaas.yaml delete mode 100644 legacy/helmcharts/postgres-dbaas/values.yaml diff --git a/legacy/helmcharts/mariadb-dbaas/.helmignore b/legacy/helmcharts/mariadb-dbaas/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/mariadb-dbaas/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/mariadb-dbaas/Chart.yaml b/legacy/helmcharts/mariadb-dbaas/Chart.yaml deleted file mode 100644 index 15abe278..00000000 --- a/legacy/helmcharts/mariadb-dbaas/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: mariadb-dbaas -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 \ No newline at end of file diff --git a/legacy/helmcharts/mariadb-dbaas/templates/_helpers.tpl b/legacy/helmcharts/mariadb-dbaas/templates/_helpers.tpl deleted file mode 100644 index 650bcc44..00000000 --- a/legacy/helmcharts/mariadb-dbaas/templates/_helpers.tpl +++ /dev/null @@ -1,79 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "mariadb-dbaas.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "mariadb-dbaas.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "mariadb-dbaas.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "mariadb-dbaas.autogeneratedHost" -}} -{{- printf "%s.%s" .Release.Name .Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} - -{{- define "mariadb-dbaas.fullnameUppercase" -}} -{{ include "mariadb-dbaas.fullname" . | upper | replace "-" "_" }} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "mariadb-dbaas.labels" -}} -helm.sh/chart: {{ include "mariadb-dbaas.chart" . }} -{{ include "mariadb-dbaas.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "mariadb-dbaas.lagoonLabels" . }} - -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "mariadb-dbaas.selectorLabels" -}} -app.kubernetes.io/name: {{ include "mariadb-dbaas.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "mariadb-dbaas.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "mariadb-dbaas.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/mariadb-dbaas/templates/dbaas.yaml b/legacy/helmcharts/mariadb-dbaas/templates/dbaas.yaml deleted file mode 100644 index b751cfe7..00000000 --- a/legacy/helmcharts/mariadb-dbaas/templates/dbaas.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: mariadb.amazee.io/v1 -kind: MariaDBConsumer -metadata: - name: {{ include "mariadb-dbaas.fullname" . }} - labels: - {{- include "mariadb-dbaas.labels" . | nindent 4 }} - annotations: - {{- include "mariadb-dbaas.annotations" . | nindent 4 }} - -spec: - environment: {{ .Values.environment}} diff --git a/legacy/helmcharts/mariadb-dbaas/values.yaml b/legacy/helmcharts/mariadb-dbaas/values.yaml deleted file mode 100644 index 38f8de1b..00000000 --- a/legacy/helmcharts/mariadb-dbaas/values.yaml +++ /dev/null @@ -1,9 +0,0 @@ -# Default values for nginx. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -environment: "" - -readReplicaHosts: "" - -imageCache: "" diff --git a/legacy/helmcharts/mongodb-dbaas/.helmignore b/legacy/helmcharts/mongodb-dbaas/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/mongodb-dbaas/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/mongodb-dbaas/Chart.yaml b/legacy/helmcharts/mongodb-dbaas/Chart.yaml deleted file mode 100644 index a9c381b6..00000000 --- a/legacy/helmcharts/mongodb-dbaas/Chart.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v2 -name: mongodb-dbaas -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 \ No newline at end of file diff --git a/legacy/helmcharts/mongodb-dbaas/templates/_helpers.tpl b/legacy/helmcharts/mongodb-dbaas/templates/_helpers.tpl deleted file mode 100644 index a8487815..00000000 --- a/legacy/helmcharts/mongodb-dbaas/templates/_helpers.tpl +++ /dev/null @@ -1,79 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "mongodb-dbaas.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "mongodb-dbaas.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "mongodb-dbaas.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "mongodb-dbaas.autogeneratedHost" -}} -{{- printf "%s.%s" .Release.Name .Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} - -{{- define "mongodb-dbaas.fullnameUppercase" -}} -{{ include "mongodb-dbaas.fullname" . | upper | replace "-" "_" }} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "mongodb-dbaas.labels" -}} -helm.sh/chart: {{ include "mongodb-dbaas.chart" . }} -{{ include "mongodb-dbaas.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "mongodb-dbaas.lagoonLabels" . }} - -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "mongodb-dbaas.selectorLabels" -}} -app.kubernetes.io/name: {{ include "mongodb-dbaas.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "mongodb-dbaas.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "mongodb-dbaas.annotations" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/mongodb-dbaas/templates/dbaas.yaml b/legacy/helmcharts/mongodb-dbaas/templates/dbaas.yaml deleted file mode 100644 index 84a1b3e4..00000000 --- a/legacy/helmcharts/mongodb-dbaas/templates/dbaas.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: mongodb.amazee.io/v1 -kind: MongoDBConsumer -metadata: - name: {{ include "mongodb-dbaas.fullname" . }} - labels: - {{- include "mongodb-dbaas.labels" . | nindent 4 }} - annotations: - {{- include "mongodb-dbaas.annotations" . | nindent 4 }} - -spec: - environment: {{ .Values.environment}} diff --git a/legacy/helmcharts/mongodb-dbaas/values.yaml b/legacy/helmcharts/mongodb-dbaas/values.yaml deleted file mode 100644 index 495f8cc0..00000000 --- a/legacy/helmcharts/mongodb-dbaas/values.yaml +++ /dev/null @@ -1,7 +0,0 @@ -# Default values for nginx. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -environment: "" - -imageCache: "" diff --git a/legacy/helmcharts/postgres-dbaas/.helmignore b/legacy/helmcharts/postgres-dbaas/.helmignore deleted file mode 100644 index 50af0317..00000000 --- a/legacy/helmcharts/postgres-dbaas/.helmignore +++ /dev/null @@ -1,22 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/legacy/helmcharts/postgres-dbaas/Chart.yaml b/legacy/helmcharts/postgres-dbaas/Chart.yaml deleted file mode 100644 index d1491904..00000000 --- a/legacy/helmcharts/postgres-dbaas/Chart.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: v2 -name: postgres-dbaas -description: A Helm chart for Kubernetes - -# A chart can be either an 'application' or a 'library' chart. -# -# Application charts are a collection of templates that can be packaged into versioned archives -# to be deployed. -# -# Library charts provide useful utilities or functions for the chart developer. They're included as -# a dependency of application charts to inject those utilities and functions into the rendering -# pipeline. Library charts do not define any templates and therefore cannot be deployed. -type: application - -# This is the chart version. This version number should be incremented each time you make changes -# to the chart and its templates, including the app version. -version: 0.1.0 - -# This is the version number of the application being deployed. This version number should be -# incremented each time you make changes to the application. -appVersion: 1.16.0 diff --git a/legacy/helmcharts/postgres-dbaas/templates/_helpers.tpl b/legacy/helmcharts/postgres-dbaas/templates/_helpers.tpl deleted file mode 100644 index d8680f0a..00000000 --- a/legacy/helmcharts/postgres-dbaas/templates/_helpers.tpl +++ /dev/null @@ -1,87 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "postgres-dbaas.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a default fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "postgres-dbaas.fullname" -}} -{{- .Release.Name | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "postgres-dbaas.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create full hostname for autogenerated hosts -*/}} -{{- define "postgres-dbaas.autogeneratedHost" -}} -{{- printf "%s.%s" .Release.Name .Values.routesAutogenerateSuffix | trimSuffix "-" -}} -{{- end -}} - -{{- define "postgres-dbaas.fullnameUppercase" -}} -{{ include "postgres-dbaas.fullname" . | upper | replace "-" "_" }} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "postgres-dbaas.labels" -}} -helm.sh/chart: {{ include "postgres-dbaas.chart" . }} -{{ include "postgres-dbaas.selectorLabels" . }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{ include "postgres-dbaas.lagoonLabels" . }} -{{- end -}} - -{{/* -Add annotations -*/}} -{{- define "postgres-dbaas.annotations" -}} -{{ if .Values.annotations }} -{{- toYaml .Values.annotations }} -{{- end }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "postgres-dbaas.selectorLabels" -}} -app.kubernetes.io/name: {{ include "postgres-dbaas.name" . }} -app.kubernetes.io/instance: {{ .Release.Name }} -{{- end -}} - -{{/* -Lagoon Labels -*/}} -{{- define "postgres-dbaas.lagoonLabels" -}} -lagoon.sh/service: {{ .Release.Name }} -lagoon.sh/service-type: {{ .Chart.Name }} -lagoon.sh/project: {{ .Values.project }} -lagoon.sh/environment: {{ .Values.environment }} -lagoon.sh/environmentType: {{ .Values.environmentType }} -lagoon.sh/buildType: {{ .Values.buildType }} -{{- end -}} - -{{/* -Annotations -*/}} -{{- define "postgres-dbaas" -}} -lagoon.sh/version: {{ .Values.lagoonVersion | quote }} -{{- if .Values.branch }} -lagoon.sh/branch: {{ .Values.branch | quote }} -{{- end }} -{{- if .Values.prNumber }} -lagoon.sh/prNumber: {{ .Values.prNumber | quote }} -lagoon.sh/prHeadBranch: {{ .Values.prHeadBranch | quote }} -lagoon.sh/prBaseBranch: {{ .Values.prBaseBranch | quote }} -{{- end }} -{{- end -}} diff --git a/legacy/helmcharts/postgres-dbaas/templates/dbaas.yaml b/legacy/helmcharts/postgres-dbaas/templates/dbaas.yaml deleted file mode 100644 index 231c05a6..00000000 --- a/legacy/helmcharts/postgres-dbaas/templates/dbaas.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: postgres.amazee.io/v1 -kind: PostgreSQLConsumer -metadata: - name: {{ include "postgres-dbaas.fullname" . }} - labels: - {{- include "postgres-dbaas.labels" . | nindent 4 }} - annotations: - {{- include "postgres-dbaas.annotations" . | nindent 4 }} - -spec: - environment: {{ .Values.environment}} \ No newline at end of file diff --git a/legacy/helmcharts/postgres-dbaas/values.yaml b/legacy/helmcharts/postgres-dbaas/values.yaml deleted file mode 100644 index 03e79048..00000000 --- a/legacy/helmcharts/postgres-dbaas/values.yaml +++ /dev/null @@ -1,9 +0,0 @@ -# Default values for postgres-dbaas. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. - -environment: "" - -readReplicaHosts: "" - -imageCache: "" From 998d865ff55657251c1cc075375e6128e80bb0b5 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 28 Feb 2024 15:45:52 +1100 Subject: [PATCH 12/13] refactor: support mongo-mongodb type conversion and add tests for mongo to mongodb-dbaas conversion --- cmd/template_dbaas_test.go | 27 ++++++ internal/generator/services.go | 1 + .../templating/dbaas/template_dbaas_test.go | 24 +++++ .../test-resources/result-mongodb-2.yaml | 30 +++++++ .../node/dbaas-templates/dbaas-1/dbaas.yaml | 90 +++++++++++++++++++ .../node/dbaas-templates/dbaas-2/dbaas.yaml | 60 +++++++++++++ .../testdata/node/docker-compose.mongo.yml | 55 ++++++++++++ internal/testdata/node/lagoon.mongo.yml | 70 +++++++++++++++ 8 files changed, 357 insertions(+) create mode 100644 internal/templating/dbaas/test-resources/result-mongodb-2.yaml create mode 100644 internal/testdata/node/dbaas-templates/dbaas-1/dbaas.yaml create mode 100644 internal/testdata/node/dbaas-templates/dbaas-2/dbaas.yaml create mode 100644 internal/testdata/node/docker-compose.mongo.yml create mode 100644 internal/testdata/node/lagoon.mongo.yml diff --git a/cmd/template_dbaas_test.go b/cmd/template_dbaas_test.go index e54bb159..6569098f 100644 --- a/cmd/template_dbaas_test.go +++ b/cmd/template_dbaas_test.go @@ -60,6 +60,33 @@ func TestDBaaSTemplateGeneration(t *testing.T) { templatePath: "testdata/output", want: "../internal/testdata/complex/dbaas-templates/dbaas-3", }, + { + name: "test4 - mongo", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/node/lagoon.mongo.yml", + }, true), + templatePath: "testdata/output", + want: "../internal/testdata/node/dbaas-templates/dbaas-1", + }, + { + name: "test5 - mongo override (the mongo should not generate because it has a mongodb-single override)", + args: testdata.GetSeedData( + testdata.TestData{ + ProjectName: "example-project", + EnvironmentName: "main", + Branch: "main", + LagoonYAML: "../internal/testdata/node/lagoon.mongo.yml", + ProjectVariables: []lagoon.EnvironmentVariable{ + {Name: "LAGOON_SERVICE_TYPES", Value: "mongo:mongodb-single", Scope: "build"}, + }, + }, true), + templatePath: "testdata/output", + want: "../internal/testdata/node/dbaas-templates/dbaas-2", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/generator/services.go b/internal/generator/services.go index 27d24913..e382d4ac 100644 --- a/internal/generator/services.go +++ b/internal/generator/services.go @@ -17,6 +17,7 @@ var oldServiceMap = map[string]string{ "postgres-shared": "postgres-dbaas", "mongo-shared": "mongodb-dbaas", "python-ckandatapusher": "python", + "mongo": "mongodb", } // these are lagoon types that support autogenerated routes diff --git a/internal/templating/dbaas/template_dbaas_test.go b/internal/templating/dbaas/template_dbaas_test.go index 31774af0..3a696df1 100644 --- a/internal/templating/dbaas/template_dbaas_test.go +++ b/internal/templating/dbaas/template_dbaas_test.go @@ -92,6 +92,30 @@ func TestGenerateDBaaSTemplate(t *testing.T) { }, want: "test-resources/result-postgres-1.yaml", }, + { + name: "test4 - mongo", + args: args{ + lValues: generator.BuildValues{ + Project: "example-project", + Environment: "environment-with-really-really-reall-3fdb", + EnvironmentType: "production", + Namespace: "myexample-project-environment-with-really-really-reall-3fdb", + BuildType: "branch", + LagoonVersion: "v2.x.x", + Kubernetes: "generator.local", + Branch: "environment-with-really-really-reall-3fdb", + Services: []generator.ServiceValues{ + { + Name: "mongo", + OverrideName: "mongo", + Type: "mongodb-dbaas", + DBaaSEnvironment: "development", + }, + }, + }, + }, + want: "test-resources/result-mongodb-2.yaml", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/templating/dbaas/test-resources/result-mongodb-2.yaml b/internal/templating/dbaas/test-resources/result-mongodb-2.yaml new file mode 100644 index 00000000..aec1f51b --- /dev/null +++ b/internal/templating/dbaas/test-resources/result-mongodb-2.yaml @@ -0,0 +1,30 @@ +--- +apiVersion: mongodb.amazee.io/v1 +kind: MongoDBConsumer +metadata: + annotations: + lagoon.sh/branch: environment-with-really-really-reall-3fdb + lagoon.sh/version: v2.x.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mongo + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mongodb-dbaas + lagoon.sh/buildType: branch + lagoon.sh/environment: environment-with-really-really-reall-3fdb + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mongo + lagoon.sh/service-type: mongodb-dbaas + lagoon.sh/template: mongodb-dbaas-0.1.0 + name: mongo +spec: + consumer: + auth: + tls: false + services: {} + environment: development + provider: + auth: + tls: false +status: {} diff --git a/internal/testdata/node/dbaas-templates/dbaas-1/dbaas.yaml b/internal/testdata/node/dbaas-templates/dbaas-1/dbaas.yaml new file mode 100644 index 00000000..8835d7dd --- /dev/null +++ b/internal/testdata/node/dbaas-templates/dbaas-1/dbaas.yaml @@ -0,0 +1,90 @@ +--- +apiVersion: mongodb.amazee.io/v1 +kind: MongoDBConsumer +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mongo + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mongodb-dbaas + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mongo + lagoon.sh/service-type: mongodb-dbaas + lagoon.sh/template: mongodb-dbaas-0.1.0 + name: mongo +spec: + consumer: + auth: + tls: false + services: {} + environment: production + provider: + auth: + tls: false +status: {} +--- +apiVersion: mongodb.amazee.io/v1 +kind: MongoDBConsumer +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mongo2 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mongodb-dbaas + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mongo2 + lagoon.sh/service-type: mongodb-dbaas + lagoon.sh/template: mongodb-dbaas-0.1.0 + name: mongo2 +spec: + consumer: + auth: + tls: false + services: {} + environment: production + provider: + auth: + tls: false +status: {} +--- +apiVersion: mongodb.amazee.io/v1 +kind: MongoDBConsumer +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mongo3 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mongodb-dbaas + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mongo3 + lagoon.sh/service-type: mongodb-dbaas + lagoon.sh/template: mongodb-dbaas-0.1.0 + name: mongo3 +spec: + consumer: + auth: + tls: false + services: {} + environment: production + provider: + auth: + tls: false +status: {} diff --git a/internal/testdata/node/dbaas-templates/dbaas-2/dbaas.yaml b/internal/testdata/node/dbaas-templates/dbaas-2/dbaas.yaml new file mode 100644 index 00000000..c42f53ca --- /dev/null +++ b/internal/testdata/node/dbaas-templates/dbaas-2/dbaas.yaml @@ -0,0 +1,60 @@ +--- +apiVersion: mongodb.amazee.io/v1 +kind: MongoDBConsumer +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mongo2 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mongodb-dbaas + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mongo2 + lagoon.sh/service-type: mongodb-dbaas + lagoon.sh/template: mongodb-dbaas-0.1.0 + name: mongo2 +spec: + consumer: + auth: + tls: false + services: {} + environment: production + provider: + auth: + tls: false +status: {} +--- +apiVersion: mongodb.amazee.io/v1 +kind: MongoDBConsumer +metadata: + annotations: + lagoon.sh/branch: main + lagoon.sh/version: v2.7.x + creationTimestamp: null + labels: + app.kubernetes.io/instance: mongo3 + app.kubernetes.io/managed-by: build-deploy-tool + app.kubernetes.io/name: mongodb-dbaas + lagoon.sh/buildType: branch + lagoon.sh/environment: main + lagoon.sh/environmentType: production + lagoon.sh/project: example-project + lagoon.sh/service: mongo3 + lagoon.sh/service-type: mongodb-dbaas + lagoon.sh/template: mongodb-dbaas-0.1.0 + name: mongo3 +spec: + consumer: + auth: + tls: false + services: {} + environment: production + provider: + auth: + tls: false +status: {} diff --git a/internal/testdata/node/docker-compose.mongo.yml b/internal/testdata/node/docker-compose.mongo.yml new file mode 100644 index 00000000..0a4cf494 --- /dev/null +++ b/internal/testdata/node/docker-compose.mongo.yml @@ -0,0 +1,55 @@ +version: '2' +services: + node: + networks: + - amazeeio-network + - default + build: + context: . + dockerfile: node.dockerfile + labels: + lagoon.type: node + volumes: + - .:/app:delegated + environment: + - LAGOON_LOCALDEV_HTTP_PORT=3000 + - LAGOON_ROUTE=http://node.docker.amazee.io + + mongo: + image: fake/mongo:latest + labels: + lagoon.type: mongo + ports: + - "27100" # exposes the port 9200 with a random local port, find it with `docker-compose port opensearch 9200` + volumes: + - data:/mongo/data + + mongo2: + image: fake/mongo:latest + labels: + lagoon.type: mongodb + ports: + - "27100" # exposes the port 9200 with a random local port, find it with `docker-compose port opensearch 9200` + volumes: + - data2:/mongo/data + + mongo3: + image: fake/mongo:latest + labels: + lagoon.type: mongo-shared + ports: + - "27100" # exposes the port 9200 with a random local port, find it with `docker-compose port opensearch 9200` + volumes: + - data3:/mongo/data + +networks: + amazeeio-network: + external: true + +volumes: + data: + {} + data2: + {} + data3: + {} \ No newline at end of file diff --git a/internal/testdata/node/lagoon.mongo.yml b/internal/testdata/node/lagoon.mongo.yml new file mode 100644 index 00000000..c33fd315 --- /dev/null +++ b/internal/testdata/node/lagoon.mongo.yml @@ -0,0 +1,70 @@ +docker-compose-yaml: ../internal/testdata/node/docker-compose.mongo.yml + + +environment_variables: + git_sha: "true" + +environments: + main: + routes: + - node: + - example.com + + autogendisabled: + autogenerateRoutes: false + routes: + - node: + - example.com + + tworoutes: + routes: + - node: + - example.com + - www.example.com + + branch/routes: + routes: + - node: + - customdomain-will-be-main-domain.com + - customdomain-will-be-not-be-main-domain.com + + ingressclass: + routes: + - node: + - example.com: + ingressClass: "custom-ingress" + hsts: + routes: + - node: + - example.com: + hstsEnabled: true + hstsMaxAge: 10000 + + hsts2: + routes: + - node: + - example.com: + hstsEnabled: true + hstsMaxAge: 10000 + hstsIncludeSubdomains: true + hstsPreload: true + + pr-4841: + routes: + - nginx: + - performance.example.com + + alternativename: + routes: + - node: + - example.com: + alternativenames: + - www.example.com + - en.example.com + + wildcard: + routes: + - node: + - example.com: + tls-acme: false + wildcard: true \ No newline at end of file From 11d5bcba1ff66459236416ccb31ae8cfdee0c24b Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 28 Feb 2024 16:43:53 +1100 Subject: [PATCH 13/13] refactor: remove dbaas images from images to pull --- legacy/build-deploy-docker-compose.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 1b3b08b1..692adb0c 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -1303,6 +1303,8 @@ do SERVICE_NAME=${DBAAS_ENTRY_SPLIT[0]} SERVICE_TYPE=${DBAAS_ENTRY_SPLIT[1]} + # remove the image from images to pull + unset IMAGES_PULL[$SERVICE_NAME] SERVICE_NAME_UPPERCASE=$(echo "$SERVICE_NAME" | tr '[:lower:]' '[:upper:]' | tr '-' '_')