Skip to content

Commit f15802f

Browse files
authored
update zk client (#128)
Signed-off-by: Rudro-25 <rudro@appscode.com>
1 parent 5182394 commit f15802f

File tree

10 files changed

+150
-82
lines changed

10 files changed

+150
-82
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ require (
3333
k8s.io/klog/v2 v2.130.1
3434
kmodules.xyz/client-go v0.30.13
3535
kmodules.xyz/custom-resources v0.30.0
36-
kubedb.dev/apimachinery v0.47.1-0.20240924090635-38154e492f4e
36+
kubedb.dev/apimachinery v0.47.1-0.20240924051141-f0421dd9f647
3737
sigs.k8s.io/controller-runtime v0.18.4
3838
xorm.io/xorm v1.3.6
3939
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,8 @@ kmodules.xyz/monitoring-agent-api v0.29.0 h1:gpFl6OZrlMLb/ySMHdREI9EwGtnJ91oZBn9
802802
kmodules.xyz/monitoring-agent-api v0.29.0/go.mod h1:iNbvaMTgVFOI5q2LJtGK91j4Dmjv4ZRiRdasGmWLKQI=
803803
kmodules.xyz/offshoot-api v0.30.0 h1:dq9F93pu4Q8rL9oTcCk+vGGy8vpS7RNt0GSwx7Bvhec=
804804
kmodules.xyz/offshoot-api v0.30.0/go.mod h1:o9VoA3ImZMDBp3lpLb8+kc2d/KBxioRwCpaKDfLIyDw=
805-
kubedb.dev/apimachinery v0.47.1-0.20240924090635-38154e492f4e h1:Js68QYtwGJh06liBeFfSWfLRqdqeFEBzzBgcNve1HUM=
806-
kubedb.dev/apimachinery v0.47.1-0.20240924090635-38154e492f4e/go.mod h1:iD6XKg9Blvfd9iYEO0N9GKiSz6r+yzEPZnfkYdESNG4=
805+
kubedb.dev/apimachinery v0.47.1-0.20240924051141-f0421dd9f647 h1:yRqO/MkRwf4FxE/LktLz6fgkHn58FSxiNrR4NAMDxdQ=
806+
kubedb.dev/apimachinery v0.47.1-0.20240924051141-f0421dd9f647/go.mod h1:iD6XKg9Blvfd9iYEO0N9GKiSz6r+yzEPZnfkYdESNG4=
807807
kubeops.dev/petset v0.0.5-0.20240603165102-e2d9decb8abe h1:uWyps3VIDFwGuL0yQa0eMGaLg4ofVwpy59U14Trxnz8=
808808
kubeops.dev/petset v0.0.5-0.20240603165102-e2d9decb8abe/go.mod h1:A15vh0r979NsvL65DTIZKWsa/NoX9VapHBAEw1ZsdYI=
809809
lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=

vendor/kubedb.dev/apimachinery/apis/kubedb/constants.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,6 @@ const (
576576
PgBouncerConfigMountPath = "/etc/config"
577577
PgBouncerSecretMountPath = "/var/run/pgbouncer/secret"
578578
PgBouncerServingCertMountPath = "/var/run/pgbouncer/tls/serving"
579-
PgBouncerConfigSectionDatabases = "databases"
580-
PgBouncerConfigSectionPeers = "peers"
581-
PgBouncerConfigSectionPgbouncer = "pgbouncer"
582-
PgBouncerConfigSectionUsers = "users"
583579

584580
// =========================== Pgpool Constants ============================
585581
EnvPostgresUsername = "POSTGRES_USERNAME"

vendor/kubedb.dev/apimachinery/apis/kubedb/v1/openapi_generated.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/kubedb.dev/apimachinery/apis/kubedb/v1/pgbouncer_helpers.go

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ limitations under the License.
1717
package v1
1818

1919
import (
20-
"context"
2120
"fmt"
22-
"strconv"
2321

2422
"kubedb.dev/apimachinery/apis"
2523
catalog "kubedb.dev/apimachinery/apis/catalog/v1alpha1"
@@ -31,7 +29,6 @@ import (
3129
core "k8s.io/api/core/v1"
3230
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3331
"k8s.io/apimachinery/pkg/labels"
34-
"k8s.io/apimachinery/pkg/types"
3532
kmapi "kmodules.xyz/client-go/api/v1"
3633
"kmodules.xyz/client-go/apiextensions"
3734
core_util "kmodules.xyz/client-go/core/v1"
@@ -130,19 +127,8 @@ func (p PgBouncer) GetBackendSecretName() string {
130127
return meta_util.NameWithSuffix(p.OffshootName(), "backend")
131128
}
132129

133-
func (p PgBouncer) IsPgBouncerFinalConfigSecretExist() bool {
134-
secret, err := p.GetPgBouncerFinalConfigSecret()
135-
return (secret != nil && err == nil)
136-
}
137-
138-
func (p PgBouncer) GetPgBouncerFinalConfigSecret() (*core.Secret, error) {
139-
var secret core.Secret
140-
err := DefaultClient.Get(context.TODO(), types.NamespacedName{Name: p.PgBouncerFinalConfigSecretName(), Namespace: p.GetNamespace()}, &secret)
141-
return &secret, err
142-
}
143-
144-
func (p PgBouncer) PgBouncerFinalConfigSecretName() string {
145-
return meta_util.NameWithSuffix(p.ServiceName(), "final-config")
130+
func (p PgBouncer) ConfigSecretName() string {
131+
return meta_util.NameWithSuffix(p.ServiceName(), "config")
146132
}
147133

148134
type pgbouncerApp struct {
@@ -214,6 +200,8 @@ func (p *PgBouncer) SetDefaults(pgBouncerVersion *catalog.PgBouncerVersion, uses
214200
p.Spec.DeletionPolicy = DeletionPolicyDelete
215201
}
216202

203+
p.setConnectionPoolConfigDefaults()
204+
217205
if p.Spec.TLS != nil {
218206
if p.Spec.SSLMode == "" {
219207
p.Spec.SSLMode = PgBouncerSSLModeVerifyFull
@@ -285,7 +273,7 @@ func (p *PgBouncer) GetPersistentSecrets() []string {
285273
var secrets []string
286274
secrets = append(secrets, p.GetAuthSecretName())
287275
secrets = append(secrets, p.GetBackendSecretName())
288-
secrets = append(secrets, p.PgBouncerFinalConfigSecretName())
276+
secrets = append(secrets, p.ConfigSecretName())
289277

290278
return secrets
291279
}
@@ -320,6 +308,48 @@ func (p *PgBouncer) SetHealthCheckerDefaults() {
320308
}
321309
}
322310

311+
func (p *PgBouncer) setConnectionPoolConfigDefaults() {
312+
if p.Spec.ConnectionPool == nil {
313+
p.Spec.ConnectionPool = &ConnectionPoolConfig{}
314+
}
315+
if p.Spec.ConnectionPool.Port == nil {
316+
p.Spec.ConnectionPool.Port = pointer.Int32P(5432)
317+
}
318+
if p.Spec.ConnectionPool.PoolMode == "" {
319+
p.Spec.ConnectionPool.PoolMode = kubedb.PgBouncerDefaultPoolMode
320+
}
321+
if p.Spec.ConnectionPool.MaxClientConnections == nil {
322+
p.Spec.ConnectionPool.MaxClientConnections = pointer.Int64P(100)
323+
}
324+
if p.Spec.ConnectionPool.DefaultPoolSize == nil {
325+
p.Spec.ConnectionPool.DefaultPoolSize = pointer.Int64P(20)
326+
}
327+
if p.Spec.ConnectionPool.MinPoolSize == nil {
328+
p.Spec.ConnectionPool.MinPoolSize = pointer.Int64P(0)
329+
}
330+
if p.Spec.ConnectionPool.ReservePoolSize == nil {
331+
p.Spec.ConnectionPool.ReservePoolSize = pointer.Int64P(0)
332+
}
333+
if p.Spec.ConnectionPool.ReservePoolTimeoutSeconds == nil {
334+
p.Spec.ConnectionPool.ReservePoolTimeoutSeconds = pointer.Int64P(5)
335+
}
336+
if p.Spec.ConnectionPool.MaxDBConnections == nil {
337+
p.Spec.ConnectionPool.MaxDBConnections = pointer.Int64P(0)
338+
}
339+
if p.Spec.ConnectionPool.MaxUserConnections == nil {
340+
p.Spec.ConnectionPool.MaxUserConnections = pointer.Int64P(0)
341+
}
342+
if p.Spec.ConnectionPool.StatsPeriodSeconds == nil {
343+
p.Spec.ConnectionPool.StatsPeriodSeconds = pointer.Int64P(60)
344+
}
345+
if p.Spec.ConnectionPool.AuthType == "" {
346+
p.Spec.ConnectionPool.AuthType = PgBouncerClientAuthModeMD5
347+
}
348+
if p.Spec.ConnectionPool.IgnoreStartupParameters == "" {
349+
p.Spec.ConnectionPool.IgnoreStartupParameters = kubedb.PgBouncerDefaultIgnoreStartupParameters
350+
}
351+
}
352+
323353
func (p *PgBouncer) SetSecurityContext(pgBouncerVersion *catalog.PgBouncerVersion) {
324354
container := core_util.GetContainerByName(p.Spec.PodTemplate.Spec.Containers, kubedb.PgBouncerContainerName)
325355
if container == nil {
@@ -375,32 +405,3 @@ func (p *PgBouncer) SetSecurityContext(pgBouncerVersion *catalog.PgBouncerVersio
375405
core_util.UpsertContainer(p.Spec.PodTemplate.Spec.Containers, *container)
376406
}
377407
}
378-
379-
func PgBouncerConfigSections() *[]string {
380-
sections := []string{
381-
kubedb.PgBouncerConfigSectionDatabases, kubedb.PgBouncerConfigSectionPeers,
382-
kubedb.PgBouncerConfigSectionPgbouncer, kubedb.PgBouncerConfigSectionUsers,
383-
}
384-
return &sections
385-
}
386-
387-
func PgBouncerDefaultConfig() string {
388-
defaultConfig := "[pgbouncer]\n" +
389-
"\n" +
390-
"listen_port = " + strconv.Itoa(kubedb.PgBouncerDatabasePort) + "\n" +
391-
"pool_mode = " + kubedb.PgBouncerDefaultPoolMode + "\n" +
392-
"max_client_conn = 100\n" +
393-
"default_pool_size = 20\n" +
394-
"min_pool_size = 1\n" +
395-
"reserve_pool_size = 1\n" +
396-
"reserve_pool_timeout = 5\n" +
397-
"max_db_connections = 1\n" +
398-
"max_user_connections = 2\n" +
399-
"stats_period = 60\n" +
400-
"auth_type = " + string(PgBouncerClientAuthModeMD5) + "\n" +
401-
"ignore_startup_parameters = " + "extra_float_digits, " + kubedb.PgBouncerDefaultIgnoreStartupParameters + "\n" +
402-
"logfile = /tmp/pgbouncer.log\n" +
403-
"pidfile = /tmp/pgbouncer.pid\n" +
404-
"listen_addr = *"
405-
return defaultConfig
406-
}

vendor/kubedb.dev/apimachinery/apis/kubedb/v1/pgbouncer_types.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type PgBouncerSpec struct {
7373
PodTemplate ofstv2.PodTemplateSpec `json:"podTemplate,omitempty"`
7474

7575
// Database to proxy by connection pooling.
76-
Database Database `json:"database"`
76+
Database Database `json:"database,omitempty"`
7777

7878
// ConnectionPoolConfig defines Connection pool configuration.
7979
// +optional
@@ -136,42 +136,54 @@ type Database struct {
136136

137137
type ConnectionPoolConfig struct {
138138
// Port is the port number on which PgBouncer listens to clients. Default: 5432.
139+
// +kubebuilder:default=5432
139140
// +optional
140141
Port *int32 `json:"port,omitempty"`
141142
// PoolMode is the pooling mechanism type. Default: session.
143+
// +kubebuilder:default="session"
142144
// +optional
143145
PoolMode string `json:"poolMode,omitempty"`
144146
// MaxClientConnections is the maximum number of allowed client connections. Default: 100.
147+
// +kubebuilder:default=100
145148
// +optional
146149
MaxClientConnections *int64 `json:"maxClientConnections,omitempty"`
147150
// DefaultPoolSize specifies how many server connections to allow per user/database pair. Default: 20.
151+
// +kubebuilder:default=20
148152
// +optional
149153
DefaultPoolSize *int64 `json:"defaultPoolSize,omitempty"`
150154
// MinPoolSize is used to add more server connections to pool if below this number. Default: 0 (disabled).
155+
// +kubebuilder:default=0
151156
// +optional
152157
MinPoolSize *int64 `json:"minPoolSize,omitempty"`
153158
// ReservePoolSize specifies how many additional connections to allow to a pool. 0 disables. Default: 0 (disabled).
159+
// +kubebuilder:default=0
154160
// +optional
155161
ReservePoolSize *int64 `json:"reservePoolSize,omitempty"`
156162
// ReservePoolTimeoutSeconds is the number of seconds in which if a client has not been serviced,
157163
// pgbouncer enables use of additional connections from reserve pool. 0 disables. Default: 5.0.
164+
// +kubebuilder:default=5
158165
// +optional
159166
ReservePoolTimeoutSeconds *int64 `json:"reservePoolTimeoutSeconds,omitempty"`
160167
// MaxDBConnections is the maximum number of connections allowed per-database. Default: 0 (unlimited).
168+
// +kubebuilder:default=0
161169
// +optional
162170
MaxDBConnections *int64 `json:"maxDBConnections,omitempty"`
163171
// MaxUserConnections is the maximum number of users allowed per-database. Default: 0 (unlimited).
172+
// +kubebuilder:default=0
164173
// +optional
165174
MaxUserConnections *int64 `json:"maxUserConnections,omitempty"`
166175
// StatsPeriodSeconds sets how often the averages shown in various SHOW commands are updated
167176
// and how often aggregated statistics are written to the log. Default: 60
177+
// +kubebuilder:default=60
168178
// +optional
169179
StatsPeriodSeconds *int64 `json:"statsPeriodSeconds,omitempty"`
170180
// AuthType specifies how to authenticate users. Default: md5 (md5+plain text).
181+
// +kubebuilder:default=md5
171182
// +optional
172183
AuthType PgBouncerClientAuthMode `json:"authType,omitempty"`
173184
// IgnoreStartupParameters specifies comma-separated startup parameters that
174185
// pgbouncer knows are handled by admin and it can ignore them. Default: empty
186+
// +kubebuilder:default="empty"
175187
// +optional
176188
IgnoreStartupParameters string `json:"ignoreStartupParameters,omitempty"`
177189
// AdminUsers specifies an array of users who can act as PgBouncer administrators.

vendor/kubedb.dev/apimachinery/crds/kubedb.com_pgbouncers.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,40 +72,52 @@ spec:
7272
connectionPool:
7373
properties:
7474
authType:
75+
default: md5
7576
enum:
7677
- md5
7778
- scram-sha-256
7879
- cert
7980
type: string
8081
defaultPoolSize:
82+
default: 20
8183
format: int64
8284
type: integer
8385
ignoreStartupParameters:
86+
default: empty
8487
type: string
8588
maxClientConnections:
89+
default: 100
8690
format: int64
8791
type: integer
8892
maxDBConnections:
93+
default: 0
8994
format: int64
9095
type: integer
9196
maxUserConnections:
97+
default: 0
9298
format: int64
9399
type: integer
94100
minPoolSize:
101+
default: 0
95102
format: int64
96103
type: integer
97104
poolMode:
105+
default: session
98106
type: string
99107
port:
108+
default: 5432
100109
format: int32
101110
type: integer
102111
reservePoolSize:
112+
default: 0
103113
format: int64
104114
type: integer
105115
reservePoolTimeoutSeconds:
116+
default: 5
106117
format: int64
107118
type: integer
108119
statsPeriodSeconds:
120+
default: 60
109121
format: int64
110122
type: integer
111123
type: object
@@ -3614,7 +3626,6 @@ spec:
36143626
version:
36153627
type: string
36163628
required:
3617-
- database
36183629
- version
36193630
type: object
36203631
status:

vendor/kubedb.dev/apimachinery/crds/ops.kubedb.com_pgbounceropsrequests.yaml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,6 @@ spec:
4949
- Always
5050
type: string
5151
configuration:
52-
properties:
53-
pgbouncer:
54-
properties:
55-
applyConfig:
56-
additionalProperties:
57-
type: string
58-
type: object
59-
configSecret:
60-
properties:
61-
name:
62-
default: ""
63-
type: string
64-
type: object
65-
x-kubernetes-map-type: atomic
66-
removeCustomConfig:
67-
type: boolean
68-
type: object
69-
required:
70-
- pgbouncer
7152
type: object
7253
horizontalScaling:
7354
properties:
@@ -196,7 +177,6 @@ spec:
196177
- HorizontalScaling
197178
- VerticalScaling
198179
- UpdateVersion
199-
- Reconfigure
200180
type: string
201181
updateVersion:
202182
properties:

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ kmodules.xyz/offshoot-api/api/v1
15611561
kmodules.xyz/offshoot-api/api/v1/conversion
15621562
kmodules.xyz/offshoot-api/api/v2
15631563
kmodules.xyz/offshoot-api/util
1564-
# kubedb.dev/apimachinery v0.47.1-0.20240924090635-38154e492f4e
1564+
# kubedb.dev/apimachinery v0.47.1-0.20240924051141-f0421dd9f647
15651565
## explicit; go 1.22.1
15661566
kubedb.dev/apimachinery/apis
15671567
kubedb.dev/apimachinery/apis/catalog

0 commit comments

Comments
 (0)