chore: fix problems with latest lint

Signed-off-by: Terry Howe <terrylhowe@gmail.com>
pull/13516/head
Terry Howe 9 months ago
parent b91a772d71
commit 569f62e58b

@ -177,22 +177,15 @@ func formatAppVersion(c *chart.Chart) string {
return c.AppVersion() return c.AppVersion()
} }
func min(x, y int) int {
if x < y {
return x
}
return y
}
func compListRevisions(_ string, cfg *action.Configuration, releaseName string) ([]string, cobra.ShellCompDirective) { func compListRevisions(_ string, cfg *action.Configuration, releaseName string) ([]string, cobra.ShellCompDirective) {
client := action.NewHistory(cfg) client := action.NewHistory(cfg)
var revisions []string var revisions []string
if hist, err := client.Run(releaseName); err == nil { if hist, err := client.Run(releaseName); err == nil {
for _, release := range hist { for _, version := range hist {
appVersion := fmt.Sprintf("App: %s", release.Chart.Metadata.AppVersion) appVersion := fmt.Sprintf("App: %s", version.Chart.Metadata.AppVersion)
chartDesc := fmt.Sprintf("Chart: %s-%s", release.Chart.Metadata.Name, release.Chart.Metadata.Version) chartDesc := fmt.Sprintf("Chart: %s-%s", version.Chart.Metadata.Name, version.Chart.Metadata.Version)
revisions = append(revisions, fmt.Sprintf("%s\t%s, %s", strconv.Itoa(release.Version), appVersion, chartDesc)) revisions = append(revisions, fmt.Sprintf("%s\t%s, %s", strconv.Itoa(version.Version), appVersion, chartDesc))
} }
return revisions, cobra.ShellCompDirectiveNoFileComp return revisions, cobra.ShellCompDirectiveNoFileComp
} }

@ -78,7 +78,7 @@ func (o *pluginUninstallOptions) run(out io.Writer) error {
} }
} }
if len(errorPlugins) > 0 { if len(errorPlugins) > 0 {
return errors.Errorf(strings.Join(errorPlugins, "\n")) return errors.New(strings.Join(errorPlugins, "\n"))
} }
return nil return nil
} }

@ -81,7 +81,7 @@ func (o *pluginUpdateOptions) run(out io.Writer) error {
} }
} }
if len(errorPlugins) > 0 { if len(errorPlugins) > 0 {
return errors.Errorf(strings.Join(errorPlugins, "\n")) return errors.New(strings.Join(errorPlugins, "\n"))
} }
return nil return nil
} }

@ -162,9 +162,9 @@ func TestRepoIndexCmd(t *testing.T) {
} }
} }
func linkOrCopy(old, new string) error { func linkOrCopy(source, target string) error {
if err := os.Link(old, new); err != nil { if err := os.Link(source, target); err != nil {
return copyFile(old, new) return copyFile(source, target)
} }
return nil return nil

@ -140,7 +140,7 @@ func (s statusPrinter) WriteTable(out io.Writer) error {
} }
_, _ = fmt.Fprintf(out, "DESCRIPTION: %s\n", s.release.Info.Description) _, _ = fmt.Fprintf(out, "DESCRIPTION: %s\n", s.release.Info.Description)
if s.release.Info.Resources != nil && len(s.release.Info.Resources) > 0 { if len(s.release.Info.Resources) > 0 {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
printFlags := get.NewHumanPrintFlags() printFlags := get.NewHumanPrintFlags()
typePrinter, _ := printFlags.ToPrinter("") typePrinter, _ := printFlags.ToPrinter("")

@ -219,7 +219,7 @@ func isTestHook(h *release.Hook) bool {
// bug introduced by #8156. As part of the todo to refactor renderResources // bug introduced by #8156. As part of the todo to refactor renderResources
// this duplicate code should be removed. It is added here so that the API // this duplicate code should be removed. It is added here so that the API
// surface area is as minimally impacted as possible in fixing the issue. // surface area is as minimally impacted as possible in fixing the issue.
func writeToFile(outputDir string, name string, data string, append bool) error { func writeToFile(outputDir string, name string, data string, appendData bool) error {
outfileName := strings.Join([]string{outputDir, name}, string(filepath.Separator)) outfileName := strings.Join([]string{outputDir, name}, string(filepath.Separator))
err := ensureDirectoryForFile(outfileName) err := ensureDirectoryForFile(outfileName)
@ -227,7 +227,7 @@ func writeToFile(outputDir string, name string, data string, append bool) error
return err return err
} }
f, err := createOrOpenFile(outfileName, append) f, err := createOrOpenFile(outfileName, appendData)
if err != nil { if err != nil {
return err return err
} }
@ -244,8 +244,8 @@ func writeToFile(outputDir string, name string, data string, append bool) error
return nil return nil
} }
func createOrOpenFile(filename string, append bool) (*os.File, error) { func createOrOpenFile(filename string, appendData bool) (*os.File, error) {
if append { if appendData {
return os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0600) return os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0600)
} }
return os.Create(filename) return os.Create(filename)

@ -108,12 +108,12 @@ func checkMarks(t *testing.T, report bool) {
} }
// Assumes that each node name is unique. Good enough for a test. // Assumes that each node name is unique. Good enough for a test.
// If clear is true, any incoming error is cleared before return. The errors // If clearIncomingError is true, any incoming error is cleared before
// are always accumulated, though. // return. The errors are always accumulated, though.
func mark(info os.FileInfo, err error, errors *[]error, clear bool) error { func mark(info os.FileInfo, err error, errors *[]error, clearIncomingError bool) error {
if err != nil { if err != nil {
*errors = append(*errors, err) *errors = append(*errors, err)
if clear { if clearIncomingError {
return nil return nil
} }
return err return err
@ -130,9 +130,8 @@ func mark(info os.FileInfo, err error, errors *[]error, clear bool) error {
func TestWalk(t *testing.T) { func TestWalk(t *testing.T) {
makeTree(t) makeTree(t)
errors := make([]error, 0, 10) errors := make([]error, 0, 10)
clear := true
markFn := func(_ string, info os.FileInfo, err error) error { markFn := func(_ string, info os.FileInfo, err error) error {
return mark(info, err, &errors, clear) return mark(info, err, &errors, true)
} }
// Expect no errors. // Expect no errors.
err := Walk(tree.name, markFn) err := Walk(tree.name, markFn)

@ -44,7 +44,7 @@ func (cfg *Configuration) execHook(rl *release.Release, hook release.HookEvent,
for _, h := range executingHooks { for _, h := range executingHooks {
// Set default delete policy to before-hook-creation // Set default delete policy to before-hook-creation
if h.DeletePolicies == nil || len(h.DeletePolicies) == 0 { if len(h.DeletePolicies) == 0 {
// TODO(jlegrone): Only apply before-hook-creation delete policy to run to completion // TODO(jlegrone): Only apply before-hook-creation delete policy to run to completion
// resources. For all other resource types update in place if a // resources. For all other resource types update in place if a
// resource with the same name already exists and is owned by the // resource with the same name already exists and is owned by the

@ -598,8 +598,8 @@ func (i *Install) replaceRelease(rel *release.Release) error {
return i.recordRelease(last) return i.recordRelease(last)
} }
// write the <data> to <output-dir>/<name>. <append> controls if the file is created or content will be appended // write the <data> to <output-dir>/<name>. <appendData> controls if the file is created or content will be appended
func writeToFile(outputDir string, name string, data string, append bool) error { func writeToFile(outputDir string, name string, data string, appendData bool) error {
outfileName := strings.Join([]string{outputDir, name}, string(filepath.Separator)) outfileName := strings.Join([]string{outputDir, name}, string(filepath.Separator))
err := ensureDirectoryForFile(outfileName) err := ensureDirectoryForFile(outfileName)
@ -607,7 +607,7 @@ func writeToFile(outputDir string, name string, data string, append bool) error
return err return err
} }
f, err := createOrOpenFile(outfileName, append) f, err := createOrOpenFile(outfileName, appendData)
if err != nil { if err != nil {
return err return err
} }
@ -624,8 +624,8 @@ func writeToFile(outputDir string, name string, data string, append bool) error
return nil return nil
} }
func createOrOpenFile(filename string, append bool) (*os.File, error) { func createOrOpenFile(filename string, appendData bool) (*os.File, error) {
if append { if appendData {
return os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0600) return os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0600)
} }
return os.Create(filename) return os.Create(filename)

@ -206,7 +206,7 @@ func (e Engine) initFunMap(t *template.Template) {
log.Printf("[INFO] Missing required value: %s", warn) log.Printf("[INFO] Missing required value: %s", warn)
return "", nil return "", nil
} }
return val, errors.Errorf(warnWrap(warn)) return val, errors.New(warnWrap(warn))
} else if _, ok := val.(string); ok { } else if _, ok := val.(string); ok {
if val == "" { if val == "" {
if e.LintMode { if e.LintMode {
@ -214,7 +214,7 @@ func (e Engine) initFunMap(t *template.Template) {
log.Printf("[INFO] Missing required value: %s", warn) log.Printf("[INFO] Missing required value: %s", warn)
return "", nil return "", nil
} }
return val, errors.Errorf(warnWrap(warn)) return val, errors.New(warnWrap(warn))
} }
} }
return val, nil return val, nil

@ -435,7 +435,7 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err
case err != nil: case err != nil:
return res, err return res, err
case len(updateErrors) != 0: case len(updateErrors) != 0:
return res, errors.Errorf(strings.Join(updateErrors, " && ")) return res, errors.New(strings.Join(updateErrors, " && "))
} }
for _, info := range original.Difference(target) { for _, info := range original.Difference(target) {

@ -153,7 +153,7 @@ func SelectorsForObject(object runtime.Object) (selector labels.Selector, err er
case *batchv1.Job: case *batchv1.Job:
selector, err = metav1.LabelSelectorAsSelector(t.Spec.Selector) selector, err = metav1.LabelSelectorAsSelector(t.Spec.Selector)
case *corev1.Service: case *corev1.Service:
if t.Spec.Selector == nil || len(t.Spec.Selector) == 0 { if len(t.Spec.Selector) == 0 {
return nil, fmt.Errorf("invalid service '%s': Service is defined without a selector", t.Name) return nil, fmt.Errorf("invalid service '%s': Service is defined without a selector", t.Name)
} }
selector = labels.SelectorFromSet(t.Spec.Selector) selector = labels.SelectorFromSet(t.Spec.Selector)

@ -73,16 +73,16 @@ func validateNoDeprecations(resource *K8sYamlStruct, kubeVersion *chartutil.Kube
return err return err
} }
maj, err := strconv.Atoi(majorVersion) major, err := strconv.Atoi(majorVersion)
if err != nil { if err != nil {
return err return err
} }
min, err := strconv.Atoi(minorVersion) minor, err := strconv.Atoi(minorVersion)
if err != nil { if err != nil {
return err return err
} }
if !deprecation.IsDeprecated(runtimeObject, maj, min) { if !deprecation.IsDeprecated(runtimeObject, major, minor) {
return nil return nil
} }
gvk := fmt.Sprintf("%s %s", resource.APIVersion, resource.Kind) gvk := fmt.Sprintf("%s %s", resource.APIVersion, resource.Kind)

@ -208,7 +208,7 @@ func generateChartOCIAnnotations(meta *chart.Metadata, creationTime string) map[
chartOCIAnnotations = addToMap(chartOCIAnnotations, ocispec.AnnotationSource, meta.Sources[0]) chartOCIAnnotations = addToMap(chartOCIAnnotations, ocispec.AnnotationSource, meta.Sources[0])
} }
if meta.Maintainers != nil && len(meta.Maintainers) > 0 { if len(meta.Maintainers) > 0 {
var maintainerSb strings.Builder var maintainerSb strings.Builder
for maintainerIdx, maintainer := range meta.Maintainers { for maintainerIdx, maintainer := range meta.Maintainers {

@ -161,15 +161,15 @@ func (s *Storage) History(name string) ([]*rspb.Release, error) {
// //
// We allow max to be set explicitly so that calling functions can "make space" // We allow max to be set explicitly so that calling functions can "make space"
// for the new records they are going to write. // for the new records they are going to write.
func (s *Storage) removeLeastRecent(name string, max int) error { func (s *Storage) removeLeastRecent(name string, maximum int) error {
if max < 0 { if maximum < 0 {
return nil return nil
} }
h, err := s.History(name) h, err := s.History(name)
if err != nil { if err != nil {
return err return err
} }
if len(h) <= max { if len(h) <= maximum {
return nil return nil
} }
@ -183,8 +183,8 @@ func (s *Storage) removeLeastRecent(name string, max int) error {
var toDelete []*rspb.Release var toDelete []*rspb.Release
for _, rel := range h { for _, rel := range h {
// once we have enough releases to delete to reach the max, stop // once we have enough releases to delete to reach the maximum, stop
if len(h)-len(toDelete) == max { if len(h)-len(toDelete) == maximum {
break break
} }
if lastDeployed != nil { if lastDeployed != nil {

@ -30,7 +30,7 @@ import (
var emptyString = `""` var emptyString = `""`
// Time is a convenience wrapper around stdlib time, but with different // Time is a convenience wrapper around stdlib time, but with different
// marshalling and unmarshaling for zero values // marshalling and unmarshalling for zero values
type Time struct { type Time struct {
time.Time time.Time
} }
@ -70,8 +70,8 @@ func ParseInLocation(layout, value string, loc *time.Location) (Time, error) {
return Time{Time: t}, err return Time{Time: t}, err
} }
func Date(year int, month time.Month, day, hour, min, sec, nsec int, loc *time.Location) Time { func Date(year int, month time.Month, day, hour, minute, second, nanoSecond int, loc *time.Location) Time {
return Time{Time: time.Date(year, month, day, hour, min, sec, nsec, loc)} return Time{Time: time.Date(year, month, day, hour, minute, second, nanoSecond, loc)}
} }
func Unix(sec int64, nsec int64) Time { return Time{Time: time.Unix(sec, nsec)} } func Unix(sec int64, nsec int64) Time { return Time{Time: time.Unix(sec, nsec)} }

Loading…
Cancel
Save