Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pgpool OpsRequest API #1209

Merged
merged 5 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 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
PgpoolPcpPort = 9595
PgpoolExporterDatabase = "postgres"
EnvPgpoolExporterDatabase = "POSTGRES_DATABASE"
EnvPgpoolService = "PGPOOL_SERVICE"
Expand All @@ -596,6 +597,8 @@ const (
PgpoolRootUser = "postgres"
PgpoolPrimaryServicePortName = "primary"
PgpoolDatabasePortName = "db"
PgpoolPcpPortName = "pcp"
PgpoolCustomConfigFile = "pgpool.conf"
// ========================================== ZooKeeper Constants =================================================//

KubeDBZooKeeperRoleName = "kubedb:zookeeper-version-reader"
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"),
MobarakHsn marked this conversation as resolved.
Show resolved Hide resolved
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.Namespace,
}, &secret)
if err != nil {
errorList = append(errorList, field.Invalid(field.NewPath("spec").Child("configSecret"),
p.Name,
err.Error(),
))
}
_, ok := secret.Data[PgpoolCustomConfigFile]
if !ok {
errorList = append(errorList, field.Invalid(field.NewPath("spec").Child("configSecret"),
p.Name,
fmt.Sprintf("`%v` is missing", PgpoolCustomConfigFile),
))
}
}

apb := appcat.AppBinding{}
err := DefaultClient.Get(context.TODO(), types.NamespacedName{
Name: p.Spec.PostgresRef.Name,
Expand Down
227 changes: 227 additions & 0 deletions apis/ops/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions apis/ops/v1alpha1/pgpool_ops_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
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 v1alpha1

import (
"fmt"

"kubedb.dev/apimachinery/apis"
"kubedb.dev/apimachinery/apis/ops"
"kubedb.dev/apimachinery/crds"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"kmodules.xyz/client-go/apiextensions"
)

func (r *PgpoolOpsRequest) CustomResourceDefinition() *apiextensions.CustomResourceDefinition {
return crds.MustCustomResourceDefinition(SchemeGroupVersion.WithResource(ResourcePluralPgpoolOpsRequest))
}

var _ apis.ResourceInfo = &PgpoolOpsRequest{}

func (r *PgpoolOpsRequest) ResourceFQN() string {
return fmt.Sprintf("%s.%s", ResourcePluralPgpoolOpsRequest, ops.GroupName)
}

func (r *PgpoolOpsRequest) ResourceShortCode() string {
return ResourceCodePgpoolOpsRequest
}

func (r *PgpoolOpsRequest) ResourceKind() string {
return ResourceKindPgpoolOpsRequest
}

func (r *PgpoolOpsRequest) ResourceSingular() string {
return ResourceSingularPgpoolOpsRequest
}

func (r *PgpoolOpsRequest) ResourcePlural() string {
return ResourcePluralPgpoolOpsRequest
}

var _ Accessor = &PgpoolOpsRequest{}

func (r *PgpoolOpsRequest) GetObjectMeta() metav1.ObjectMeta {
return r.ObjectMeta
}

func (r *PgpoolOpsRequest) GetDBRefName() string {
return r.Spec.DatabaseRef.Name
}

func (r *PgpoolOpsRequest) GetRequestType() any {
return r.Spec.Type
}

func (r *PgpoolOpsRequest) GetStatus() OpsRequestStatus {
return r.Status
}

func (r *PgpoolOpsRequest) SetStatus(s OpsRequestStatus) {
r.Status = s
}
Loading
Loading