mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 15:37:24 +00:00
controllers: simplify deepcopy calls
This commit is contained in:
@@ -358,26 +358,15 @@ func (a *HorizontalController) reconcileKey(key string) error {
|
||||
|
||||
func (a *HorizontalController) reconcileAutoscaler(hpav1Shared *autoscalingv1.HorizontalPodAutoscaler) error {
|
||||
// make a copy so that we never mutate the shared informer cache (conversion can mutate the object)
|
||||
hpav1Raw, err := scheme.Scheme.DeepCopy(hpav1Shared)
|
||||
if err != nil {
|
||||
a.eventRecorder.Event(hpav1Shared, v1.EventTypeWarning, "FailedConvertHPA", err.Error())
|
||||
return fmt.Errorf("failed to deep-copy the HPA: %v", err)
|
||||
}
|
||||
|
||||
hpav1 := hpav1Shared.DeepCopy()
|
||||
// then, convert to autoscaling/v2, which makes our lives easier when calculating metrics
|
||||
hpav1 := hpav1Raw.(*autoscalingv1.HorizontalPodAutoscaler)
|
||||
hpaRaw, err := UnsafeConvertToVersionVia(hpav1, autoscalingv2.SchemeGroupVersion)
|
||||
if err != nil {
|
||||
a.eventRecorder.Event(hpav1, v1.EventTypeWarning, "FailedConvertHPA", err.Error())
|
||||
return fmt.Errorf("failed to convert the given HPA to %s: %v", autoscalingv2.SchemeGroupVersion.String(), err)
|
||||
}
|
||||
hpa := hpaRaw.(*autoscalingv2.HorizontalPodAutoscaler)
|
||||
hpaStatusOriginalRaw, err := scheme.Scheme.DeepCopy(&hpa.Status)
|
||||
if err != nil {
|
||||
a.eventRecorder.Event(hpav1Shared, v1.EventTypeWarning, "FailedConvertHPA", err.Error())
|
||||
return fmt.Errorf("failed to deep-copy the HPA status: %v", err)
|
||||
}
|
||||
hpaStatusOriginal := hpaStatusOriginalRaw.(*autoscalingv2.HorizontalPodAutoscalerStatus)
|
||||
hpaStatusOriginal := hpa.Status.DeepCopy()
|
||||
|
||||
reference := fmt.Sprintf("%s/%s/%s", hpa.Spec.ScaleTargetRef.Kind, hpa.Namespace, hpa.Spec.ScaleTargetRef.Name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user