From 89b72e34547e958bdd1b2737c01f1a6213327de7 Mon Sep 17 00:00:00 2001 From: druppelt <44848632+druppelt@users.noreply.github.com> Date: Fri, 13 Sep 2024 01:23:21 +0200 Subject: [PATCH] fix: export ResourceUsage.Resources ResourceUsage.Resources were not exported, breaking the cmd --- cmd/kuota-calc.go | 16 ++++++++-------- internal/calc/calc.go | 2 +- internal/calc/cronjob.go | 2 +- internal/calc/cronjob_test.go | 8 ++++---- internal/calc/daemonset.go | 2 +- internal/calc/daemonset_test.go | 8 ++++---- internal/calc/deployment.go | 4 ++-- internal/calc/deploymentConfig.go | 4 ++-- internal/calc/deploymentConfig_test.go | 8 ++++---- internal/calc/deployment_test.go | 8 ++++---- internal/calc/job.go | 2 +- internal/calc/job_test.go | 8 ++++---- internal/calc/pod.go | 2 +- internal/calc/pod_test.go | 8 ++++---- internal/calc/statefulset.go | 2 +- internal/calc/statefulset_test.go | 8 ++++---- 16 files changed, 46 insertions(+), 46 deletions(-) diff --git a/cmd/kuota-calc.go b/cmd/kuota-calc.go index 5bea206..75ee123 100644 --- a/cmd/kuota-calc.go +++ b/cmd/kuota-calc.go @@ -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, ) } @@ -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", diff --git a/internal/calc/calc.go b/internal/calc/calc.go index 797c2a6..f15aaf8 100644 --- a/internal/calc/calc.go +++ b/internal/calc/calc.go @@ -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 } diff --git a/internal/calc/cronjob.go b/internal/calc/cronjob.go index 8324679..349c086 100644 --- a/internal/calc/cronjob.go +++ b/internal/calc/cronjob.go @@ -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, diff --git a/internal/calc/cronjob_test.go b/internal/calc/cronjob_test.go index e86863b..9856cc0 100644 --- a/internal/calc/cronjob_test.go +++ b/internal/calc/cronjob_test.go @@ -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") diff --git a/internal/calc/daemonset.go b/internal/calc/daemonset.go index e3b42e3..08e38ee 100644 --- a/internal/calc/daemonset.go +++ b/internal/calc/daemonset.go @@ -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, diff --git a/internal/calc/daemonset_test.go b/internal/calc/daemonset_test.go index 659da0d..bb52637 100644 --- a/internal/calc/daemonset_test.go +++ b/internal/calc/daemonset_test.go @@ -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") diff --git a/internal/calc/deployment.go b/internal/calc/deployment.go index 01e97eb..fa897fd 100644 --- a/internal/calc/deployment.go +++ b/internal/calc/deployment.go @@ -21,7 +21,7 @@ func deployment(deployment appsv1.Deployment) (*ResourceUsage, error) { if *replicas == 0 { return &ResourceUsage{ - resources: *new(Resources), + Resources: *new(Resources), Details: Details{ Version: deployment.APIVersion, Kind: deployment.Kind, @@ -96,7 +96,7 @@ func deployment(deployment appsv1.Deployment) (*ResourceUsage, error) { newResources := (*podResources).Mul(float64(*replicas)).Mul(resourceOverhead) resourceUsage := ResourceUsage{ - resources: newResources, + Resources: newResources, Details: Details{ Version: deployment.APIVersion, Kind: deployment.Kind, diff --git a/internal/calc/deploymentConfig.go b/internal/calc/deploymentConfig.go index 87d812f..7b880d8 100644 --- a/internal/calc/deploymentConfig.go +++ b/internal/calc/deploymentConfig.go @@ -21,7 +21,7 @@ func deploymentConfig(deploymentConfig openshiftAppsV1.DeploymentConfig) (*Resou if replicas == 0 { return &ResourceUsage{ - resources: *new(Resources), + Resources: *new(Resources), Details: Details{ Version: deploymentConfig.APIVersion, Kind: deploymentConfig.Kind, @@ -97,7 +97,7 @@ func deploymentConfig(deploymentConfig openshiftAppsV1.DeploymentConfig) (*Resou newResources := (*podResources).Mul(float64(replicas)).Mul(resourceOverhead).Add(strategyResources) resourceUsage := ResourceUsage{ - resources: newResources, + Resources: newResources, Details: Details{ Version: deploymentConfig.APIVersion, Kind: deploymentConfig.Kind, diff --git a/internal/calc/deploymentConfig_test.go b/internal/calc/deploymentConfig_test.go index c1c1871..acbd569 100644 --- a/internal/calc/deploymentConfig_test.go +++ b/internal/calc/deploymentConfig_test.go @@ -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") diff --git a/internal/calc/deployment_test.go b/internal/calc/deployment_test.go index 09d5098..ed308d2 100644 --- a/internal/calc/deployment_test.go +++ b/internal/calc/deployment_test.go @@ -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") diff --git a/internal/calc/job.go b/internal/calc/job.go index b248746..714c256 100644 --- a/internal/calc/job.go +++ b/internal/calc/job.go @@ -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, diff --git a/internal/calc/job_test.go b/internal/calc/job_test.go index 1022fb4..a7bbcf5 100644 --- a/internal/calc/job_test.go +++ b/internal/calc/job_test.go @@ -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") diff --git a/internal/calc/pod.go b/internal/calc/pod.go index 2efb103..18f1630 100644 --- a/internal/calc/pod.go +++ b/internal/calc/pod.go @@ -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, diff --git a/internal/calc/pod_test.go b/internal/calc/pod_test.go index 7dec8a0..1839fbe 100644 --- a/internal/calc/pod_test.go +++ b/internal/calc/pod_test.go @@ -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") diff --git a/internal/calc/statefulset.go b/internal/calc/statefulset.go index 499ea9f..96cc159 100644 --- a/internal/calc/statefulset.go +++ b/internal/calc/statefulset.go @@ -21,7 +21,7 @@ func statefulSet(s appsv1.StatefulSet) *ResourceUsage { newResources := (*podResources).Mul(float64(replicas)) resourceUsage := ResourceUsage{ - resources: newResources, + Resources: newResources, Details: Details{ Version: s.APIVersion, Kind: s.Kind, diff --git a/internal/calc/statefulset_test.go b/internal/calc/statefulset_test.go index b768007..bc78e67 100644 --- a/internal/calc/statefulset_test.go +++ b/internal/calc/statefulset_test.go @@ -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")