From f1b32c4a248a7233135a2b589e287779c9c4daf4 Mon Sep 17 00:00:00 2001 From: chazu Date: Thu, 14 Apr 2022 12:31:21 -0400 Subject: [PATCH 1/4] focus pg controller tests. pass termination protection into createorupdate --- Makefile | 2 +- controllers/postgresql_controller.go | 26 ++++++++++++----------- controllers/postgresql_controller_test.go | 17 +++++++++------ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 864ad945..d6f317f8 100644 --- a/Makefile +++ b/Makefile @@ -109,7 +109,7 @@ test-acc: test-check-project-env test-check-token-env $(GINKGO) $(ENVTEST_TOOLS) KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT=120s \ KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT=true \ KUBEBUILDER_ASSETS=$(abspath $(ENVTEST_TOOLS_DIR)) \ - $(GINKGO) \ + $(GINKGO) focus \ --nodes=4 \ --race \ --randomizeAllSpecs \ diff --git a/controllers/postgresql_controller.go b/controllers/postgresql_controller.go index 0b18f4e7..ecbeb05e 100644 --- a/controllers/postgresql_controller.go +++ b/controllers/postgresql_controller.go @@ -71,13 +71,14 @@ func (h PostgreSQLHandler) createOrUpdate(avn *aiven.Client, i client.Object) er MaintenanceWindow: getMaintenanceWindow( pg.Spec.MaintenanceWindowDow, pg.Spec.MaintenanceWindowTime), - Plan: pg.Spec.Plan, - ProjectVPCID: prVPCID, - ServiceName: pg.Name, - ServiceType: "pg", - UserConfig: UserConfigurationToAPI(pg.Spec.UserConfig).(map[string]interface{}), - ServiceIntegrations: nil, - DiskSpaceMB: v1alpha1.ConvertDiscSpace(pg.Spec.DiskSpace), + Plan: pg.Spec.Plan, + TerminationProtection: pg.Spec.TerminationProtection, + ProjectVPCID: prVPCID, + ServiceName: pg.Name, + ServiceType: "pg", + UserConfig: UserConfigurationToAPI(pg.Spec.UserConfig).(map[string]interface{}), + ServiceIntegrations: nil, + DiskSpaceMB: v1alpha1.ConvertDiscSpace(pg.Spec.DiskSpace), }) if err != nil { return err @@ -90,11 +91,12 @@ func (h PostgreSQLHandler) createOrUpdate(avn *aiven.Client, i client.Object) er MaintenanceWindow: getMaintenanceWindow( pg.Spec.MaintenanceWindowDow, pg.Spec.MaintenanceWindowTime), - Plan: pg.Spec.Plan, - ProjectVPCID: prVPCID, - UserConfig: UserConfigurationToAPI(pg.Spec.UserConfig).(map[string]interface{}), - Powered: true, - DiskSpaceMB: v1alpha1.ConvertDiscSpace(pg.Spec.DiskSpace), + Plan: pg.Spec.Plan, + TerminationProtection: pg.Spec.TerminationProtection, + ProjectVPCID: prVPCID, + UserConfig: UserConfigurationToAPI(pg.Spec.UserConfig).(map[string]interface{}), + Powered: true, + DiskSpaceMB: v1alpha1.ConvertDiscSpace(pg.Spec.DiskSpace), }) if err != nil { return err diff --git a/controllers/postgresql_controller_test.go b/controllers/postgresql_controller_test.go index c35a931c..ba9dd4ca 100644 --- a/controllers/postgresql_controller_test.go +++ b/controllers/postgresql_controller_test.go @@ -4,6 +4,7 @@ package controllers import ( "context" + "fmt" "os" "time" @@ -18,7 +19,7 @@ import ( . "github.com/onsi/gomega" ) -var _ = Describe("PostgreSQL Controller", func() { +var _ = FDescribe("PostgreSQL Controller", func() { // Define utility constants for object names and testing timeouts/durations and intervals. const ( namespace = "default" @@ -71,11 +72,14 @@ var _ = Describe("PostgreSQL Controller", func() { pgLookupKey := types.NamespacedName{Name: serviceName, Namespace: namespace} Expect(k8sClient.Get(ctx, pgLookupKey, createdPostgreSQL)).Should(Succeed()) - + //pgSpec := k8sClient.Get(ctx, pgLookupKey, createdPostgreSQL) By("by checking that after creation of a PostreSQL service secret is created") createdSecret := &corev1.Secret{} Expect(k8sClient.Get(ctx, types.NamespacedName{Name: serviceName, Namespace: namespace}, createdSecret)).Should(Succeed()) + fmt.Println("fnord") + fmt.Printf("%#v", createdPostgreSQL) + fmt.Printf("%#v", createdSecret) Expect(createdSecret.Data["PGHOST"]).NotTo(BeEmpty()) Expect(createdSecret.Data["PGPORT"]).NotTo(BeEmpty()) Expect(createdSecret.Data["PGDATABASE"]).NotTo(BeEmpty()) @@ -83,7 +87,7 @@ var _ = Describe("PostgreSQL Controller", func() { Expect(createdSecret.Data["PGPASSWORD"]).NotTo(BeEmpty()) Expect(createdSecret.Data["PGSSLMODE"]).NotTo(BeEmpty()) Expect(createdSecret.Data["DATABASE_URI"]).NotTo(BeEmpty()) - + Expect(createdPostgreSQL.Spec.TerminationProtection).Should(Equal(true)) Expect(createdPostgreSQL.Status.State).Should(Equal("RUNNING")) }) }) @@ -107,9 +111,10 @@ func pgSpec(serviceName, namespace string) *v1alpha1.PostgreSQL { Spec: v1alpha1.PostgreSQLSpec{ DiskSpace: "100Gib", ServiceCommonSpec: v1alpha1.ServiceCommonSpec{ - Project: os.Getenv("AIVEN_PROJECT_NAME"), - Plan: "business-4", - CloudName: "google-europe-west1", + Project: os.Getenv("AIVEN_PROJECT_NAME"), + Plan: "business-4", + CloudName: "google-europe-west1", + TerminationProtection: true, }, UserConfig: v1alpha1.PostgreSQLUserconfig{ PublicAccess: v1alpha1.PublicAccessUserConfig{ From 52ecc0dea2579222f97da772802784d03ee1968c Mon Sep 17 00:00:00 2001 From: chazu Date: Thu, 14 Apr 2022 14:29:05 -0400 Subject: [PATCH 2/4] remove printlining, remove termination protection from test --- controllers/postgresql_controller_test.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/controllers/postgresql_controller_test.go b/controllers/postgresql_controller_test.go index ba9dd4ca..6cde0187 100644 --- a/controllers/postgresql_controller_test.go +++ b/controllers/postgresql_controller_test.go @@ -4,7 +4,6 @@ package controllers import ( "context" - "fmt" "os" "time" @@ -72,14 +71,10 @@ var _ = FDescribe("PostgreSQL Controller", func() { pgLookupKey := types.NamespacedName{Name: serviceName, Namespace: namespace} Expect(k8sClient.Get(ctx, pgLookupKey, createdPostgreSQL)).Should(Succeed()) - //pgSpec := k8sClient.Get(ctx, pgLookupKey, createdPostgreSQL) By("by checking that after creation of a PostreSQL service secret is created") createdSecret := &corev1.Secret{} Expect(k8sClient.Get(ctx, types.NamespacedName{Name: serviceName, Namespace: namespace}, createdSecret)).Should(Succeed()) - fmt.Println("fnord") - fmt.Printf("%#v", createdPostgreSQL) - fmt.Printf("%#v", createdSecret) Expect(createdSecret.Data["PGHOST"]).NotTo(BeEmpty()) Expect(createdSecret.Data["PGPORT"]).NotTo(BeEmpty()) Expect(createdSecret.Data["PGDATABASE"]).NotTo(BeEmpty()) @@ -87,7 +82,6 @@ var _ = FDescribe("PostgreSQL Controller", func() { Expect(createdSecret.Data["PGPASSWORD"]).NotTo(BeEmpty()) Expect(createdSecret.Data["PGSSLMODE"]).NotTo(BeEmpty()) Expect(createdSecret.Data["DATABASE_URI"]).NotTo(BeEmpty()) - Expect(createdPostgreSQL.Spec.TerminationProtection).Should(Equal(true)) Expect(createdPostgreSQL.Status.State).Should(Equal("RUNNING")) }) }) @@ -111,10 +105,9 @@ func pgSpec(serviceName, namespace string) *v1alpha1.PostgreSQL { Spec: v1alpha1.PostgreSQLSpec{ DiskSpace: "100Gib", ServiceCommonSpec: v1alpha1.ServiceCommonSpec{ - Project: os.Getenv("AIVEN_PROJECT_NAME"), - Plan: "business-4", - CloudName: "google-europe-west1", - TerminationProtection: true, + Project: os.Getenv("AIVEN_PROJECT_NAME"), + Plan: "business-4", + CloudName: "google-europe-west1", }, UserConfig: v1alpha1.PostgreSQLUserconfig{ PublicAccess: v1alpha1.PublicAccessUserConfig{ From 09940fe24509999888ba6debc1b424c916957b1a Mon Sep 17 00:00:00 2001 From: chazu Date: Thu, 14 Apr 2022 14:38:03 -0400 Subject: [PATCH 3/4] remove focus in makefile, remove added newlines, unfocus describe in test. --- Makefile | 2 +- controllers/postgresql_controller_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d6f317f8..864ad945 100644 --- a/Makefile +++ b/Makefile @@ -109,7 +109,7 @@ test-acc: test-check-project-env test-check-token-env $(GINKGO) $(ENVTEST_TOOLS) KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT=120s \ KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT=true \ KUBEBUILDER_ASSETS=$(abspath $(ENVTEST_TOOLS_DIR)) \ - $(GINKGO) focus \ + $(GINKGO) \ --nodes=4 \ --race \ --randomizeAllSpecs \ diff --git a/controllers/postgresql_controller_test.go b/controllers/postgresql_controller_test.go index 6cde0187..98c4bc54 100644 --- a/controllers/postgresql_controller_test.go +++ b/controllers/postgresql_controller_test.go @@ -18,7 +18,7 @@ import ( . "github.com/onsi/gomega" ) -var _ = FDescribe("PostgreSQL Controller", func() { +var _ = Describe("PostgreSQL Controller", func() { // Define utility constants for object names and testing timeouts/durations and intervals. const ( namespace = "default" From 090f67285a8d5d2aa312588273cda2b9e041716c Mon Sep 17 00:00:00 2001 From: chazu Date: Thu, 14 Apr 2022 14:40:30 -0400 Subject: [PATCH 4/4] add back newlines --- controllers/postgresql_controller_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/controllers/postgresql_controller_test.go b/controllers/postgresql_controller_test.go index 98c4bc54..c35a931c 100644 --- a/controllers/postgresql_controller_test.go +++ b/controllers/postgresql_controller_test.go @@ -71,6 +71,7 @@ var _ = Describe("PostgreSQL Controller", func() { pgLookupKey := types.NamespacedName{Name: serviceName, Namespace: namespace} Expect(k8sClient.Get(ctx, pgLookupKey, createdPostgreSQL)).Should(Succeed()) + By("by checking that after creation of a PostreSQL service secret is created") createdSecret := &corev1.Secret{} Expect(k8sClient.Get(ctx, types.NamespacedName{Name: serviceName, Namespace: namespace}, createdSecret)).Should(Succeed()) @@ -82,6 +83,7 @@ var _ = Describe("PostgreSQL Controller", func() { Expect(createdSecret.Data["PGPASSWORD"]).NotTo(BeEmpty()) Expect(createdSecret.Data["PGSSLMODE"]).NotTo(BeEmpty()) Expect(createdSecret.Data["DATABASE_URI"]).NotTo(BeEmpty()) + Expect(createdPostgreSQL.Status.State).Should(Equal("RUNNING")) }) })