Merge pull request #12908 from mwielgus/kubectl_get_hpa

HorizontalPodAutoscaler in kubectl get
This commit is contained in:
Quinton Hoole 2015-09-04 09:07:08 -07:00
commit ded8569524
4 changed files with 54 additions and 0 deletions

View File

@ -285,6 +285,7 @@ _kubectl_get()
must_have_one_noun+=("deployment")
must_have_one_noun+=("endpoints")
must_have_one_noun+=("event")
must_have_one_noun+=("horizontalpodautoscaler")
must_have_one_noun+=("limitrange")
must_have_one_noun+=("namespace")
must_have_one_noun+=("node")
@ -460,6 +461,7 @@ _kubectl_delete()
must_have_one_noun+=("deployment")
must_have_one_noun+=("endpoints")
must_have_one_noun+=("event")
must_have_one_noun+=("horizontalpodautoscaler")
must_have_one_noun+=("limitrange")
must_have_one_noun+=("namespace")
must_have_one_noun+=("node")
@ -848,6 +850,7 @@ _kubectl_label()
must_have_one_noun+=("deployment")
must_have_one_noun+=("endpoints")
must_have_one_noun+=("event")
must_have_one_noun+=("horizontalpodautoscaler")
must_have_one_noun+=("limitrange")
must_have_one_noun+=("namespace")
must_have_one_noun+=("node")

View File

@ -103,6 +103,7 @@ type HorizontalPodAutoscalerSpec struct {
// HorizontalPodAutoscalerStatus contains the current status of a horizontal pod autoscaler
type HorizontalPodAutoscalerStatus struct {
// TODO: Consider if it is needed.
// CurrentReplicas is the number of replicas of pods managed by this autoscaler.
CurrentReplicas int `json:"currentReplicas"`

View File

@ -96,6 +96,7 @@ func expandResourceShortcut(resource string) string {
"cs": "componentstatuses",
"ev": "events",
"ep": "endpoints",
"hpa": "horizontalpodautoscalers",
"limits": "limitranges",
"no": "nodes",
"ns": "namespaces",

View File

@ -366,6 +366,7 @@ var persistentVolumeColumns = []string{"NAME", "LABELS", "CAPACITY", "ACCESSMODE
var persistentVolumeClaimColumns = []string{"NAME", "LABELS", "STATUS", "VOLUME", "CAPACITY", "ACCESSMODES", "AGE"}
var componentStatusColumns = []string{"NAME", "STATUS", "MESSAGE", "ERROR"}
var thirdPartyResourceColumns = []string{"NAME", "DESCRIPTION", "VERSION(S)"}
var horizontalPodAutoscalerColumns = []string{"NAME", "REFERENCE", "TARGET", "CURRENT", "MINPODS", "MAXPODS", "AGE"}
var withNamespacePrefixColumns = []string{"NAMESPACE"} // TODO(erictune): print cluster name too.
var deploymentColumns = []string{"NAME", "UPDATEDREPLICAS", "AGE"}
@ -405,6 +406,8 @@ func (h *HumanReadablePrinter) addDefaultHandlers() {
h.Handler(thirdPartyResourceColumns, printThirdPartyResourceList)
h.Handler(deploymentColumns, printDeployment)
h.Handler(deploymentColumns, printDeploymentList)
h.Handler(horizontalPodAutoscalerColumns, printHorizontalPodAutoscaler)
h.Handler(horizontalPodAutoscalerColumns, printHorizontalPodAutoscalerList)
}
func (h *HumanReadablePrinter) unknown(data []byte, w io.Writer) error {
@ -1150,6 +1153,52 @@ func printDeploymentList(list *expapi.DeploymentList, w io.Writer, withNamespace
return nil
}
func printHorizontalPodAutoscaler(hpa *expapi.HorizontalPodAutoscaler, w io.Writer, withNamespace bool, wide bool, showAll bool, columnLabels []string) error {
namespace := hpa.Namespace
name := hpa.Name
reference := fmt.Sprintf("%s/%s/%s/%s",
hpa.Spec.ScaleRef.Kind,
hpa.Spec.ScaleRef.Namespace,
hpa.Spec.ScaleRef.Name,
hpa.Spec.ScaleRef.Subresource)
target := fmt.Sprintf("%s %v", hpa.Spec.Target.Quantity.String(), hpa.Spec.Target.Resource)
current := "<waiting>"
if hpa.Status != nil && hpa.Status.CurrentConsumption != nil {
current = fmt.Sprintf("%s %v", hpa.Status.CurrentConsumption.Quantity.String(), hpa.Status.CurrentConsumption.Resource)
}
minPods := hpa.Spec.MinCount
maxPods := hpa.Spec.MaxCount
if withNamespace {
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
return err
}
}
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\t%d\t%s",
name,
reference,
target,
current,
minPods,
maxPods,
translateTimestamp(hpa.CreationTimestamp),
); err != nil {
return err
}
_, err := fmt.Fprint(w, appendLabels(hpa.Labels, columnLabels))
return err
}
func printHorizontalPodAutoscalerList(list *expapi.HorizontalPodAutoscalerList, w io.Writer, withNamespace bool, wide bool, showAll bool, columnLabels []string) error {
for i := range list.Items {
if err := printHorizontalPodAutoscaler(&list.Items[i], w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func appendLabels(itemLabels map[string]string, columnLabels []string) string {
var buffer bytes.Buffer