Skip to content

Commit

Permalink
Add Pgpool Autoscaler API (#1223)
Browse files Browse the repository at this point in the history
Signed-off-by: MobarakHsn <[email protected]>
  • Loading branch information
MobarakHsn authored May 31, 2024
1 parent b0c77eb commit a0277a7
Show file tree
Hide file tree
Showing 17 changed files with 1,461 additions and 0 deletions.
189 changes: 189 additions & 0 deletions apis/autoscaling/v1alpha1/openapi_generated.go

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

67 changes: 67 additions & 0 deletions apis/autoscaling/v1alpha1/pgpool_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
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/autoscaling"
"kubedb.dev/apimachinery/crds"

"kmodules.xyz/client-go/apiextensions"
)

func (r PgpoolAutoscaler) CustomResourceDefinition() *apiextensions.CustomResourceDefinition {
return crds.MustCustomResourceDefinition(SchemeGroupVersion.WithResource(ResourcePluralPgpoolAutoscaler))
}

var _ apis.ResourceInfo = &PgpoolAutoscaler{}

func (r PgpoolAutoscaler) ResourceFQN() string {
return fmt.Sprintf("%s.%s", ResourcePluralPgpoolAutoscaler, autoscaling.GroupName)
}

func (r PgpoolAutoscaler) ResourceShortCode() string {
return ResourceCodePgpoolAutoscaler
}

func (r PgpoolAutoscaler) ResourceKind() string {
return ResourceKindPgpoolAutoscaler
}

func (r PgpoolAutoscaler) ResourceSingular() string {
return ResourceSingularPgpoolAutoscaler
}

func (r PgpoolAutoscaler) ResourcePlural() string {
return ResourcePluralPgpoolAutoscaler
}

func (r PgpoolAutoscaler) ValidateSpecs() error {
return nil
}

var _ StatusAccessor = &PgpoolAutoscaler{}

func (r *PgpoolAutoscaler) GetStatus() AutoscalerStatus {
return r.Status
}

func (r *PgpoolAutoscaler) SetStatus(s AutoscalerStatus) {
r.Status = s
}
95 changes: 95 additions & 0 deletions apis/autoscaling/v1alpha1/pgpool_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
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 (
opsapi "kubedb.dev/apimachinery/apis/ops/v1alpha1"

core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
ResourceCodePgpoolAutoscaler = "ppscaler"
ResourceKindPgpoolAutoscaler = "PgpoolAutoscaler"
ResourceSingularPgpoolAutoscaler = "pgpoolautoscaler"
ResourcePluralPgpoolAutoscaler = "pgpoolautoscalers"
)

// PgpoolAutoscaler is the configuration for pgpool
// autoscaler, which automatically manages pod resources based on historical and
// real time resource utilization.

// +genclient
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// +kubebuilder:object:root=true
// +kubebuilder:resource:path=pgpoolautoscalers,singular=pgpoolautoscaler,shortName=ppscaler,categories={datastore,kubedb,appscode}
// +kubebuilder:subresource:status
type PgpoolAutoscaler struct {
metav1.TypeMeta `json:",inline"`
// Standard object metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`

// Specification of the behavior of the autoscaler.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status.
Spec PgpoolAutoscalerSpec `json:"spec"`

// Current information about the autoscaler.
// +optional
Status AutoscalerStatus `json:"status,omitempty"`
}

// PgpoolAutoscalerSpec is the specification of the behavior of the autoscaler.
type PgpoolAutoscalerSpec struct {
DatabaseRef *core.LocalObjectReference `json:"databaseRef"`

// This field will be used to control the behaviour of ops-manager
OpsRequestOptions *PgpoolOpsRequestOptions `json:"opsRequestOptions,omitempty"`

Compute *PgpoolComputeAutoscalerSpec `json:"compute,omitempty"`
}

type PgpoolComputeAutoscalerSpec struct {
// +optional
NodeTopology *NodeTopology `json:"nodeTopology,omitempty"`

Pgpool *ComputeAutoscalerSpec `json:"pgpool,omitempty"`
}

type PgpoolOpsRequestOptions struct {
// 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.
Timeout *metav1.Duration `json:"timeout,omitempty"`

// ApplyOption is to control the execution of OpsRequest depending on the database state.
// +kubebuilder:default="IfReady"
Apply opsapi.ApplyOption `json:"apply,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// PgpoolAutoscalerList is a list of PgpoolAutoscaler objects.
type PgpoolAutoscalerList struct {
metav1.TypeMeta `json:",inline"`
// metadata is the standard list metadata.
// +optional
metav1.ListMeta `json:"metadata"`

// items is the list of pgpool database autoscaler objects.
Items []PgpoolAutoscaler `json:"items"`
}
Loading

0 comments on commit a0277a7

Please sign in to comment.