Skip to content

Commit

Permalink
fix some linter findings
Browse files Browse the repository at this point in the history
  • Loading branch information
druppelt committed Sep 11, 2024
1 parent 7010c5e commit 4d75e82
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
16 changes: 9 additions & 7 deletions cmd/kuota-calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
}
Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion internal/calc/cronjob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
},
)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/calc/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/calc/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
},
)
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

//nolint:gochecknoglobals // Set by goreleaser on build
var (
version, date, commit string = "master", "?", "?"
version, date, commit = "master", "?", "?"
)

const (
Expand Down

0 comments on commit 4d75e82

Please sign in to comment.