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

feat: support NodeCountScaler #7258

Merged
merged 14 commits into from
May 7, 2024
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,13 @@ resources:
kind: StorageProvider
path: github.com/apecloud/kubeblocks/apis/dataprotection/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: kubeblocks.io
group: experimental
kind: NodeCountScaler
path: github.com/apecloud/kubeblocks/apis/experimental/v1alpha1
version: v1alpha1
version: "3"
29 changes: 29 additions & 0 deletions apis/experimental/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright (C) 2022-2024 ApeCloud Co., Ltd

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 experimental is a group of APIs that are in experimental.

We often encounter needs and ideas from community users, customers, or internal discussions.
These ideas or features typically require a lot of preparatory work before they can be officially supported in KubeBlocks.
This includes requirements analysis, solution research, API design and discussions, solution design and discussions, and so on.
This process often takes a considerable amount of time.

To quickly validate the feasibility of feature functionalities, an experimental API is now added to KubeBlocks.
This API is used for rapidly verifying the feasibility of a specific feature.
Please note that experimental APIs do not guarantee backward compatibility.
*/
package experimental
39 changes: 39 additions & 0 deletions apis/experimental/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright (C) 2022-2024 ApeCloud Co., Ltd

This file is part of KubeBlocks project

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

// Package v1alpha1 contains API Schema definitions for the experimental v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=experimental.kubeblocks.io
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "experimental.kubeblocks.io", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
128 changes: 128 additions & 0 deletions apis/experimental/v1alpha1/nodecountscaler_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
Copyright (C) 2022-2024 ApeCloud Co., Ltd

This file is part of KubeBlocks project

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// NodeCountScalerSpec defines the desired state of NodeCountScaler
type NodeCountScalerSpec struct {
// Specified the target Cluster name this scaler applies to.
TargetClusterName string `json:"targetClusterName"`

// Specified the target Component names this scaler applies to.
// All Components will be applied if not set.
//
// +optional
TargetComponentNames []string `json:"targetComponentNames,omitempty"`
}

// NodeCountScalerStatus defines the observed state of NodeCountScaler
type NodeCountScalerStatus struct {
// Records the current status information of all Components specified in the NodeCountScalerSpec.
//
// +optional
ComponentStatuses []ComponentStatus `json:"componentStatuses,omitempty"`

// Represents the latest available observations of a nodecountscaler's current state.
// Known .status.conditions.type are: "ScaleReady".
// ScaleReady - All target components are ready.
//
// +optional
// +patchMergeKey=type
// +patchStrategy=merge
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`

// LastScaleTime is the last time the NodeCountScaler scaled the number of instances.
//
// +optional
LastScaleTime metav1.Time `json:"lastScaleTime,omitempty"`
}

type ComponentStatus struct {
// Specified the Component name.
Name string `json:"name"`

// The current number of instances of this component.
CurrentReplicas int32 `json:"currentReplicas"`

// The number of instances of this component with a Ready condition.
ReadyReplicas int32 `json:"readyReplicas"`

// The number of instances of this component with a Ready condition for at least MinReadySeconds defined in the instance template.
AvailableReplicas int32 `json:"availableReplicas"`

// The desired number of instances of this component.
// Usually, it should be the number of nodes.
DesiredReplicas int32 `json:"desiredReplicas"`
}

type ConditionType string

const (
// ScaleReady is added to a nodecountscaler when all target components are ready.
ScaleReady ConditionType = "ScaleReady"
)

const (
// ReasonNotReady is a reason for condition ScaleReady.
ReasonNotReady = "NotReady"

// ReasonReady is a reason for condition ScaleReady.
ReasonReady = "Ready"
)

// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:categories={kubeblocks,all},shortName=ncs
// +kubebuilder:printcolumn:name="TARGET-CLUSTER-NAME",type="string",JSONPath=".spec.targetClusterName",description="target cluster name."
// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type==\"ScaleReady\")].status",description="scale ready."
// +kubebuilder:printcolumn:name="REASON",type="string",JSONPath=".status.conditions[?(@.type==\"ScaleReady\")].reason",description="reason."
// +kubebuilder:printcolumn:name="MESSAGE",type="string",JSONPath=".status.conditions[?(@.type==\"ScaleReady\")].message",description="message."
// +kubebuilder:printcolumn:name="LAST-SCALE-TIME",type="date",JSONPath=".status.lastScaleTime"

// NodeCountScaler is the Schema for the nodecountscalers API
type NodeCountScaler struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec NodeCountScalerSpec `json:"spec,omitempty"`
Status NodeCountScalerStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// NodeCountScalerList contains a list of NodeCountScaler
type NodeCountScalerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []NodeCountScaler `json:"items"`
}

func init() {
SchemeBuilder.Register(&NodeCountScaler{}, &NodeCountScalerList{})
}
152 changes: 152 additions & 0 deletions apis/experimental/v1alpha1/zz_generated.deepcopy.go

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

Loading
Loading