Merge pull request #39279 from andrewsykim/kubectl-get-hpa-show-current-replicas

Automatic merge from submit-queue (batch tested with PRs 35782, 35831, 39279, 40853, 40867)

kubectl get hpa should print number of replicas

**What this PR does / why we need it**:
Prints number of replicas on deployment managed by HPA. 

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #
None, couldn't find one related.

**Special notes for your reviewer**:
Couldn't find any tests for validating kubectl output for hpa, if there are please point me to them and I will add. 

**Release note**:

```release-note
```
This commit is contained in:
Kubernetes Submit Queue 2017-02-02 09:53:50 -08:00 committed by GitHub
commit 9721459536

View File

@ -533,7 +533,7 @@ var (
// TODO: consider having 'KIND' for third party resource data // TODO: consider having 'KIND' for third party resource data
thirdPartyResourceDataColumns = []string{"NAME", "LABELS", "DATA"} thirdPartyResourceDataColumns = []string{"NAME", "LABELS", "DATA"}
horizontalPodAutoscalerColumns = []string{"NAME", "REFERENCE", "TARGET", "CURRENT", "MINPODS", "MAXPODS", "AGE"} horizontalPodAutoscalerColumns = []string{"NAME", "REFERENCE", "TARGET", "CURRENT", "MINPODS", "MAXPODS", "REPLICAS", "AGE"}
withNamespacePrefixColumns = []string{"NAMESPACE"} // TODO(erictune): print cluster name too. withNamespacePrefixColumns = []string{"NAMESPACE"} // TODO(erictune): print cluster name too.
deploymentColumns = []string{"NAME", "DESIRED", "CURRENT", "UP-TO-DATE", "AVAILABLE", "AGE"} deploymentColumns = []string{"NAME", "DESIRED", "CURRENT", "UP-TO-DATE", "AVAILABLE", "AGE"}
deploymentWideColumns = []string{"CONTAINER(S)", "IMAGE(S)", "SELECTOR"} deploymentWideColumns = []string{"CONTAINER(S)", "IMAGE(S)", "SELECTOR"}
@ -2165,6 +2165,7 @@ func printHorizontalPodAutoscaler(hpa *autoscaling.HorizontalPodAutoscaler, w io
minPods = fmt.Sprintf("%d", *hpa.Spec.MinReplicas) minPods = fmt.Sprintf("%d", *hpa.Spec.MinReplicas)
} }
maxPods := hpa.Spec.MaxReplicas maxPods := hpa.Spec.MaxReplicas
currentReplicas := hpa.Status.CurrentReplicas
if options.WithNamespace { if options.WithNamespace {
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil { if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
@ -2172,13 +2173,14 @@ func printHorizontalPodAutoscaler(hpa *autoscaling.HorizontalPodAutoscaler, w io
} }
} }
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%d\t%s", if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%d\t%d\t%s",
name, name,
reference, reference,
target, target,
current, current,
minPods, minPods,
maxPods, maxPods,
currentReplicas,
translateTimestamp(hpa.CreationTimestamp), translateTimestamp(hpa.CreationTimestamp),
); err != nil { ); err != nil {
return err return err