Skip to content

Commit

Permalink
fix: linter findings
Browse files Browse the repository at this point in the history
  • Loading branch information
druppelt committed Sep 12, 2024
1 parent 89b72e3 commit 1495ba0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
8 changes: 4 additions & 4 deletions cmd/kuota-calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ func (opts *KuotaCalcOpts) printDetailed(usage []*calc.ResourceUsage) {
u.Details.Replicas,
u.Details.Strategy,
u.Details.MaxReplicas,
u.Resources.CPUMin,
u.Resources.CPUMax,
u.Resources.MemoryMin,
u.Resources.MemoryMax,
u.Resources.CPUMin.String(),
u.Resources.CPUMax.String(),
u.Resources.MemoryMin.String(),
u.Resources.MemoryMax.String(),
)
}

Expand Down
5 changes: 5 additions & 0 deletions internal/calc/calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ type Details struct {
MaxReplicas int32
}

// Resources contains the limits and requests for cpu and memory that are typically used in kubernetes and openshift.
// Can be used to apply arithmetic operations equally on all quantities.
type Resources struct {
CPUMin resource.Quantity
CPUMax resource.Quantity
MemoryMin resource.Quantity
MemoryMax resource.Quantity
}

// ConvertToResources converts a kubernetes/openshift ResourceRequirements struct to a Resources struct
func ConvertToResources(req *v1.ResourceRequirements) Resources {
return Resources{
CPUMin: *req.Requests.Cpu(),
Expand All @@ -82,6 +85,7 @@ func (r Resources) Add(y Resources) Resources {
r.CPUMax.Add(y.CPUMax)
r.MemoryMin.Add(y.MemoryMin)
r.MemoryMax.Add(y.MemoryMax)

return r
}

Expand All @@ -92,6 +96,7 @@ func (r Resources) Mul(y float64) Resources {
r.CPUMax.SetMilli(int64(float64(r.CPUMax.MilliValue()) * y))
r.MemoryMin.SetMilli(int64(float64(r.MemoryMin.MilliValue()) * y))
r.MemoryMax.SetMilli(int64(float64(r.MemoryMax.MilliValue()) * y))

return r
}

Expand Down
4 changes: 2 additions & 2 deletions internal/calc/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func deployment(deployment appsv1.Deployment) (*ResourceUsage, error) {

if *replicas == 0 {
return &ResourceUsage{
Resources: *new(Resources),
Resources: Resources{},
Details: Details{
Version: deployment.APIVersion,
Kind: deployment.Kind,
Expand Down Expand Up @@ -93,7 +93,7 @@ func deployment(deployment appsv1.Deployment) (*ResourceUsage, error) {
}

podResources := podResources(&deployment.Spec.Template.Spec)
newResources := (*podResources).Mul(float64(*replicas)).Mul(resourceOverhead)
newResources := podResources.Mul(float64(*replicas)).Mul(resourceOverhead)

resourceUsage := ResourceUsage{
Resources: newResources,
Expand Down
4 changes: 2 additions & 2 deletions internal/calc/deploymentConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func deploymentConfig(deploymentConfig openshiftAppsV1.DeploymentConfig) (*Resou

if replicas == 0 {
return &ResourceUsage{
Resources: *new(Resources),
Resources: Resources{},
Details: Details{
Version: deploymentConfig.APIVersion,
Kind: deploymentConfig.Kind,
Expand Down Expand Up @@ -94,7 +94,7 @@ func deploymentConfig(deploymentConfig openshiftAppsV1.DeploymentConfig) (*Resou

podResources := podResources(&deploymentConfig.Spec.Template.Spec)
strategyResources := ConvertToResources(&deploymentConfig.Spec.Strategy.Resources)
newResources := (*podResources).Mul(float64(replicas)).Mul(resourceOverhead).Add(strategyResources)
newResources := podResources.Mul(float64(replicas)).Mul(resourceOverhead).Add(strategyResources)

resourceUsage := ResourceUsage{
Resources: newResources,
Expand Down
2 changes: 1 addition & 1 deletion internal/calc/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func statefulSet(s appsv1.StatefulSet) *ResourceUsage {
}

podResources := podResources(&s.Spec.Template.Spec)
newResources := (*podResources).Mul(float64(replicas))
newResources := podResources.Mul(float64(replicas))

resourceUsage := ResourceUsage{
Resources: newResources,
Expand Down

0 comments on commit 1495ba0

Please sign in to comment.