Skip to content

Commit

Permalink
plans: fix display for custom CPU with burst
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Oct 18, 2023
1 parent 2e710c7 commit 9966709
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tsuru/client/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ func renderPlans(plans []apptypes.Plan, opts renderPlansOpts) string {
memory = resource.NewQuantity(p.Memory, resource.BinarySI).String()
}

cpuMilli := p.CPUMilli
if p.Override.CPUMilli != nil {
cpuMilli = *p.Override.CPUMilli
cpu = fmt.Sprintf("%g", float64(*p.Override.CPUMilli)/10) + "% (override)"
} else if p.CPUMilli > 0 {
cpu = fmt.Sprintf("%g", float64(p.CPUMilli)/10) + "%"
Expand All @@ -108,11 +110,11 @@ func renderPlans(plans []apptypes.Plan, opts renderPlansOpts) string {
cpuBurstObservation = " (override)"
}

row = append(row, displayCPUBurst(p.CPUMilli, cpuBurst)+cpuBurstObservation)
row = append(row, displayCPUBurst(cpuMilli, cpuBurst)+cpuBurstObservation)
}

if showBurstColumn && opts.showMaxBurstAllowed {
row = append(row, displayCPUBurst(p.CPUMilli, p.CPUBurst.MaxAllowed))
row = append(row, displayCPUBurst(cpuMilli, p.CPUBurst.MaxAllowed))
}

if opts.showDefaultColumn {
Expand Down
29 changes: 29 additions & 0 deletions tsuru/client/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,35 @@ func (s *S) TestPlanListWithBurst(c *check.C) {
c.Assert(stdout.String(), check.Equals, expected)
}

func (s *S) TestPlanListWithBurstAndCPUOverrided(c *check.C) {
var stdout, stderr bytes.Buffer
result := `[
{"name": "test", "cpumilli": 300, "memory": 536870912, "default": false, "cpuBurst": {"default": 1.1}, "override": {"cpumilli": 1000}}
]`
expected := `+------+-----------------+--------+---------------------+---------+
| Name | CPU | Memory | CPU Burst (default) | Default |
+------+-----------------+--------+---------------------+---------+
| test | 100% (override) | 512Mi | up to 110% | false |
+------+-----------------+--------+---------------------+---------+
`
context := cmd.Context{
Args: []string{},
Stdout: &stdout,
Stderr: &stderr,
}
trans := &cmdtest.ConditionalTransport{
Transport: cmdtest.Transport{Message: string(result), Status: http.StatusOK},
CondFunc: func(req *http.Request) bool {
return strings.HasSuffix(req.URL.Path, "/plans") && req.Method == "GET"
},
}
client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)
command := PlanList{}
err := command.Run(&context, client)
c.Assert(err, check.IsNil)
c.Assert(stdout.String(), check.Equals, expected)
}

func (s *S) TestPlanListWithBurstKubernetesFriendly(c *check.C) {
var stdout, stderr bytes.Buffer
result := `[
Expand Down

0 comments on commit 9966709

Please sign in to comment.