From 4f460cbc45e51139e465d4a63ea1ee73a73626b7 Mon Sep 17 00:00:00 2001 From: Shuaiyi Date: Mon, 7 Aug 2023 23:56:05 -0700 Subject: [PATCH] feat: expose core db connection settings (#1056) Allow to change core.spec.database.maxIdleConnections and core.spec.database.maxOpenConnections in harborcluster. Signed-off-by: Eric Liu Co-authored-by: Eric Liu --- apis/goharbor.io/v1beta1/harbor_types.go | 10 ++++++++++ .../v1beta1/zz_generated.deepcopy.go | 10 ++++++++++ controllers/goharbor/harbor/core.go | 2 ++ controllers/goharbor/harbor_test.go | 6 ++++++ manifests/cluster/deployment.yaml | 20 +++++++++++++++++++ manifests/harbor/deployment.yaml | 20 +++++++++++++++++++ 6 files changed, 68 insertions(+) diff --git a/apis/goharbor.io/v1beta1/harbor_types.go b/apis/goharbor.io/v1beta1/harbor_types.go index b8cb4dc67..0470db17a 100644 --- a/apis/goharbor.io/v1beta1/harbor_types.go +++ b/apis/goharbor.io/v1beta1/harbor_types.go @@ -374,6 +374,16 @@ type CoreComponentSpec struct { // +kubebuilder:validation:Optional Metrics *harbormetav1.MetricsSpec `json:"metrics,omitempty"` + + // +kubebuilder:validation:Optional + // +kubebuilder:validation:Minimum=0 + // +kubebuilder:default=50 + MaxIdleConnections *int32 `json:"maxIdleConnections,omitempty"` + + // +kubebuilder:validation:Optional + // +kubebuilder:validation:Minimum=0 + // +kubebuilder:default=1000 + MaxOpenConnections *int32 `json:"maxOpenConnections,omitempty"` } type JobServiceComponentSpec struct { diff --git a/apis/goharbor.io/v1beta1/zz_generated.deepcopy.go b/apis/goharbor.io/v1beta1/zz_generated.deepcopy.go index eb08c49c3..89393cb92 100644 --- a/apis/goharbor.io/v1beta1/zz_generated.deepcopy.go +++ b/apis/goharbor.io/v1beta1/zz_generated.deepcopy.go @@ -631,6 +631,16 @@ func (in *CoreComponentSpec) DeepCopyInto(out *CoreComponentSpec) { *out = new(v1alpha1.MetricsSpec) **out = **in } + if in.MaxIdleConnections != nil { + in, out := &in.MaxIdleConnections, &out.MaxIdleConnections + *out = new(int32) + **out = **in + } + if in.MaxOpenConnections != nil { + in, out := &in.MaxOpenConnections, &out.MaxOpenConnections + *out = new(int32) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CoreComponentSpec. diff --git a/controllers/goharbor/harbor/core.go b/controllers/goharbor/harbor/core.go index b2523007a..0b3685e18 100644 --- a/controllers/goharbor/harbor/core.go +++ b/controllers/goharbor/harbor/core.go @@ -454,6 +454,8 @@ func (r *Reconciler) GetCore(ctx context.Context, harbor *goharborv1.Harbor) (*g CSRFKeyRef: csrfRef, Database: goharborv1.CoreDatabaseSpec{ PostgresConnectionWithParameters: *storage, + MaxIdleConnections: harbor.Spec.Core.MaxIdleConnections, + MaxOpenConnections: harbor.Spec.Core.MaxOpenConnections, EncryptionKeyRef: encryptionKeyRef, }, ExternalEndpoint: harbor.Spec.ExternalURL, diff --git a/controllers/goharbor/harbor_test.go b/controllers/goharbor/harbor_test.go index 6b7e4e4c0..b226848a7 100644 --- a/controllers/goharbor/harbor_test.go +++ b/controllers/goharbor/harbor_test.go @@ -138,6 +138,10 @@ func setupValidHarbor(ctx context.Context, ns string) (Resource, client.ObjectKe Host: "the.dns", } + var maxIdleConnections int32 = 50 + + var maxOpenConnections int32 = 100 + harbor := &goharborv1.Harbor{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -168,6 +172,8 @@ func setupValidHarbor(ctx context.Context, ns string) (Resource, client.ObjectKe TokenIssuer: cmmeta.ObjectReference{ Name: tokenIssuerName, }, + MaxIdleConnections: &maxIdleConnections, + MaxOpenConnections: &maxOpenConnections, }, Database: &goharborv1.HarborDatabaseSpec{ PostgresCredentials: database.PostgresCredentials, diff --git a/manifests/cluster/deployment.yaml b/manifests/cluster/deployment.yaml index 4b4b8f368..0c1b57c29 100644 --- a/manifests/cluster/deployment.yaml +++ b/manifests/cluster/deployment.yaml @@ -10025,6 +10025,16 @@ spec: type: object x-kubernetes-map-type: atomic type: array + maxIdleConnections: + default: 50 + format: int32 + minimum: 0 + type: integer + maxOpenConnections: + default: 1000 + format: int32 + minimum: 0 + type: integer metrics: properties: enabled: @@ -15986,6 +15996,16 @@ spec: type: object x-kubernetes-map-type: atomic type: array + maxIdleConnections: + default: 50 + format: int32 + minimum: 0 + type: integer + maxOpenConnections: + default: 1000 + format: int32 + minimum: 0 + type: integer metrics: properties: enabled: diff --git a/manifests/harbor/deployment.yaml b/manifests/harbor/deployment.yaml index 45226d1c5..5d328b9d1 100644 --- a/manifests/harbor/deployment.yaml +++ b/manifests/harbor/deployment.yaml @@ -10025,6 +10025,16 @@ spec: type: object x-kubernetes-map-type: atomic type: array + maxIdleConnections: + default: 50 + format: int32 + minimum: 0 + type: integer + maxOpenConnections: + default: 1000 + format: int32 + minimum: 0 + type: integer metrics: properties: enabled: @@ -15986,6 +15996,16 @@ spec: type: object x-kubernetes-map-type: atomic type: array + maxIdleConnections: + default: 50 + format: int32 + minimum: 0 + type: integer + maxOpenConnections: + default: 1000 + format: int32 + minimum: 0 + type: integer metrics: properties: enabled: