From 063e5bd31ce50c6ec72cf1cc78d0e62d05b83097 Mon Sep 17 00:00:00 2001 From: MobarakHsn Date: Fri, 17 May 2024 19:12:33 +0600 Subject: [PATCH] Add reconfigure ops-request Signed-off-by: MobarakHsn --- apis/kubedb/v1alpha2/constants.go | 1 + apis/kubedb/v1alpha2/pgpool_webhook.go | 8 +-- apis/ops/v1alpha1/openapi_generated.go | 61 +++++++++++++++++----- apis/ops/v1alpha1/pgpool_ops_types.go | 16 +++--- apis/ops/v1alpha1/pgpool_ops_types_enum.go | 5 ++ apis/ops/v1alpha1/zz_generated.deepcopy.go | 49 +++++++++++------ crds/ops.kubedb.com_pgpoolopsrequests.yaml | 17 +++++- 7 files changed, 117 insertions(+), 40 deletions(-) diff --git a/apis/kubedb/v1alpha2/constants.go b/apis/kubedb/v1alpha2/constants.go index bca65c9335..a36c2bdbe7 100644 --- a/apis/kubedb/v1alpha2/constants.go +++ b/apis/kubedb/v1alpha2/constants.go @@ -598,6 +598,7 @@ const ( PgpoolPrimaryServicePortName = "primary" PgpoolDatabasePortName = "db" PgpoolPcpServicePortName = "pcp" + PgpoolCustomConfigFile = "pgpool.conf" // ========================================== ZooKeeper Constants =================================================// KubeDBZooKeeperRoleName = "kubedb:zookeeper-version-reader" diff --git a/apis/kubedb/v1alpha2/pgpool_webhook.go b/apis/kubedb/v1alpha2/pgpool_webhook.go index 308a740ea9..c99bb086e6 100644 --- a/apis/kubedb/v1alpha2/pgpool_webhook.go +++ b/apis/kubedb/v1alpha2/pgpool_webhook.go @@ -121,7 +121,7 @@ func (p *Pgpool) ValidateCreateOrUpdate() field.ErrorList { )) } - if p.Spec.ConfigSecret != nil && (p.Spec.InitConfiguration != nil || p.Spec.InitConfiguration.PgpoolConfig != nil) { + 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`")) @@ -134,7 +134,7 @@ func (p *Pgpool) ValidateCreateOrUpdate() field.ErrorList { secret := core.Secret{} err := DefaultClient.Get(context.TODO(), types.NamespacedName{ Name: p.Spec.ConfigSecret.Name, - Namespace: p.Spec.PostgresRef.Namespace, + Namespace: p.Namespace, }, &secret) if err != nil { errorList = append(errorList, field.Invalid(field.NewPath("spec").Child("configSecret"), @@ -142,11 +142,11 @@ func (p *Pgpool) ValidateCreateOrUpdate() field.ErrorList { err.Error(), )) } - _, ok := secret.Data["pgpool.conf"] + _, ok := secret.Data[PgpoolCustomConfigFile] if !ok { errorList = append(errorList, field.Invalid(field.NewPath("spec").Child("configSecret"), p.Name, - "`pgpool.conf` is missing", + fmt.Sprintf("`%v` is missing", PgpoolCustomConfigFile), )) } } diff --git a/apis/ops/v1alpha1/openapi_generated.go b/apis/ops/v1alpha1/openapi_generated.go index 1c6bae0d06..87be58cd20 100644 --- a/apis/ops/v1alpha1/openapi_generated.go +++ b/apis/ops/v1alpha1/openapi_generated.go @@ -556,10 +556,10 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "kubedb.dev/apimachinery/apis/ops/v1alpha1.PgBouncerReplicaReadinessCriteria": schema_apimachinery_apis_ops_v1alpha1_PgBouncerReplicaReadinessCriteria(ref), "kubedb.dev/apimachinery/apis/ops/v1alpha1.PgBouncerUpdateVersionSpec": schema_apimachinery_apis_ops_v1alpha1_PgBouncerUpdateVersionSpec(ref), "kubedb.dev/apimachinery/apis/ops/v1alpha1.PgBouncerVerticalScalingSpec": schema_apimachinery_apis_ops_v1alpha1_PgBouncerVerticalScalingSpec(ref), + "kubedb.dev/apimachinery/apis/ops/v1alpha1.PgpoolCustomConfigurationSpec": schema_apimachinery_apis_ops_v1alpha1_PgpoolCustomConfigurationSpec(ref), "kubedb.dev/apimachinery/apis/ops/v1alpha1.PgpoolOpsRequest": schema_apimachinery_apis_ops_v1alpha1_PgpoolOpsRequest(ref), "kubedb.dev/apimachinery/apis/ops/v1alpha1.PgpoolOpsRequestList": schema_apimachinery_apis_ops_v1alpha1_PgpoolOpsRequestList(ref), "kubedb.dev/apimachinery/apis/ops/v1alpha1.PgpoolOpsRequestSpec": schema_apimachinery_apis_ops_v1alpha1_PgpoolOpsRequestSpec(ref), - "kubedb.dev/apimachinery/apis/ops/v1alpha1.PgpoolReplicaReadinessCriteria": schema_apimachinery_apis_ops_v1alpha1_PgpoolReplicaReadinessCriteria(ref), "kubedb.dev/apimachinery/apis/ops/v1alpha1.PgpoolVerticalScalingSpec": schema_apimachinery_apis_ops_v1alpha1_PgpoolVerticalScalingSpec(ref), "kubedb.dev/apimachinery/apis/ops/v1alpha1.PodResources": schema_apimachinery_apis_ops_v1alpha1_PodResources(ref), "kubedb.dev/apimachinery/apis/ops/v1alpha1.PostgresCustomConfiguration": schema_apimachinery_apis_ops_v1alpha1_PostgresCustomConfiguration(ref), @@ -26699,6 +26699,46 @@ func schema_apimachinery_apis_ops_v1alpha1_PgBouncerVerticalScalingSpec(ref comm } } +func schema_apimachinery_apis_ops_v1alpha1_PgpoolCustomConfigurationSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "configSecret": { + SchemaProps: spec.SchemaProps{ + Ref: ref("k8s.io/api/core/v1.LocalObjectReference"), + }, + }, + "applyConfig": { + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + "removeCustomConfig": { + SchemaProps: spec.SchemaProps{ + Type: []string{"boolean"}, + Format: "", + }, + }, + }, + }, + }, + Dependencies: []string{ + "k8s.io/api/core/v1.LocalObjectReference"}, + } +} + func schema_apimachinery_apis_ops_v1alpha1_PgpoolOpsRequest(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -26822,6 +26862,12 @@ func schema_apimachinery_apis_ops_v1alpha1_PgpoolOpsRequestSpec(ref common.Refer Ref: ref("kubedb.dev/apimachinery/apis/ops/v1alpha1.PgpoolVerticalScalingSpec"), }, }, + "configuration": { + SchemaProps: spec.SchemaProps{ + Description: "Specifies information necessary for custom configuration of Pgpool", + Ref: ref("kubedb.dev/apimachinery/apis/ops/v1alpha1.PgpoolCustomConfigurationSpec"), + }, + }, "restart": { SchemaProps: spec.SchemaProps{ Description: "Specifies information necessary for restarting database", @@ -26846,18 +26892,7 @@ func schema_apimachinery_apis_ops_v1alpha1_PgpoolOpsRequestSpec(ref common.Refer }, }, Dependencies: []string{ - "k8s.io/api/core/v1.LocalObjectReference", "k8s.io/apimachinery/pkg/apis/meta/v1.Duration", "kubedb.dev/apimachinery/apis/ops/v1alpha1.PgpoolVerticalScalingSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.RestartSpec"}, - } -} - -func schema_apimachinery_apis_ops_v1alpha1_PgpoolReplicaReadinessCriteria(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "PgpoolReplicaReadinessCriteria is the criteria for checking readiness of a Pgpool pod after updating, horizontal scaling etc.", - Type: []string{"object"}, - }, - }, + "k8s.io/api/core/v1.LocalObjectReference", "k8s.io/apimachinery/pkg/apis/meta/v1.Duration", "kubedb.dev/apimachinery/apis/ops/v1alpha1.PgpoolCustomConfigurationSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.PgpoolVerticalScalingSpec", "kubedb.dev/apimachinery/apis/ops/v1alpha1.RestartSpec"}, } } diff --git a/apis/ops/v1alpha1/pgpool_ops_types.go b/apis/ops/v1alpha1/pgpool_ops_types.go index f839259ae8..b0bb8097d1 100644 --- a/apis/ops/v1alpha1/pgpool_ops_types.go +++ b/apis/ops/v1alpha1/pgpool_ops_types.go @@ -56,6 +56,8 @@ type PgpoolOpsRequestSpec struct { Type PgpoolOpsRequestType `json:"type"` // Specifies information necessary for vertical scaling VerticalScaling *PgpoolVerticalScalingSpec `json:"verticalScaling,omitempty"` + // Specifies information necessary for custom configuration of Pgpool + Configuration *PgpoolCustomConfigurationSpec `json:"configuration,omitempty"` // Specifies information necessary for restarting database Restart *RestartSpec `json:"restart,omitempty"` // Timeout for each step of the ops request in second. If a step doesn't finish within the specified timeout, the ops request will result in failure. @@ -65,20 +67,22 @@ type PgpoolOpsRequestSpec struct { Apply ApplyOption `json:"apply,omitempty"` } -// +kubebuilder:validation:Enum=VerticalScaling;VolumeExpansion;Restart -// ENUM(VerticalScaling, Restart) +// +kubebuilder:validation:Enum=VerticalScaling;Reconfigure;Restart +// ENUM(VerticalScaling, Restart, Reconfigure) type PgpoolOpsRequestType string -// PgpoolReplicaReadinessCriteria is the criteria for checking readiness of a Pgpool pod -// after updating, horizontal scaling etc. -type PgpoolReplicaReadinessCriteria struct{} - // PgpoolVerticalScalingSpec contains the vertical scaling information of a Pgpool cluster type PgpoolVerticalScalingSpec struct { // Resource spec for nodes Node *PodResources `json:"node,omitempty"` } +type PgpoolCustomConfigurationSpec struct { + ConfigSecret *core.LocalObjectReference `json:"configSecret,omitempty"` + ApplyConfig map[string]string `json:"applyConfig,omitempty"` + RemoveCustomConfig bool `json:"removeCustomConfig,omitempty"` +} + // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // PgpoolOpsRequestList is a list of PgpoolOpsRequests diff --git a/apis/ops/v1alpha1/pgpool_ops_types_enum.go b/apis/ops/v1alpha1/pgpool_ops_types_enum.go index 1ed3f9c384..b787338018 100644 --- a/apis/ops/v1alpha1/pgpool_ops_types_enum.go +++ b/apis/ops/v1alpha1/pgpool_ops_types_enum.go @@ -16,6 +16,8 @@ const ( PgpoolOpsRequestTypeVerticalScaling PgpoolOpsRequestType = "VerticalScaling" // PgpoolOpsRequestTypeRestart is a PgpoolOpsRequestType of type Restart. PgpoolOpsRequestTypeRestart PgpoolOpsRequestType = "Restart" + // PgpoolOpsRequestTypeReconfigure is a PgpoolOpsRequestType of type Reconfigure. + PgpoolOpsRequestTypeReconfigure PgpoolOpsRequestType = "Reconfigure" ) var ErrInvalidPgpoolOpsRequestType = fmt.Errorf("not a valid PgpoolOpsRequestType, try [%s]", strings.Join(_PgpoolOpsRequestTypeNames, ", ")) @@ -23,6 +25,7 @@ var ErrInvalidPgpoolOpsRequestType = fmt.Errorf("not a valid PgpoolOpsRequestTyp var _PgpoolOpsRequestTypeNames = []string{ string(PgpoolOpsRequestTypeVerticalScaling), string(PgpoolOpsRequestTypeRestart), + string(PgpoolOpsRequestTypeReconfigure), } // PgpoolOpsRequestTypeNames returns a list of possible string values of PgpoolOpsRequestType. @@ -37,6 +40,7 @@ func PgpoolOpsRequestTypeValues() []PgpoolOpsRequestType { return []PgpoolOpsRequestType{ PgpoolOpsRequestTypeVerticalScaling, PgpoolOpsRequestTypeRestart, + PgpoolOpsRequestTypeReconfigure, } } @@ -55,6 +59,7 @@ func (x PgpoolOpsRequestType) IsValid() bool { var _PgpoolOpsRequestTypeValue = map[string]PgpoolOpsRequestType{ "VerticalScaling": PgpoolOpsRequestTypeVerticalScaling, "Restart": PgpoolOpsRequestTypeRestart, + "Reconfigure": PgpoolOpsRequestTypeReconfigure, } // ParsePgpoolOpsRequestType attempts to convert a string to a PgpoolOpsRequestType. diff --git a/apis/ops/v1alpha1/zz_generated.deepcopy.go b/apis/ops/v1alpha1/zz_generated.deepcopy.go index cde0cd6597..d7ae08c6b3 100644 --- a/apis/ops/v1alpha1/zz_generated.deepcopy.go +++ b/apis/ops/v1alpha1/zz_generated.deepcopy.go @@ -2944,6 +2944,34 @@ func (in *PgBouncerVerticalScalingSpec) DeepCopy() *PgBouncerVerticalScalingSpec return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PgpoolCustomConfigurationSpec) DeepCopyInto(out *PgpoolCustomConfigurationSpec) { + *out = *in + if in.ConfigSecret != nil { + in, out := &in.ConfigSecret, &out.ConfigSecret + *out = new(v1.LocalObjectReference) + **out = **in + } + if in.ApplyConfig != nil { + in, out := &in.ApplyConfig, &out.ApplyConfig + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PgpoolCustomConfigurationSpec. +func (in *PgpoolCustomConfigurationSpec) DeepCopy() *PgpoolCustomConfigurationSpec { + if in == nil { + return nil + } + out := new(PgpoolCustomConfigurationSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PgpoolOpsRequest) DeepCopyInto(out *PgpoolOpsRequest) { *out = *in @@ -3014,6 +3042,11 @@ func (in *PgpoolOpsRequestSpec) DeepCopyInto(out *PgpoolOpsRequestSpec) { *out = new(PgpoolVerticalScalingSpec) (*in).DeepCopyInto(*out) } + if in.Configuration != nil { + in, out := &in.Configuration, &out.Configuration + *out = new(PgpoolCustomConfigurationSpec) + (*in).DeepCopyInto(*out) + } if in.Restart != nil { in, out := &in.Restart, &out.Restart *out = new(RestartSpec) @@ -3037,22 +3070,6 @@ func (in *PgpoolOpsRequestSpec) DeepCopy() *PgpoolOpsRequestSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PgpoolReplicaReadinessCriteria) DeepCopyInto(out *PgpoolReplicaReadinessCriteria) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PgpoolReplicaReadinessCriteria. -func (in *PgpoolReplicaReadinessCriteria) DeepCopy() *PgpoolReplicaReadinessCriteria { - if in == nil { - return nil - } - out := new(PgpoolReplicaReadinessCriteria) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PgpoolVerticalScalingSpec) DeepCopyInto(out *PgpoolVerticalScalingSpec) { *out = *in diff --git a/crds/ops.kubedb.com_pgpoolopsrequests.yaml b/crds/ops.kubedb.com_pgpoolopsrequests.yaml index 35140dc24b..98f8ff23bb 100644 --- a/crds/ops.kubedb.com_pgpoolopsrequests.yaml +++ b/crds/ops.kubedb.com_pgpoolopsrequests.yaml @@ -48,6 +48,21 @@ spec: - IfReady - Always type: string + configuration: + properties: + applyConfig: + additionalProperties: + type: string + type: object + configSecret: + properties: + name: + type: string + type: object + x-kubernetes-map-type: atomic + removeCustomConfig: + type: boolean + type: object databaseRef: properties: name: @@ -61,7 +76,7 @@ spec: type: enum: - VerticalScaling - - VolumeExpansion + - Reconfigure - Restart type: string verticalScaling: