From 2165625c344b8c38776f128a5cdc1dbcfb7a9dc2 Mon Sep 17 00:00:00 2001
From: Marco Nenciarini
Date: Thu, 31 Oct 2024 15:03:13 +0100
Subject: [PATCH] chore: Remove the owner field
Signed-off-by: Marco Nenciarini
---
api/v1/publication_types.go | 4 ---
api/v1/subscription_types.go | 4 ---
.../postgresql.cnpg.io_publications.yaml | 3 --
.../postgresql.cnpg.io_subscriptions.yaml | 3 --
docs/src/cloudnative-pg.v1.md | 14 --------
.../controller/publication_controller_sql.go | 27 ++--------------
.../publication_controller_sql_test.go | 26 ---------------
.../controller/subscription_controller_sql.go | 27 ++--------------
.../subscription_controller_sql_test.go | 32 -------------------
9 files changed, 4 insertions(+), 136 deletions(-)
diff --git a/api/v1/publication_types.go b/api/v1/publication_types.go
index 4ac56a5be0..eda3c36822 100644
--- a/api/v1/publication_types.go
+++ b/api/v1/publication_types.go
@@ -48,10 +48,6 @@ type PublicationSpec struct {
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="dbname is immutable"
DBName string `json:"dbname"`
- // The owner
- // +optional
- Owner string `json:"owner,omitempty"`
-
// Parameters
// +optional
Parameters map[string]string `json:"parameters,omitempty"`
diff --git a/api/v1/subscription_types.go b/api/v1/subscription_types.go
index f408959b14..d644e9f74a 100644
--- a/api/v1/subscription_types.go
+++ b/api/v1/subscription_types.go
@@ -44,10 +44,6 @@ type SubscriptionSpec struct {
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="name is immutable"
Name string `json:"name"`
- // The owner
- // +optional
- Owner string `json:"owner,omitempty"`
-
// The name of the database
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="dbname is immutable"
DBName string `json:"dbname"`
diff --git a/config/crd/bases/postgresql.cnpg.io_publications.yaml b/config/crd/bases/postgresql.cnpg.io_publications.yaml
index 9b8ed22fd9..2c5837ceb5 100644
--- a/config/crd/bases/postgresql.cnpg.io_publications.yaml
+++ b/config/crd/bases/postgresql.cnpg.io_publications.yaml
@@ -82,9 +82,6 @@ spec:
x-kubernetes-validations:
- message: name is immutable
rule: self == oldSelf
- owner:
- description: The owner
- type: string
parameters:
additionalProperties:
type: string
diff --git a/config/crd/bases/postgresql.cnpg.io_subscriptions.yaml b/config/crd/bases/postgresql.cnpg.io_subscriptions.yaml
index 9ef6421163..a8972f94ba 100644
--- a/config/crd/bases/postgresql.cnpg.io_subscriptions.yaml
+++ b/config/crd/bases/postgresql.cnpg.io_subscriptions.yaml
@@ -85,9 +85,6 @@ spec:
x-kubernetes-validations:
- message: name is immutable
rule: self == oldSelf
- owner:
- description: The owner
- type: string
parameters:
additionalProperties:
type: string
diff --git a/docs/src/cloudnative-pg.v1.md b/docs/src/cloudnative-pg.v1.md
index d36b94afda..764ed904c5 100644
--- a/docs/src/cloudnative-pg.v1.md
+++ b/docs/src/cloudnative-pg.v1.md
@@ -4101,13 +4101,6 @@ the primary server of the cluster as part of rolling updates
The name of the database
-owner
-string
- |
-
- The owner
- |
-
parameters
map[string]string
|
@@ -5182,13 +5175,6 @@ Size cannot be decreased.
The name inside PostgreSQL
-owner [Required]
-string
- |
-
- The owner
- |
-
dbname [Required]
string
|
diff --git a/internal/management/controller/publication_controller_sql.go b/internal/management/controller/publication_controller_sql.go
index 22de0621e7..f3bff98877 100644
--- a/internal/management/controller/publication_controller_sql.go
+++ b/internal/management/controller/publication_controller_sql.go
@@ -94,8 +94,6 @@ func (r *PublicationReconciler) createPublication(
}
func toPublicationCreateSQL(obj *apiv1.Publication) []string {
- result := make([]string, 0, 2)
-
createQuery := fmt.Sprintf(
"CREATE PUBLICATION %s %s",
pgx.Identifier{obj.Spec.Name}.Sanitize(),
@@ -104,23 +102,12 @@ func toPublicationCreateSQL(obj *apiv1.Publication) []string {
if len(obj.Spec.Parameters) > 0 {
createQuery = fmt.Sprintf("%s WITH (%s)", createQuery, toPostgresParameters(obj.Spec.Parameters))
}
- result = append(result, createQuery)
-
- if len(obj.Spec.Owner) > 0 {
- result = append(result,
- fmt.Sprintf(
- "ALTER PUBLICATION %s OWNER to %s",
- pgx.Identifier{obj.Spec.Name}.Sanitize(),
- pgx.Identifier{obj.Spec.Owner}.Sanitize(),
- ),
- )
- }
- return result
+ return []string{createQuery}
}
func toPublicationAlterSQL(obj *apiv1.Publication) []string {
- result := make([]string, 0, 3)
+ result := make([]string, 0, 2)
if len(obj.Spec.Target.Objects) > 0 {
result = append(result,
@@ -132,16 +119,6 @@ func toPublicationAlterSQL(obj *apiv1.Publication) []string {
)
}
- if len(obj.Spec.Owner) > 0 {
- result = append(result,
- fmt.Sprintf(
- "ALTER PUBLICATION %s OWNER TO %s",
- pgx.Identifier{obj.Spec.Name}.Sanitize(),
- pgx.Identifier{obj.Spec.Owner}.Sanitize(),
- ),
- )
- }
-
if len(obj.Spec.Parameters) > 0 {
result = append(result,
fmt.Sprintf(
diff --git a/internal/management/controller/publication_controller_sql_test.go b/internal/management/controller/publication_controller_sql_test.go
index ec1b2192f6..13d04d2b5d 100644
--- a/internal/management/controller/publication_controller_sql_test.go
+++ b/internal/management/controller/publication_controller_sql_test.go
@@ -89,18 +89,6 @@ var _ = Describe("publication sql", func() {
Expect(sqls).To(ContainElement(`ALTER PUBLICATION "test_pub" SET TABLES IN SCHEMA "public"`))
})
- It("generates correct SQL for altering publication with owner", func() {
- obj := &apiv1.Publication{
- Spec: apiv1.PublicationSpec{
- Name: "test_pub",
- Owner: "new_owner",
- },
- }
-
- sqls := toPublicationAlterSQL(obj)
- Expect(sqls).To(ContainElement(`ALTER PUBLICATION "test_pub" OWNER TO "new_owner"`))
- })
-
It("generates correct SQL for altering publication with parameters", func() {
obj := &apiv1.Publication{
Spec: apiv1.PublicationSpec{
@@ -159,20 +147,6 @@ var _ = Describe("publication sql", func() {
Expect(sqls).To(ContainElement(`CREATE PUBLICATION "test_pub" FOR TABLE "test"."table" ("a", "b")`))
})
- It("generates correct SQL for creating publication with owner", func() {
- obj := &apiv1.Publication{
- Spec: apiv1.PublicationSpec{
- Name: "test_pub",
- Owner: "new_owner",
- Target: apiv1.PublicationTarget{AllTables: true},
- },
- }
-
- sqls := toPublicationCreateSQL(obj)
- Expect(sqls).To(ContainElement(`CREATE PUBLICATION "test_pub" FOR ALL TABLES`))
- Expect(sqls).To(ContainElement(`ALTER PUBLICATION "test_pub" OWNER to "new_owner"`))
- })
-
It("generates correct SQL for creating publication with parameters", func() {
obj := &apiv1.Publication{
Spec: apiv1.PublicationSpec{
diff --git a/internal/management/controller/subscription_controller_sql.go b/internal/management/controller/subscription_controller_sql.go
index fb12099d93..db73ca7a75 100644
--- a/internal/management/controller/subscription_controller_sql.go
+++ b/internal/management/controller/subscription_controller_sql.go
@@ -101,8 +101,6 @@ func (r *SubscriptionReconciler) createSubscription(
}
func toSubscriptionCreateSQL(obj *apiv1.Subscription, connString string) []string {
- result := make([]string, 0, 2)
-
createQuery := fmt.Sprintf(
"CREATE SUBSCRIPTION %s CONNECTION %s PUBLICATION %s",
pgx.Identifier{obj.Spec.Name}.Sanitize(),
@@ -112,23 +110,12 @@ func toSubscriptionCreateSQL(obj *apiv1.Subscription, connString string) []strin
if len(obj.Spec.Parameters) > 0 {
createQuery = fmt.Sprintf("%s WITH (%s)", createQuery, toPostgresParameters(obj.Spec.Parameters))
}
- result = append(result, createQuery)
-
- if len(obj.Spec.Owner) > 0 {
- result = append(result,
- fmt.Sprintf(
- "ALTER SUBSCRIPTION %s OWNER TO %s",
- pgx.Identifier{obj.Spec.Name}.Sanitize(),
- pgx.Identifier{obj.Spec.Owner}.Sanitize(),
- ),
- )
- }
- return result
+ return []string{createQuery}
}
func toSubscriptionAlterSQL(obj *apiv1.Subscription, connString string) []string {
- result := make([]string, 0, 4)
+ result := make([]string, 0, 3)
setPublicationSQL := fmt.Sprintf(
"ALTER SUBSCRIPTION %s SET PUBLICATION %s",
@@ -143,16 +130,6 @@ func toSubscriptionAlterSQL(obj *apiv1.Subscription, connString string) []string
)
result = append(result, setPublicationSQL, setConnStringSQL)
- if len(obj.Spec.Owner) > 0 {
- result = append(result,
- fmt.Sprintf(
- "ALTER SUBSCRIPTION %s OWNER TO %s",
- pgx.Identifier{obj.Spec.Name}.Sanitize(),
- pgx.Identifier{obj.Spec.Owner}.Sanitize(),
- ),
- )
- }
-
if len(obj.Spec.Parameters) > 0 {
result = append(result,
fmt.Sprintf(
diff --git a/internal/management/controller/subscription_controller_sql_test.go b/internal/management/controller/subscription_controller_sql_test.go
index bd3bcd5049..7d5aa4da19 100644
--- a/internal/management/controller/subscription_controller_sql_test.go
+++ b/internal/management/controller/subscription_controller_sql_test.go
@@ -106,22 +106,6 @@ var _ = Describe("subscription sql", func() {
Expect(sqls).To(ContainElement(expectedElement))
})
- It("generates correct SQL for creating subscription with owner", func() {
- obj := &apiv1.Subscription{
- Spec: apiv1.SubscriptionSpec{
- Name: "test_sub",
- PublicationName: "test_pub",
- Owner: "new_owner",
- },
- }
- connString := "host=localhost user=test dbname=test"
-
- sqls := toSubscriptionCreateSQL(obj, connString)
- Expect(sqls).To(ContainElement(
- `CREATE SUBSCRIPTION "test_sub" CONNECTION 'host=localhost user=test dbname=test' PUBLICATION "test_pub"`))
- Expect(sqls).To(ContainElement(`ALTER SUBSCRIPTION "test_sub" OWNER TO "new_owner"`))
- })
-
It("returns correct SQL for creating subscription with no owner or parameters", func() {
obj := &apiv1.Subscription{
Spec: apiv1.SubscriptionSpec{
@@ -150,22 +134,6 @@ var _ = Describe("subscription sql", func() {
Expect(sqls).To(ContainElement(`ALTER SUBSCRIPTION "test_sub" CONNECTION 'host=localhost user=test dbname=test'`))
})
- It("generates correct SQL for altering subscription with owner", func() {
- obj := &apiv1.Subscription{
- Spec: apiv1.SubscriptionSpec{
- Name: "test_sub",
- PublicationName: "test_pub",
- Owner: "new_owner",
- },
- }
- connString := "host=localhost user=test dbname=test"
-
- sqls := toSubscriptionAlterSQL(obj, connString)
- Expect(sqls).To(ContainElement(`ALTER SUBSCRIPTION "test_sub" SET PUBLICATION "test_pub"`))
- Expect(sqls).To(ContainElement(`ALTER SUBSCRIPTION "test_sub" CONNECTION 'host=localhost user=test dbname=test'`))
- Expect(sqls).To(ContainElement(`ALTER SUBSCRIPTION "test_sub" OWNER TO "new_owner"`))
- })
-
It("generates correct SQL for altering subscription with parameters", func() {
obj := &apiv1.Subscription{
Spec: apiv1.SubscriptionSpec{