From e161c7115765843050ca383017db13cc8fcb3dd0 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Fri, 7 Jul 2023 22:51:17 +0000 Subject: [PATCH] feat: expose core db connection settings Allow to change core.spec.database.maxIdleConnections and core.spec.database.maxOpenConnections in harborcluster. Signed-off-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..472077e5d 100644 --- a/controllers/goharbor/harbor_test.go +++ b/controllers/goharbor/harbor_test.go @@ -137,6 +137,10 @@ func setupValidHarbor(ctx context.Context, ns string) (Resource, client.ObjectKe Scheme: "http", Host: "the.dns", } + var ( + maxIdleConnections int32 = 50 + maxOpenConnections int32 = 100 + ) harbor := &goharborv1.Harbor{ ObjectMeta: metav1.ObjectMeta{ @@ -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 173b5bb56..9382590b5 100644 --- a/manifests/cluster/deployment.yaml +++ b/manifests/cluster/deployment.yaml @@ -9940,6 +9940,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: @@ -15801,6 +15811,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 ce46f0059..909955a08 100644 --- a/manifests/harbor/deployment.yaml +++ b/manifests/harbor/deployment.yaml @@ -9940,6 +9940,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: @@ -15801,6 +15811,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: