This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from bookingcom/isutton/6-capacity-fleet-summary
Introduce fleet summary report in Capacity Target
- Loading branch information
Showing
11 changed files
with
1,481 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package builder | ||
|
||
import ( | ||
"sort" | ||
|
||
shipper "github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1" | ||
) | ||
|
||
type ContainerStateBreakdown struct { | ||
containerName string | ||
states []*shipper.ClusterCapacityReportContainerStateBreakdown | ||
} | ||
|
||
func NewContainerBreakdown(containerName string) *ContainerStateBreakdown { | ||
return &ContainerStateBreakdown{containerName: containerName} | ||
} | ||
|
||
func (c *ContainerStateBreakdown) AddOrIncrementState( | ||
podExampleName string, | ||
containerConditionType string, | ||
containerConditionReason string, | ||
containerExampleMessage string, | ||
) *ContainerStateBreakdown { | ||
|
||
var m *string | ||
if len(containerExampleMessage) > 0 { | ||
m = &containerExampleMessage | ||
} | ||
|
||
for _, s := range c.states { | ||
if s.Type == containerConditionType && s.Reason == containerConditionReason { | ||
s.Count += 1 | ||
return c | ||
} | ||
} | ||
|
||
breakdown := shipper.ClusterCapacityReportContainerStateBreakdown{ | ||
Count: 1, | ||
Type: containerConditionType, | ||
Reason: containerConditionReason, | ||
Example: shipper.ClusterCapacityReportContainerBreakdownExample{ | ||
Pod: podExampleName, | ||
Message: m, | ||
}, | ||
} | ||
c.states = append(c.states, &breakdown) | ||
return c | ||
} | ||
|
||
func (c *ContainerStateBreakdown) Build() shipper.ClusterCapacityReportContainerBreakdown { | ||
stateCount := len(c.states) | ||
orderedStates := make([]shipper.ClusterCapacityReportContainerStateBreakdown, stateCount) | ||
for i, v := range c.states { | ||
orderedStates[i] = *v | ||
} | ||
|
||
sort.Slice(orderedStates, func(i, j int) bool { | ||
return orderedStates[i].Type < orderedStates[j].Type | ||
}) | ||
|
||
return shipper.ClusterCapacityReportContainerBreakdown{ | ||
Name: c.containerName, | ||
States: orderedStates, | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
pkg/controller/capacity/builder/pod_condition_breakdown.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package builder | ||
|
||
import ( | ||
"sort" | ||
|
||
shipper "github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1" | ||
) | ||
|
||
type containerStateBreakdownBuilders map[string]*ContainerStateBreakdown | ||
|
||
func (c containerStateBreakdownBuilders) Get(containerName string) *ContainerStateBreakdown { | ||
var b *ContainerStateBreakdown | ||
var ok bool | ||
if b, ok = c[containerName]; !ok { | ||
b = NewContainerBreakdown(containerName) | ||
c[containerName] = b | ||
} | ||
return b | ||
} | ||
|
||
type PodConditionBreakdown struct { | ||
podCount uint32 | ||
podConditionType string | ||
podConditionStatus string | ||
podConditionReason string | ||
|
||
containerStateBreakdownBuilders containerStateBreakdownBuilders | ||
} | ||
|
||
func NewPodConditionBreakdown( | ||
initialPodCount uint32, | ||
podConditionType string, | ||
podConditionStatus string, | ||
podConditionReason string, | ||
) *PodConditionBreakdown { | ||
return &PodConditionBreakdown{ | ||
podCount: initialPodCount, | ||
podConditionType: podConditionType, | ||
podConditionStatus: podConditionStatus, | ||
podConditionReason: podConditionReason, | ||
containerStateBreakdownBuilders: make(containerStateBreakdownBuilders), | ||
} | ||
} | ||
|
||
func PodConditionBreakdownKey(typ, status, reason string) string { | ||
return typ + status + reason | ||
} | ||
|
||
func (p *PodConditionBreakdown) Key() string { | ||
return PodConditionBreakdownKey(p.podConditionType, p.podConditionStatus, p.podConditionReason) | ||
} | ||
|
||
func (p *PodConditionBreakdown) AddOrIncrementContainerState( | ||
containerName string, | ||
podExampleName string, | ||
containerConditionType string, | ||
containerConditionReason string, | ||
containerExampleMessage string, | ||
) *PodConditionBreakdown { | ||
p.containerStateBreakdownBuilders. | ||
Get(containerName). | ||
AddOrIncrementState(podExampleName, containerConditionType, containerConditionReason, containerExampleMessage) | ||
return p | ||
} | ||
|
||
func (p *PodConditionBreakdown) IncrementCount() *PodConditionBreakdown { | ||
p.podCount += 1 | ||
return p | ||
} | ||
|
||
func (p *PodConditionBreakdown) Build() shipper.ClusterCapacityReportBreakdown { | ||
|
||
orderedContainers := make([]shipper.ClusterCapacityReportContainerBreakdown, 0) | ||
|
||
for _, v := range p.containerStateBreakdownBuilders { | ||
orderedContainers = append(orderedContainers, v.Build()) | ||
} | ||
|
||
sort.Slice(orderedContainers, func(i, j int) bool { | ||
return orderedContainers[i].Name < orderedContainers[j].Name | ||
}) | ||
|
||
return shipper.ClusterCapacityReportBreakdown{ | ||
Type: p.podConditionType, | ||
Status: p.podConditionStatus, | ||
Count: p.podCount, | ||
Reason: p.podConditionReason, | ||
Containers: orderedContainers, | ||
} | ||
} |
Oops, something went wrong.