Skip to content

Commit

Permalink
bump golangci-lint to 1.53.3 and resolve linter errors
Browse files Browse the repository at this point in the history
Signed-off-by: everettraven <everettraven@gmail.com>
  • Loading branch information
everettraven committed Dec 14, 2023
1 parent ace0426 commit 52cc899
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions hack/generate/samples/internal/pkg/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/helm/client/secrets_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
12 changes: 6 additions & 6 deletions internal/helm/controller/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand All @@ -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{
Expand Down Expand Up @@ -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")
}
}
Expand Down
24 changes: 12 additions & 12 deletions internal/helm/release/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions internal/olm/installer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/olm/installer/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 2 additions & 4 deletions internal/olm/operator/registry/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/scorecard/scorecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions internal/testutils/olm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 1 addition & 4 deletions internal/validate/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion release/changelog/internal/fragment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 52cc899

Please sign in to comment.