Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(postgres): allow creation with postgres 15 #879

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export GSB_SERVICE_CSB_GOOGLE_POSTGRES_PLANS='[{"name":"small","id":"5b45de36-cb90-11ec-a755-77f8be95a49d","description":"PostgreSQL with default version, shared CPU, minimum 0.6GB ram, 10GB storage","metadata":{"displayName":"small"},"tier":"db-f1-micro","storage_gb":10},{"name":"medium","id":"a3359fa6-cb90-11ec-bcb6-cb68544eda78","description":"PostgreSQL with default version, shared CPU, minimum 1.7GB ram, 20GB storage","metadata":{"displayName":"medium"},"tier":"db-g1-small","storage_gb":20},{"name":"large","id":"cd95c5b4-cb90-11ec-a5da-df87b7fb7426","description":"PostgreSQL with default version, minimum 8 cores, minimum 8GB ram, 50GB storage","metadata":{"displayName":"large"},"tier":"db-custom-8-8192","storage_gb":50}]'
export GSB_SERVICE_CSB_GOOGLE_POSTGRES_PLANS='[{"name":"small","id":"5b45de36-cb90-11ec-a755-77f8be95a49d","description":"PostgreSQL with default version, shared CPU, minimum 0.6GB ram, 10GB storage","metadata":{"displayName":"small"},"tier":"db-f1-micro","storage_gb":10},{"name":"medium","id":"a3359fa6-cb90-11ec-bcb6-cb68544eda78","description":"PostgreSQL with default version, shared CPU, minimum 1.7GB ram, 20GB storage","metadata":{"displayName":"medium"},"tier":"db-g1-small","storage_gb":20}, {"name":"pg15","id":"5b45de36-cb90-11ec-a755-77f8be95a49e","description":"PostgreSQL with PostgreSQL 15, shared CPU, minimum 0.6GB ram, 10GB storage","metadata":{"displayName":"pg15"},"tier":"db-f1-micro","storage_gb":10}]'
export GSB_SERVICE_CSB_GOOGLE_MYSQL_PLANS='[{"name":"default","id":"eec62c9b-b25e-4e65-bad5-6b74d90274bf","description":"Default MySQL v8.0 10GB storage","metadata":{"displayName":"default"},"mysql_version":"MYSQL_8_0","storage_gb":10,"tier":"db-n1-standard-2"}]'
export GSB_SERVICE_CSB_GOOGLE_STORAGE_BUCKET_PLANS='[{"name":"default","id":"2875f0f0-a69f-4fe6-a5ec-5ed7f6e89a01","description":"Cloud Storage Bucket service with default configuration","metadata":{"display_name":"default"}}]'
# We keep the old Redis plans to be able to execute two examples (see service definition):
Expand Down
139 changes: 80 additions & 59 deletions acceptance-tests/postgresql_test.go
Original file line number Diff line number Diff line change
@@ -1,84 +1,50 @@
package acceptance_test

import (
"csbbrokerpakgcp/acceptance-tests/helpers/brokers"
"csbbrokerpakgcp/acceptance-tests/helpers/matchers"
"csbbrokerpakgcp/acceptance-tests/helpers/random"
"net"
"net/url"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"csbbrokerpakgcp/acceptance-tests/helpers/apps"
"csbbrokerpakgcp/acceptance-tests/helpers/brokers"
"csbbrokerpakgcp/acceptance-tests/helpers/matchers"
"csbbrokerpakgcp/acceptance-tests/helpers/random"
"csbbrokerpakgcp/acceptance-tests/helpers/services"
)

var _ = Describe("PostgreSQL", func() {
It("can be accessed by an app", Label("postgresql"), func() {
By("creating a service broker with Beta services disabled")
broker := brokers.Create(
brokers.WithPrefix("csb-postgresql"),
brokers.WithLatestEnv(),
brokers.WithEnv(apps.EnvVar{Name: "GSB_COMPATIBILITY_ENABLE_BETA_SERVICES", Value: "false"}),
)
defer broker.Delete()

By("creating a service instance")
serviceInstance := services.CreateInstance("csb-google-postgres", "small", services.WithBroker(broker))
defer serviceInstance.Delete()
Describe("Can be accessed by an app", func() {
var broker *brokers.Broker

By("pushing the unstarted app twice")
appOne := apps.Push(apps.WithApp(apps.PostgreSQL))
appTwo := apps.Push(apps.WithApp(apps.PostgreSQL))
defer apps.Delete(appOne, appTwo)
BeforeEach(func() {
broker = brokers.Create(
brokers.WithPrefix("csb-postgresql"),
brokers.WithLatestEnv(),
brokers.WithEnv(apps.EnvVar{Name: "GSB_COMPATIBILITY_ENABLE_BETA_SERVICES", Value: "false"}),
)
defer broker.Delete()
})

By("binding the first app to the service instance")
binding := serviceInstance.Bind(appOne)
It("works with the default postgres version", Label("postgresql"), func() {
By("creating a service instance")
serviceInstance := services.CreateInstance("csb-google-postgres", "small", services.WithBroker(broker))
defer serviceInstance.Delete()

By("starting the first app")
apps.Start(appOne)
postgresTestMultipleApps(serviceInstance)

By("checking that the app environment has a credhub reference for credentials")
Expect(binding.Credential()).To(matchers.HaveCredHubRef)
})

By("creating a schema using the first app")
schema := random.Name(random.WithMaxLength(10))
appOne.PUT("", schema)
It("works with latest changes to public schema in postgres 15", Label("Postgres15"), func() {
By("creating a service instance")
serviceInstance := services.CreateInstance("csb-google-postgres", "pg15", services.WithBroker(broker))
defer serviceInstance.Delete()

By("setting a key-value using the first app")
key := random.Hexadecimal()
value := random.Hexadecimal()
appOne.PUT(value, "%s/%s", schema, key)
postgresTestMultipleApps(serviceInstance)

By("binding the second app to the service instance")
serviceInstance.Bind(appTwo)
})

By("starting the second app")
apps.Start(appTwo)

By("getting the value using the second app")
got := appTwo.GET("%s/%s", schema, key).String()
Expect(got).To(Equal(value))

By("triggering ownership of schema to pass to provision user")
binding.Unbind()

By("getting the value again using the second app")
got2 := appTwo.GET("%s/%s", schema, key).String()
Expect(got2).To(Equal(value))

By("setting another value using the second app")
key2 := random.Hexadecimal()
value2 := random.Hexadecimal()
appTwo.PUT(value2, "%s/%s", schema, key2)

By("getting the other value using the second app")
got3 := appTwo.GET("%s/%s", schema, key2).String()
Expect(got3).To(Equal(value2))

By("dropping the schema using the second app")
appTwo.DELETE(schema)
})

It("can create service keys with a public IP address", Label("postgresql-public-ip"), func() {
Expand Down Expand Up @@ -107,3 +73,58 @@ var _ = Describe("PostgreSQL", func() {
Expect(uriIP.IsPrivate()).To(BeFalse())
})
})

func postgresTestMultipleApps(serviceInstance *services.ServiceInstance) {
By("pushing the unstarted app twice")
pivotal-marcela-campo marked this conversation as resolved.
Show resolved Hide resolved
appOne := apps.Push(apps.WithApp(apps.PostgreSQL))
appTwo := apps.Push(apps.WithApp(apps.PostgreSQL))
defer apps.Delete(appOne, appTwo)

By("binding the first app to the service instance")
binding := serviceInstance.Bind(appOne)

By("starting the first app")
apps.Start(appOne)

By("checking that the app environment has a credhub reference for credentials")
Expect(binding.Credential()).To(matchers.HaveCredHubRef)

By("creating a schema using the first app")
schema := random.Name(random.WithMaxLength(10))
appOne.PUT("", schema)

By("setting a key-value using the first app")
key := random.Hexadecimal()
value := random.Hexadecimal()
appOne.PUT(value, "%s/%s", schema, key)

By("binding the second app to the service instance")
serviceInstance.Bind(appTwo)

By("starting the second app")
apps.Start(appTwo)

By("getting the value using the second app")
got := appTwo.GET("%s/%s", schema, key).String()
Expect(got).To(Equal(value))

By("triggering ownership of schema to pass to provision user")
binding.Unbind()

By("getting the value again using the second app")
got2 := appTwo.GET("%s/%s", schema, key).String()
Expect(got2).To(Equal(value))

By("setting another value using the second app")
key2 := random.Hexadecimal()
value2 := random.Hexadecimal()
appTwo.PUT(value2, "%s/%s", schema, key2)

By("getting the other value using the second app")
got3 := appTwo.GET("%s/%s", schema, key2).String()
Expect(got3).To(Equal(value2))

By("dropping the schema using the second app")
appTwo.DELETE(schema)

}
1 change: 1 addition & 0 deletions google-postgresql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ provision:
POSTGRES_12: POSTGRES_12
POSTGRES_13: POSTGRES_13
POSTGRES_14: POSTGRES_14
POSTGRES_15: POSTGRES_15
- field_name: storage_gb
required: true
type: number
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,18 @@ var _ = Describe("postgres", Label("postgres"), func() {
Entry("12", "POSTGRES_12"),
Entry("13", "POSTGRES_13"),
Entry("14", "POSTGRES_14"),
Entry("15", "POSTGRES_15"),
)

DescribeTable(
"does not allow versions other than 11-14",
"does not allow versions other than 11-15",
func(version any) {
_, err := broker.Provision("csb-google-postgres", postgresNoOverridesPlan["name"].(string), map[string]any{"tier": "db-f1-micro", "postgres_version": version})

Expect(err).To(MatchError(ContainSubstring("postgres_version: postgres_version must be one of the following")))
Expect(mockTerraform.ApplyInvocations()).To(HaveLen(0))
},
Entry("10", "POSTGRES_10"),
Entry("15", "POSTGRES_15"),
Entry("16", "POSTGRES_16"),
)
})
Expand Down