Skip to content

Commit

Permalink
Merge pull request #16918 from juanvallejo/jvallejo/add-limit-limitra…
Browse files Browse the repository at this point in the history
…tio-describe-project

Automatic merge from submit-queue.

add Limit & Limit/Request columns

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1278683

Adds the "Limit" and "Limit/Request" columns seen when describing a
LimitRange to the "describe" output of projects.

**Before**
```
$ oc describe project myproject
...
Resource limits:
        Name:           limits
        Type            Resource        Min     Max     Default
        ----            --------        ---     ---     ---
        Pod             cpu             200m    2       -
        Pod             memory          6Mi     1Gi     -
        Container       cpu             100m    2       300m
        Container       memory          4Mi     1Gi     200Mi
```

**After**
```
$ oc describe project myproject
...
Resource limits:
        Name:           limits
        Type            Resource        Min     Max     Default Limit   Limit/Request
        ----            --------        ---     ---     ---     -----   -------------
        Pod             cpu             200m    2       -       -       -
        Pod             memory          6Mi     1Gi     -       -       -
        Container       cpu             100m    2       300m    300m    10
        Container       memory          4Mi     1Gi     200Mi   200Mi   -
```

cc @openshift/cli-review
  • Loading branch information
openshift-merge-robot authored Oct 26, 2017
2 parents d3924ff + e27fc1b commit e92d5c5
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions pkg/oc/cli/describe/describer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,13 +1017,15 @@ func (d *ProjectDescriber) Describe(namespace, name string, settings kprinters.D
for i := range limitRangeList.Items {
limitRange := &limitRangeList.Items[i]
fmt.Fprintf(out, "\tName:\t%s\n", limitRange.Name)
fmt.Fprintf(out, "\tType\tResource\tMin\tMax\tDefault\n")
fmt.Fprintf(out, "\t----\t--------\t---\t---\t---\n")
fmt.Fprintf(out, "\tType\tResource\tMin\tMax\tDefault\tLimit\tLimit/Request\n")
fmt.Fprintf(out, "\t----\t--------\t---\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
defaultRequestResources := item.DefaultRequest
ratio := item.MaxLimitRequestRatio

set := map[kapi.ResourceName]bool{}
for k := range maxResources {
Expand All @@ -1035,12 +1037,20 @@ func (d *ProjectDescriber) Describe(namespace, name string, settings kprinters.D
for k := range defaultResources {
set[k] = true
}
for k := range defaultRequestResources {
set[k] = true
}
for k := range ratio {
set[k] = true
}

for k := range set {
// if no value is set, we output -
maxValue := "-"
minValue := "-"
defaultValue := "-"
defaultLimitValue := "-"
ratioValue := "-"

maxQuantity, maxQuantityFound := maxResources[k]
if maxQuantityFound {
Expand All @@ -1057,8 +1067,18 @@ func (d *ProjectDescriber) Describe(namespace, name string, settings kprinters.D
defaultValue = defaultQuantity.String()
}

msg := "\t%v\t%v\t%v\t%v\t%v\n"
fmt.Fprintf(out, msg, item.Type, k, minValue, maxValue, defaultValue)
defaultLimitQuantity, defaultLimitQuantityFound := defaultResources[k]
if defaultLimitQuantityFound {
defaultLimitValue = defaultLimitQuantity.String()
}

ratioQuantity, ratioQuantityFound := ratio[k]
if ratioQuantityFound {
ratioValue = ratioQuantity.String()
}

msg := "\t%v\t%v\t%v\t%v\t%v\t%v\t%v\n"
fmt.Fprintf(out, msg, item.Type, k, minValue, maxValue, defaultValue, defaultLimitValue, ratioValue)
}
}
}
Expand Down

0 comments on commit e92d5c5

Please sign in to comment.