Skip to content

Commit

Permalink
Update Pgpool webhook for config secret
Browse files Browse the repository at this point in the history
Signed-off-by: MobarakHsn <[email protected]>
  • Loading branch information
MobarakHsn committed May 31, 2024
1 parent 9200cc3 commit 18fbdb3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apis/kubedb/v1alpha2/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ const (
PgpoolContainerName = "pgpool"
PgpoolDefaultServicePort = 9999
PgpoolMonitoringDefaultServicePort = 9719
PgpoolPcpServicePort = 9595
PgpoolExporterDatabase = "postgres"
EnvPgpoolExporterDatabase = "POSTGRES_DATABASE"
EnvPgpoolService = "PGPOOL_SERVICE"
Expand All @@ -596,6 +597,7 @@ const (
PgpoolRootUser = "postgres"
PgpoolPrimaryServicePortName = "primary"
PgpoolDatabasePortName = "db"
PgpoolPcpServicePortName = "pcp"
// ========================================== ZooKeeper Constants =================================================//

KubeDBZooKeeperRoleName = "kubedb:zookeeper-version-reader"
Expand Down
4 changes: 4 additions & 0 deletions apis/kubedb/v1alpha2/pgpool_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func (p *Pgpool) ServiceName() string {
return p.OffshootName()
}

func (p *Pgpool) PcpServiceName() string {
return meta_util.NameWithSuffix(p.ServiceName(), "pcp")
}

// Owner returns owner reference to resources
func (p *Pgpool) Owner() *meta.OwnerReference {
return meta.NewControllerRef(p, SchemeGroupVersion.WithKind(p.ResourceKind()))
Expand Down
30 changes: 30 additions & 0 deletions apis/kubedb/v1alpha2/pgpool_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,36 @@ func (p *Pgpool) ValidateCreateOrUpdate() field.ErrorList {
))
}

if p.Spec.ConfigSecret != nil && (p.Spec.InitConfiguration != nil || p.Spec.InitConfiguration.PgpoolConfig != nil) {
errorList = append(errorList, field.Invalid(field.NewPath("spec").Child("configSecret"),
p.Name,
"use either `spec.configSecret` or `spec.initConfig`"))
errorList = append(errorList, field.Invalid(field.NewPath("spec").Child("initConfig"),
p.Name,
"use either `spec.configSecret` or `spec.initConfig`"))
}

if p.Spec.ConfigSecret != nil {
secret := core.Secret{}
err := DefaultClient.Get(context.TODO(), types.NamespacedName{
Name: p.Spec.ConfigSecret.Name,
Namespace: p.Spec.PostgresRef.Namespace,
}, &secret)
if err != nil {
errorList = append(errorList, field.Invalid(field.NewPath("spec").Child("configSecret"),
p.Name,
err.Error(),
))
}
_, ok := secret.Data["pgpool.conf"]
if !ok {
errorList = append(errorList, field.Invalid(field.NewPath("spec").Child("configSecret"),
p.Name,
"`pgpool.conf` is missing",
))
}
}

apb := appcat.AppBinding{}
err := DefaultClient.Get(context.TODO(), types.NamespacedName{
Name: p.Spec.PostgresRef.Name,
Expand Down
1 change: 1 addition & 0 deletions apis/kubedb/v1alpha2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const (
PrimaryServiceAlias ServiceAlias = "primary"
StandbyServiceAlias ServiceAlias = "standby"
StatsServiceAlias ServiceAlias = "stats"
PcpServiceAlias ServiceAlias = "pcp"
)

// +kubebuilder:validation:Enum=DNS;IP;IPv4;IPv6
Expand Down

0 comments on commit 18fbdb3

Please sign in to comment.