diff --git a/.golangci.yaml b/.golangci.yaml index 5dcf8e616..cece74ca9 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -8,6 +8,13 @@ linters: enable: - errorlint - unconvert + - unparam - prealloc disable: - errcheck + +issues: + exclude-rules: + - path: test # Excludes /test, *_test.go etc. + linters: + - unparam diff --git a/pkg/kn/commands/revision/list.go b/pkg/kn/commands/revision/list.go index fb1a217c4..4999d98e7 100644 --- a/pkg/kn/commands/revision/list.go +++ b/pkg/kn/commands/revision/list.go @@ -70,7 +70,7 @@ func NewRevisionListCommand(p *commands.KnParams) *cobra.Command { if err != nil { return err } - params, err = appendRevisionNameFilter(params, client, args) + params, err = appendRevisionNameFilter(params, args) if err != nil { return err } @@ -131,7 +131,7 @@ func appendServiceFilter(lConfig []clientservingv1.ListConfig, client clientserv } // If an additional name is given append this as a revision name filter to the given list -func appendRevisionNameFilter(lConfigs []clientservingv1.ListConfig, client clientservingv1.KnServingClient, args []string) ([]clientservingv1.ListConfig, error) { +func appendRevisionNameFilter(lConfigs []clientservingv1.ListConfig, args []string) ([]clientservingv1.ListConfig, error) { switch len(args) { case 0: diff --git a/pkg/kn/commands/service/update.go b/pkg/kn/commands/service/update.go index 836cb1095..008170448 100644 --- a/pkg/kn/commands/service/update.go +++ b/pkg/kn/commands/service/update.go @@ -132,7 +132,7 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command { }, PreRunE: func(cmd *cobra.Command, args []string) error { - return preCheck(cmd, args) + return preCheck(cmd) }, } @@ -144,7 +144,7 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command { return serviceUpdateCommand } -func preCheck(cmd *cobra.Command, args []string) error { +func preCheck(cmd *cobra.Command) error { if cmd.Flags().NFlag() == 0 { return fmt.Errorf("flag(s) not set\nUsage: %s", cmd.Use) } diff --git a/pkg/kn/flags/podspec_helper.go b/pkg/kn/flags/podspec_helper.go index 298d687ce..f9b19d65f 100644 --- a/pkg/kn/flags/podspec_helper.go +++ b/pkg/kn/flags/podspec_helper.go @@ -43,22 +43,19 @@ func (vt VolumeSourceType) String() string { return names[vt] } -func containerOfPodSpec(spec *corev1.PodSpec) (*corev1.Container, error) { +func containerOfPodSpec(spec *corev1.PodSpec) *corev1.Container { if len(spec.Containers) == 0 { newContainer := corev1.Container{} spec.Containers = append(spec.Containers, newContainer) } - return &spec.Containers[0], nil + return &spec.Containers[0] } // UpdateEnvVars gives the configuration all the env var values listed in the given map of // vars. Does not touch any environment variables not mentioned, but it can add // new env vars and change the values of existing ones, then sort by env key name. func UpdateEnvVars(spec *corev1.PodSpec, toUpdate map[string]string, toRemove []string) error { - container, err := containerOfPodSpec(spec) - if err != nil { - return err - } + container := containerOfPodSpec(spec) updated := updateEnvVarsFromMap(container.Env, toUpdate) updated = removeEnvVars(updated, toRemove) // Sort by env key name @@ -72,10 +69,7 @@ func UpdateEnvVars(spec *corev1.PodSpec, toUpdate map[string]string, toRemove [] // UpdateEnvFrom updates envFrom func UpdateEnvFrom(spec *corev1.PodSpec, toUpdate []string, toRemove []string) error { - container, err := containerOfPodSpec(spec) - if err != nil { - return err - } + container := containerOfPodSpec(spec) envFrom, err := updateEnvFrom(container.EnvFrom, toUpdate) if err != nil { return err @@ -87,12 +81,9 @@ func UpdateEnvFrom(spec *corev1.PodSpec, toUpdate []string, toRemove []string) e // UpdateVolumeMountsAndVolumes updates the configuration for volume mounts and volumes. func UpdateVolumeMountsAndVolumes(spec *corev1.PodSpec, mountsToUpdate *util.OrderedMap, mountsToRemove []string, volumesToUpdate *util.OrderedMap, volumesToRemove []string) error { - container, err := containerOfPodSpec(spec) - if err != nil { - return err - } + container := containerOfPodSpec(spec) - volumeSourceInfoByName, mountsToUpdate, err := reviseVolumeInfoAndMountsToUpdate(spec.Volumes, mountsToUpdate, volumesToUpdate) + volumeSourceInfoByName, mountsToUpdate, err := reviseVolumeInfoAndMountsToUpdate(mountsToUpdate, volumesToUpdate) if err != nil { return err } @@ -118,43 +109,32 @@ func UpdateVolumeMountsAndVolumes(spec *corev1.PodSpec, // UpdateImage a given image func UpdateImage(spec *corev1.PodSpec, image string) error { // When not setting the image to a digest, add the user image annotation. - container, err := containerOfPodSpec(spec) - if err != nil { - return err - } + container := containerOfPodSpec(spec) container.Image = image return nil } // UpdateContainerCommand updates container with a given argument func UpdateContainerCommand(spec *corev1.PodSpec, command string) error { - container, err := containerOfPodSpec(spec) - if err != nil { - return err - } + container := containerOfPodSpec(spec) container.Command = []string{command} return nil } // UpdateContainerArg updates container with a given argument func UpdateContainerArg(spec *corev1.PodSpec, arg []string) error { - container, err := containerOfPodSpec(spec) - if err != nil { - return err - } + container := containerOfPodSpec(spec) container.Args = arg return nil } // UpdateContainerPort updates container with a given name:port func UpdateContainerPort(spec *corev1.PodSpec, port string) error { - container, err := containerOfPodSpec(spec) - if err != nil { - return err - } + container := containerOfPodSpec(spec) var containerPort int64 var name string + var err error elements := strings.SplitN(port, ":", 2) if len(elements) == 2 { @@ -180,10 +160,7 @@ func UpdateContainerPort(spec *corev1.PodSpec, port string) error { // UpdateUser updates container with a given user id func UpdateUser(spec *corev1.PodSpec, user int64) error { - container, err := containerOfPodSpec(spec) - if err != nil { - return err - } + container := containerOfPodSpec(spec) container.SecurityContext = &corev1.SecurityContext{ RunAsUser: &user, } @@ -192,10 +169,7 @@ func UpdateUser(spec *corev1.PodSpec, user int64) error { // UpdateResources updates container resources for given revision spec func UpdateResources(spec *corev1.PodSpec, resources corev1.ResourceRequirements, requestsToRemove, limitsToRemove []string) error { - container, err := containerOfPodSpec(spec) - if err != nil { - return err - } + container := containerOfPodSpec(spec) if container.Resources.Requests == nil { container.Resources.Requests = corev1.ResourceList{} @@ -522,8 +496,7 @@ func existsVolumeNameInVolumeMounts(volumeName string, volumeMounts []corev1.Vol // ======================================================================================= -func reviseVolumeInfoAndMountsToUpdate(volumes []corev1.Volume, mountsToUpdate *util.OrderedMap, - volumesToUpdate *util.OrderedMap) (*util.OrderedMap, *util.OrderedMap, error) { +func reviseVolumeInfoAndMountsToUpdate(mountsToUpdate *util.OrderedMap, volumesToUpdate *util.OrderedMap) (*util.OrderedMap, *util.OrderedMap, error) { volumeSourceInfoByName := util.NewOrderedMap() //make(map[string]*volumeSourceInfo) mountsToUpdateRevised := util.NewOrderedMap() //make(map[string]string) diff --git a/pkg/kn/traffic/compute.go b/pkg/kn/traffic/compute.go index 94ee9aaae..f924d5049 100644 --- a/pkg/kn/traffic/compute.go +++ b/pkg/kn/traffic/compute.go @@ -83,7 +83,7 @@ func (e ServiceTraffic) isTagPresent(tag string) bool { return false } -func (e ServiceTraffic) untagRevision(tag string, serviceName string) bool { +func (e ServiceTraffic) untagRevision(tag string) bool { for i, target := range e { if target.Tag == tag { e[i].Tag = "" @@ -281,7 +281,7 @@ func Compute(cmd *cobra.Command, targets []servingv1.TrafficTarget, // First precedence: Untag revisions var errTagNames []string for _, tag := range trafficFlags.UntagRevisions { - tagExists := traffic.untagRevision(tag, serviceName) + tagExists := traffic.untagRevision(tag) if !tagExists { errTagNames = append(errTagNames, tag) } diff --git a/pkg/printers/tableprinter.go b/pkg/printers/tableprinter.go index c2d7ae4eb..ae7a02039 100644 --- a/pkg/printers/tableprinter.go +++ b/pkg/printers/tableprinter.go @@ -90,7 +90,7 @@ func printRowsForHandlerEntry(output io.Writer, handler *handlerEntry, obj runti if results[1].IsNil() { rows := results[0].Interface().([]metav1beta1.TableRow) - printRows(output, rows, options) + printRows(output, rows) return nil } return results[1].Interface().(error) @@ -104,7 +104,7 @@ func printHeader(columnNames []string, w io.Writer) error { } // printRows writes the provided rows to output. -func printRows(output io.Writer, rows []metav1beta1.TableRow, options PrintOptions) { +func printRows(output io.Writer, rows []metav1beta1.TableRow) { for _, row := range rows { for i, cell := range row.Cells { if i != 0 { diff --git a/pkg/wait/poll_watcher.go b/pkg/wait/poll_watcher.go index c89588b95..cdfb524af 100644 --- a/pkg/wait/poll_watcher.go +++ b/pkg/wait/poll_watcher.go @@ -77,14 +77,11 @@ func NewWatcher(watchFunc watchF, c rest.Interface, ns string, resource string, polling := &pollingWatcher{ c, ns, resource, name, timeout, make(chan bool), make(chan watch.Event), &sync.WaitGroup{}, newTickerPollInterval(time.Second), nativePoll(c, ns, resource, name)} - err = polling.start() - if err != nil { - return nil, err - } + polling.start() return polling, nil } -func (w *pollingWatcher) start() error { +func (w *pollingWatcher) start() { w.wg.Add(1) go func() { @@ -149,7 +146,6 @@ func (w *pollingWatcher) start() error { } } }() - return nil } func (w *pollingWatcher) ResultChan() <-chan watch.Event { diff --git a/pkg/wait/wait_for_ready.go b/pkg/wait/wait_for_ready.go index 855176b52..0d0ddb534 100644 --- a/pkg/wait/wait_for_ready.go +++ b/pkg/wait/wait_for_ready.go @@ -114,7 +114,7 @@ func (w *waitForReadyConfig) Wait(watcher watch.Interface, name string, options floatingTimeout := timeout for { start := time.Now() - retry, timeoutReached, err := w.waitForReadyCondition(watcher, start, name, floatingTimeout, options.errorWindowWithDefault(), msgCallback) + retry, timeoutReached, err := w.waitForReadyCondition(watcher, start, floatingTimeout, options.errorWindowWithDefault(), msgCallback) if err != nil { return err, time.Since(start) } @@ -137,7 +137,7 @@ func (w *waitForReadyConfig) Wait(watcher watch.Interface, name string, options // An errorWindow can be specified which takes into account of intermediate "false" ready conditions. So before returning // an error, this methods waits for the errorWindow duration and if an "True" or "Unknown" event arrives in the meantime // for the "Ready" condition, then the method continues to wait. -func (w *waitForReadyConfig) waitForReadyCondition(watcher watch.Interface, start time.Time, name string, timeout time.Duration, errorWindow time.Duration, msgCallback MessageCallback) (retry bool, timeoutReached bool, err error) { +func (w *waitForReadyConfig) waitForReadyCondition(watcher watch.Interface, start time.Time, timeout time.Duration, errorWindow time.Duration, msgCallback MessageCallback) (retry bool, timeoutReached bool, err error) { // channel used to transport the error that has been received errChan := make(chan error)