Introduce concept of a default limit

This commit is contained in:
derekwaynecarr
2015-03-31 10:12:57 -04:00
parent f7f133784f
commit c2b670513c
13 changed files with 251 additions and 175 deletions

View File

@@ -1559,6 +1559,8 @@ type LimitRangeItem struct {
Max ResourceList `json:"max,omitempty"`
// Min usage constraints on this kind by resource name
Min ResourceList `json:"min,omitempty"`
// Default usage constraints on this kind by resource name
Default ResourceList `json:"default,omitempty"`
}
// LimitRangeSpec defines a min/max usage limit for resources that match on kind

View File

@@ -923,6 +923,9 @@ func init() {
if err := s.Convert(&in.Min, &out.Min, 0); err != nil {
return err
}
if err := s.Convert(&in.Default, &out.Default, 0); err != nil {
return err
}
return nil
},
func(in *LimitRangeItem, out *newer.LimitRangeItem, s conversion.Scope) error {
@@ -934,6 +937,9 @@ func init() {
if err := s.Convert(&in.Min, &out.Min, 0); err != nil {
return err
}
if err := s.Convert(&in.Default, &out.Default, 0); err != nil {
return err
}
return nil
},

View File

@@ -1358,6 +1358,8 @@ type LimitRangeItem struct {
Max ResourceList `json:"max,omitempty" description:"max usage constraints on this kind by resource name"`
// Min usage constraints on this kind by resource name
Min ResourceList `json:"min,omitempty" description:"min usage constraints on this kind by resource name"`
// Default usage constraints on this kind by resource name
Default ResourceList `json:"default,omitempty" description:"default values on this kind by resource name if omitted"`
}
// LimitRangeSpec defines a min/max usage limit for resources that match on kind

View File

@@ -854,6 +854,9 @@ func init() {
if err := s.Convert(&in.Min, &out.Min, 0); err != nil {
return err
}
if err := s.Convert(&in.Default, &out.Default, 0); err != nil {
return err
}
return nil
},
func(in *LimitRangeItem, out *newer.LimitRangeItem, s conversion.Scope) error {
@@ -865,6 +868,9 @@ func init() {
if err := s.Convert(&in.Min, &out.Min, 0); err != nil {
return err
}
if err := s.Convert(&in.Default, &out.Default, 0); err != nil {
return err
}
return nil
},

View File

@@ -1420,6 +1420,8 @@ type LimitRangeItem struct {
Max ResourceList `json:"max,omitempty" description:"max usage constraints on this kind by resource name"`
// Min usage constraints on this kind by resource name
Min ResourceList `json:"min,omitempty" description:"min usage constraints on this kind by resource name"`
// Default usage constraints on this kind by resource name
Default ResourceList `json:"default,omitempty" description:"default values on this kind by resource name if omitted"`
}
// LimitRangeSpec defines a min/max usage limit for resources that match on kind

View File

@@ -1464,6 +1464,8 @@ type LimitRangeItem struct {
Max ResourceList `json:"max,omitempty" description:"max usage constraints on this kind by resource name"`
// Min usage constraints on this kind by resource name
Min ResourceList `json:"min,omitempty" description:"min usage constraints on this kind by resource name"`
// Default usage constraints on this kind by resource name
Default ResourceList `json:"default,omitempty" description:"default values on this kind by resource name if omitted"`
}
// LimitRangeSpec defines a min/max usage limit for resources that match on kind

View File

@@ -115,12 +115,13 @@ func (d *LimitRangeDescriber) Describe(namespace, name string) (string, error) {
func describeLimitRange(limitRange *api.LimitRange) (string, error) {
return tabbedString(func(out io.Writer) error {
fmt.Fprintf(out, "Name:\t%s\n", limitRange.Name)
fmt.Fprintf(out, "Type\tResource\tMin\tMax\n")
fmt.Fprintf(out, "----\t--------\t---\t---\n")
fmt.Fprintf(out, "Type\tResource\tMin\tMax\tDefault\n")
fmt.Fprintf(out, "----\t--------\t---\t---\t---\n")
for i := range limitRange.Spec.Limits {
item := limitRange.Spec.Limits[i]
maxResources := item.Max
minResources := item.Min
defaultResources := item.Default
set := map[api.ResourceName]bool{}
for k := range maxResources {
@@ -129,11 +130,15 @@ func describeLimitRange(limitRange *api.LimitRange) (string, error) {
for k := range minResources {
set[k] = true
}
for k := range defaultResources {
set[k] = true
}
for k := range set {
// if no value is set, we output -
maxValue := "-"
minValue := "-"
defaultValue := "-"
maxQuantity, maxQuantityFound := maxResources[k]
if maxQuantityFound {
@@ -145,8 +150,13 @@ func describeLimitRange(limitRange *api.LimitRange) (string, error) {
minValue = minQuantity.String()
}
msg := "%v\t%v\t%v\t%v\n"
fmt.Fprintf(out, msg, item.Type, k, minValue, maxValue)
defaultQuantity, defaultQuantityFound := defaultResources[k]
if defaultQuantityFound {
defaultValue = defaultQuantity.String()
}
msg := "%v\t%v\t%v\t%v\t%v\n"
fmt.Fprintf(out, msg, item.Type, k, minValue, maxValue, defaultValue)
}
}
return nil