Add a limit range resource

This commit is contained in:
derekwaynecarr
2015-01-22 16:52:40 -05:00
parent 358ace610d
commit 091cbe5fa2
26 changed files with 1208 additions and 16 deletions

View File

@@ -47,10 +47,66 @@ func DescriberFor(kind string, c *client.Client) (Describer, bool) {
return &ServiceDescriber{c}, true
case "Minion", "Node":
return &MinionDescriber{c}, true
case "LimitRange":
return &LimitRangeDescriber{c}, true
}
return nil, false
}
// LimitRangeDescriber generates information about a limit range
type LimitRangeDescriber struct {
client.Interface
}
func (d *LimitRangeDescriber) Describe(namespace, name string) (string, error) {
lr := d.LimitRanges(namespace)
limitRange, err := lr.Get(name)
if err != nil {
return "", err
}
return tabbedString(func(out io.Writer) error {
fmt.Fprintf(out, "Name:\t%s\n", limitRange.Name)
fmt.Fprintf(out, "Kind\tResource\tMin\tMax\n")
fmt.Fprintf(out, "----\t--------\t---\t---\n")
for i, _ := range limitRange.Spec.Limits {
item := limitRange.Spec.Limits[i]
kind := item.Kind
maxResources := item.Max
minResources := item.Min
set := map[api.ResourceName]bool{}
for k, _ := range maxResources {
set[k] = true
}
for k, _ := range minResources {
set[k] = true
}
for k, _ := range set {
// if no value is set, we output -
maxValue := "-"
minValue := "-"
maxQuantity, maxQuantityFound := maxResources[k]
if maxQuantityFound {
maxValue = maxQuantity.String()
}
minQuantity, minQuantityFound := minResources[k]
if minQuantityFound {
minValue = minQuantity.String()
}
msg := "%v\t%v\t%v\t%v\n"
fmt.Fprintf(out, msg, kind, k, minValue, maxValue)
}
}
return nil
})
}
// PodDescriber generates information about a pod and the replication controllers that
// create it.
type PodDescriber struct {