-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package v1alpha2 | ||
|
||
import ( | ||
"github.com/gardener/hvpa-controller/apis/autoscaling/v1alpha1" | ||
autoscalingv2 "k8s.io/api/autoscaling/v2" | ||
autoscalingv2beta1 "k8s.io/api/autoscaling/v2beta1" | ||
"sigs.k8s.io/controller-runtime/pkg/conversion" | ||
) | ||
|
||
func (src *Hvpa) ConvertTo(dstRaw conversion.Hub) error { | ||
return nil | ||
} | ||
|
||
func Convert_v2beta1_ResourceMetricSource_To_autoscaling_ResourceMetricSource(in *autoscalingv2beta1.ResourceMetricSource) *autoscalingv2.ResourceMetricSource { | ||
out := &autoscalingv2.ResourceMetricSource{} | ||
out.Name = in.Name | ||
utilization := in.TargetAverageUtilization | ||
averageValue := in.TargetAverageValue | ||
|
||
var metricType autoscalingv2.MetricTargetType | ||
if utilization == nil { | ||
metricType = autoscalingv2.AverageValueMetricType | ||
} else { | ||
metricType = autoscalingv2.UtilizationMetricType | ||
} | ||
out.Target = autoscalingv2.MetricTarget{ | ||
Type: metricType, | ||
AverageValue: averageValue, | ||
AverageUtilization: utilization, | ||
} | ||
return out | ||
} | ||
|
||
func (dst *Hvpa) ConvertFrom(srcRaw conversion.Hub) error { | ||
src := srcRaw.(*v1alpha1.Hvpa) | ||
|
||
dst.Spec.Replicas = src.Spec.Replicas | ||
dst.Spec.Vpa = VpaSpec{ | ||
Selector: src.Spec.Vpa.Selector, | ||
Deploy: src.Spec.Vpa.Deploy, | ||
ScaleUp: Convert_v1alpha1_ScaleType_To_ScaleType(src.Spec.Vpa.ScaleUp), | ||
ScaleDown: Convert_v1alpha1_ScaleType_To_ScaleType(src.Spec.Vpa.ScaleDown), | ||
Template: VpaTemplate{ | ||
ObjectMeta: src.Spec.Vpa.Template.ObjectMeta, | ||
Spec: VpaTemplateSpec(src.Spec.Vpa.Template.Spec), | ||
}, | ||
LimitsRequestsGapScaleParams: Convert_v1alpha1_ScaleParams_To_ScaleParams(src.Spec.Vpa.LimitsRequestsGapScaleParams), | ||
} | ||
dst.Spec.WeightBasedScalingIntervals = []WeightBasedScalingInterval{} | ||
for _, weightBasedScalingInterval := range src.Spec.WeightBasedScalingIntervals { | ||
dst.Spec.WeightBasedScalingIntervals = append(dst.Spec.WeightBasedScalingIntervals, WeightBasedScalingInterval(weightBasedScalingInterval)) | ||
} | ||
dst.Spec.TargetRef = &autoscalingv2.CrossVersionObjectReference{ | ||
Kind: src.Spec.TargetRef.Kind, | ||
Name: src.Spec.TargetRef.Name, | ||
APIVersion: src.Spec.TargetRef.APIVersion, | ||
} | ||
mw := MaintenanceTimeWindow(*src.Spec.MaintenanceTimeWindow) | ||
dst.Spec.MaintenanceTimeWindow = &mw | ||
|
||
dst.Spec.Hpa.Selector = src.Spec.Hpa.Selector | ||
dst.Spec.Hpa.Deploy = src.Spec.Hpa.Deploy | ||
dst.Spec.Hpa.ScaleUp = Convert_v1alpha1_ScaleType_To_ScaleType(src.Spec.Hpa.ScaleUp) | ||
dst.Spec.Hpa.ScaleDown = Convert_v1alpha1_ScaleType_To_ScaleType(src.Spec.Hpa.ScaleDown) | ||
dst.Spec.Hpa.Template.ObjectMeta = src.Spec.Hpa.Template.ObjectMeta | ||
dst.Spec.Hpa.Template.Spec.MinReplicas = src.Spec.Hpa.Template.Spec.MinReplicas | ||
dst.Spec.Hpa.Template.Spec.MaxReplicas = src.Spec.Hpa.Template.Spec.MaxReplicas | ||
for _, metric := range src.Spec.Hpa.Template.Spec.Metrics { | ||
ms := autoscalingv2.MetricSpec{ | ||
Type: autoscalingv2.MetricSourceType(metric.Type), | ||
Object: nil, | ||
Pods: nil, | ||
Resource: Convert_v2beta1_ResourceMetricSource_To_autoscaling_ResourceMetricSource(metric.Resource), | ||
ContainerResource: nil, | ||
External: nil, | ||
} | ||
dst.Spec.Hpa.Template.Spec.Metrics = append(dst.Spec.Hpa.Template.Spec.Metrics, ms) | ||
|
||
} | ||
|
||
return nil | ||
} | ||
|
||
func Convert_v1alpha1_ScaleParams_To_ScaleParams(in v1alpha1.ScaleParams) ScaleParams { | ||
return ScaleParams{ | ||
CPU: ChangeParams(in.CPU), | ||
Memory: ChangeParams(in.Memory), | ||
Replicas: ChangeParams(in.Replicas), | ||
} | ||
} | ||
|
||
func Convert_v1alpha1_ScaleType_To_ScaleType(in v1alpha1.ScaleType) ScaleType { | ||
return ScaleType{ | ||
UpdatePolicy: UpdatePolicy(in.UpdatePolicy), | ||
MinChange: Convert_v1alpha1_ScaleParams_To_ScaleParams(in.MinChange), | ||
StabilizationDuration: in.StabilizationDuration, | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
vendor/github.com/gardener/hvpa-controller/apis/autoscaling/v1alpha1/hvpa_types.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
vendor/github.com/gardener/hvpa-controller/apis/autoscaling/v1alpha2/hvpa_conversion.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.