diff --git a/vendor/github.com/lib/pq/conn.go b/vendor/github.com/lib/pq/conn.go index e70b386ff..da4ff9de6 100644 --- a/vendor/github.com/lib/pq/conn.go +++ b/vendor/github.com/lib/pq/conn.go @@ -2,6 +2,7 @@ package pq import ( "bufio" + "bytes" "context" "crypto/md5" "crypto/sha256" @@ -112,7 +113,9 @@ type defaultDialer struct { func (d defaultDialer) Dial(network, address string) (net.Conn, error) { return d.d.Dial(network, address) } -func (d defaultDialer) DialTimeout(network, address string, timeout time.Duration) (net.Conn, error) { +func (d defaultDialer) DialTimeout( + network, address string, timeout time.Duration, +) (net.Conn, error) { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() return d.DialContext(ctx, network, address) @@ -260,47 +263,56 @@ func (cn *conn) handlePgpass(o values) { } defer file.Close() scanner := bufio.NewScanner(io.Reader(file)) + // From: https://github.com/tg/pgpass/blob/master/reader.go + for scanner.Scan() { + if scanText(scanner.Text(), o) { + break + } + } +} + +// GetFields is a helper function for scanText. +func getFields(s string) []string { + fs := make([]string, 0, 5) + f := make([]rune, 0, len(s)) + + var esc bool + for _, c := range s { + switch { + case esc: + f = append(f, c) + esc = false + case c == '\\': + esc = true + case c == ':': + fs = append(fs, string(f)) + f = f[:0] + default: + f = append(f, c) + } + } + return append(fs, string(f)) +} + +// ScanText assists HandlePgpass in it's objective. +func scanText(line string, o values) bool { hostname := o["host"] ntw, _ := network(o) port := o["port"] db := o["dbname"] username := o["user"] - // From: https://github.com/tg/pgpass/blob/master/reader.go - getFields := func(s string) []string { - fs := make([]string, 0, 5) - f := make([]rune, 0, len(s)) - - var esc bool - for _, c := range s { - switch { - case esc: - f = append(f, c) - esc = false - case c == '\\': - esc = true - case c == ':': - fs = append(fs, string(f)) - f = f[:0] - default: - f = append(f, c) - } - } - return append(fs, string(f)) + if len(line) == 0 || line[0] == '#' { + return false } - for scanner.Scan() { - line := scanner.Text() - if len(line) == 0 || line[0] == '#' { - continue - } - split := getFields(line) - if len(split) != 5 { - continue - } - if (split[0] == "*" || split[0] == hostname || (split[0] == "localhost" && (hostname == "" || ntw == "unix"))) && (split[1] == "*" || split[1] == port) && (split[2] == "*" || split[2] == db) && (split[3] == "*" || split[3] == username) { - o["password"] = split[4] - return - } + split := getFields(line) + if len(split) != 5 { + return false + } + if (split[0] == "*" || split[0] == hostname || (split[0] == "localhost" && (hostname == "" || ntw == "unix"))) && (split[1] == "*" || split[1] == port) && (split[2] == "*" || split[2] == db) && (split[3] == "*" || split[3] == username) { + o["password"] = split[4] + return true } + return false } func (cn *conn) writeBuf(b byte) *writeBuf { @@ -765,7 +777,9 @@ func (noRows) RowsAffected() (int64, error) { // Decides which column formats to use for a prepared statement. The input is // an array of type oids, one element per result column. -func decideColumnFormats(colTyps []fieldDesc, forceText bool) (colFmts []format, colFmtData []byte) { +func decideColumnFormats( + colTyps []fieldDesc, forceText bool, +) (colFmts []format, colFmtData []byte) { if len(colTyps) == 0 { return nil, colFmtDataAllText } @@ -1631,10 +1645,10 @@ func (rs *rows) NextResultSet() error { // QuoteIdentifier quotes an "identifier" (e.g. a table or a column name) to be // used as part of an SQL statement. For example: // -// tblname := "my_table" -// data := "my_data" -// quoted := pq.QuoteIdentifier(tblname) -// err := db.Exec(fmt.Sprintf("INSERT INTO %s VALUES ($1)", quoted), data) +// tblname := "my_table" +// data := "my_data" +// quoted := pq.QuoteIdentifier(tblname) +// err := db.Exec(fmt.Sprintf("INSERT INTO %s VALUES ($1)", quoted), data) // // Any double quotes in name will be escaped. The quoted identifier will be // case sensitive when used in a query. If the input string contains a zero @@ -1647,12 +1661,24 @@ func QuoteIdentifier(name string) string { return `"` + strings.Replace(name, `"`, `""`, -1) + `"` } +// BufferQuoteIdentifier satisfies the same purpose as QuoteIdentifier, but backed by a +// byte buffer. +func BufferQuoteIdentifier(name string, buffer *bytes.Buffer) { + end := strings.IndexRune(name, 0) + if end > -1 { + name = name[:end] + } + buffer.WriteRune('"') + buffer.WriteString(strings.Replace(name, `"`, `""`, -1)) + buffer.WriteRune('"') +} + // QuoteLiteral quotes a 'literal' (e.g. a parameter, often used to pass literal // to DDL and other statements that do not accept parameters) to be used as part // of an SQL statement. For example: // -// exp_date := pq.QuoteLiteral("2023-01-05 15:00:00Z") -// err := db.Exec(fmt.Sprintf("CREATE ROLE my_user VALID UNTIL %s", exp_date)) +// exp_date := pq.QuoteLiteral("2023-01-05 15:00:00Z") +// err := db.Exec(fmt.Sprintf("CREATE ROLE my_user VALID UNTIL %s", exp_date)) // // Any single quotes in name will be escaped. Any backslashes (i.e. "\") will be // replaced by two backslashes (i.e. "\\") and the C-style escape identifier @@ -1808,7 +1834,11 @@ func (cn *conn) readParseResponse() { } } -func (cn *conn) readStatementDescribeResponse() (paramTyps []oid.Oid, colNames []string, colTyps []fieldDesc) { +func (cn *conn) readStatementDescribeResponse() ( + paramTyps []oid.Oid, + colNames []string, + colTyps []fieldDesc, +) { for { t, r := cn.recv1() switch t { @@ -1896,7 +1926,9 @@ func (cn *conn) postExecuteWorkaround() { } // Only for Exec(), since we ignore the returned data -func (cn *conn) readExecuteResponse(protocolState string) (res driver.Result, commandTag string, err error) { +func (cn *conn) readExecuteResponse( + protocolState string, +) (res driver.Result, commandTag string, err error) { for { t, r := cn.recv1() switch t { @@ -2062,3 +2094,19 @@ func alnumLowerASCII(ch rune) rune { } return -1 // discard } + +// The database/sql/driver package says: +// All Conn implementations should implement the following interfaces: Pinger, SessionResetter, and Validator. +var _ driver.Pinger = &conn{} +var _ driver.SessionResetter = &conn{} + +func (cn *conn) ResetSession(ctx context.Context) error { + // Ensure bad connections are reported: From database/sql/driver: + // If a connection is never returned to the connection pool but immediately reused, then + // ResetSession is called prior to reuse but IsValid is not called. + return cn.err.get() +} + +func (cn *conn) IsValid() bool { + return cn.err.get() == nil +} diff --git a/vendor/github.com/lib/pq/conn_go115.go b/vendor/github.com/lib/pq/conn_go115.go new file mode 100644 index 000000000..f4ef030f9 --- /dev/null +++ b/vendor/github.com/lib/pq/conn_go115.go @@ -0,0 +1,8 @@ +//go:build go1.15 +// +build go1.15 + +package pq + +import "database/sql/driver" + +var _ driver.Validator = &conn{} diff --git a/vendor/github.com/lib/pq/copy.go b/vendor/github.com/lib/pq/copy.go index 2f5c1ec8a..a8f16b2b2 100644 --- a/vendor/github.com/lib/pq/copy.go +++ b/vendor/github.com/lib/pq/copy.go @@ -1,6 +1,7 @@ package pq import ( + "bytes" "context" "database/sql/driver" "encoding/binary" @@ -20,29 +21,35 @@ var ( // CopyIn creates a COPY FROM statement which can be prepared with // Tx.Prepare(). The target table should be visible in search_path. func CopyIn(table string, columns ...string) string { - stmt := "COPY " + QuoteIdentifier(table) + " (" + buffer := bytes.NewBufferString("COPY ") + BufferQuoteIdentifier(table, buffer) + buffer.WriteString(" (") + makeStmt(buffer, columns...) + return buffer.String() +} + +// MakeStmt makes the stmt string for CopyIn and CopyInSchema. +func makeStmt(buffer *bytes.Buffer, columns ...string) { + //s := bytes.NewBufferString() for i, col := range columns { if i != 0 { - stmt += ", " + buffer.WriteString(", ") } - stmt += QuoteIdentifier(col) + BufferQuoteIdentifier(col, buffer) } - stmt += ") FROM STDIN" - return stmt + buffer.WriteString(") FROM STDIN") } // CopyInSchema creates a COPY FROM statement which can be prepared with // Tx.Prepare(). func CopyInSchema(schema, table string, columns ...string) string { - stmt := "COPY " + QuoteIdentifier(schema) + "." + QuoteIdentifier(table) + " (" - for i, col := range columns { - if i != 0 { - stmt += ", " - } - stmt += QuoteIdentifier(col) - } - stmt += ") FROM STDIN" - return stmt + buffer := bytes.NewBufferString("COPY ") + BufferQuoteIdentifier(schema, buffer) + buffer.WriteRune('.') + BufferQuoteIdentifier(table, buffer) + buffer.WriteString(" (") + makeStmt(buffer, columns...) + return buffer.String() } type copyin struct { diff --git a/vendor/kubedb.dev/pgpool/api/catalog/v1alpha1/groupversion_info.go b/vendor/kubedb.dev/pgpool/api/catalog/v1alpha1/groupversion_info.go new file mode 100644 index 000000000..886ea5fd9 --- /dev/null +++ b/vendor/kubedb.dev/pgpool/api/catalog/v1alpha1/groupversion_info.go @@ -0,0 +1,36 @@ +/* +Copyright 2023. + +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 v1alpha1 contains API Schema definitions for the catalog v1alpha1 API group +// +kubebuilder:object:generate=true +// +groupName=catalog.kubedb.com +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +var ( + // GroupVersion is group version used to register these objects + GroupVersion = schema.GroupVersion{Group: "catalog.kubedb.com", Version: "v1alpha1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/vendor/kubedb.dev/pgpool/api/catalog/v1alpha1/pgpoolversion_types.go b/vendor/kubedb.dev/pgpool/api/catalog/v1alpha1/pgpoolversion_types.go new file mode 100644 index 000000000..0ddbcbb8e --- /dev/null +++ b/vendor/kubedb.dev/pgpool/api/catalog/v1alpha1/pgpoolversion_types.go @@ -0,0 +1,75 @@ +/* +Copyright 2023. +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 v1alpha1 + +import ( + meta "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +const ( + ResourceCodePgpoolVersion = "ppversion" + ResourceKindPgpoolVersion = "PgpoolVersion" + ResourceSingularPgpoolVersion = "pgpoolversion" + ResourcePluralPgpoolVersion = "pgpoolversions" +) + +// +genclient +// +genclient:nonNamespaced +// +genclient:skipVerbs=updateStatus +// +k8s:openapi-gen=true +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// +kubebuilder:object:root=true +// +kubebuilder:resource:path=pgpoolversions,singular=pgpoolversion,scope=Cluster,shortName=ppversion,categories={datastore,kubedb,appscode} +// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.version" +// +kubebuilder:printcolumn:name="PGPOOL_IMAGE",type="string",JSONPath=".spec.pgpool.image" +// +kubebuilder:printcolumn:name="Deprecated",type="boolean",JSONPath=".spec.deprecated" +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" +type PgpoolVersion struct { + meta.TypeMeta `json:",inline"` + meta.ObjectMeta `json:"metadata,omitempty"` + Spec PgpoolVersionSpec `json:"spec,omitempty"` +} + +// PgpoolVersionSpec defines the desired state of PgpoolVersion +type PgpoolVersionSpec struct { + // Version + Version string `json:"version"` + // Database Image + Pgpool PgpoolVersionDatabase `json:"pgpool"` + // +optional + Deprecated bool `json:"deprecated,omitempty"` +} + +// PgBouncerVersionDatabase is the PgBouncer Database image +type PgpoolVersionDatabase struct { + Image string `json:"image"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +//+kubebuilder:object:root=true + +// PgpoolVersionList contains a list of PgpoolVersion +type PgpoolVersionList struct { + meta.TypeMeta `json:",inline"` + meta.ListMeta `json:"metadata,omitempty"` + Items []PgpoolVersion `json:"items"` +} + +func init() { + SchemeBuilder.Register(&PgpoolVersion{}, &PgpoolVersionList{}) +} diff --git a/vendor/kubedb.dev/pgpool/api/catalog/v1alpha1/zz_generated.deepcopy.go b/vendor/kubedb.dev/pgpool/api/catalog/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 000000000..c49948949 --- /dev/null +++ b/vendor/kubedb.dev/pgpool/api/catalog/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,114 @@ +//go:build !ignore_autogenerated + +/* +Copyright 2023. + +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. +*/ + +// Code generated by controller-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PgpoolVersion) DeepCopyInto(out *PgpoolVersion) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PgpoolVersion. +func (in *PgpoolVersion) DeepCopy() *PgpoolVersion { + if in == nil { + return nil + } + out := new(PgpoolVersion) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PgpoolVersion) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PgpoolVersionDatabase) DeepCopyInto(out *PgpoolVersionDatabase) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PgpoolVersionDatabase. +func (in *PgpoolVersionDatabase) DeepCopy() *PgpoolVersionDatabase { + if in == nil { + return nil + } + out := new(PgpoolVersionDatabase) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PgpoolVersionList) DeepCopyInto(out *PgpoolVersionList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]PgpoolVersion, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PgpoolVersionList. +func (in *PgpoolVersionList) DeepCopy() *PgpoolVersionList { + if in == nil { + return nil + } + out := new(PgpoolVersionList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PgpoolVersionList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PgpoolVersionSpec) DeepCopyInto(out *PgpoolVersionSpec) { + *out = *in + out.Pgpool = in.Pgpool +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PgpoolVersionSpec. +func (in *PgpoolVersionSpec) DeepCopy() *PgpoolVersionSpec { + if in == nil { + return nil + } + out := new(PgpoolVersionSpec) + in.DeepCopyInto(out) + return out +} diff --git a/vendor/kubedb.dev/pgpool/api/v1alpha2/constants.go b/vendor/kubedb.dev/pgpool/api/v1alpha2/constants.go new file mode 100644 index 000000000..6f7b490da --- /dev/null +++ b/vendor/kubedb.dev/pgpool/api/v1alpha2/constants.go @@ -0,0 +1,32 @@ +package v1alpha2 + +// Environment variables +const ( + EnvPostgresUsername = "POSTGRES_USERNAME" + EnvPostgresPassword = "POSTGRES_PASSWORD" + EnvPgpoolPcpUser = "PGPOOL_PCP_USER" + EnvPgpoolPcpPassword = "PGPOOL_PCP_PASSWORD" + EnvPgpoolPasswordEncryptionMethod = "PGPOOL_PASSWORD_ENCRYPTION_METHOD" + EnvEnablePoolPasswd = "PGPOOL_ENABLE_POOL_PASSWD" + EnvSkipPasswdEncryption = "PGPOOL_SKIP_PASSWORD_ENCRYPTION" +) + +const DatabasePaused = "Paused" + +// For pgpool statefulSet +const ( + ConfigSecretMountPath = "/config" + ConfigVolumeName = "pgpool-config" + ContainerName = "pgpool" +) + +// Pgpool secret +const ( + PgpoolAuthUsername = "pcp" + DefaultPasswordLength = 16 +) + +// Sync users +const ( + SyncPeriod = 10 +) diff --git a/vendor/kubedb.dev/pgpool/api/v1alpha2/mutator.go b/vendor/kubedb.dev/pgpool/api/v1alpha2/mutator.go new file mode 100644 index 000000000..8e8346472 --- /dev/null +++ b/vendor/kubedb.dev/pgpool/api/v1alpha2/mutator.go @@ -0,0 +1,24 @@ +package v1alpha2 + +import ( + "gomodules.xyz/pointer" + apm "kubedb.dev/apimachinery/apis/kubedb/v1alpha2" +) + +func (p *Pgpool) MutatePgpool() { + if p == nil { + return + } + if p.Spec.TerminationPolicy == "" { + p.Spec.TerminationPolicy = apm.TerminationPolicyDelete + } + // TODO ssl mode is not here for now + + if p.Spec.Replicas == nil { + p.Spec.Replicas = pointer.Int32P(1) + } + //if p.Spec.PodTemplate != nil && p.Spec.PodTemplate.Spec.ServiceAccountName == "" { + // p.Spec.PodTemplate.Spec.ServiceAccountName = p.OffshootName() + //} + p.SetHealthCheckerDefaults() +} diff --git a/vendor/kubedb.dev/pgpool/api/v1alpha2/pgpool_helpers.go b/vendor/kubedb.dev/pgpool/api/v1alpha2/pgpool_helpers.go index 334e484d3..6a97586e4 100644 --- a/vendor/kubedb.dev/pgpool/api/v1alpha2/pgpool_helpers.go +++ b/vendor/kubedb.dev/pgpool/api/v1alpha2/pgpool_helpers.go @@ -2,6 +2,7 @@ package v1alpha2 import ( "fmt" + "gomodules.xyz/pointer" meta "k8s.io/apimachinery/pkg/apis/meta/v1" meta_util "kmodules.xyz/client-go/meta" "kubedb.dev/apimachinery/apis/kubedb" @@ -50,11 +51,21 @@ func (p *Pgpool) Owner() *meta.OwnerReference { } func (p *Pgpool) PodLabels(extraLabels ...map[string]string) map[string]string { - return p.offshootLabels(meta_util.OverwriteKeys(p.OffshootSelectors(), extraLabels...), p.Spec.PodTemplate.Labels) + var labels map[string]string + if p.Spec.PodTemplate != nil { + return p.offshootLabels(meta_util.OverwriteKeys(p.OffshootSelectors(), extraLabels...), p.Spec.PodTemplate.Labels) + } else { + return p.offshootLabels(meta_util.OverwriteKeys(p.OffshootSelectors(), extraLabels...), labels) + } } func (p *Pgpool) PodControllerLabels(extraLabels ...map[string]string) map[string]string { - return p.offshootLabels(meta_util.OverwriteKeys(p.OffshootSelectors(), extraLabels...), p.Spec.PodTemplate.Controller.Labels) + var labels map[string]string + if p.Spec.PodTemplate != nil { + return p.offshootLabels(meta_util.OverwriteKeys(p.OffshootSelectors(), extraLabels...), p.Spec.PodTemplate.Controller.Labels) + } else { + return p.offshootLabels(meta_util.OverwriteKeys(p.OffshootSelectors(), extraLabels...), labels) + } } func (p *Pgpool) OffshootLabels() map[string]string { @@ -89,3 +100,24 @@ func (p *Pgpool) GetAuthSecretName() string { } return meta_util.NameWithSuffix(p.OffshootName(), "auth") } + +func (p *Pgpool) SetHealthCheckerDefaults() { + if p.Spec.HealthChecker.PeriodSeconds == nil { + p.Spec.HealthChecker.PeriodSeconds = pointer.Int32P(10) + } + if p.Spec.HealthChecker.TimeoutSeconds == nil { + p.Spec.HealthChecker.TimeoutSeconds = pointer.Int32P(10) + } + if p.Spec.HealthChecker.FailureThreshold == nil { + p.Spec.HealthChecker.FailureThreshold = pointer.Int32P(1) + } +} + +// PrimaryServiceDNS make primary host dns with require template +func (p *Pgpool) PrimaryServiceDNS() string { + return fmt.Sprintf("%v.%v.svc", p.ServiceName(), p.Namespace) +} + +func (p *Pgpool) GetNameSpacedName() string { + return p.Namespace + "/" + p.Name +} diff --git a/vendor/kubedb.dev/pgpool/api/v1alpha2/pgpool_types.go b/vendor/kubedb.dev/pgpool/api/v1alpha2/pgpool_types.go index 348ed22f7..85d31854b 100644 --- a/vendor/kubedb.dev/pgpool/api/v1alpha2/pgpool_types.go +++ b/vendor/kubedb.dev/pgpool/api/v1alpha2/pgpool_types.go @@ -63,7 +63,7 @@ type PgpoolSpec struct { // +optional // SyncUsers is a boolean type and when enabled, operator fetches all users created in the backend server to the // Pgpool server . Password changes are also synced in pgpool when it is enabled. - //SyncUsers bool `json:"syncUsers,omitempty"` + SyncUsers bool `json:"syncUsers,omitempty"` // Version of Pgpool to be deployed. Version string `json:"version"` @@ -85,7 +85,7 @@ type PgpoolSpec struct { // PodTemplate is an optional configuration for pods used to expose Pgpool // +optional - PodTemplate ofst.PodTemplateSpec `json:"podTemplate,omitempty"` + PodTemplate *ofst.PodTemplateSpec `json:"podTemplate,omitempty"` // +optional // InitConfiguration contains information with which the Pgpool will bootstrap @@ -95,6 +95,11 @@ type PgpoolSpec struct { // +optional ServiceTemplates []api.NamedServiceTemplateSpec `json:"serviceTemplates,omitempty"` + // HealthChecker defines attributes of the health checker + // +optional + // +kubebuilder:default={periodSeconds: 10, timeoutSeconds: 10, failureThreshold: 1} + HealthChecker *kmapi.HealthCheckSpec `json:"healthChecker"` + // TerminationPolicy controls the delete operation for Pgpool // +optional TerminationPolicy api.TerminationPolicy `json:"terminationPolicy,omitempty"` diff --git a/vendor/kubedb.dev/pgpool/api/v1alpha2/validator.go b/vendor/kubedb.dev/pgpool/api/v1alpha2/validator.go new file mode 100644 index 000000000..40a69e93c --- /dev/null +++ b/vendor/kubedb.dev/pgpool/api/v1alpha2/validator.go @@ -0,0 +1,65 @@ +package v1alpha2 + +import ( + "context" + "errors" + "fmt" + core "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/types" + amv "kubedb.dev/apimachinery/pkg/validator" + catalog "kubedb.dev/pgpool/api/catalog/v1alpha1" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +var forbiddenEnvVars = []string{ + EnvPostgresUsername, EnvPostgresPassword, EnvPgpoolPcpUser, EnvPgpoolPcpPassword, + EnvPgpoolPasswordEncryptionMethod, EnvEnablePoolPasswd, EnvSkipPasswdEncryption, +} + +func (p *Pgpool) ValidatePgpool(KBClient client.Client) error { + if p.Spec.Version == "" { + return errors.New(`'spec.version' is missing`) + } + version := &catalog.PgpoolVersion{} + if err := KBClient.Get(context.TODO(), types.NamespacedName{ + Name: p.Spec.Version, + }, version); err != nil { + return err + } + + if p.Spec.Replicas == nil || *p.Spec.Replicas < 1 { + if p.Spec.Replicas == nil { + return errors.New(`'spec.replicas' is missing`) + } + return fmt.Errorf(`spec.replicas "%v" invalid. Must be greater than zero`, *p.Spec.Replicas) + } + + if p.Spec.PodTemplate != nil { + if err := amv.ValidateEnvVar(getMainContainerEnvs(p), forbiddenEnvVars, p.ResourceKind()); err != nil { + return err + } + } + + if p.Spec.AuthSecret != nil && p.Spec.AuthSecret.ExternallyManaged && p.Spec.AuthSecret.Name == "" { + return fmt.Errorf(`for externallyManaged auth secret, user must configure "spec.authSecret.name"`) + } + + if p.Spec.TerminationPolicy == "" { + return fmt.Errorf(`'spec.terminationPolicy' is missing`) + } + + if err := amv.ValidateHealth(p.Spec.HealthChecker); err != nil { + return err + } + + return nil +} + +func getMainContainerEnvs(p *Pgpool) []core.EnvVar { + for _, container := range p.Spec.PodTemplate.Spec.Containers { + if container.Name == ContainerName { + return container.Env + } + } + return []core.EnvVar{} +} diff --git a/vendor/kubedb.dev/pgpool/api/v1alpha2/zz_generated.deepcopy.go b/vendor/kubedb.dev/pgpool/api/v1alpha2/zz_generated.deepcopy.go index 676f40965..bf60013ec 100644 --- a/vendor/kubedb.dev/pgpool/api/v1alpha2/zz_generated.deepcopy.go +++ b/vendor/kubedb.dev/pgpool/api/v1alpha2/zz_generated.deepcopy.go @@ -24,6 +24,7 @@ import ( "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" apiv1 "kmodules.xyz/client-go/api/v1" + "kmodules.xyz/offshoot-api/api/v2" kubedbv1alpha2 "kubedb.dev/apimachinery/apis/kubedb/v1alpha2" ) @@ -129,7 +130,11 @@ func (in *PgpoolSpec) DeepCopyInto(out *PgpoolSpec) { *out = new(v1.LocalObjectReference) **out = **in } - in.PodTemplate.DeepCopyInto(&out.PodTemplate) + if in.PodTemplate != nil { + in, out := &in.PodTemplate, &out.PodTemplate + *out = new(v2.PodTemplateSpec) + (*in).DeepCopyInto(*out) + } if in.InitConfiguration != nil { in, out := &in.InitConfiguration, &out.InitConfiguration *out = new(PgpoolConfiguration) @@ -142,6 +147,11 @@ func (in *PgpoolSpec) DeepCopyInto(out *PgpoolSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.HealthChecker != nil { + in, out := &in.HealthChecker, &out.HealthChecker + *out = new(apiv1.HealthCheckSpec) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PgpoolSpec.