From acb88d9b936ee27fcfb67bc307e6461300f1c7ba Mon Sep 17 00:00:00 2001 From: Nandan Date: Mon, 24 Feb 2025 09:01:52 -0800 Subject: [PATCH 1/2] 2867: Configurable api group for postgres operator with default In Kubernetes, there is tight coupling of API group, CRD and Custom Resources managed by operators. CRDs are cluster resource and unique per cluster. CRD operatorconfigurations.acid.zalan.do defines the operator configurations for postgres operator. CRD postgresqls.acid.zalan.do defines minimum and maximum supported postgresql versions. This leads to issues in a multi-tenant k8s cluster, an example provided below. In Namespace X, user X deploys web tier application which uses zalando postgres-operator with max version PG 15. In Namespace Y, user Y deploys web tier application which also uses zalando postgres-operator but needs PG 17 runs into an issue as CRD postgresqls.acid.zalan.do supports only PG 15. This happens because CRD is cluster scope and all namespace scoped applications should adhere to it. With large k8s clusters, postgresql being a very popular database, zalando postgres operator being defacto way to manage databases, there is a need to keep this configurable so applications can manage the API group of CRDs. Take API group for postgres operator as an env variable, assuming that the relevant CRDs with API groups are installed. --- pkg/apis/acid.zalan.do/register.go | 18 +++++++++++++++--- pkg/apis/acid.zalan.do/v1/crds.go | 7 +++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/pkg/apis/acid.zalan.do/register.go b/pkg/apis/acid.zalan.do/register.go index f99396656..0d6587277 100644 --- a/pkg/apis/acid.zalan.do/register.go +++ b/pkg/apis/acid.zalan.do/register.go @@ -1,6 +1,18 @@ package acidzalando -const ( - // GroupName is the group name for the operator CRDs - GroupName = "acid.zalan.do" +import "os" + +var ( + // GroupName is the group name for the operator CRDs + GroupName = getEnvWithDefault("POSTGRES_OPERATOR_API_GROUP", "ost.cloud.rakuten.com") ) + +func getEnvWithDefault(key, defaultValue string) string { + if value := os.Getenv(key); value != "" { + return value + } + return defaultValue +} + + + diff --git a/pkg/apis/acid.zalan.do/v1/crds.go b/pkg/apis/acid.zalan.do/v1/crds.go index 3f6bf25d9..8f0db6ea6 100644 --- a/pkg/apis/acid.zalan.do/v1/crds.go +++ b/pkg/apis/acid.zalan.do/v1/crds.go @@ -15,16 +15,19 @@ const ( PostgresCRDResourceKind = "postgresql" PostgresCRDResourcePlural = "postgresqls" PostgresCRDResourceList = PostgresCRDResourceKind + "List" - PostgresCRDResouceName = PostgresCRDResourcePlural + "." + acidzalando.GroupName PostgresCRDResourceShort = "pg" OperatorConfigCRDResouceKind = "OperatorConfiguration" OperatorConfigCRDResourcePlural = "operatorconfigurations" OperatorConfigCRDResourceList = OperatorConfigCRDResouceKind + "List" - OperatorConfigCRDResourceName = OperatorConfigCRDResourcePlural + "." + acidzalando.GroupName OperatorConfigCRDResourceShort = "opconfig" ) +var ( + PostgresCRDResouceName = PostgresCRDResourcePlural + "." + acidzalando.GroupName + OperatorConfigCRDResourceName = OperatorConfigCRDResourcePlural + "." + acidzalando.GroupName +) + // PostgresCRDResourceColumns definition of AdditionalPrinterColumns for postgresql CRD var PostgresCRDResourceColumns = []apiextv1.CustomResourceColumnDefinition{ { From 63b95d958aab7eed4b9a71c26d05e7ab2b0497e4 Mon Sep 17 00:00:00 2001 From: Nandan Date: Mon, 24 Feb 2025 09:16:54 -0800 Subject: [PATCH 2/2] 2867 change the api group default value to existing one --- pkg/apis/acid.zalan.do/register.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/apis/acid.zalan.do/register.go b/pkg/apis/acid.zalan.do/register.go index 0d6587277..2798f5690 100644 --- a/pkg/apis/acid.zalan.do/register.go +++ b/pkg/apis/acid.zalan.do/register.go @@ -4,7 +4,7 @@ import "os" var ( // GroupName is the group name for the operator CRDs - GroupName = getEnvWithDefault("POSTGRES_OPERATOR_API_GROUP", "ost.cloud.rakuten.com") + GroupName = getEnvWithDefault("POSTGRES_OPERATOR_API_GROUP", "acid.zalan.do") ) func getEnvWithDefault(key, defaultValue string) string {