diff --git a/cmd/kuota-calc.go b/cmd/kuota-calc.go index 6670995..f76fb20 100644 --- a/cmd/kuota-calc.go +++ b/cmd/kuota-calc.go @@ -66,7 +66,7 @@ func NewKuotaCalcCmd(version *Version, streams genericclioptions.IOStreams) *cob } func (opts *KuotaCalcOpts) printVersion() error { - fmt.Fprintf(opts.Out, "version %s (revision: %s)\n\tbuild date: %s\n\tgo version: %s\n", + _, _ = fmt.Fprintf(opts.Out, "version %s (revision: %s)\n\tbuild date: %s\n\tgo version: %s\n", opts.versionInfo.Version, opts.versionInfo.Commit, opts.versionInfo.Date, @@ -97,7 +97,7 @@ func (opts *KuotaCalcOpts) run() error { if err != nil { if errors.Is(err, calc.ErrResourceNotSupported) { if opts.debug { - fmt.Fprintf(opts.Out, "DEBUG: %s\n", err) + _, _ = fmt.Fprintf(opts.Out, "DEBUG: %s\n", err) } continue @@ -121,10 +121,10 @@ func (opts *KuotaCalcOpts) run() error { func (opts *KuotaCalcOpts) printDetailed(usage []*calc.ResourceUsage) { w := tabwriter.NewWriter(opts.Out, 0, 0, 4, ' ', tabwriter.TabIndent) - fmt.Fprintf(w, "Version\tKind\tName\tReplicas\tStrategy\tMaxReplicas\tCPURequest\tCPULimit\tMemoryRequest\tMemoryLimit\t\n") + _, _ = fmt.Fprintf(w, "Version\tKind\tName\tReplicas\tStrategy\tMaxReplicas\tCPURequest\tCPULimit\tMemoryRequest\tMemoryLimit\t\n") for _, u := range usage { - fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%s\t%d\t%s\t%s\t%s\t%s\t\n", + _, _ = fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%s\t%d\t%s\t%s\t%s\t%s\t\n", u.Details.Version, u.Details.Kind, u.Details.Name, @@ -138,9 +138,11 @@ func (opts *KuotaCalcOpts) printDetailed(usage []*calc.ResourceUsage) { ) } - w.Flush() + if err := w.Flush(); err != nil { + _, _ = fmt.Fprintf(opts.Out, "printing detailed resources to tabwriter failed: %v\n", err) + } - fmt.Fprintf(opts.Out, "\nTotal\n") + _, _ = fmt.Fprintf(opts.Out, "\nTotal\n") opts.printSummary(usage) } @@ -160,7 +162,7 @@ func (opts *KuotaCalcOpts) printSummary(usage []*calc.ResourceUsage) { memoryMaxUsage.Add(*u.MemoryMax) } - fmt.Fprintf(opts.Out, "CPU Request: %s\nCPU Limit: %s\nMemory Request: %s\nMemory Limit: %s\n", + _, _ = fmt.Fprintf(opts.Out, "CPU Request: %s\nCPU Limit: %s\nMemory Request: %s\nMemory Limit: %s\n", cpuMinUsage.String(), cpuMaxUsage.String(), memoryMinUsage.String(), diff --git a/internal/calc/cronjob_test.go b/internal/calc/cronjob_test.go index 568b5b4..d5f805c 100644 --- a/internal/calc/cronjob_test.go +++ b/internal/calc/cronjob_test.go @@ -44,7 +44,7 @@ func TestCronJob(t *testing.T) { AssertEqualQuantities(r, test.memoryMax, *usage.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") + r.Equalf(test.strategy, usage.Details.Strategy, "strategy") }, ) } diff --git a/internal/calc/deployment.go b/internal/calc/deployment.go index 3b8f347..3ef2c3d 100644 --- a/internal/calc/deployment.go +++ b/internal/calc/deployment.go @@ -72,14 +72,14 @@ func deployment(deployment appsv1.Deployment) (*ResourceUsage, error) { maxSurgeValue = *strategy.RollingUpdate.MaxSurge } - // docs say, that the asolute number is calculated by rounding down. - maxUnavailable, err := intstr.GetValueFromIntOrPercent(&maxUnavailableValue, int(*replicas), false) + // docs say, that the absolute number is calculated by rounding down. + maxUnavailable, err := intstr.GetScaledValueFromIntOrPercent(&maxUnavailableValue, int(*replicas), false) if err != nil { return nil, err } // docs say, absolute number is calculated by rounding up. - maxSurge, err := intstr.GetValueFromIntOrPercent(&maxSurgeValue, int(*replicas), true) + maxSurge, err := intstr.GetScaledValueFromIntOrPercent(&maxSurgeValue, int(*replicas), true) if err != nil { return nil, err } diff --git a/internal/calc/job_test.go b/internal/calc/job_test.go index 28aacde..8442638 100644 --- a/internal/calc/job_test.go +++ b/internal/calc/job_test.go @@ -44,7 +44,7 @@ func TestJob(t *testing.T) { AssertEqualQuantities(r, test.memoryMax, *usage.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") + r.Equalf(test.strategy, usage.Details.Strategy, "strategy") }, ) } diff --git a/main.go b/main.go index 81a91d6..0a6d965 100644 --- a/main.go +++ b/main.go @@ -10,7 +10,7 @@ import ( //nolint:gochecknoglobals // Set by goreleaser on build var ( - version, date, commit string = "master", "?", "?" + version, date, commit = "master", "?", "?" ) const (