Skip to content

Commit

Permalink
Add support for autoscaling/v2
Browse files Browse the repository at this point in the history
  • Loading branch information
halim-lee committed Mar 28, 2024
1 parent 4f58550 commit a3c6975
Show file tree
Hide file tree
Showing 18 changed files with 2,678 additions and 50 deletions.
26 changes: 26 additions & 0 deletions api/v1/runtimecomponent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
routev1 "github.com/openshift/api/route/v1"
prometheusv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
appsv1 "k8s.io/api/apps/v1"
autoscalingv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -225,6 +226,16 @@ type RuntimeComponentAutoScaling struct {
// Target average CPU utilization, represented as a percentage of requested CPU, over all the pods.
// +operator-sdk:csv:customresourcedefinitions:order=3,type=spec,displayName="Target CPU Utilization Percentage",xDescriptors="urn:alm:descriptor:com.tectonic.ui:number"
TargetCPUUtilizationPercentage *int32 `json:"targetCPUUtilizationPercentage,omitempty"`

// Target average Memory utilization, represented as a percentage of requested memory, over all the pods.
// +operator-sdk:csv:customresourcedefinitions:order=4,type=spec,displayName="Target Memory Utilization Percentage",xDescriptors="urn:alm:descriptor:com.tectonic.ui:number"
TargetMemoryUtilizationPercentage *int32 `json:"targetMemoryUtilizationPercentage,omitempty"`

// Specifications used for replica count calculation
Metrics []autoscalingv2.MetricSpec `json:"metrics,omitempty"`

// Scaling behavior of the target. If not set, the default HPAScalingRules for scale up and scale down are used.
Behavior *autoscalingv2.HorizontalPodAutoscalerBehavior `json:"behavior,omitempty"`
}

// Configures parameters for the network service of pods.
Expand Down Expand Up @@ -762,6 +773,21 @@ func (a *RuntimeComponentAutoScaling) GetTargetCPUUtilizationPercentage() *int32
return a.TargetCPUUtilizationPercentage
}

// GetTargetMemoryUtilizationPercentage returns target memory usage
func (a *RuntimeComponentAutoScaling) GetTargetMemoryUtilizationPercentage() *int32 {
return a.TargetMemoryUtilizationPercentage
}

// GetMetrics returns metrics for resource utilization
func (a *RuntimeComponentAutoScaling) GetMetrics() []autoscalingv2.MetricSpec {
return a.Metrics
}

// GetHorizontalPodAutoscalerBehavior returns behavior configures the scaling behavior of the target
func (a *RuntimeComponentAutoScaling) GetHorizontalPodAutoscalerBehavior() *autoscalingv2.HorizontalPodAutoscalerBehavior {
return a.Behavior
}

// GetSize returns persistent volume size
func (s *RuntimeComponentStorage) GetSize() string {
return s.Size
Expand Down
18 changes: 18 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

16 changes: 16 additions & 0 deletions api/v1beta2/runtimecomponent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
routev1 "github.com/openshift/api/route/v1"
prometheusv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
appsv1 "k8s.io/api/apps/v1"
autoscalingv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -666,6 +667,21 @@ func (a *RuntimeComponentAutoScaling) GetTargetCPUUtilizationPercentage() *int32
return a.TargetCPUUtilizationPercentage
}

// GetTargetMemoryUtilizationPercentage returns target memory usage
func (a *RuntimeComponentAutoScaling) GetTargetMemoryUtilizationPercentage() *int32 {
return nil
}

// GetMetrics returns metrics for resource utilization
func (a *RuntimeComponentAutoScaling) GetMetrics() []autoscalingv2.MetricSpec {
return nil
}

// GetHorizontalPodAutoscalerBehavior returns behavior configures the scaling behavior of the target
func (a *RuntimeComponentAutoScaling) GetHorizontalPodAutoscalerBehavior() *autoscalingv2.HorizontalPodAutoscalerBehavior {
return nil
}

// GetSize returns persistent volume size
func (s *RuntimeComponentStorage) GetSize() string {
return s.Size
Expand Down
Loading

0 comments on commit a3c6975

Please sign in to comment.