Merge pull request #134263 from ardaguclu/autoscale-dryrun-client

Add given namespace in dryrun=client output of HPA
This commit is contained in:
Kubernetes Prow Robot
2025-11-03 09:34:05 -08:00
committed by GitHub
2 changed files with 12 additions and 0 deletions

View File

@@ -362,6 +362,10 @@ func (o *AutoscaleOptions) createHorizontalPodAutoscalerV2(refName string, mappi
scaler.Spec.MinReplicas = &o.Min
}
if o.enforceNamespace {
scaler.ObjectMeta.Namespace = o.namespace
}
metrics := []autoscalingv2.MetricSpec{}
// add CPU metric if any of the CPU targets are specified
@@ -470,6 +474,10 @@ func (o *AutoscaleOptions) createHorizontalPodAutoscalerV1(refName string, mappi
scaler.Spec.TargetCPUUtilizationPercentage = &c
}
if o.enforceNamespace {
scaler.ObjectMeta.Namespace = o.namespace
}
return &scaler
}

View File

@@ -811,6 +811,10 @@ run_rs_tests() {
kube::test::if_has_string "${output_message}" 'kubectl-autoscale'
# Clean up
kubectl delete hpa frontend "${kube_flags[@]:?}"
# autoscale with --dry-run=client should include namespace in output
autoscale_namespace=$(kubectl get rs frontend "${kube_flags[@]:?}" -o jsonpath='{.metadata.namespace}')
output_message=$(kubectl autoscale rs frontend "${kube_flags[@]:?}" --max=3 -n "$autoscale_namespace" --dry-run=client -o yaml 2>&1)
kube::test::if_has_string "${output_message}" 'namespace:'
# autoscale without specifying --max should fail
! kubectl autoscale rs frontend "${kube_flags[@]:?}" || exit 1
# Clean up