diff --git a/pkg/features/kube_features.go b/pkg/features/kube_features.go index 69885ec3c5b..570f41836e0 100644 --- a/pkg/features/kube_features.go +++ b/pkg/features/kube_features.go @@ -280,7 +280,7 @@ const ( // kep: https://kep.k8s.io/1610 // alpha: v1.20 // beta: v1.27 - // beta: v1.30 + // GA: v1.30 // // Add support for the HPA to scale based on metrics from individual containers // in target pods @@ -995,7 +995,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS GracefulNodeShutdownBasedOnPodPriority: {Default: true, PreRelease: featuregate.Beta}, - HPAContainerMetrics: {Default: true, PreRelease: featuregate.GA}, + HPAContainerMetrics: {Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.32 HonorPVReclaimPolicy: {Default: false, PreRelease: featuregate.Alpha}, diff --git a/pkg/registry/autoscaling/horizontalpodautoscaler/strategy.go b/pkg/registry/autoscaling/horizontalpodautoscaler/strategy.go index 59cc45f647b..8558440f7aa 100644 --- a/pkg/registry/autoscaling/horizontalpodautoscaler/strategy.go +++ b/pkg/registry/autoscaling/horizontalpodautoscaler/strategy.go @@ -65,7 +65,12 @@ func (autoscalerStrategy) GetResetFields() map[fieldpath.APIVersion]*fieldpath.S } // PrepareForCreate clears fields that are not allowed to be set by end users on creation. -func (autoscalerStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {} +func (autoscalerStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) { + newHPA := obj.(*autoscaling.HorizontalPodAutoscaler) + + // create cannot set status + newHPA.Status = autoscaling.HorizontalPodAutoscalerStatus{} +} // Validate validates a new autoscaler. func (autoscalerStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList { @@ -88,7 +93,12 @@ func (autoscalerStrategy) AllowCreateOnUpdate() bool { } // PrepareForUpdate clears fields that are not allowed to be set by end users on update. -func (autoscalerStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {} +func (autoscalerStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) { + newHPA := obj.(*autoscaling.HorizontalPodAutoscaler) + oldHPA := old.(*autoscaling.HorizontalPodAutoscaler) + // Update is not allowed to set status + newHPA.Status = oldHPA.Status +} // ValidateUpdate is the default update validation for an end user. func (autoscalerStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {