From f622d2d3c1879f0d925dfe523118bd2f49fac30b Mon Sep 17 00:00:00 2001 From: sabbir-hossain70 <103355337+sabbir-hossain70@users.noreply.github.com> Date: Mon, 23 Sep 2024 19:54:46 +0600 Subject: [PATCH] Add Cassandra Autoscaler Api (#1308) Signed-off-by: Sabbir --- .../autoscaling/v1alpha1/cassandra_helpers.go | 67 ++++ apis/autoscaling/v1alpha1/cassandra_types.go | 100 +++++ .../autoscaling/v1alpha1/cassandra_webhook.go | 111 ++++++ .../autoscaling/v1alpha1/openapi_generated.go | 214 +++++++++++ .../v1alpha1/zz_generated.deepcopy.go | 165 +++++++++ .../v1alpha1/autoscaling_client.go | 5 + .../v1alpha1/cassandraautoscaler.go | 196 ++++++++++ .../v1alpha1/fake/fake_autoscaling_client.go | 4 + .../v1alpha1/fake/fake_cassandraautoscaler.go | 142 +++++++ .../v1alpha1/generated_expansion.go | 2 + .../v1alpha1/cassandraautoscaler.go | 91 +++++ .../autoscaling/v1alpha1/interface.go | 7 + client/informers/externalversions/generic.go | 2 + .../v1alpha1/cassandraautoscaler.go | 100 +++++ .../v1alpha1/expansion_generated.go | 8 + ...aling.kubedb.com_cassandraautoscalers.yaml | 345 ++++++++++++++++++ 16 files changed, 1559 insertions(+) create mode 100644 apis/autoscaling/v1alpha1/cassandra_helpers.go create mode 100644 apis/autoscaling/v1alpha1/cassandra_types.go create mode 100644 apis/autoscaling/v1alpha1/cassandra_webhook.go create mode 100644 client/clientset/versioned/typed/autoscaling/v1alpha1/cassandraautoscaler.go create mode 100644 client/clientset/versioned/typed/autoscaling/v1alpha1/fake/fake_cassandraautoscaler.go create mode 100644 client/informers/externalversions/autoscaling/v1alpha1/cassandraautoscaler.go create mode 100644 client/listers/autoscaling/v1alpha1/cassandraautoscaler.go create mode 100644 crds/autoscaling.kubedb.com_cassandraautoscalers.yaml diff --git a/apis/autoscaling/v1alpha1/cassandra_helpers.go b/apis/autoscaling/v1alpha1/cassandra_helpers.go new file mode 100644 index 0000000000..87ce96271d --- /dev/null +++ b/apis/autoscaling/v1alpha1/cassandra_helpers.go @@ -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 CassandraAutoscaler) CustomResourceDefinition() *apiextensions.CustomResourceDefinition { + return crds.MustCustomResourceDefinition(SchemeGroupVersion.WithResource(ResourcePluralCassandraAutoscaler)) +} + +var _ apis.ResourceInfo = &CassandraAutoscaler{} + +func (r CassandraAutoscaler) ResourceFQN() string { + return fmt.Sprintf("%s.%s", ResourcePluralCassandraAutoscaler, autoscaling.GroupName) +} + +func (r CassandraAutoscaler) ResourceShortCode() string { + return ResourceCodeCassandraAutoscaler +} + +func (r CassandraAutoscaler) ResourceKind() string { + return ResourceKindCassandraAutoscaler +} + +func (r CassandraAutoscaler) ResourceSingular() string { + return ResourceSingularCassandraAutoscaler +} + +func (r CassandraAutoscaler) ResourcePlural() string { + return ResourcePluralCassandraAutoscaler +} + +func (r CassandraAutoscaler) ValidateSpecs() error { + return nil +} + +var _ StatusAccessor = &CassandraAutoscaler{} + +func (r *CassandraAutoscaler) GetStatus() AutoscalerStatus { + return r.Status +} + +func (r *CassandraAutoscaler) SetStatus(s AutoscalerStatus) { + r.Status = s +} diff --git a/apis/autoscaling/v1alpha1/cassandra_types.go b/apis/autoscaling/v1alpha1/cassandra_types.go new file mode 100644 index 0000000000..247d6831dc --- /dev/null +++ b/apis/autoscaling/v1alpha1/cassandra_types.go @@ -0,0 +1,100 @@ +/* +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 ( + ResourceCodeCassandraAutoscaler = "casscaler" + ResourceKindCassandraAutoscaler = "CassandraAutoscaler" + ResourceSingularCassandraAutoscaler = "cassandraautoscaler" + ResourcePluralCassandraAutoscaler = "cassandraautoscalers" +) + +// CassandraAutoscaler is the configuration for a cassandra database +// 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=cassandraautoscalers,singular=cassandraautoscaler,shortName=casscaler,categories={autoscaler,kubedb,appscode} +// +kubebuilder:subresource:status +type CassandraAutoscaler 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 CassandraAutoscalerSpec `json:"spec"` + + // Current information about the autoscaler. + // +optional + Status AutoscalerStatus `json:"status,omitempty"` +} + +// CassandraAutoscalerSpec is the specification of the behavior of the autoscaler. +type CassandraAutoscalerSpec struct { + DatabaseRef *core.LocalObjectReference `json:"databaseRef"` + + // This field will be used to control the behaviour of ops-manager + OpsRequestOptions *CassandraOpsRequestOptions `json:"opsRequestOptions,omitempty"` + + Compute *CassandraComputeAutoscalerSpec `json:"compute,omitempty"` + Storage *CassandraStorageAutoscalerSpec `json:"storage,omitempty"` +} + +type CassandraComputeAutoscalerSpec struct { + // +optional + NodeTopology *NodeTopology `json:"nodeTopology,omitempty"` + + Cassandra *ComputeAutoscalerSpec `json:"cassandra,omitempty"` +} + +type CassandraStorageAutoscalerSpec struct { + Cassandra *StorageAutoscalerSpec `json:"cassandra,omitempty"` +} + +type CassandraOpsRequestOptions 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 +// CassandraAutoscalerList is a list of CassandraAutoscaler objects. +type CassandraAutoscalerList struct { + metav1.TypeMeta `json:",inline"` + // metadata is the standard list metadata. + // +optional + metav1.ListMeta `json:"metadata"` + + // items is the list of cassandra database autoscaler objects. + Items []CassandraAutoscaler `json:"items"` +} diff --git a/apis/autoscaling/v1alpha1/cassandra_webhook.go b/apis/autoscaling/v1alpha1/cassandra_webhook.go new file mode 100644 index 0000000000..9c470354d9 --- /dev/null +++ b/apis/autoscaling/v1alpha1/cassandra_webhook.go @@ -0,0 +1,111 @@ +/* +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 ( + "context" + "errors" + "fmt" + + olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2" + opsapi "kubedb.dev/apimachinery/apis/ops/v1alpha1" + + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/webhook" + "sigs.k8s.io/controller-runtime/pkg/webhook/admission" +) + +// log is for logging in this package. +var casLog = logf.Log.WithName("cassandra-autoscaler") + +var _ webhook.Defaulter = &CassandraAutoscaler{} + +// Default implements webhook.CustomDefaulter so a webhook will be registered for the type +func (r *CassandraAutoscaler) Default() { + casLog.Info("defaulting", "name", r.Name) + r.setDefaults() +} + +func (r *CassandraAutoscaler) setDefaults() { + var db olddbapi.Cassandra + err := DefaultClient.Get(context.TODO(), types.NamespacedName{ + Name: r.Spec.DatabaseRef.Name, + Namespace: r.Namespace, + }, &db) + if err != nil { + _ = fmt.Errorf("can't get Cassandra %s/%s \n", r.Namespace, r.Spec.DatabaseRef.Name) + return + } + + r.setOpsReqOptsDefaults() + + if r.Spec.Storage != nil { + setDefaultStorageValues(r.Spec.Storage.Cassandra) + } + + if r.Spec.Compute != nil { + setDefaultComputeValues(r.Spec.Compute.Cassandra) + } +} + +func (r *CassandraAutoscaler) setOpsReqOptsDefaults() { + if r.Spec.OpsRequestOptions == nil { + r.Spec.OpsRequestOptions = &CassandraOpsRequestOptions{} + } + // Timeout is defaulted to 600s in ops-manager retries.go (to retry 120 times with 5sec pause between each) + // OplogMaxLagSeconds & ObjectsCountDiffPercentage are defaults to 0 + if r.Spec.OpsRequestOptions.Apply == "" { + r.Spec.OpsRequestOptions.Apply = opsapi.ApplyOptionIfReady + } +} + +var _ webhook.Validator = &CassandraAutoscaler{} + +// ValidateCreate implements webhook.Validator so a webhook will be registered for the type +func (r *CassandraAutoscaler) ValidateCreate() (admission.Warnings, error) { + casLog.Info("validate create", "name", r.Name) + return nil, r.validate() +} + +// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type +func (r *CassandraAutoscaler) ValidateUpdate(oldObj runtime.Object) (admission.Warnings, error) { + casLog.Info("validate create", "name", r.Name) + return nil, r.validate() +} + +func (r *CassandraAutoscaler) ValidateDelete() (admission.Warnings, error) { + return nil, nil +} + +func (r *CassandraAutoscaler) validate() error { + if r.Spec.DatabaseRef == nil { + return errors.New("databaseRef can't be empty") + } + var kf olddbapi.Cassandra + err := DefaultClient.Get(context.TODO(), types.NamespacedName{ + Name: r.Spec.DatabaseRef.Name, + Namespace: r.Namespace, + }, &kf) + if err != nil { + _ = fmt.Errorf("can't get Cassandra %s/%s \n", r.Namespace, r.Spec.DatabaseRef.Name) + return err + } + + return nil +} diff --git a/apis/autoscaling/v1alpha1/openapi_generated.go b/apis/autoscaling/v1alpha1/openapi_generated.go index df43276508..cd42a80e4d 100644 --- a/apis/autoscaling/v1alpha1/openapi_generated.go +++ b/apis/autoscaling/v1alpha1/openapi_generated.go @@ -489,6 +489,12 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "kmodules.xyz/offshoot-api/api/v1.VolumeSource": schema_kmodulesxyz_offshoot_api_api_v1_VolumeSource(ref), "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.AutoscalerStatus": schema_apimachinery_apis_autoscaling_v1alpha1_AutoscalerStatus(ref), "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.BucketWeight": schema_apimachinery_apis_autoscaling_v1alpha1_BucketWeight(ref), + "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.CassandraAutoscaler": schema_apimachinery_apis_autoscaling_v1alpha1_CassandraAutoscaler(ref), + "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.CassandraAutoscalerList": schema_apimachinery_apis_autoscaling_v1alpha1_CassandraAutoscalerList(ref), + "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.CassandraAutoscalerSpec": schema_apimachinery_apis_autoscaling_v1alpha1_CassandraAutoscalerSpec(ref), + "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.CassandraComputeAutoscalerSpec": schema_apimachinery_apis_autoscaling_v1alpha1_CassandraComputeAutoscalerSpec(ref), + "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.CassandraOpsRequestOptions": schema_apimachinery_apis_autoscaling_v1alpha1_CassandraOpsRequestOptions(ref), + "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.CassandraStorageAutoscalerSpec": schema_apimachinery_apis_autoscaling_v1alpha1_CassandraStorageAutoscalerSpec(ref), "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.Checkpoint": schema_apimachinery_apis_autoscaling_v1alpha1_Checkpoint(ref), "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.CheckpointReference": schema_apimachinery_apis_autoscaling_v1alpha1_CheckpointReference(ref), "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.ClickHouseAutoscaler": schema_apimachinery_apis_autoscaling_v1alpha1_ClickHouseAutoscaler(ref), @@ -25337,6 +25343,214 @@ func schema_apimachinery_apis_autoscaling_v1alpha1_BucketWeight(ref common.Refer } } +func schema_apimachinery_apis_autoscaling_v1alpha1_CassandraAutoscaler(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Description: "Standard object metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata", + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), + }, + }, + "spec": { + SchemaProps: spec.SchemaProps{ + Description: "Specification of the behavior of the autoscaler. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status.", + Default: map[string]interface{}{}, + Ref: ref("kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.CassandraAutoscalerSpec"), + }, + }, + "status": { + SchemaProps: spec.SchemaProps{ + Description: "Current information about the autoscaler.", + Default: map[string]interface{}{}, + Ref: ref("kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.AutoscalerStatus"), + }, + }, + }, + Required: []string{"spec"}, + }, + }, + Dependencies: []string{ + "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta", "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.AutoscalerStatus", "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.CassandraAutoscalerSpec"}, + } +} + +func schema_apimachinery_apis_autoscaling_v1alpha1_CassandraAutoscalerList(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "CassandraAutoscalerList is a list of CassandraAutoscaler objects.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Description: "metadata is the standard list metadata.", + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), + }, + }, + "items": { + SchemaProps: spec.SchemaProps{ + Description: "items is the list of cassandra database autoscaler objects.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.CassandraAutoscaler"), + }, + }, + }, + }, + }, + }, + Required: []string{"items"}, + }, + }, + Dependencies: []string{ + "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta", "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.CassandraAutoscaler"}, + } +} + +func schema_apimachinery_apis_autoscaling_v1alpha1_CassandraAutoscalerSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "CassandraAutoscalerSpec is the specification of the behavior of the autoscaler.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "databaseRef": { + SchemaProps: spec.SchemaProps{ + Ref: ref("k8s.io/api/core/v1.LocalObjectReference"), + }, + }, + "opsRequestOptions": { + SchemaProps: spec.SchemaProps{ + Description: "This field will be used to control the behaviour of ops-manager", + Ref: ref("kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.CassandraOpsRequestOptions"), + }, + }, + "compute": { + SchemaProps: spec.SchemaProps{ + Ref: ref("kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.CassandraComputeAutoscalerSpec"), + }, + }, + "storage": { + SchemaProps: spec.SchemaProps{ + Ref: ref("kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.CassandraStorageAutoscalerSpec"), + }, + }, + }, + Required: []string{"databaseRef"}, + }, + }, + Dependencies: []string{ + "k8s.io/api/core/v1.LocalObjectReference", "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.CassandraComputeAutoscalerSpec", "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.CassandraOpsRequestOptions", "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.CassandraStorageAutoscalerSpec"}, + } +} + +func schema_apimachinery_apis_autoscaling_v1alpha1_CassandraComputeAutoscalerSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "nodeTopology": { + SchemaProps: spec.SchemaProps{ + Ref: ref("kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.NodeTopology"), + }, + }, + "cassandra": { + SchemaProps: spec.SchemaProps{ + Ref: ref("kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.ComputeAutoscalerSpec"), + }, + }, + }, + }, + }, + Dependencies: []string{ + "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.ComputeAutoscalerSpec", "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.NodeTopology"}, + } +} + +func schema_apimachinery_apis_autoscaling_v1alpha1_CassandraOpsRequestOptions(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "timeout": { + SchemaProps: spec.SchemaProps{ + Description: "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.", + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.Duration"), + }, + }, + "apply": { + SchemaProps: spec.SchemaProps{ + Description: "ApplyOption is to control the execution of OpsRequest depending on the database state.", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + Dependencies: []string{ + "k8s.io/apimachinery/pkg/apis/meta/v1.Duration"}, + } +} + +func schema_apimachinery_apis_autoscaling_v1alpha1_CassandraStorageAutoscalerSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "cassandra": { + SchemaProps: spec.SchemaProps{ + Ref: ref("kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.StorageAutoscalerSpec"), + }, + }, + }, + }, + }, + Dependencies: []string{ + "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1.StorageAutoscalerSpec"}, + } +} + func schema_apimachinery_apis_autoscaling_v1alpha1_Checkpoint(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/apis/autoscaling/v1alpha1/zz_generated.deepcopy.go b/apis/autoscaling/v1alpha1/zz_generated.deepcopy.go index 5f600faafa..d3e713bb4e 100644 --- a/apis/autoscaling/v1alpha1/zz_generated.deepcopy.go +++ b/apis/autoscaling/v1alpha1/zz_generated.deepcopy.go @@ -84,6 +84,171 @@ func (in *BucketWeight) DeepCopy() *BucketWeight { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CassandraAutoscaler) DeepCopyInto(out *CassandraAutoscaler) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CassandraAutoscaler. +func (in *CassandraAutoscaler) DeepCopy() *CassandraAutoscaler { + if in == nil { + return nil + } + out := new(CassandraAutoscaler) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *CassandraAutoscaler) 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 *CassandraAutoscalerList) DeepCopyInto(out *CassandraAutoscalerList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]CassandraAutoscaler, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CassandraAutoscalerList. +func (in *CassandraAutoscalerList) DeepCopy() *CassandraAutoscalerList { + if in == nil { + return nil + } + out := new(CassandraAutoscalerList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *CassandraAutoscalerList) 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 *CassandraAutoscalerSpec) DeepCopyInto(out *CassandraAutoscalerSpec) { + *out = *in + if in.DatabaseRef != nil { + in, out := &in.DatabaseRef, &out.DatabaseRef + *out = new(corev1.LocalObjectReference) + **out = **in + } + if in.OpsRequestOptions != nil { + in, out := &in.OpsRequestOptions, &out.OpsRequestOptions + *out = new(CassandraOpsRequestOptions) + (*in).DeepCopyInto(*out) + } + if in.Compute != nil { + in, out := &in.Compute, &out.Compute + *out = new(CassandraComputeAutoscalerSpec) + (*in).DeepCopyInto(*out) + } + if in.Storage != nil { + in, out := &in.Storage, &out.Storage + *out = new(CassandraStorageAutoscalerSpec) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CassandraAutoscalerSpec. +func (in *CassandraAutoscalerSpec) DeepCopy() *CassandraAutoscalerSpec { + if in == nil { + return nil + } + out := new(CassandraAutoscalerSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CassandraComputeAutoscalerSpec) DeepCopyInto(out *CassandraComputeAutoscalerSpec) { + *out = *in + if in.NodeTopology != nil { + in, out := &in.NodeTopology, &out.NodeTopology + *out = new(NodeTopology) + (*in).DeepCopyInto(*out) + } + if in.Cassandra != nil { + in, out := &in.Cassandra, &out.Cassandra + *out = new(ComputeAutoscalerSpec) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CassandraComputeAutoscalerSpec. +func (in *CassandraComputeAutoscalerSpec) DeepCopy() *CassandraComputeAutoscalerSpec { + if in == nil { + return nil + } + out := new(CassandraComputeAutoscalerSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CassandraOpsRequestOptions) DeepCopyInto(out *CassandraOpsRequestOptions) { + *out = *in + if in.Timeout != nil { + in, out := &in.Timeout, &out.Timeout + *out = new(metav1.Duration) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CassandraOpsRequestOptions. +func (in *CassandraOpsRequestOptions) DeepCopy() *CassandraOpsRequestOptions { + if in == nil { + return nil + } + out := new(CassandraOpsRequestOptions) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CassandraStorageAutoscalerSpec) DeepCopyInto(out *CassandraStorageAutoscalerSpec) { + *out = *in + if in.Cassandra != nil { + in, out := &in.Cassandra, &out.Cassandra + *out = new(StorageAutoscalerSpec) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CassandraStorageAutoscalerSpec. +func (in *CassandraStorageAutoscalerSpec) DeepCopy() *CassandraStorageAutoscalerSpec { + if in == nil { + return nil + } + out := new(CassandraStorageAutoscalerSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Checkpoint) DeepCopyInto(out *Checkpoint) { *out = *in diff --git a/client/clientset/versioned/typed/autoscaling/v1alpha1/autoscaling_client.go b/client/clientset/versioned/typed/autoscaling/v1alpha1/autoscaling_client.go index f0b8c92502..dcbe8c5601 100644 --- a/client/clientset/versioned/typed/autoscaling/v1alpha1/autoscaling_client.go +++ b/client/clientset/versioned/typed/autoscaling/v1alpha1/autoscaling_client.go @@ -29,6 +29,7 @@ import ( type AutoscalingV1alpha1Interface interface { RESTClient() rest.Interface + CassandraAutoscalersGetter ClickHouseAutoscalersGetter DruidAutoscalersGetter ElasticsearchAutoscalersGetter @@ -58,6 +59,10 @@ type AutoscalingV1alpha1Client struct { restClient rest.Interface } +func (c *AutoscalingV1alpha1Client) CassandraAutoscalers(namespace string) CassandraAutoscalerInterface { + return newCassandraAutoscalers(c, namespace) +} + func (c *AutoscalingV1alpha1Client) ClickHouseAutoscalers(namespace string) ClickHouseAutoscalerInterface { return newClickHouseAutoscalers(c, namespace) } diff --git a/client/clientset/versioned/typed/autoscaling/v1alpha1/cassandraautoscaler.go b/client/clientset/versioned/typed/autoscaling/v1alpha1/cassandraautoscaler.go new file mode 100644 index 0000000000..4b9eb743e3 --- /dev/null +++ b/client/clientset/versioned/typed/autoscaling/v1alpha1/cassandraautoscaler.go @@ -0,0 +1,196 @@ +/* +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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + "time" + + v1alpha1 "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1" + scheme "kubedb.dev/apimachinery/client/clientset/versioned/scheme" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// CassandraAutoscalersGetter has a method to return a CassandraAutoscalerInterface. +// A group's client should implement this interface. +type CassandraAutoscalersGetter interface { + CassandraAutoscalers(namespace string) CassandraAutoscalerInterface +} + +// CassandraAutoscalerInterface has methods to work with CassandraAutoscaler resources. +type CassandraAutoscalerInterface interface { + Create(ctx context.Context, cassandraAutoscaler *v1alpha1.CassandraAutoscaler, opts v1.CreateOptions) (*v1alpha1.CassandraAutoscaler, error) + Update(ctx context.Context, cassandraAutoscaler *v1alpha1.CassandraAutoscaler, opts v1.UpdateOptions) (*v1alpha1.CassandraAutoscaler, error) + UpdateStatus(ctx context.Context, cassandraAutoscaler *v1alpha1.CassandraAutoscaler, opts v1.UpdateOptions) (*v1alpha1.CassandraAutoscaler, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.CassandraAutoscaler, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.CassandraAutoscalerList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CassandraAutoscaler, err error) + CassandraAutoscalerExpansion +} + +// cassandraAutoscalers implements CassandraAutoscalerInterface +type cassandraAutoscalers struct { + client rest.Interface + ns string +} + +// newCassandraAutoscalers returns a CassandraAutoscalers +func newCassandraAutoscalers(c *AutoscalingV1alpha1Client, namespace string) *cassandraAutoscalers { + return &cassandraAutoscalers{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the cassandraAutoscaler, and returns the corresponding cassandraAutoscaler object, and an error if there is any. +func (c *cassandraAutoscalers) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.CassandraAutoscaler, err error) { + result = &v1alpha1.CassandraAutoscaler{} + err = c.client.Get(). + Namespace(c.ns). + Resource("cassandraautoscalers"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of CassandraAutoscalers that match those selectors. +func (c *cassandraAutoscalers) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.CassandraAutoscalerList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.CassandraAutoscalerList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("cassandraautoscalers"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested cassandraAutoscalers. +func (c *cassandraAutoscalers) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("cassandraautoscalers"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a cassandraAutoscaler and creates it. Returns the server's representation of the cassandraAutoscaler, and an error, if there is any. +func (c *cassandraAutoscalers) Create(ctx context.Context, cassandraAutoscaler *v1alpha1.CassandraAutoscaler, opts v1.CreateOptions) (result *v1alpha1.CassandraAutoscaler, err error) { + result = &v1alpha1.CassandraAutoscaler{} + err = c.client.Post(). + Namespace(c.ns). + Resource("cassandraautoscalers"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(cassandraAutoscaler). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a cassandraAutoscaler and updates it. Returns the server's representation of the cassandraAutoscaler, and an error, if there is any. +func (c *cassandraAutoscalers) Update(ctx context.Context, cassandraAutoscaler *v1alpha1.CassandraAutoscaler, opts v1.UpdateOptions) (result *v1alpha1.CassandraAutoscaler, err error) { + result = &v1alpha1.CassandraAutoscaler{} + err = c.client.Put(). + Namespace(c.ns). + Resource("cassandraautoscalers"). + Name(cassandraAutoscaler.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(cassandraAutoscaler). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *cassandraAutoscalers) UpdateStatus(ctx context.Context, cassandraAutoscaler *v1alpha1.CassandraAutoscaler, opts v1.UpdateOptions) (result *v1alpha1.CassandraAutoscaler, err error) { + result = &v1alpha1.CassandraAutoscaler{} + err = c.client.Put(). + Namespace(c.ns). + Resource("cassandraautoscalers"). + Name(cassandraAutoscaler.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(cassandraAutoscaler). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the cassandraAutoscaler and deletes it. Returns an error if one occurs. +func (c *cassandraAutoscalers) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("cassandraautoscalers"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *cassandraAutoscalers) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("cassandraautoscalers"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched cassandraAutoscaler. +func (c *cassandraAutoscalers) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CassandraAutoscaler, err error) { + result = &v1alpha1.CassandraAutoscaler{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("cassandraautoscalers"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/client/clientset/versioned/typed/autoscaling/v1alpha1/fake/fake_autoscaling_client.go b/client/clientset/versioned/typed/autoscaling/v1alpha1/fake/fake_autoscaling_client.go index a7a3a384fd..1d70f0ae3e 100644 --- a/client/clientset/versioned/typed/autoscaling/v1alpha1/fake/fake_autoscaling_client.go +++ b/client/clientset/versioned/typed/autoscaling/v1alpha1/fake/fake_autoscaling_client.go @@ -29,6 +29,10 @@ type FakeAutoscalingV1alpha1 struct { *testing.Fake } +func (c *FakeAutoscalingV1alpha1) CassandraAutoscalers(namespace string) v1alpha1.CassandraAutoscalerInterface { + return &FakeCassandraAutoscalers{c, namespace} +} + func (c *FakeAutoscalingV1alpha1) ClickHouseAutoscalers(namespace string) v1alpha1.ClickHouseAutoscalerInterface { return &FakeClickHouseAutoscalers{c, namespace} } diff --git a/client/clientset/versioned/typed/autoscaling/v1alpha1/fake/fake_cassandraautoscaler.go b/client/clientset/versioned/typed/autoscaling/v1alpha1/fake/fake_cassandraautoscaler.go new file mode 100644 index 0000000000..92b4f3d083 --- /dev/null +++ b/client/clientset/versioned/typed/autoscaling/v1alpha1/fake/fake_cassandraautoscaler.go @@ -0,0 +1,142 @@ +/* +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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1alpha1 "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeCassandraAutoscalers implements CassandraAutoscalerInterface +type FakeCassandraAutoscalers struct { + Fake *FakeAutoscalingV1alpha1 + ns string +} + +var cassandraautoscalersResource = v1alpha1.SchemeGroupVersion.WithResource("cassandraautoscalers") + +var cassandraautoscalersKind = v1alpha1.SchemeGroupVersion.WithKind("CassandraAutoscaler") + +// Get takes name of the cassandraAutoscaler, and returns the corresponding cassandraAutoscaler object, and an error if there is any. +func (c *FakeCassandraAutoscalers) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.CassandraAutoscaler, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(cassandraautoscalersResource, c.ns, name), &v1alpha1.CassandraAutoscaler{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.CassandraAutoscaler), err +} + +// List takes label and field selectors, and returns the list of CassandraAutoscalers that match those selectors. +func (c *FakeCassandraAutoscalers) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.CassandraAutoscalerList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(cassandraautoscalersResource, cassandraautoscalersKind, c.ns, opts), &v1alpha1.CassandraAutoscalerList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.CassandraAutoscalerList{ListMeta: obj.(*v1alpha1.CassandraAutoscalerList).ListMeta} + for _, item := range obj.(*v1alpha1.CassandraAutoscalerList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested cassandraAutoscalers. +func (c *FakeCassandraAutoscalers) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(cassandraautoscalersResource, c.ns, opts)) + +} + +// Create takes the representation of a cassandraAutoscaler and creates it. Returns the server's representation of the cassandraAutoscaler, and an error, if there is any. +func (c *FakeCassandraAutoscalers) Create(ctx context.Context, cassandraAutoscaler *v1alpha1.CassandraAutoscaler, opts v1.CreateOptions) (result *v1alpha1.CassandraAutoscaler, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(cassandraautoscalersResource, c.ns, cassandraAutoscaler), &v1alpha1.CassandraAutoscaler{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.CassandraAutoscaler), err +} + +// Update takes the representation of a cassandraAutoscaler and updates it. Returns the server's representation of the cassandraAutoscaler, and an error, if there is any. +func (c *FakeCassandraAutoscalers) Update(ctx context.Context, cassandraAutoscaler *v1alpha1.CassandraAutoscaler, opts v1.UpdateOptions) (result *v1alpha1.CassandraAutoscaler, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(cassandraautoscalersResource, c.ns, cassandraAutoscaler), &v1alpha1.CassandraAutoscaler{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.CassandraAutoscaler), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeCassandraAutoscalers) UpdateStatus(ctx context.Context, cassandraAutoscaler *v1alpha1.CassandraAutoscaler, opts v1.UpdateOptions) (*v1alpha1.CassandraAutoscaler, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(cassandraautoscalersResource, "status", c.ns, cassandraAutoscaler), &v1alpha1.CassandraAutoscaler{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.CassandraAutoscaler), err +} + +// Delete takes name of the cassandraAutoscaler and deletes it. Returns an error if one occurs. +func (c *FakeCassandraAutoscalers) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(cassandraautoscalersResource, c.ns, name, opts), &v1alpha1.CassandraAutoscaler{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeCassandraAutoscalers) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(cassandraautoscalersResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha1.CassandraAutoscalerList{}) + return err +} + +// Patch applies the patch and returns the patched cassandraAutoscaler. +func (c *FakeCassandraAutoscalers) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.CassandraAutoscaler, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(cassandraautoscalersResource, c.ns, name, pt, data, subresources...), &v1alpha1.CassandraAutoscaler{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.CassandraAutoscaler), err +} diff --git a/client/clientset/versioned/typed/autoscaling/v1alpha1/generated_expansion.go b/client/clientset/versioned/typed/autoscaling/v1alpha1/generated_expansion.go index e3467456f6..e31550aeb0 100644 --- a/client/clientset/versioned/typed/autoscaling/v1alpha1/generated_expansion.go +++ b/client/clientset/versioned/typed/autoscaling/v1alpha1/generated_expansion.go @@ -18,6 +18,8 @@ limitations under the License. package v1alpha1 +type CassandraAutoscalerExpansion interface{} + type ClickHouseAutoscalerExpansion interface{} type DruidAutoscalerExpansion interface{} diff --git a/client/informers/externalversions/autoscaling/v1alpha1/cassandraautoscaler.go b/client/informers/externalversions/autoscaling/v1alpha1/cassandraautoscaler.go new file mode 100644 index 0000000000..520b125a1e --- /dev/null +++ b/client/informers/externalversions/autoscaling/v1alpha1/cassandraautoscaler.go @@ -0,0 +1,91 @@ +/* +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. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + time "time" + + autoscalingv1alpha1 "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1" + versioned "kubedb.dev/apimachinery/client/clientset/versioned" + internalinterfaces "kubedb.dev/apimachinery/client/informers/externalversions/internalinterfaces" + v1alpha1 "kubedb.dev/apimachinery/client/listers/autoscaling/v1alpha1" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// CassandraAutoscalerInformer provides access to a shared informer and lister for +// CassandraAutoscalers. +type CassandraAutoscalerInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.CassandraAutoscalerLister +} + +type cassandraAutoscalerInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewCassandraAutoscalerInformer constructs a new informer for CassandraAutoscaler type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewCassandraAutoscalerInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredCassandraAutoscalerInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredCassandraAutoscalerInformer constructs a new informer for CassandraAutoscaler type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredCassandraAutoscalerInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.AutoscalingV1alpha1().CassandraAutoscalers(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.AutoscalingV1alpha1().CassandraAutoscalers(namespace).Watch(context.TODO(), options) + }, + }, + &autoscalingv1alpha1.CassandraAutoscaler{}, + resyncPeriod, + indexers, + ) +} + +func (f *cassandraAutoscalerInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredCassandraAutoscalerInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *cassandraAutoscalerInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&autoscalingv1alpha1.CassandraAutoscaler{}, f.defaultInformer) +} + +func (f *cassandraAutoscalerInformer) Lister() v1alpha1.CassandraAutoscalerLister { + return v1alpha1.NewCassandraAutoscalerLister(f.Informer().GetIndexer()) +} diff --git a/client/informers/externalversions/autoscaling/v1alpha1/interface.go b/client/informers/externalversions/autoscaling/v1alpha1/interface.go index 5fa305b7e7..0395f63741 100644 --- a/client/informers/externalversions/autoscaling/v1alpha1/interface.go +++ b/client/informers/externalversions/autoscaling/v1alpha1/interface.go @@ -24,6 +24,8 @@ import ( // Interface provides access to all the informers in this group version. type Interface interface { + // CassandraAutoscalers returns a CassandraAutoscalerInformer. + CassandraAutoscalers() CassandraAutoscalerInformer // ClickHouseAutoscalers returns a ClickHouseAutoscalerInformer. ClickHouseAutoscalers() ClickHouseAutoscalerInformer // DruidAutoscalers returns a DruidAutoscalerInformer. @@ -81,6 +83,11 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } +// CassandraAutoscalers returns a CassandraAutoscalerInformer. +func (v *version) CassandraAutoscalers() CassandraAutoscalerInformer { + return &cassandraAutoscalerInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + // ClickHouseAutoscalers returns a ClickHouseAutoscalerInformer. func (v *version) ClickHouseAutoscalers() ClickHouseAutoscalerInformer { return &clickHouseAutoscalerInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} diff --git a/client/informers/externalversions/generic.go b/client/informers/externalversions/generic.go index d13509226e..1939f851de 100644 --- a/client/informers/externalversions/generic.go +++ b/client/informers/externalversions/generic.go @@ -75,6 +75,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.Archiver().V1alpha1().PostgresArchivers().Informer()}, nil // Group=autoscaling.kubedb.com, Version=v1alpha1 + case autoscalingv1alpha1.SchemeGroupVersion.WithResource("cassandraautoscalers"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Autoscaling().V1alpha1().CassandraAutoscalers().Informer()}, nil case autoscalingv1alpha1.SchemeGroupVersion.WithResource("clickhouseautoscalers"): return &genericInformer{resource: resource.GroupResource(), informer: f.Autoscaling().V1alpha1().ClickHouseAutoscalers().Informer()}, nil case autoscalingv1alpha1.SchemeGroupVersion.WithResource("druidautoscalers"): diff --git a/client/listers/autoscaling/v1alpha1/cassandraautoscaler.go b/client/listers/autoscaling/v1alpha1/cassandraautoscaler.go new file mode 100644 index 0000000000..1288d53410 --- /dev/null +++ b/client/listers/autoscaling/v1alpha1/cassandraautoscaler.go @@ -0,0 +1,100 @@ +/* +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. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "kubedb.dev/apimachinery/apis/autoscaling/v1alpha1" + + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// CassandraAutoscalerLister helps list CassandraAutoscalers. +// All objects returned here must be treated as read-only. +type CassandraAutoscalerLister interface { + // List lists all CassandraAutoscalers in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.CassandraAutoscaler, err error) + // CassandraAutoscalers returns an object that can list and get CassandraAutoscalers. + CassandraAutoscalers(namespace string) CassandraAutoscalerNamespaceLister + CassandraAutoscalerListerExpansion +} + +// cassandraAutoscalerLister implements the CassandraAutoscalerLister interface. +type cassandraAutoscalerLister struct { + indexer cache.Indexer +} + +// NewCassandraAutoscalerLister returns a new CassandraAutoscalerLister. +func NewCassandraAutoscalerLister(indexer cache.Indexer) CassandraAutoscalerLister { + return &cassandraAutoscalerLister{indexer: indexer} +} + +// List lists all CassandraAutoscalers in the indexer. +func (s *cassandraAutoscalerLister) List(selector labels.Selector) (ret []*v1alpha1.CassandraAutoscaler, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.CassandraAutoscaler)) + }) + return ret, err +} + +// CassandraAutoscalers returns an object that can list and get CassandraAutoscalers. +func (s *cassandraAutoscalerLister) CassandraAutoscalers(namespace string) CassandraAutoscalerNamespaceLister { + return cassandraAutoscalerNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// CassandraAutoscalerNamespaceLister helps list and get CassandraAutoscalers. +// All objects returned here must be treated as read-only. +type CassandraAutoscalerNamespaceLister interface { + // List lists all CassandraAutoscalers in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.CassandraAutoscaler, err error) + // Get retrieves the CassandraAutoscaler from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha1.CassandraAutoscaler, error) + CassandraAutoscalerNamespaceListerExpansion +} + +// cassandraAutoscalerNamespaceLister implements the CassandraAutoscalerNamespaceLister +// interface. +type cassandraAutoscalerNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all CassandraAutoscalers in the indexer for a given namespace. +func (s cassandraAutoscalerNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.CassandraAutoscaler, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.CassandraAutoscaler)) + }) + return ret, err +} + +// Get retrieves the CassandraAutoscaler from the indexer for a given namespace and name. +func (s cassandraAutoscalerNamespaceLister) Get(name string) (*v1alpha1.CassandraAutoscaler, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("cassandraautoscaler"), name) + } + return obj.(*v1alpha1.CassandraAutoscaler), nil +} diff --git a/client/listers/autoscaling/v1alpha1/expansion_generated.go b/client/listers/autoscaling/v1alpha1/expansion_generated.go index bc4bcc1a44..2604c74c36 100644 --- a/client/listers/autoscaling/v1alpha1/expansion_generated.go +++ b/client/listers/autoscaling/v1alpha1/expansion_generated.go @@ -18,6 +18,14 @@ limitations under the License. package v1alpha1 +// CassandraAutoscalerListerExpansion allows custom methods to be added to +// CassandraAutoscalerLister. +type CassandraAutoscalerListerExpansion interface{} + +// CassandraAutoscalerNamespaceListerExpansion allows custom methods to be added to +// CassandraAutoscalerNamespaceLister. +type CassandraAutoscalerNamespaceListerExpansion interface{} + // ClickHouseAutoscalerListerExpansion allows custom methods to be added to // ClickHouseAutoscalerLister. type ClickHouseAutoscalerListerExpansion interface{} diff --git a/crds/autoscaling.kubedb.com_cassandraautoscalers.yaml b/crds/autoscaling.kubedb.com_cassandraautoscalers.yaml new file mode 100644 index 0000000000..b999887477 --- /dev/null +++ b/crds/autoscaling.kubedb.com_cassandraautoscalers.yaml @@ -0,0 +1,345 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + creationTimestamp: null + labels: + app.kubernetes.io/name: kubedb + name: cassandraautoscalers.autoscaling.kubedb.com +spec: + group: autoscaling.kubedb.com + names: + categories: + - autoscaler + - kubedb + - appscode + kind: CassandraAutoscaler + listKind: CassandraAutoscalerList + plural: cassandraautoscalers + shortNames: + - casscaler + singular: cassandraautoscaler + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + properties: + apiVersion: + type: string + kind: + type: string + metadata: + type: object + spec: + properties: + compute: + properties: + cassandra: + properties: + containerControlledValues: + enum: + - RequestsAndLimits + - RequestsOnly + type: string + controlledResources: + items: + type: string + type: array + inMemoryStorage: + properties: + scalingFactorPercentage: + format: int32 + type: integer + usageThresholdPercentage: + format: int32 + type: integer + type: object + maxAllowed: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + minAllowed: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + podLifeTimeThreshold: + type: string + resourceDiffPercentage: + format: int32 + type: integer + trigger: + type: string + type: object + nodeTopology: + properties: + name: + type: string + scaleDownDiffPercentage: + default: 25 + format: int32 + type: integer + scaleUpDiffPercentage: + default: 15 + format: int32 + type: integer + type: object + type: object + databaseRef: + properties: + name: + default: "" + type: string + type: object + x-kubernetes-map-type: atomic + opsRequestOptions: + properties: + apply: + default: IfReady + enum: + - IfReady + - Always + type: string + timeout: + type: string + type: object + storage: + properties: + cassandra: + properties: + expansionMode: + enum: + - Offline + - Online + type: string + scalingRules: + items: + properties: + appliesUpto: + type: string + threshold: + type: string + required: + - appliesUpto + - threshold + type: object + type: array + scalingThreshold: + format: int32 + type: integer + trigger: + type: string + upperBound: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + usageThreshold: + format: int32 + type: integer + required: + - expansionMode + type: object + type: object + required: + - databaseRef + type: object + status: + properties: + checkpoints: + items: + properties: + cpuHistogram: + properties: + bucketWeights: + items: + properties: + index: + type: integer + weight: + format: int32 + type: integer + required: + - index + - weight + type: object + type: array + x-kubernetes-preserve-unknown-fields: true + referenceTimestamp: + format: date-time + nullable: true + type: string + totalWeight: + format: double + type: number + type: object + firstSampleStart: + format: date-time + nullable: true + type: string + lastSampleStart: + format: date-time + nullable: true + type: string + lastUpdateTime: + format: date-time + nullable: true + type: string + memoryHistogram: + properties: + bucketWeights: + items: + properties: + index: + type: integer + weight: + format: int32 + type: integer + required: + - index + - weight + type: object + type: array + x-kubernetes-preserve-unknown-fields: true + referenceTimestamp: + format: date-time + nullable: true + type: string + totalWeight: + format: double + type: number + type: object + ref: + properties: + containerName: + type: string + vpaObjectName: + type: string + type: object + totalSamplesCount: + type: integer + version: + type: string + type: object + type: array + conditions: + items: + properties: + lastTransitionTime: + format: date-time + type: string + message: + type: string + observedGeneration: + format: int64 + type: integer + reason: + type: string + severity: + type: string + status: + type: string + type: + type: string + required: + - lastTransitionTime + - status + - type + type: object + type: array + observedGeneration: + format: int64 + type: integer + phase: + enum: + - InProgress + - Current + - Terminating + - Failed + type: string + vpas: + items: + properties: + conditions: + items: + properties: + lastTransitionTime: + format: date-time + type: string + message: + type: string + reason: + type: string + status: + type: string + type: + type: string + required: + - status + - type + type: object + type: array + recommendation: + properties: + containerRecommendations: + items: + properties: + containerName: + type: string + lowerBound: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + target: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + uncappedTarget: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + upperBound: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + required: + - target + type: object + type: array + type: object + vpaName: + type: string + type: object + type: array + type: object + required: + - spec + type: object + served: true + storage: true + subresources: + status: {}