Skip to content

Commit 70df1e8

Browse files
authored
feat: support NodeCountScaler (apecloud#7258)
1 parent db57bba commit 70df1e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2153
-88
lines changed

PROJECT

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,13 @@ resources:
246246
kind: StorageProvider
247247
path: github.com/apecloud/kubeblocks/apis/dataprotection/v1alpha1
248248
version: v1alpha1
249+
- api:
250+
crdVersion: v1
251+
namespaced: true
252+
controller: true
253+
domain: kubeblocks.io
254+
group: experimental
255+
kind: NodeCountScaler
256+
path: github.com/apecloud/kubeblocks/apis/experimental/v1alpha1
257+
version: v1alpha1
249258
version: "3"

apis/experimental/doc.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright (C) 2022-2024 ApeCloud Co., Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
/*
18+
Package experimental is a group of APIs that are in experimental.
19+
20+
We often encounter needs and ideas from community users, customers, or internal discussions.
21+
These ideas or features typically require a lot of preparatory work before they can be officially supported in KubeBlocks.
22+
This includes requirements analysis, solution research, API design and discussions, solution design and discussions, and so on.
23+
This process often takes a considerable amount of time.
24+
25+
To quickly validate the feasibility of feature functionalities, an experimental API is now added to KubeBlocks.
26+
This API is used for rapidly verifying the feasibility of a specific feature.
27+
Please note that experimental APIs do not guarantee backward compatibility.
28+
*/
29+
package experimental
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Copyright (C) 2022-2024 ApeCloud Co., Ltd
3+
4+
This file is part of KubeBlocks project
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU Affero General Public License for more details.
15+
16+
You should have received a copy of the GNU Affero General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
// Package v1alpha1 contains API Schema definitions for the experimental v1alpha1 API group
21+
// +kubebuilder:object:generate=true
22+
// +groupName=experimental.kubeblocks.io
23+
package v1alpha1
24+
25+
import (
26+
"k8s.io/apimachinery/pkg/runtime/schema"
27+
"sigs.k8s.io/controller-runtime/pkg/scheme"
28+
)
29+
30+
var (
31+
// GroupVersion is group version used to register these objects
32+
GroupVersion = schema.GroupVersion{Group: "experimental.kubeblocks.io", Version: "v1alpha1"}
33+
34+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
35+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
36+
37+
// AddToScheme adds the types in this group-version to the given scheme.
38+
AddToScheme = SchemeBuilder.AddToScheme
39+
)
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
Copyright (C) 2022-2024 ApeCloud Co., Ltd
3+
4+
This file is part of KubeBlocks project
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU Affero General Public License for more details.
15+
16+
You should have received a copy of the GNU Affero General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
package v1alpha1
21+
22+
import (
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
)
25+
26+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
27+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
28+
29+
// NodeCountScalerSpec defines the desired state of NodeCountScaler
30+
type NodeCountScalerSpec struct {
31+
// Specified the target Cluster name this scaler applies to.
32+
TargetClusterName string `json:"targetClusterName"`
33+
34+
// Specified the target Component names this scaler applies to.
35+
// All Components will be applied if not set.
36+
//
37+
// +optional
38+
TargetComponentNames []string `json:"targetComponentNames,omitempty"`
39+
}
40+
41+
// NodeCountScalerStatus defines the observed state of NodeCountScaler
42+
type NodeCountScalerStatus struct {
43+
// Records the current status information of all Components specified in the NodeCountScalerSpec.
44+
//
45+
// +optional
46+
ComponentStatuses []ComponentStatus `json:"componentStatuses,omitempty"`
47+
48+
// Represents the latest available observations of a nodecountscaler's current state.
49+
// Known .status.conditions.type are: "ScaleReady".
50+
// ScaleReady - All target components are ready.
51+
//
52+
// +optional
53+
// +patchMergeKey=type
54+
// +patchStrategy=merge
55+
// +listType=map
56+
// +listMapKey=type
57+
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
58+
59+
// LastScaleTime is the last time the NodeCountScaler scaled the number of instances.
60+
//
61+
// +optional
62+
LastScaleTime metav1.Time `json:"lastScaleTime,omitempty"`
63+
}
64+
65+
type ComponentStatus struct {
66+
// Specified the Component name.
67+
Name string `json:"name"`
68+
69+
// The current number of instances of this component.
70+
CurrentReplicas int32 `json:"currentReplicas"`
71+
72+
// The number of instances of this component with a Ready condition.
73+
ReadyReplicas int32 `json:"readyReplicas"`
74+
75+
// The number of instances of this component with a Ready condition for at least MinReadySeconds defined in the instance template.
76+
AvailableReplicas int32 `json:"availableReplicas"`
77+
78+
// The desired number of instances of this component.
79+
// Usually, it should be the number of nodes.
80+
DesiredReplicas int32 `json:"desiredReplicas"`
81+
}
82+
83+
type ConditionType string
84+
85+
const (
86+
// ScaleReady is added to a nodecountscaler when all target components are ready.
87+
ScaleReady ConditionType = "ScaleReady"
88+
)
89+
90+
const (
91+
// ReasonNotReady is a reason for condition ScaleReady.
92+
ReasonNotReady = "NotReady"
93+
94+
// ReasonReady is a reason for condition ScaleReady.
95+
ReasonReady = "Ready"
96+
)
97+
98+
// +genclient
99+
// +kubebuilder:object:root=true
100+
// +kubebuilder:subresource:status
101+
// +kubebuilder:resource:categories={kubeblocks,all},shortName=ncs
102+
// +kubebuilder:printcolumn:name="TARGET-CLUSTER-NAME",type="string",JSONPath=".spec.targetClusterName",description="target cluster name."
103+
// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type==\"ScaleReady\")].status",description="scale ready."
104+
// +kubebuilder:printcolumn:name="REASON",type="string",JSONPath=".status.conditions[?(@.type==\"ScaleReady\")].reason",description="reason."
105+
// +kubebuilder:printcolumn:name="MESSAGE",type="string",JSONPath=".status.conditions[?(@.type==\"ScaleReady\")].message",description="message."
106+
// +kubebuilder:printcolumn:name="LAST-SCALE-TIME",type="date",JSONPath=".status.lastScaleTime"
107+
108+
// NodeCountScaler is the Schema for the nodecountscalers API
109+
type NodeCountScaler struct {
110+
metav1.TypeMeta `json:",inline"`
111+
metav1.ObjectMeta `json:"metadata,omitempty"`
112+
113+
Spec NodeCountScalerSpec `json:"spec,omitempty"`
114+
Status NodeCountScalerStatus `json:"status,omitempty"`
115+
}
116+
117+
//+kubebuilder:object:root=true
118+
119+
// NodeCountScalerList contains a list of NodeCountScaler
120+
type NodeCountScalerList struct {
121+
metav1.TypeMeta `json:",inline"`
122+
metav1.ListMeta `json:"metadata,omitempty"`
123+
Items []NodeCountScaler `json:"items"`
124+
}
125+
126+
func init() {
127+
SchemeBuilder.Register(&NodeCountScaler{}, &NodeCountScalerList{})
128+
}

apis/experimental/v1alpha1/zz_generated.deepcopy.go

Lines changed: 152 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)