Skip to content

Commit

Permalink
fix: export ResourceUsage.Resources
Browse files Browse the repository at this point in the history
ResourceUsage.Resources were not exported, breaking the cmd
  • Loading branch information
druppelt committed Sep 12, 2024
1 parent 7fc13b7 commit 89b72e3
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 46 deletions.
16 changes: 8 additions & 8 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.CPUMin,
u.CPUMax,
u.MemoryMin,
u.MemoryMax,
u.Resources.CPUMin,
u.Resources.CPUMax,
u.Resources.MemoryMin,
u.Resources.MemoryMax,
)
}

Expand All @@ -156,10 +156,10 @@ func (opts *KuotaCalcOpts) printSummary(usage []*calc.ResourceUsage) {
)

for _, u := range usage {
cpuMinUsage.Add(*u.CPUMin)
cpuMaxUsage.Add(*u.CPUMax)
memoryMinUsage.Add(*u.MemoryMin)
memoryMaxUsage.Add(*u.MemoryMax)
cpuMinUsage.Add(u.Resources.CPUMin)
cpuMaxUsage.Add(u.Resources.CPUMax)
memoryMinUsage.Add(u.Resources.MemoryMin)
memoryMaxUsage.Add(u.Resources.MemoryMax)
}

_, _ = fmt.Fprintf(opts.Out, "CPU Request: %s\nCPU Limit: %s\nMemory Request: %s\nMemory Limit: %s\n",
Expand Down
2 changes: 1 addition & 1 deletion internal/calc/calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (cErr CalculationError) Unwrap() error {

// ResourceUsage summarizes the usage of compute resources for a k8s resource.
type ResourceUsage struct {
resources Resources
Resources Resources
Details Details
}

Expand Down
2 changes: 1 addition & 1 deletion internal/calc/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ func cronjob(cronjob batchV1.CronJob) *ResourceUsage {
podResources := podResources(&cronjob.Spec.JobTemplate.Spec.Template.Spec)

resourceUsage := ResourceUsage{
resources: *podResources,
Resources: *podResources,
Details: Details{
Version: cronjob.APIVersion,
Kind: cronjob.Kind,
Expand Down
8 changes: 4 additions & 4 deletions internal/calc/cronjob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ func TestCronJob(t *testing.T) {
r.NoError(err)
r.NotEmpty(usage)

AssertEqualQuantities(r, test.cpuMin, usage.resources.CPUMin, "cpu request value")
AssertEqualQuantities(r, test.cpuMax, usage.resources.CPUMax, "cpu limit value")
AssertEqualQuantities(r, test.memoryMin, usage.resources.MemoryMin, "memory request value")
AssertEqualQuantities(r, test.memoryMax, usage.resources.MemoryMax, "memory limit value")
AssertEqualQuantities(r, test.cpuMin, usage.Resources.CPUMin, "cpu request value")
AssertEqualQuantities(r, test.cpuMax, usage.Resources.CPUMax, "cpu limit value")
AssertEqualQuantities(r, test.memoryMin, usage.Resources.MemoryMin, "memory request value")
AssertEqualQuantities(r, test.memoryMax, usage.Resources.MemoryMax, "memory limit value")
r.Equalf(test.replicas, usage.Details.Replicas, "replicas")
r.Equalf(test.maxReplicas, usage.Details.MaxReplicas, "maxReplicas")
r.Equalf(test.strategy, usage.Details.Strategy, "strategy")
Expand Down
2 changes: 1 addition & 1 deletion internal/calc/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func daemonSet(dSet appsv1.DaemonSet) *ResourceUsage {
podResources := podResources(&dSet.Spec.Template.Spec)

resourceUsage := ResourceUsage{
resources: *podResources,
Resources: *podResources,
Details: Details{
Version: dSet.APIVersion,
Kind: dSet.Kind,
Expand Down
8 changes: 4 additions & 4 deletions internal/calc/daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ func TestDaemonSet(t *testing.T) {
r.NoError(err)
r.NotEmpty(usage)

AssertEqualQuantities(r, test.cpuMin, usage.resources.CPUMin, "cpu request value")
AssertEqualQuantities(r, test.cpuMax, usage.resources.CPUMax, "cpu limit value")
AssertEqualQuantities(r, test.memoryMin, usage.resources.MemoryMin, "memory request value")
AssertEqualQuantities(r, test.memoryMax, usage.resources.MemoryMax, "memory limit value")
AssertEqualQuantities(r, test.cpuMin, usage.Resources.CPUMin, "cpu request value")
AssertEqualQuantities(r, test.cpuMax, usage.Resources.CPUMax, "cpu limit value")
AssertEqualQuantities(r, test.memoryMin, usage.Resources.MemoryMin, "memory request value")
AssertEqualQuantities(r, test.memoryMax, usage.Resources.MemoryMax, "memory limit value")
r.Equalf(test.replicas, usage.Details.Replicas, "replicas")
r.Equalf(test.maxReplicas, usage.Details.MaxReplicas, "maxReplicas")
r.Equalf(string(test.strategy), usage.Details.Strategy, "strategy")
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: *new(Resources),

Check failure on line 24 in internal/calc/deployment.go

View workflow job for this annotation

GitHub Actions / lint

newDeref: replace `*new(Resources)` with `Resources{}` (gocritic)
Details: Details{
Version: deployment.APIVersion,
Kind: deployment.Kind,
Expand Down Expand Up @@ -96,7 +96,7 @@ func deployment(deployment appsv1.Deployment) (*ResourceUsage, error) {
newResources := (*podResources).Mul(float64(*replicas)).Mul(resourceOverhead)

Check failure on line 96 in internal/calc/deployment.go

View workflow job for this annotation

GitHub Actions / lint

underef: could simplify (*podResources).Mul to podResources.Mul (gocritic)

resourceUsage := ResourceUsage{
resources: newResources,
Resources: newResources,
Details: Details{
Version: deployment.APIVersion,
Kind: deployment.Kind,
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: *new(Resources),

Check failure on line 24 in internal/calc/deploymentConfig.go

View workflow job for this annotation

GitHub Actions / lint

newDeref: replace `*new(Resources)` with `Resources{}` (gocritic)
Details: Details{
Version: deploymentConfig.APIVersion,
Kind: deploymentConfig.Kind,
Expand Down Expand Up @@ -97,7 +97,7 @@ func deploymentConfig(deploymentConfig openshiftAppsV1.DeploymentConfig) (*Resou
newResources := (*podResources).Mul(float64(replicas)).Mul(resourceOverhead).Add(strategyResources)

Check failure on line 97 in internal/calc/deploymentConfig.go

View workflow job for this annotation

GitHub Actions / lint

underef: could simplify (*podResources).Mul to podResources.Mul (gocritic)

resourceUsage := ResourceUsage{
resources: newResources,
Resources: newResources,
Details: Details{
Version: deploymentConfig.APIVersion,
Kind: deploymentConfig.Kind,
Expand Down
8 changes: 4 additions & 4 deletions internal/calc/deploymentConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func TestDeploymentConfig(t *testing.T) {
r.NoError(err)
r.NotEmpty(usage)

AssertEqualQuantities(r, test.cpuMin, usage.resources.CPUMin, "cpu request value")
AssertEqualQuantities(r, test.cpuMax, usage.resources.CPUMax, "cpu limit value")
AssertEqualQuantities(r, test.memoryMin, usage.resources.MemoryMin, "memory request value")
AssertEqualQuantities(r, test.memoryMax, usage.resources.MemoryMax, "memory limit value")
AssertEqualQuantities(r, test.cpuMin, usage.Resources.CPUMin, "cpu request value")
AssertEqualQuantities(r, test.cpuMax, usage.Resources.CPUMax, "cpu limit value")
AssertEqualQuantities(r, test.memoryMin, usage.Resources.MemoryMin, "memory request value")
AssertEqualQuantities(r, test.memoryMax, usage.Resources.MemoryMax, "memory limit value")
r.Equal(test.replicas, usage.Details.Replicas, "replicas")
r.Equal(string(test.strategy), usage.Details.Strategy, "strategy")
r.Equal(test.maxReplicas, usage.Details.MaxReplicas, "maxReplicas")
Expand Down
8 changes: 4 additions & 4 deletions internal/calc/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ func TestDeployment(t *testing.T) {
r.NoError(err)
r.NotEmpty(usage)

AssertEqualQuantities(r, test.cpuMin, usage.resources.CPUMin, "cpu request value")
AssertEqualQuantities(r, test.cpuMax, usage.resources.CPUMax, "cpu limit value")
AssertEqualQuantities(r, test.memoryMin, usage.resources.MemoryMin, "memory request value")
AssertEqualQuantities(r, test.memoryMax, usage.resources.MemoryMax, "memory limit value")
AssertEqualQuantities(r, test.cpuMin, usage.Resources.CPUMin, "cpu request value")
AssertEqualQuantities(r, test.cpuMax, usage.Resources.CPUMax, "cpu limit value")
AssertEqualQuantities(r, test.memoryMin, usage.Resources.MemoryMin, "memory request value")
AssertEqualQuantities(r, test.memoryMax, usage.Resources.MemoryMax, "memory limit value")
r.Equal(test.replicas, usage.Details.Replicas, "replicas")
r.Equal(string(test.strategy), usage.Details.Strategy, "strategy")
r.Equal(test.maxReplicas, usage.Details.MaxReplicas, "maxReplicas")
Expand Down
2 changes: 1 addition & 1 deletion internal/calc/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ func job(job batchV1.Job) *ResourceUsage {
podResources := podResources(&job.Spec.Template.Spec)

resourceUsage := ResourceUsage{
resources: *podResources,
Resources: *podResources,
Details: Details{
Version: job.APIVersion,
Kind: job.Kind,
Expand Down
8 changes: 4 additions & 4 deletions internal/calc/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ func TestJob(t *testing.T) {
r.NoError(err)
r.NotEmpty(usage)

AssertEqualQuantities(r, test.cpuMin, usage.resources.CPUMin, "cpu request value")
AssertEqualQuantities(r, test.cpuMax, usage.resources.CPUMax, "cpu limit value")
AssertEqualQuantities(r, test.memoryMin, usage.resources.MemoryMin, "memory request value")
AssertEqualQuantities(r, test.memoryMax, usage.resources.MemoryMax, "memory limit value")
AssertEqualQuantities(r, test.cpuMin, usage.Resources.CPUMin, "cpu request value")
AssertEqualQuantities(r, test.cpuMax, usage.Resources.CPUMax, "cpu limit value")
AssertEqualQuantities(r, test.memoryMin, usage.Resources.MemoryMin, "memory request value")
AssertEqualQuantities(r, test.memoryMax, usage.Resources.MemoryMax, "memory limit value")
r.Equalf(test.replicas, usage.Details.Replicas, "replicas")
r.Equalf(test.maxReplicas, usage.Details.MaxReplicas, "maxReplicas")
r.Equalf(test.strategy, usage.Details.Strategy, "strategy")
Expand Down
2 changes: 1 addition & 1 deletion internal/calc/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ func pod(pod v1.Pod) *ResourceUsage {
podResources := podResources(&pod.Spec)

resourceUsage := ResourceUsage{
resources: *podResources,
Resources: *podResources,
Details: Details{
Version: pod.APIVersion,
Kind: pod.Kind,
Expand Down
8 changes: 4 additions & 4 deletions internal/calc/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func TestPod(t *testing.T) {
r.NoError(err)
r.NotEmpty(usage)

AssertEqualQuantities(r, test.cpuMin, usage.resources.CPUMin, "cpu request value")
AssertEqualQuantities(r, test.cpuMax, usage.resources.CPUMax, "cpu limit value")
AssertEqualQuantities(r, test.memoryMin, usage.resources.MemoryMin, "memory request value")
AssertEqualQuantities(r, test.memoryMax, usage.resources.MemoryMax, "memory limit value")
AssertEqualQuantities(r, test.cpuMin, usage.Resources.CPUMin, "cpu request value")
AssertEqualQuantities(r, test.cpuMax, usage.Resources.CPUMax, "cpu limit value")
AssertEqualQuantities(r, test.memoryMin, usage.Resources.MemoryMin, "memory request value")
AssertEqualQuantities(r, test.memoryMax, usage.Resources.MemoryMax, "memory limit value")
r.Equalf(test.replicas, usage.Details.Replicas, "replicas")
r.Equalf(test.maxReplicas, usage.Details.MaxReplicas, "maxReplicas")
r.Equalf(string(test.strategy), usage.Details.Strategy, "strategy")
Expand Down
2 changes: 1 addition & 1 deletion internal/calc/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func statefulSet(s appsv1.StatefulSet) *ResourceUsage {
newResources := (*podResources).Mul(float64(replicas))

Check failure on line 21 in internal/calc/statefulset.go

View workflow job for this annotation

GitHub Actions / lint

underef: could simplify (*podResources).Mul to podResources.Mul (gocritic)

resourceUsage := ResourceUsage{
resources: newResources,
Resources: newResources,
Details: Details{
Version: s.APIVersion,
Kind: s.Kind,
Expand Down
8 changes: 4 additions & 4 deletions internal/calc/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ func TestStatefulSet(t *testing.T) {
r.NoError(err)
r.NotEmpty(usage)

AssertEqualQuantities(r, test.cpuMin, usage.resources.CPUMin, "cpu request value")
AssertEqualQuantities(r, test.cpuMax, usage.resources.CPUMax, "cpu limit value")
AssertEqualQuantities(r, test.memoryMin, usage.resources.MemoryMin, "memory request value")
AssertEqualQuantities(r, test.memoryMax, usage.resources.MemoryMax, "memory limit value")
AssertEqualQuantities(r, test.cpuMin, usage.Resources.CPUMin, "cpu request value")
AssertEqualQuantities(r, test.cpuMax, usage.Resources.CPUMax, "cpu limit value")
AssertEqualQuantities(r, test.memoryMin, usage.Resources.MemoryMin, "memory request value")
AssertEqualQuantities(r, test.memoryMax, usage.Resources.MemoryMax, "memory limit value")
r.Equalf(test.replicas, usage.Details.Replicas, "replicas")
r.Equalf(test.maxReplicas, usage.Details.MaxReplicas, "maxReplicas")
r.Equalf(string(test.strategy), usage.Details.Strategy, "strategy")
Expand Down

0 comments on commit 89b72e3

Please sign in to comment.