|
| 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 | +} |
0 commit comments