|
| 1 | +/* |
| 2 | +Copyright 2020 The actions-runner-controller 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 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | +) |
| 22 | + |
| 23 | +// HorizontalRunnerAutoscalerSpec defines the desired state of HorizontalRunnerAutoscaler |
| 24 | +type HorizontalRunnerAutoscalerSpec struct { |
| 25 | + // ScaleTargetRef sis the reference to scaled resource like RunnerDeployment |
| 26 | + ScaleTargetRef ScaleTargetRef `json:"scaleTargetRef,omitempty"` |
| 27 | + |
| 28 | + // MinReplicas is the minimum number of replicas the deployment is allowed to scale |
| 29 | + // +optional |
| 30 | + MinReplicas *int `json:"minReplicas,omitempty"` |
| 31 | + |
| 32 | + // MinReplicas is the maximum number of replicas the deployment is allowed to scale |
| 33 | + // +optional |
| 34 | + MaxReplicas *int `json:"maxReplicas,omitempty"` |
| 35 | + |
| 36 | + // ScaleDownDelaySecondsAfterScaleUp is the approximate delay for a scale down followed by a scale up |
| 37 | + // Used to prevent flapping (down->up->down->... loop) |
| 38 | + // +optional |
| 39 | + ScaleDownDelaySecondsAfterScaleUp *int `json:"scaleDownDelaySecondsAfterScaleOut,omitempty"` |
| 40 | + |
| 41 | + // Metrics is the collection of various metric targets to calculate desired number of runners |
| 42 | + // +optional |
| 43 | + Metrics []MetricSpec `json:"metrics,omitempty"` |
| 44 | +} |
| 45 | + |
| 46 | +type ScaleTargetRef struct { |
| 47 | + Name string `json:"name,omitempty"` |
| 48 | +} |
| 49 | + |
| 50 | +type MetricSpec struct { |
| 51 | + // Type is the type of metric to be used for autoscaling. |
| 52 | + // The only supported Type is TotalNumberOfQueuedAndInProgressWorkflowRuns |
| 53 | + Type string `json:"type,omitempty"` |
| 54 | + |
| 55 | + // RepositoryNames is the list of repository names to be used for calculating the metric. |
| 56 | + // For example, a repository name is the REPO part of `github.com/USER/REPO`. |
| 57 | + // +optional |
| 58 | + RepositoryNames []string `json:"repositoryNames,omitempty"` |
| 59 | +} |
| 60 | + |
| 61 | +type HorizontalRunnerAutoscalerStatus struct { |
| 62 | + // ObservedGeneration is the most recent generation observed for the target. It corresponds to e.g. |
| 63 | + // RunnerDeployment's generation, which is updated on mutation by the API Server. |
| 64 | + // +optional |
| 65 | + ObservedGeneration int64 `json:"observedGeneration,omitempty"` |
| 66 | + |
| 67 | + // DesiredReplicas is the total number of desired, non-terminated and latest pods to be set for the primary RunnerSet |
| 68 | + // This doesn't include outdated pods while upgrading the deployment and replacing the runnerset. |
| 69 | + // +optional |
| 70 | + DesiredReplicas *int `json:"desiredReplicas,omitempty"` |
| 71 | + |
| 72 | + // +optional |
| 73 | + LastSuccessfulScaleOutTime *metav1.Time `json:"lastSuccessfulScaleOutTime,omitempty"` |
| 74 | +} |
| 75 | + |
| 76 | +// +kubebuilder:object:root=true |
| 77 | +// +kubebuilder:subresource:status |
| 78 | +// +kubebuilder:printcolumn:JSONPath=".spec.minReplicas",name=Min,type=number |
| 79 | +// +kubebuilder:printcolumn:JSONPath=".spec.maxReplicas",name=Max,type=number |
| 80 | +// +kubebuilder:printcolumn:JSONPath=".status.desiredReplicas",name=Desired,type=number |
| 81 | + |
| 82 | +// HorizontalRunnerAutoscaler is the Schema for the horizontalrunnerautoscaler API |
| 83 | +type HorizontalRunnerAutoscaler struct { |
| 84 | + metav1.TypeMeta `json:",inline"` |
| 85 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 86 | + |
| 87 | + Spec HorizontalRunnerAutoscalerSpec `json:"spec,omitempty"` |
| 88 | + Status HorizontalRunnerAutoscalerStatus `json:"status,omitempty"` |
| 89 | +} |
| 90 | + |
| 91 | +// +kubebuilder:object:root=true |
| 92 | + |
| 93 | +// HorizontalRunnerAutoscalerList contains a list of HorizontalRunnerAutoscaler |
| 94 | +type HorizontalRunnerAutoscalerList struct { |
| 95 | + metav1.TypeMeta `json:",inline"` |
| 96 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 97 | + Items []HorizontalRunnerAutoscaler `json:"items"` |
| 98 | +} |
| 99 | + |
| 100 | +func init() { |
| 101 | + SchemeBuilder.Register(&HorizontalRunnerAutoscaler{}, &HorizontalRunnerAutoscalerList{}) |
| 102 | +} |
0 commit comments