diff --git a/Makefile b/Makefile index 52bb98e1bc..e07c701a07 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,7 @@ fix: ## Fixup files in the repo. .PHONY: setup-lint setup-lint: ## Setup the lint - $(SCRIPTS_DIR)/fetch golangci-lint 1.51.2 + $(SCRIPTS_DIR)/fetch golangci-lint 1.53.3 .PHONY: lint lint: setup-lint ## Run the lint check diff --git a/hack/generate/samples/internal/pkg/utils.go b/hack/generate/samples/internal/pkg/utils.go index 431b6267ac..679d7caf06 100644 --- a/hack/generate/samples/internal/pkg/utils.go +++ b/hack/generate/samples/internal/pkg/utils.go @@ -54,11 +54,8 @@ func (ctx SampleContext) StripBundleAnnotations() (err error) { filepath.Join(ctx.Dir, "bundle", "manifests", ctx.ProjectName+".clusterserviceversion.yaml"), filepath.Join(ctx.Dir, "config", "manifests", "bases", ctx.ProjectName+".clusterserviceversion.yaml"), } - if err = removeAllAnnotationLines(manifestsAnnotations, manifestsFiles); err != nil { - return err - } - return nil + return removeAllAnnotationLines(manifestsAnnotations, manifestsFiles) } // removeAllAnnotationLines removes each line containing a key in annotations from all files at filePaths. diff --git a/internal/cmd/operator-sdk/generate/packagemanifests/packagemanifests.go b/internal/cmd/operator-sdk/generate/packagemanifests/packagemanifests.go index 293d49c908..38f128617d 100644 --- a/internal/cmd/operator-sdk/generate/packagemanifests/packagemanifests.go +++ b/internal/cmd/operator-sdk/generate/packagemanifests/packagemanifests.go @@ -239,8 +239,5 @@ func (c packagemanifestsCmd) generatePackageManifest() error { IsDefaultChannel: c.isDefaultChannel, } - if err := c.generator.Generate(c.packageName, c.version, c.outputDir, opts); err != nil { - return err - } - return nil + return c.generator.Generate(c.packageName, c.version, c.outputDir, opts) } diff --git a/internal/generate/clusterserviceversion/clusterserviceversion_updaters.go b/internal/generate/clusterserviceversion/clusterserviceversion_updaters.go index f43103b78a..98d7540705 100644 --- a/internal/generate/clusterserviceversion/clusterserviceversion_updaters.go +++ b/internal/generate/clusterserviceversion/clusterserviceversion_updaters.go @@ -574,7 +574,7 @@ func mutatingToWebhookDescription(webhook admissionregv1.MutatingWebhook, depNam func findMatchingDeploymentAndServiceForWebhook(c *collector.Manifests, wcc admissionregv1.WebhookClientConfig) (depName string, ws *corev1.Service) { // Return if a service reference is not specified, since a URL will be in that case. if wcc.Service == nil { - return + return depName, ws } // Find the matching service, if any. The webhook server may be externally managed @@ -586,18 +586,18 @@ func findMatchingDeploymentAndServiceForWebhook(c *collector.Manifests, wcc admi } } if ws == nil { - return + return depName, ws } // Only ExternalName-type services cannot have selectors. if ws.Spec.Type == corev1.ServiceTypeExternalName { - return + return depName, ws } // If a selector does not exist, there is either an Endpoint or EndpointSlice object accompanying // the service so it should not be added to the CSV. if len(ws.Spec.Selector) == 0 { - return + return depName, ws } depName = findMatchingDepNameFromService(c, ws) diff --git a/internal/helm/client/secrets_watch.go b/internal/helm/client/secrets_watch.go index e9cd468017..a61c7532ab 100644 --- a/internal/helm/client/secrets_watch.go +++ b/internal/helm/client/secrets_watch.go @@ -117,7 +117,7 @@ func (w *WatchedSecrets) Watch(ctx context.Context, opts metav1.ListOptions) (wa return w.inner.Watch(ctx, opts) } -func (w *WatchedSecrets) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *corev1.Secret, err error) { +func (w *WatchedSecrets) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, _ ...string) (result *corev1.Secret, err error) { return w.inner.Patch(ctx, name, pt, data, opts) } diff --git a/internal/helm/controller/reconcile.go b/internal/helm/controller/reconcile.go index da784d5284..386b37aba2 100644 --- a/internal/helm/controller/reconcile.go +++ b/internal/helm/controller/reconcile.go @@ -125,7 +125,7 @@ func (r HelmOperatorReconciler) Reconcile(ctx context.Context, request reconcile return reconcile.Result{}, nil } - uninstalledRelease, err := manager.UninstallRelease(ctx) + uninstalledRelease, err := manager.UninstallRelease() if err != nil && !errors.Is(err, driver.ErrReleaseNotFound) { log.Error(err, "Failed to uninstall release") status.SetCondition(types.HelmAppCondition{ @@ -173,7 +173,7 @@ func (r HelmOperatorReconciler) Reconcile(ctx context.Context, request reconcile if wait && status.DeployedRelease != nil && status.DeployedRelease.Manifest != "" { log.Info("Uninstall wait") - isAllResourcesDeleted, err := manager.CleanupRelease(ctx, status.DeployedRelease.Manifest) + isAllResourcesDeleted, err := manager.CleanupRelease(status.DeployedRelease.Manifest) if err != nil { log.Error(err, "Failed to cleanup release") status.SetCondition(types.HelmAppCondition{ @@ -217,7 +217,7 @@ func (r HelmOperatorReconciler) Reconcile(ctx context.Context, request reconcile Status: types.StatusTrue, }) - if err := manager.Sync(ctx); err != nil { + if err := manager.Sync(); err != nil { log.Error(err, "Failed to sync release") status.SetCondition(types.HelmAppCondition{ Type: types.ConditionIrreconcilable, @@ -240,7 +240,7 @@ func (r HelmOperatorReconciler) Reconcile(ctx context.Context, request reconcile r.EventRecorder.Eventf(o, "Warning", "OverrideValuesInUse", "Chart value %q overridden to %q by operator's watches.yaml", k, v) } - installedRelease, err := manager.InstallRelease(ctx) + installedRelease, err := manager.InstallRelease() if err != nil { log.Error(err, "Release failed") status.SetCondition(types.HelmAppCondition{ @@ -314,14 +314,14 @@ func (r HelmOperatorReconciler) Reconcile(ctx context.Context, request reconcile } force := hasAnnotation(helmUpgradeForceAnnotation, o) - previousRelease, upgradedRelease, err := manager.UpgradeRelease(ctx, release.ForceUpgrade(force)) + previousRelease, upgradedRelease, err := manager.UpgradeRelease(release.ForceUpgrade(force)) if err != nil { if errors.Is(err, release.ErrUpgradeFailed) { // the forceRollback variable takes the value of the annotation, // "helm.sdk.operatorframework.io/rollback-force". // The default value for the annotation is true forceRollback := readBoolAnnotationWithDefault(o, helmRollbackForceAnnotation, true) - if err := manager.RollBack(ctx, release.ForceRollback(forceRollback)); err != nil { + if err := manager.RollBack(release.ForceRollback(forceRollback)); err != nil { log.Error(err, "Error rolling back release") } } diff --git a/internal/helm/release/manager.go b/internal/helm/release/manager.go index 1aa24e41f6..62744efcd1 100644 --- a/internal/helm/release/manager.go +++ b/internal/helm/release/manager.go @@ -51,13 +51,13 @@ type Manager interface { ReleaseName() string IsInstalled() bool IsUpgradeRequired() bool - Sync(context.Context) error - InstallRelease(context.Context, ...InstallOption) (*rpb.Release, error) - UpgradeRelease(context.Context, ...UpgradeOption) (*rpb.Release, *rpb.Release, error) - RollBack(context.Context, ...RollBackOption) error + Sync() error + InstallRelease(...InstallOption) (*rpb.Release, error) + UpgradeRelease(...UpgradeOption) (*rpb.Release, *rpb.Release, error) + RollBack(...RollBackOption) error ReconcileRelease(context.Context) (*rpb.Release, error) - UninstallRelease(context.Context, ...UninstallOption) (*rpb.Release, error) - CleanupRelease(context.Context, string) (bool, error) + UninstallRelease(...UninstallOption) (*rpb.Release, error) + CleanupRelease(string) (bool, error) } type manager struct { @@ -97,7 +97,7 @@ func (m manager) IsUpgradeRequired() bool { // Sync ensures the Helm storage backend is in sync with the status of the // custom resource. -func (m *manager) Sync(ctx context.Context) error { +func (m *manager) Sync() error { // Get release history for this release name releases, err := m.storageBackend.History(m.releaseName) if err != nil && !notFoundErr(err) { @@ -163,7 +163,7 @@ func (m manager) getCandidateRelease(namespace, name string, chart *cpb.Chart, } // InstallRelease performs a Helm release install. -func (m manager) InstallRelease(ctx context.Context, opts ...InstallOption) (*rpb.Release, error) { +func (m manager) InstallRelease(opts ...InstallOption) (*rpb.Release, error) { install := action.NewInstall(m.actionConfig) install.ReleaseName = m.releaseName install.Namespace = m.namespace @@ -207,7 +207,7 @@ func ForceUpgrade(force bool) UpgradeOption { var ErrUpgradeFailed = errors.New("upgrade failed; rollback required") // UpgradeRelease performs a Helm release upgrade. -func (m manager) UpgradeRelease(ctx context.Context, opts ...UpgradeOption) (*rpb.Release, *rpb.Release, error) { +func (m manager) UpgradeRelease(opts ...UpgradeOption) (*rpb.Release, *rpb.Release, error) { upgrade := action.NewUpgrade(m.actionConfig) upgrade.Namespace = m.namespace @@ -243,7 +243,7 @@ func ForceRollback(force bool) RollBackOption { } // RollBack attempts to reverse any partially applied releases -func (m manager) RollBack(ctx context.Context, opts ...RollBackOption) error { +func (m manager) RollBack(opts ...RollBackOption) error { rollback := action.NewRollback(m.actionConfig) for _, fn := range opts { @@ -387,7 +387,7 @@ func createJSONMergePatch(existingJSON, expectedJSON []byte) ([]byte, error) { } // UninstallRelease performs a Helm release uninstall. -func (m manager) UninstallRelease(ctx context.Context, opts ...UninstallOption) (*rpb.Release, error) { +func (m manager) UninstallRelease(opts ...UninstallOption) (*rpb.Release, error) { uninstall := action.NewUninstall(m.actionConfig) for _, o := range opts { if err := o(uninstall); err != nil { @@ -403,7 +403,7 @@ func (m manager) UninstallRelease(ctx context.Context, opts ...UninstallOption) // CleanupRelease deletes resources if they are not deleted already. // Return true if all the resources are deleted, false otherwise. -func (m manager) CleanupRelease(ctx context.Context, manifest string) (bool, error) { +func (m manager) CleanupRelease(manifest string) (bool, error) { dc, err := m.actionConfig.RESTClientGetter.ToDiscoveryClient() if err != nil { return false, fmt.Errorf("failed to get Kubernetes discovery client: %w", err) diff --git a/internal/olm/installer/client.go b/internal/olm/installer/client.go index 796dfe6d77..b69b61edce 100644 --- a/internal/olm/installer/client.go +++ b/internal/olm/installer/client.go @@ -173,7 +173,7 @@ func (c Client) InstallVersion(ctx context.Context, namespace, version string) ( return &status, nil } -func (c Client) UninstallVersion(ctx context.Context, namespace, version string) error { +func (c Client) UninstallVersion(ctx context.Context, version string) error { crds, resources, err := c.getResources(ctx, version) if err != nil { return fmt.Errorf("failed to get resources: %v", err) @@ -187,13 +187,10 @@ func (c Client) UninstallVersion(ctx context.Context, namespace, version string) } log.Infof("Uninstalling resources for version %q", version) - if err := c.DoDelete(ctx, objs...); err != nil { - return err - } - return nil + return c.DoDelete(ctx, objs...) } -func (c Client) GetStatus(ctx context.Context, namespace, version string) (*olmresourceclient.Status, error) { +func (c Client) GetStatus(ctx context.Context, version string) (*olmresourceclient.Status, error) { crds, resources, err := c.getResources(ctx, version) if err != nil { return nil, fmt.Errorf("failed to get resources: %v", err) diff --git a/internal/olm/installer/manager.go b/internal/olm/installer/manager.go index a859d31388..21eb098429 100644 --- a/internal/olm/installer/manager.go +++ b/internal/olm/installer/manager.go @@ -105,7 +105,7 @@ func (m *Manager) Uninstall() error { m.Version = version } - if err := m.Client.UninstallVersion(ctx, m.OLMNamespace, m.Version); err != nil { + if err := m.Client.UninstallVersion(ctx, m.Version); err != nil { return err } @@ -133,7 +133,7 @@ func (m *Manager) Status() error { m.Version = version } - status, err := m.Client.GetStatus(ctx, m.OLMNamespace, m.Version) + status, err := m.Client.GetStatus(ctx, m.Version) if err != nil { return err } diff --git a/internal/olm/operator/registry/configmap.go b/internal/olm/operator/registry/configmap.go index fee995581c..5ab2bad4d7 100644 --- a/internal/olm/operator/registry/configmap.go +++ b/internal/olm/operator/registry/configmap.go @@ -110,10 +110,8 @@ func (c *ConfigMapCatalogCreator) updateCatalogSource(ctx context.Context, cs *v } cs.Spec.Address = registryGRPCAddr cs.Spec.SourceType = v1alpha1.SourceTypeGrpc - if err := c.cfg.Client.Update(ctx, cs); err != nil { - return err - } - return nil + + return c.cfg.Client.Update(ctx, cs) }); err != nil { return fmt.Errorf("error setting grpc address on catalog source: %v", err) } diff --git a/internal/scorecard/scorecard.go b/internal/scorecard/scorecard.go index 924352f789..1d4a04d8fe 100644 --- a/internal/scorecard/scorecard.go +++ b/internal/scorecard/scorecard.go @@ -273,7 +273,7 @@ func (r PodTestRunner) RunTest(ctx context.Context, test v1alpha3.TestConfigurat } // RunTest executes a single test -func (r FakeTestRunner) RunTest(ctx context.Context, test v1alpha3.TestConfiguration, podSec bool) (result *v1alpha3.TestStatus, err error) { +func (r FakeTestRunner) RunTest(ctx context.Context, _ v1alpha3.TestConfiguration, _ bool) (result *v1alpha3.TestStatus, err error) { select { case <-time.After(r.Sleep): return r.TestStatus, r.Error diff --git a/internal/testutils/olm.go b/internal/testutils/olm.go index 8f552270c9..f3c009e59b 100644 --- a/internal/testutils/olm.go +++ b/internal/testutils/olm.go @@ -89,9 +89,5 @@ func (tc TestContext) GenerateBundle() error { return err } - if err := tc.Make("bundle", "IMG="+tc.ImageName); err != nil { - return err - } - - return nil + return tc.Make("bundle", "IMG="+tc.ImageName) } diff --git a/internal/validate/result.go b/internal/validate/result.go index 69b4b0e6ec..f7bbdf2ce9 100644 --- a/internal/validate/result.go +++ b/internal/validate/result.go @@ -109,10 +109,7 @@ func (r *Result) Combine(results ...Result) error { for _, result := range results { r.Outputs = append(r.Outputs, result.Outputs...) } - if err := r.prepare(); err != nil { - return err - } - return nil + return r.prepare() } // prepare should be used when writing an Result to a non-log writer. diff --git a/release/changelog/internal/fragment_test.go b/release/changelog/internal/fragment_test.go index 7387747156..e531e97e9b 100644 --- a/release/changelog/internal/fragment_test.go +++ b/release/changelog/internal/fragment_test.go @@ -12,7 +12,7 @@ type mockValidPRGetter struct{} var _ PullRequestNumberGetter = &mockValidPRGetter{} -func (m *mockValidPRGetter) GetPullRequestNumberFor(file string) (uint, error) { +func (m *mockValidPRGetter) GetPullRequestNumberFor(_ string) (uint, error) { return 999998, nil }