|
| 1 | +/* |
| 2 | +Copyright 2018 The Volcano Authors. |
| 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 | +package v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + v2 "k8s.io/api/autoscaling/v2" |
| 21 | + corev1 "k8s.io/api/core/v1" |
| 22 | + "k8s.io/apimachinery/pkg/api/resource" |
| 23 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 24 | +) |
| 25 | + |
| 26 | +type VerticalQueueAutoscalerType string |
| 27 | +type StepType string |
| 28 | +type Condition string |
| 29 | + |
| 30 | +const ( |
| 31 | + ResourceVQARatio corev1.ResourceName = "ratio" |
| 32 | + VerticalQueueAutoscalerTidalType VerticalQueueAutoscalerType = "tidal" |
| 33 | + VerticalQueueAutoscalerMetricsType VerticalQueueAutoscalerType = "metrics" |
| 34 | + EquivalentStepType StepType = "equivalent" |
| 35 | + EquiratioStepType StepType = "equiratio" |
| 36 | + AndCondition Condition = "and" |
| 37 | + OrCondition Condition = "or" |
| 38 | +) |
| 39 | + |
| 40 | +// +genclient |
| 41 | +// +genclient:nonNamespaced |
| 42 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 43 | +// +kubebuilder:object:root=true |
| 44 | +// +kubebuilder:resource:path=verticalqueueautoscalers,shortName=vqa;vqas,scope=Cluster |
| 45 | +// +kubebuilder:subresource:status |
| 46 | +// +kubebuilder:printcolumn:name="Last Scale",type=date,JSONPath=`.status.lastScaleTime` |
| 47 | +// +kubebuilder:printcolumn:name="Last Successful",type=date,JSONPath=`.status.lastScaleSuccessTime` |
| 48 | +// +kubebuilder:printcolumn:name="AGE",type=date,JSONPath=`.metadata.creationTimestamp` |
| 49 | +// +kubebuilder:printcolumn:name="QUEUE",type=string,priority=1,JSONPath=`.spec.queue` |
| 50 | + |
| 51 | +// VerticalQueueAutoscaler defines the volcano vertical queue autoscaler. |
| 52 | +type VerticalQueueAutoscaler struct { |
| 53 | + metav1.TypeMeta `json:",inline"` |
| 54 | + |
| 55 | + // +optional |
| 56 | + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 57 | + |
| 58 | + // Specification of the desired behavior of the volcano verticalqueueautoscaler, including tidal and metrics |
| 59 | + // +optional |
| 60 | + Spec VQASpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` |
| 61 | + |
| 62 | + // Current status of the volcano verticalqueueautoscaler |
| 63 | + // +optional |
| 64 | + Status VQAStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` |
| 65 | +} |
| 66 | + |
| 67 | +// VQASpec describes how the VerticalQueueAutoscaler will look like and actually behavior. |
| 68 | +type VQASpec struct { |
| 69 | + |
| 70 | + //Specifies the queue that will be used in the scheduler, "default" queue is used this leaves empty. |
| 71 | + Queue string `json:"queue,omitempty" protobuf:"bytes,1,opt,name=queue"` |
| 72 | + |
| 73 | + // Type is the behavior type of VQA. |
| 74 | + //+kubebuilder:validation:Enum=tidal;metrics |
| 75 | + Type VerticalQueueAutoscalerType `json:"type,omitempty" protobuf:"bytes,2,opt,name=type"` |
| 76 | + |
| 77 | + // TidalSpec define tidal autoscaling configuration |
| 78 | + // +optional |
| 79 | + TidalSpec TidalSpec `json:"tidalSpec,omitempty" protobuf:"bytes,3,opt,name=tidalSpec"` |
| 80 | + |
| 81 | + // TidalSpec define metrics autoscaling configuration |
| 82 | + // +optional |
| 83 | + MetricSpec []MetricSpec `json:"metricSpec,omitempty" protobuf:"bytes,4,opt,name=metricSpec"` |
| 84 | +} |
| 85 | + |
| 86 | +type VQAStatus struct { |
| 87 | + // LastScaleTime is the last time the VerticalQueueAutoscaler scaled the capacity of queue, |
| 88 | + // +optional |
| 89 | + LastScaleTime *metav1.Time `json:"lastScaleTime,omitempty" protobuf:"bytes,1,opt,name=lastScaleTime"` |
| 90 | + |
| 91 | + // LastScaleSuccessTime is the last time the VerticalQueueAutoscaler scaled the capacity of queue Successful, |
| 92 | + // +optional |
| 93 | + LastScaleSuccessTime *metav1.Time `json:"lastScaleSuccessTime,omitempty" protobuf:"bytes,2,opt,name=lastScaleSuccessTime"` |
| 94 | +} |
| 95 | + |
| 96 | +type TidalSpec struct { |
| 97 | + // StartingDeadlineSeconds Optional deadline in seconds for starting the job if it misses scheduled |
| 98 | + // time for any reason. Missed jobs executions will be counted as failed ones. |
| 99 | + // +optional |
| 100 | + StartingDeadlineSeconds *int64 `json:"startingDeadlineSeconds,omitempty" protobuf:"varint,1,opt,name=startingDeadlineSeconds"` |
| 101 | + |
| 102 | + // Tidal define arrays of tidal configuration |
| 103 | + Tidal []Tidal `json:"tidal,omitempty" protobuf:"bytes,2,opt,name=tidal"` |
| 104 | +} |
| 105 | + |
| 106 | +type Tidal struct { |
| 107 | + // Schedule The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron |
| 108 | + Schedule string `json:"schedule,omitempty" protobuf:"bytes,1,opt,name=schedule"` |
| 109 | + // Weight queue.spec.weight |
| 110 | + Weight int32 `json:"weight,omitempty" protobuf:"bytes,2,opt,name=weight"` |
| 111 | + // Capability queue.spec.capability |
| 112 | + Capability corev1.ResourceList `json:"capability,omitempty" protobuf:"bytes,3,opt,name=capability"` |
| 113 | + // Guarantee queue.spec.guarantee.resource |
| 114 | + Guarantee corev1.ResourceList `json:"guarantee,omitempty" protobuf:"bytes,4,opt,name=guarantee"` |
| 115 | +} |
| 116 | + |
| 117 | +type MetricSpec struct { |
| 118 | + // ScaleBehavior define scale behavior of metrics type |
| 119 | + ScaleBehavior ScaleBehavior `json:"scaleBehavior,omitempty" protobuf:"bytes,1,opt,name=scaleBehavior"` |
| 120 | + // ResourceLimit resources limit of queue |
| 121 | + ResourceLimit ResourceLimit `json:"resourceLimit,omitempty" protobuf:"bytes,2,opt,name=resourceLimit"` |
| 122 | + MetricRules MetricRules `json:"metricRules,omitempty" protobuf:"bytes,3,opt,name=metricRules"` |
| 123 | +} |
| 124 | + |
| 125 | +type ScaleBehavior struct { |
| 126 | + // StepType scale step type |
| 127 | + //+kubebuilder:validation:Enum=Delete;Orphan |
| 128 | + StepType StepType `json:"stepType,omitempty" protobuf:"bytes,1,opt,name=stepType"` |
| 129 | + // StepRatio ratio of scale step |
| 130 | + StepRatio resource.Quantity `json:"stepRatio,omitempty" protobuf:"bytes,2,opt,name=stepRatio"` |
| 131 | + // StepResources resources of scale step |
| 132 | + StepResources StepResources `json:"stepResources,omitempty" protobuf:"bytes,3,opt,name=stepResources"` |
| 133 | +} |
| 134 | + |
| 135 | +type StepResources struct { |
| 136 | + // Weight queue.spec.weight, it's a increment |
| 137 | + Weight int32 `json:"weight,omitempty" protobuf:"bytes,1,opt,name=weight"` |
| 138 | + // Capability queue.spec.capability, it's a increment |
| 139 | + Capability corev1.ResourceList `json:"capability,omitempty" protobuf:"bytes,2,opt,name=capability"` |
| 140 | + // Guarantee queue.spec.guarantee.resource, it's a increment |
| 141 | + Guarantee corev1.ResourceList `json:"guarantee,omitempty" protobuf:"bytes,3,opt,name=guarantee"` |
| 142 | +} |
| 143 | + |
| 144 | +type ScaleLimit struct { |
| 145 | + // WeightLimit limit of queue.spec.weight |
| 146 | + WeightLimit WeightLimit `json:"weightLimit,omitempty" protobuf:"bytes,1,opt,name=weightLimit"` |
| 147 | + // CapacityLimit limit of queue.spec.capability |
| 148 | + CapacityLimit ResourceLimit `json:"capacityLimit,omitempty" protobuf:"bytes,2,opt,name=capacityLimit"` |
| 149 | + // GuaranteeLimit limit of queue.spec.guarantee.resource |
| 150 | + GuaranteeLimit ResourceLimit `json:"guaratneeLimit,omitempty" protobuf:"bytes,3,opt,name=guaratneeLimit"` |
| 151 | +} |
| 152 | + |
| 153 | +type WeightLimit struct { |
| 154 | + // Min minimum of queue.spec.weight |
| 155 | + Min int32 `json:"min,omitempty" protobuf:"bytes,1,opt,name=min"` |
| 156 | + // Max maximum of queue.spec.weight |
| 157 | + Max int32 `json:"max,omitempty" protobuf:"bytes,2,opt,name=max"` |
| 158 | +} |
| 159 | + |
| 160 | +type ResourceLimit struct { |
| 161 | + // Min minimum of queue.spec.capacity or guarantee |
| 162 | + Min corev1.ResourceList `json:"min,omitempty" protobuf:"bytes,1,opt,name=min"` |
| 163 | + // Max maximum of queue.spec.capacity or guarantee |
| 164 | + Max corev1.ResourceList `json:"max,omitempty" protobuf:"bytes,2,opt,name=max"` |
| 165 | +} |
| 166 | + |
| 167 | +type MetricRules struct { |
| 168 | + // ScaleUp rule of scale up |
| 169 | + ScaleUp ScaleRule `json:"scaleUp,omitempty" protobuf:"bytes,1,opt,name=scaleUp"` |
| 170 | + // ScaleUp rule of scale down |
| 171 | + ScaleDown ScaleRule `json:"scaleDown,omitempty" protobuf:"bytes,2,opt,name=scaleDown"` |
| 172 | +} |
| 173 | + |
| 174 | +type ScaleRule struct { |
| 175 | + // StabilizationWindowSeconds is the number of seconds for which past recommendations should be |
| 176 | + // considered while scaling up or scaling down. |
| 177 | + // StabilizationWindowSeconds must be greater than or equal to zero and less than or equal to 3600 (one hour). |
| 178 | + // If not set, use the default values: |
| 179 | + // - For scale up: 0 (i.e. no stabilization is done). |
| 180 | + // - For scale down: 300 (i.e. the stabilization window is 300 seconds long). |
| 181 | + // +optional |
| 182 | + StabilizationWindowSeconds *int32 `json:"stabilizationWindowSeconds,omitempty" protobuf:"bytes,1,opt,name=stabilizationWindowSeconds"` |
| 183 | + Condition Condition `json:"condition,omitempty" protobuf:"bytes,2,opt,name=condition"` |
| 184 | + MetricSources []MetricSource `json:"metricSources,omitempty" protobuf:"bytes,3,opt,name=metricSources"` |
| 185 | +} |
| 186 | + |
| 187 | +type MetricSource struct { |
| 188 | + // PeriodSeconds specifies the window of time for which the policy should hold true. |
| 189 | + // PeriodSeconds must be greater than zero and less than or equal to 1800 (30 min). |
| 190 | + PeriodSeconds int32 `json:"periodSeconds,omitempty" protobuf:"bytes,1,opt,name=periodSeconds"` |
| 191 | + // Metric identifies the target metric by name and selector |
| 192 | + Metric v2.MetricIdentifier `json:"metric,omitempty" protobuf:"bytes,2,opt,name=metric"` |
| 193 | + // Target specifies the target value for the given metric |
| 194 | + Target v2.MetricTarget `json:"target,omitempty" protobuf:"bytes,3,opt,name=target"` |
| 195 | +} |
| 196 | + |
| 197 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 198 | + |
| 199 | +// VerticalQueueAutoscalerList is a collection of vertical queue autoscaler. |
| 200 | +type VerticalQueueAutoscalerList struct { |
| 201 | + metav1.TypeMeta |
| 202 | + // Standard list metadata |
| 203 | + // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata |
| 204 | + // +optional |
| 205 | + metav1.ListMeta |
| 206 | + |
| 207 | + // items is the list of VerticalQueueAutoscaler |
| 208 | + Items []VerticalQueueAutoscaler |
| 209 | +} |
0 commit comments