/
pgbouncer_types.go
173 lines (157 loc) · 8.71 KB
/
pgbouncer_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
Copyright AppsCode Inc. and Contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1alpha2
import (
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kmapi "kmodules.xyz/client-go/api/v1"
appcat "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
mona "kmodules.xyz/monitoring-agent-api/api/v1"
ofst "kmodules.xyz/offshoot-api/api/v1"
)
const (
ResourceCodePgBouncer = "pb"
ResourceKindPgBouncer = "PgBouncer"
ResourceSingularPgBouncer = "pgbouncer"
ResourcePluralPgBouncer = "pgbouncers"
)
// PgBouncer defines a PgBouncer Server.
// +genclient
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:resource:path=pgbouncers,singular=pgbouncer,shortName=pb,categories={proxy,kubedb,appscode,all}
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.version"
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
type PgBouncer struct {
metav1.TypeMeta `json:",inline,omitempty"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Spec PgBouncerSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
Status PgBouncerStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}
type PgBouncerSpec struct {
// Version of PgBouncer to be deployed.
Version string `json:"version" protobuf:"bytes,1,opt,name=version"`
// Number of instances to deploy for a PgBouncer instance.
// +optional
Replicas *int32 `json:"replicas,omitempty" protobuf:"varint,2,opt,name=replicas"`
// ServiceTemplates is an optional configuration for services used to expose database
// +optional
ServiceTemplates []NamedServiceTemplateSpec `json:"serviceTemplates,omitempty" protobuf:"bytes,3,rep,name=serviceTemplates"`
// PodTemplate is an optional configuration for pods.
// +optional
PodTemplate ofst.PodTemplateSpec `json:"podTemplate,omitempty" protobuf:"bytes,4,opt,name=podTemplate"`
// Databases to proxy by connection pooling.
// +optional
Databases []Databases `json:"databases,omitempty" protobuf:"bytes,5,rep,name=databases"`
// ConnectionPoolConfig defines Connection pool configuration.
// +optional
ConnectionPool *ConnectionPoolConfig `json:"connectionPool,omitempty" protobuf:"bytes,6,opt,name=connectionPool"`
// UserListSecretRef is a secret with a list of PgBouncer user and passwords.
// +optional
UserListSecretRef *core.LocalObjectReference `json:"userListSecretRef,omitempty" protobuf:"bytes,7,opt,name=userListSecretRef"`
// Monitor is used monitor database instance.
// +optional
Monitor *mona.AgentSpec `json:"monitor,omitempty" protobuf:"bytes,8,opt,name=monitor"`
// TLS contains tls configurations for client and server.
// +optional
TLS *kmapi.TLSConfig `json:"tls,omitempty" protobuf:"bytes,9,opt,name=tls"`
}
// +kubebuilder:validation:Enum=server;archiver;metrics-exporter
type PgBouncerCertificateAlias string
const (
PgBouncerServerCert PgBouncerCertificateAlias = "server"
PgBouncerClientCert PgBouncerCertificateAlias = "client"
PgBouncerMetricsExporterCert PgBouncerCertificateAlias = "metrics-exporter"
)
type Databases struct {
// Alias to uniquely identify a target database running inside a specific Postgres instance.
Alias string `json:"alias" protobuf:"bytes,1,opt,name=alias"`
// DatabaseRef specifies the database appbinding reference in any namespace.
DatabaseRef appcat.AppReference `json:"databaseRef" protobuf:"bytes,2,opt,name=databaseRef"`
// DatabaseName is the name of the target database inside a Postgres instance.
DatabaseName string `json:"databaseName" protobuf:"bytes,3,opt,name=databaseName"`
// AuthSecretRef points to a secret that contains the credentials
// (username and password) of an existing user of this database.
// It is used to bind a single user to this specific database connection.
// +optional
AuthSecretRef *core.LocalObjectReference `json:"authSecretRef,omitempty" protobuf:"bytes,4,opt,name=authSecretRef"`
}
type ConnectionPoolConfig struct {
// Port is the port number on which PgBouncer listens to clients. Default: 5432.
// +optional
Port *int32 `json:"port,omitempty" protobuf:"varint,1,opt,name=port"`
// PoolMode is the pooling mechanism type. Default: session.
// +optional
PoolMode string `json:"poolMode,omitempty" protobuf:"bytes,2,opt,name=poolMode"`
// MaxClientConnections is the maximum number of allowed client connections. Default: 100.
// +optional
MaxClientConnections *int64 `json:"maxClientConnections,omitempty" protobuf:"varint,3,opt,name=maxClientConnections"`
// DefaultPoolSize specifies how many server connections to allow per user/database pair. Default: 20.
// +optional
DefaultPoolSize *int64 `json:"defaultPoolSize,omitempty" protobuf:"varint,4,opt,name=defaultPoolSize"`
// MinPoolSize is used to add more server connections to pool if below this number. Default: 0 (disabled).
// +optional
MinPoolSize *int64 `json:"minPoolSize,omitempty" protobuf:"varint,5,opt,name=minPoolSize"`
// ReservePoolSize specifies how many additional connections to allow to a pool. 0 disables. Default: 0 (disabled).
// +optional
ReservePoolSize *int64 `json:"reservePoolSize,omitempty" protobuf:"varint,6,opt,name=reservePoolSize"`
// ReservePoolTimeoutSeconds is the number of seconds in which if a client has not been serviced,
// pgbouncer enables use of additional connections from reserve pool. 0 disables. Default: 5.0.
// +optional
ReservePoolTimeoutSeconds *int64 `json:"reservePoolTimeoutSeconds,omitempty" protobuf:"varint,7,opt,name=reservePoolTimeoutSeconds"`
// MaxDBConnections is the maximum number of connections allowed per-database. Default: unlimited.
// +optional
MaxDBConnections *int64 `json:"maxDBConnections,omitempty" protobuf:"varint,8,opt,name=maxDBConnections"`
// MaxUserConnections is the maximum number of users allowed per-database. Default: unlimited.
// +optional
MaxUserConnections *int64 `json:"maxUserConnections,omitempty" protobuf:"varint,9,opt,name=maxUserConnections"`
// StatsPeriodSeconds sets how often the averages shown in various SHOW commands are updated
// and how often aggregated statistics are written to the log.
// +optional
StatsPeriodSeconds *int64 `json:"statsPeriodSeconds,omitempty" protobuf:"varint,10,opt,name=statsPeriodSeconds"`
// AdminUsers specifies an array of users who can act as PgBouncer administrators.
// +optional
AdminUsers []string `json:"adminUsers,omitempty" protobuf:"bytes,11,rep,name=adminUsers"`
// AuthType specifies how to authenticate users. Default: md5 (md5+plain text).
// +optional
AuthType string `json:"authType,omitempty" protobuf:"bytes,12,opt,name=authType"`
// AuthUser looks up any user not specified in auth_file from pg_shadow. Default: not set.
// +optional
AuthUser string `json:"authUser,omitempty" protobuf:"bytes,13,opt,name=authUser"`
// IgnoreStartupParameters specifies comma-separated startup parameters that
// pgbouncer knows are handled by admin and it can ignore them.
// +optional
IgnoreStartupParameters string `json:"ignoreStartupParameters,omitempty" protobuf:"bytes,14,opt,name=ignoreStartupParameters"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type PgBouncerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// Items is a list of PgBouncer CRD objects.
Items []PgBouncer `json:"items,omitempty" protobuf:"bytes,2,rep,name=items"`
}
type PgBouncerStatus struct {
// Specifies the current phase of the database
// +optional
Phase DatabasePhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase,casttype=DatabasePhase"`
// observedGeneration is the most recent generation observed for this resource. It corresponds to the
// resource's generation, which is updated on mutation by the API Server.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty" protobuf:"varint,2,opt,name=observedGeneration"`
// Conditions applied to the database, such as approval or denial.
// +optional
Conditions []kmapi.Condition `json:"conditions,omitempty" protobuf:"bytes,3,rep,name=conditions"`
}