From b92198d59603a4b1c0b7f521a025e0a936c509ba Mon Sep 17 00:00:00 2001 From: karamaru-alpha Date: Wed, 8 Nov 2023 04:22:53 +0900 Subject: [PATCH] Update golangci-lint and fix lint errors Signed-off-by: karamaru-alpha --- .golangci.yml | 41 +++++++++++-------- Makefile | 2 +- .../deploymentchaincontroller/controller.go | 8 +--- .../appconfigreporter/appconfigreporter.go | 9 ++-- .../appconfigreporter_test.go | 3 +- pkg/app/piped/cmd/piped/piped.go | 19 ++++----- pkg/app/piped/controller/controller.go | 12 ++---- .../piped/driftdetector/cloudrun/detector.go | 3 +- .../driftdetector/kubernetes/detector.go | 4 +- .../piped/driftdetector/terraform/detector.go | 4 +- pkg/app/piped/executor/analysis/analysis.go | 2 +- .../piped/executor/kubernetes/kubernetes.go | 6 +-- .../executor/kubernetes/kubernetes_test.go | 2 +- pkg/app/piped/executor/kubernetes/traffic.go | 2 +- .../livestatereporter/cloudrun/report.go | 3 +- .../livestatereporter/kubernetes/reporter.go | 3 +- .../livestatestore/kubernetes/appnodes.go | 4 +- .../livestatestore/kubernetes/reflector.go | 2 +- pkg/app/piped/notifier/slack.go | 1 + .../piped/planner/kubernetes/kubernetes.go | 2 +- pkg/app/piped/planpreview/builder.go | 7 +--- .../platformprovider/kubernetes/hasher.go | 7 ++-- .../kubernetes/resourcekey.go | 4 +- .../platformprovider/kubernetes/state.go | 1 - pkg/app/piped/trigger/trigger.go | 2 +- pkg/app/server/apikeyverifier/verifier.go | 2 +- pkg/crypto/hybrid.go | 3 +- pkg/git/client.go | 2 + pkg/git/client_test.go | 1 + 29 files changed, 73 insertions(+), 88 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index a6edfd8fbe..7c3bc4bb2d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,23 +9,23 @@ run: linters: disable-all: true enable: - - prealloc + - depguard + - exportloopref + - gocritic + - goimports + - gosimple - ineffassign - - goerr113 - misspell - - errcheck - - gosimple + - prealloc - staticcheck - - gosec - - gocritic - - unparam - - deadcode - - unconvert - - typecheck - stylecheck - - exportloopref - - depguard - - goimports + - typecheck + - unconvert + - unparam + # TODO: Enable these linters + # - errcheck + # - goerr113 + # - gosec issues: exclude-rules: @@ -38,10 +38,15 @@ output: linters-settings: depguard: - list-type: blacklist - include-go-root: true - packages-with-error-message: - - sync/atomic: "Use go.uber.org/atomic instead of sync/atomic" - - io/ioutil: "Use corresponding 'os' or 'io' functions instead." + rules: + main: + deny: + - pkg: "sync/atomic" + desc: "Use go.uber.org/atomic instead of sync/atomic." + - pkg: "io/ioutil" + desc: "Use corresponding 'os' or 'io' functions instead." + gocritic: + disabled-checks: + - appendAssign goimports: local-prefixes: github.com/pipe-cd/pipecd diff --git a/Makefile b/Makefile index 5c5c81f377..ac8ac831a8 100644 --- a/Makefile +++ b/Makefile @@ -149,7 +149,7 @@ run/site: .PHONY: lint/go lint/go: FIX ?= false -lint/go: VERSION ?= sha256:78d1bbd01a9886a395dc8374218a6c0b7b67694e725dd76f0c8ac1de411b85e8 #v1.46.2 +lint/go: VERSION ?= sha256:fb70c9b2e6d0763141f057abcafde7f88d5e4bb3b5882d6b14bc79382f04481c #v1.55.2 lint/go: FLAGS ?= --rm --platform linux/amd64 -e GOCACHE=/repo/.cache/go-build -e GOLANGCI_LINT_CACHE=/repo/.cache/golangci-lint -v ${PWD}:/repo -w /repo -it lint/go: ifeq ($(FIX),true) diff --git a/pkg/app/ops/deploymentchaincontroller/controller.go b/pkg/app/ops/deploymentchaincontroller/controller.go index 93e2ba9d42..d40f65cf4f 100644 --- a/pkg/app/ops/deploymentchaincontroller/controller.go +++ b/pkg/app/ops/deploymentchaincontroller/controller.go @@ -88,9 +88,7 @@ func (d *DeploymentChainController) Run(ctx context.Context) error { d.logger.Error("failed while sync controller updaters", zap.Error(err)) } case <-syncDeploymentChainsTicker.C: - if err := d.syncDeploymentChains(ctx); err != nil { - d.logger.Error("failed while sync deployment chains", zap.Error(err)) - } + d.syncDeploymentChains(ctx) } } } @@ -130,7 +128,7 @@ func (d *DeploymentChainController) syncUpdaters(ctx context.Context) error { return nil } -func (d *DeploymentChainController) syncDeploymentChains(ctx context.Context) error { +func (d *DeploymentChainController) syncDeploymentChains(ctx context.Context) { var ( updatersNum = len(d.updaters) updaterCh = make(chan *updater, updatersNum) @@ -162,8 +160,6 @@ func (d *DeploymentChainController) syncDeploymentChains(ctx context.Context) er d.logger.Info("waiting for all updaters to finish") wg.Wait() - - return nil } func listNotCompletedDeploymentChain(ctx context.Context, dcs deploymentChainStore) ([]*model.DeploymentChain, error) { diff --git a/pkg/app/piped/appconfigreporter/appconfigreporter.go b/pkg/app/piped/appconfigreporter/appconfigreporter.go index e256e1b10c..d18ec3c9cc 100644 --- a/pkg/app/piped/appconfigreporter/appconfigreporter.go +++ b/pkg/app/piped/appconfigreporter/appconfigreporter.go @@ -167,10 +167,7 @@ func (r *Reporter) updateRegisteredApps(ctx context.Context, headCommits map[str outOfSyncRegisteredApps := make([]*model.ApplicationInfo, 0) for repoID, repo := range r.gitRepos { headCommit := headCommits[repoID] - rs, err := r.findOutOfSyncRegisteredApps(repo.GetPath(), repoID, headCommit) - if err != nil { - return err - } + rs := r.findOutOfSyncRegisteredApps(repo.GetPath(), repoID, headCommit) r.logger.Info(fmt.Sprintf("found out %d valid registered applications that config has been changed in repository %q", len(rs), repoID)) outOfSyncRegisteredApps = append(outOfSyncRegisteredApps, rs...) } @@ -233,7 +230,7 @@ func (r *Reporter) updateUnregisteredApps(ctx context.Context) error { } // findOutOfSyncRegisteredApps finds out registered application info that should be updated in the given git repository. -func (r *Reporter) findOutOfSyncRegisteredApps(repoPath, repoID, headCommit string) ([]*model.ApplicationInfo, error) { +func (r *Reporter) findOutOfSyncRegisteredApps(repoPath, repoID, headCommit string) []*model.ApplicationInfo { // Compare the apps registered on Control-plane with the latest config file // and return only the ones that have been changed. apps := make([]*model.ApplicationInfo, 0) @@ -275,7 +272,7 @@ func (r *Reporter) findOutOfSyncRegisteredApps(repoPath, repoID, headCommit stri appCfg.Id = app.Id apps = append(apps, appCfg) } - return apps, nil + return apps } func (r *Reporter) isSynced(appInfo *model.ApplicationInfo, app *model.Application) bool { diff --git a/pkg/app/piped/appconfigreporter/appconfigreporter_test.go b/pkg/app/piped/appconfigreporter/appconfigreporter_test.go index e523ea1408..91a3255193 100644 --- a/pkg/app/piped/appconfigreporter/appconfigreporter_test.go +++ b/pkg/app/piped/appconfigreporter/appconfigreporter_test.go @@ -157,8 +157,7 @@ spec: } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - got, err := tc.reporter.findOutOfSyncRegisteredApps(tc.args.repoPath, tc.args.repoID, "not-existed-head-commit") - assert.Equal(t, tc.wantErr, err != nil) + got := tc.reporter.findOutOfSyncRegisteredApps(tc.args.repoPath, tc.args.repoID, "not-existed-head-commit") assert.Equal(t, tc.want, got) }) } diff --git a/pkg/app/piped/cmd/piped/piped.go b/pkg/app/piped/cmd/piped/piped.go index ec342e3342..1a9507e6f7 100644 --- a/pkg/app/piped/cmd/piped/piped.go +++ b/pkg/app/piped/cmd/piped/piped.go @@ -696,17 +696,14 @@ func (p *piped) sendPipedMeta(ctx context.Context, client pipedservice.Client, c } // Configure secret management. - if sm := cfg.SecretManagement; sm != nil { - switch sm.Type { - case model.SecretManagementTypeKeyPair: - publicKey, err := sm.KeyPair.LoadPublicKey() - if err != nil { - return fmt.Errorf("failed to read public key for secret management (%w)", err) - } - req.SecretEncryption = &model.Piped_SecretEncryption{ - Type: sm.Type.String(), - PublicKey: string(publicKey), - } + if sm := cfg.SecretManagement; sm != nil && sm.Type == model.SecretManagementTypeKeyPair { + publicKey, err := sm.KeyPair.LoadPublicKey() + if err != nil { + return fmt.Errorf("failed to read public key for secret management (%w)", err) + } + req.SecretEncryption = &model.Piped_SecretEncryption{ + Type: sm.Type.String(), + PublicKey: string(publicKey), } } if req.SecretEncryption == nil { diff --git a/pkg/app/piped/controller/controller.go b/pkg/app/piped/controller/controller.go index 76e057de3c..65f1923520 100644 --- a/pkg/app/piped/controller/controller.go +++ b/pkg/app/piped/controller/controller.go @@ -288,7 +288,7 @@ func (c *controller) checkCommands() { } // syncPlanners adds new planner for newly PENDING deployments. -func (c *controller) syncPlanners(ctx context.Context) error { +func (c *controller) syncPlanners(ctx context.Context) { // Remove stale planners from the recently completed list. for id, t := range c.donePlanners { if time.Since(t) >= plannerStaleDuration { @@ -324,7 +324,7 @@ func (c *controller) syncPlanners(ctx context.Context) error { // Add missing planners. pendings := c.deploymentLister.ListPendings() if len(pendings) == 0 { - return nil + return } c.logger.Info(fmt.Sprintf("there are %d pending deployments for planning", len(pendings)), @@ -426,8 +426,6 @@ func (c *controller) syncPlanners(ctx context.Context) error { ) } } - - return nil } func (c *controller) startNewPlanner(ctx context.Context, d *model.Deployment) (*planner, error) { @@ -506,7 +504,7 @@ func (c *controller) startNewPlanner(ctx context.Context, d *model.Deployment) ( // syncSchedulers adds new scheduler for newly PLANNED/RUNNING deployments // as well as removes the schedulers for the completed deployments. -func (c *controller) syncSchedulers(ctx context.Context) error { +func (c *controller) syncSchedulers(ctx context.Context) { // Update the most recent successful commit hashes. for id, s := range c.schedulers { if !s.IsDone() { @@ -556,7 +554,7 @@ func (c *controller) syncSchedulers(ctx context.Context) error { targets := append(runnings, planneds...) if len(targets) == 0 { - return nil + return } c.logger.Info(fmt.Sprintf("there are %d planned/running deployments for scheduling", len(targets)), @@ -589,8 +587,6 @@ func (c *controller) syncSchedulers(ctx context.Context) error { zap.Int("count", len(c.schedulers)), ) } - - return nil } // startNewScheduler creates and starts running a new scheduler diff --git a/pkg/app/piped/driftdetector/cloudrun/detector.go b/pkg/app/piped/driftdetector/cloudrun/detector.go index d707570f40..914b51ccdb 100644 --- a/pkg/app/piped/driftdetector/cloudrun/detector.go +++ b/pkg/app/piped/driftdetector/cloudrun/detector.go @@ -122,7 +122,7 @@ func (d *detector) ProviderName() string { return d.provider.Name } -func (d *detector) check(ctx context.Context) error { +func (d *detector) check(ctx context.Context) { appsByRepo := d.listGroupedApplication() for repoID, apps := range appsByRepo { @@ -168,7 +168,6 @@ func (d *detector) check(ctx context.Context) error { } } } - return nil } func (d *detector) cloneGitRepository(ctx context.Context, repoID string) (git.Repo, error) { diff --git a/pkg/app/piped/driftdetector/kubernetes/detector.go b/pkg/app/piped/driftdetector/kubernetes/detector.go index 6eb37b67da..1f951e7fd2 100644 --- a/pkg/app/piped/driftdetector/kubernetes/detector.go +++ b/pkg/app/piped/driftdetector/kubernetes/detector.go @@ -120,7 +120,7 @@ func (d *detector) Run(ctx context.Context) error { } } -func (d *detector) check(ctx context.Context) error { +func (d *detector) check(ctx context.Context) { appsByRepo := d.listGroupedApplication() for repoID, apps := range appsByRepo { @@ -171,8 +171,6 @@ func (d *detector) check(ctx context.Context) error { } } } - - return nil } func (d *detector) checkApplication(ctx context.Context, app *model.Application, repo git.Repo, headCommit git.Commit) error { diff --git a/pkg/app/piped/driftdetector/terraform/detector.go b/pkg/app/piped/driftdetector/terraform/detector.go index 7edd099c86..005e095735 100644 --- a/pkg/app/piped/driftdetector/terraform/detector.go +++ b/pkg/app/piped/driftdetector/terraform/detector.go @@ -121,7 +121,7 @@ func (d *detector) Run(ctx context.Context) error { } } -func (d *detector) check(ctx context.Context) error { +func (d *detector) check(ctx context.Context) { appsByRepo := d.listGroupedApplication() for repoID, apps := range appsByRepo { @@ -167,8 +167,6 @@ func (d *detector) check(ctx context.Context) error { } } } - - return nil } func (d *detector) checkApplication(ctx context.Context, app *model.Application, repo git.Repo, headCommit git.Commit) error { diff --git a/pkg/app/piped/executor/analysis/analysis.go b/pkg/app/piped/executor/analysis/analysis.go index a42b43364d..12ad436481 100644 --- a/pkg/app/piped/executor/analysis/analysis.go +++ b/pkg/app/piped/executor/analysis/analysis.go @@ -116,7 +116,7 @@ func (e *Executor) Execute(sig executor.StopSignal) model.StageStatus { continue } status = model.StageStatus_STAGE_SKIPPED - // Stop the context to cancel all running analysises. + // Stop the context to cancel all running analyses. cancel() return case <-doneCh: diff --git a/pkg/app/piped/executor/kubernetes/kubernetes.go b/pkg/app/piped/executor/kubernetes/kubernetes.go index a655f7a29e..8983557920 100644 --- a/pkg/app/piped/executor/kubernetes/kubernetes.go +++ b/pkg/app/piped/executor/kubernetes/kubernetes.go @@ -308,7 +308,7 @@ func deleteResources(ctx context.Context, ag applierGetter, resources []provider } func findManifests(kind, name string, manifests []provider.Manifest) []provider.Manifest { - var out []provider.Manifest + out := make([]provider.Manifest, 0, len(manifests)) for _, m := range manifests { if m.Key.Kind != kind { continue @@ -322,7 +322,7 @@ func findManifests(kind, name string, manifests []provider.Manifest) []provider. } func findConfigMapManifests(manifests []provider.Manifest) []provider.Manifest { - var out []provider.Manifest + out := make([]provider.Manifest, 0, len(manifests)) for _, m := range manifests { if !m.Key.IsConfigMap() { continue @@ -333,7 +333,7 @@ func findConfigMapManifests(manifests []provider.Manifest) []provider.Manifest { } func findSecretManifests(manifests []provider.Manifest) []provider.Manifest { - var out []provider.Manifest + out := make([]provider.Manifest, 0, len(manifests)) for _, m := range manifests { if !m.Key.IsSecret() { continue diff --git a/pkg/app/piped/executor/kubernetes/kubernetes_test.go b/pkg/app/piped/executor/kubernetes/kubernetes_test.go index fbe77d0d1a..c2bc871a8a 100644 --- a/pkg/app/piped/executor/kubernetes/kubernetes_test.go +++ b/pkg/app/piped/executor/kubernetes/kubernetes_test.go @@ -1018,7 +1018,7 @@ func TestPatchManifests(t *testing.T) { patcher := func(m provider.Manifest, cfg config.K8sResourcePatch) (*provider.Manifest, error) { out := m - out.Key.Namespace = out.Key.Namespace + "+" + out.Key.Namespace = fmt.Sprintf("%s+", out.Key.Namespace) return &out, nil } diff --git a/pkg/app/piped/executor/kubernetes/traffic.go b/pkg/app/piped/executor/kubernetes/traffic.go index fbec34e37c..92e4779899 100644 --- a/pkg/app/piped/executor/kubernetes/traffic.go +++ b/pkg/app/piped/executor/kubernetes/traffic.go @@ -226,7 +226,7 @@ func findIstioVirtualServiceManifests(manifests []provider.Manifest, ref config. return nil, fmt.Errorf("support only %q kind for VirtualService reference", istioVirtualServiceKind) } - var out []provider.Manifest + out := make([]provider.Manifest, 0, len(manifests)) for _, m := range manifests { if !strings.HasPrefix(m.Key.APIVersion, istioNetworkingAPIVersionPrefix) { continue diff --git a/pkg/app/piped/livestatereporter/cloudrun/report.go b/pkg/app/piped/livestatereporter/cloudrun/report.go index 0c6f1a8808..3c48f172fb 100644 --- a/pkg/app/piped/livestatereporter/cloudrun/report.go +++ b/pkg/app/piped/livestatereporter/cloudrun/report.go @@ -96,7 +96,7 @@ func (r *reporter) ProviderName() string { return r.provider.Name } -func (r *reporter) flushSnapshots(ctx context.Context) error { +func (r *reporter) flushSnapshots(ctx context.Context) { apps := r.appLister.ListByPlatformProvider(r.provider.Name) for _, app := range apps { state, ok := r.stateGetter.GetState(app.Id) @@ -130,5 +130,4 @@ func (r *reporter) flushSnapshots(ctx context.Context) error { r.snapshotVersions[app.Id] = state.Version r.logger.Info(fmt.Sprintf("successfully reported application live state for application: %s", app.Id)) } - return nil } diff --git a/pkg/app/piped/livestatereporter/kubernetes/reporter.go b/pkg/app/piped/livestatereporter/kubernetes/reporter.go index 91b92ecc2c..84c86de5bd 100644 --- a/pkg/app/piped/livestatereporter/kubernetes/reporter.go +++ b/pkg/app/piped/livestatereporter/kubernetes/reporter.go @@ -109,7 +109,7 @@ func (r *reporter) Run(ctx context.Context) error { } } -func (r *reporter) flushSnapshots(ctx context.Context) error { +func (r *reporter) flushSnapshots(ctx context.Context) { // TODO: In the future, maybe we should apply worker model for this or // send multiple application states in one request. apps := r.appLister.ListByPlatformProvider(r.provider.Name) @@ -145,7 +145,6 @@ func (r *reporter) flushSnapshots(ctx context.Context) error { r.snapshotVersions[app.Id] = state.Version r.logger.Info(fmt.Sprintf("successfully reported application live state for application: %s", app.Id)) } - return nil } func (r *reporter) flushEvents(ctx context.Context) error { diff --git a/pkg/app/piped/livestatestore/kubernetes/appnodes.go b/pkg/app/piped/livestatestore/kubernetes/appnodes.go index ca2fd37738..b633991d9a 100644 --- a/pkg/app/piped/livestatestore/kubernetes/appnodes.go +++ b/pkg/app/piped/livestatestore/kubernetes/appnodes.go @@ -84,7 +84,7 @@ func (a *appNodes) addManagingResource(uid string, key provider.ResourceKey, obj }, true } -func (a *appNodes) deleteManagingResource(uid string, key provider.ResourceKey, now time.Time) (model.KubernetesResourceStateEvent, bool) { +func (a *appNodes) deleteManagingResource(uid string, _ provider.ResourceKey, now time.Time) (model.KubernetesResourceStateEvent, bool) { a.mu.Lock() n, ok := a.managingNodes[uid] if !ok { @@ -138,7 +138,7 @@ func (a *appNodes) addDependedResource(uid string, key provider.ResourceKey, obj }, true } -func (a *appNodes) deleteDependedResource(uid string, key provider.ResourceKey, now time.Time) (model.KubernetesResourceStateEvent, bool) { +func (a *appNodes) deleteDependedResource(uid string, _ provider.ResourceKey, now time.Time) (model.KubernetesResourceStateEvent, bool) { a.mu.Lock() n, ok := a.dependedNodes[uid] if !ok { diff --git a/pkg/app/piped/livestatestore/kubernetes/reflector.go b/pkg/app/piped/livestatestore/kubernetes/reflector.go index 4ef37375f9..d4ae050c6e 100644 --- a/pkg/app/piped/livestatestore/kubernetes/reflector.go +++ b/pkg/app/piped/livestatestore/kubernetes/reflector.go @@ -150,7 +150,7 @@ type reflector struct { logger *zap.Logger } -func (r *reflector) start(ctx context.Context) error { +func (r *reflector) start(_ context.Context) error { matcher := newResourceMatcher(r.config.AppStateInformer) // Use discovery to discover APIs supported by the Kubernetes API server. diff --git a/pkg/app/piped/notifier/slack.go b/pkg/app/piped/notifier/slack.go index fadd1222f1..80e9548a4f 100644 --- a/pkg/app/piped/notifier/slack.go +++ b/pkg/app/piped/notifier/slack.go @@ -350,6 +350,7 @@ func makeSlackDate(unix int64) string { return fmt.Sprintf("", unix) } +// nolint:unparam func truncateText(text string, max int) string { if len(text) <= max { return text diff --git a/pkg/app/piped/planner/kubernetes/kubernetes.go b/pkg/app/piped/planner/kubernetes/kubernetes.go index 3e42732c6e..f209c54bed 100644 --- a/pkg/app/piped/planner/kubernetes/kubernetes.go +++ b/pkg/app/piped/planner/kubernetes/kubernetes.go @@ -341,7 +341,7 @@ func findWorkloadManifests(manifests []provider.Manifest, refs []config.K8sResou } func findManifests(kind, name string, manifests []provider.Manifest) []provider.Manifest { - var out []provider.Manifest + out := make([]provider.Manifest, 0, len(manifests)) for _, m := range manifests { if m.Key.Kind != kind { continue diff --git a/pkg/app/piped/planpreview/builder.go b/pkg/app/piped/planpreview/builder.go index af6bd36711..1a307ea259 100644 --- a/pkg/app/piped/planpreview/builder.go +++ b/pkg/app/piped/planpreview/builder.go @@ -151,10 +151,7 @@ func (b *builder) build(ctx context.Context, id string, cmd model.Command_BuildP } // Find all applications that should be triggered. - triggerApps, failedResults, err := b.findTriggerApps(ctx, repo, apps, mergedCommit.Hash) - if err != nil { - return nil, err - } + triggerApps, failedResults := b.findTriggerApps(ctx, repo, apps, mergedCommit.Hash) results := failedResults if len(triggerApps) == 0 { @@ -301,7 +298,7 @@ func (b *builder) cloneHeadCommit(ctx context.Context, headBranch, headCommit st return repo, nil } -func (b *builder) findTriggerApps(ctx context.Context, repo git.Repo, apps []*model.Application, headCommit string) (triggerApps []*model.Application, failedResults []*model.ApplicationPlanPreviewResult, err error) { +func (b *builder) findTriggerApps(ctx context.Context, repo git.Repo, apps []*model.Application, headCommit string) (triggerApps []*model.Application, failedResults []*model.ApplicationPlanPreviewResult) { d := trigger.NewOnCommitDeterminer(repo, headCommit, b.commitGetter, b.logger) determine := func(app *model.Application) (bool, error) { appCfg, err := config.LoadApplication(repo.GetPath(), app.GitPath.GetApplicationConfigFilePath(), app.Kind) diff --git a/pkg/app/piped/platformprovider/kubernetes/hasher.go b/pkg/app/piped/platformprovider/kubernetes/hasher.go index 3e19a587ac..edce6c319b 100644 --- a/pkg/app/piped/platformprovider/kubernetes/hasher.go +++ b/pkg/app/piped/platformprovider/kubernetes/hasher.go @@ -47,19 +47,20 @@ func HashManifests(manifests []Manifest) (string, error) { var encoded string var err error - if m.Key.IsConfigMap() { + switch { + case m.Key.IsConfigMap(): obj := &v1.ConfigMap{} if err := m.ConvertToStructuredObject(obj); err != nil { return "", err } encoded, err = encodeConfigMap(obj) - } else if m.Key.IsSecret() { + case m.Key.IsSecret(): obj := &v1.Secret{} if err := m.ConvertToStructuredObject(obj); err != nil { return "", err } encoded, err = encodeSecret(obj) - } else { + default: var encodedBytes []byte encodedBytes, err = m.MarshalJSON() encoded = string(encodedBytes) diff --git a/pkg/app/piped/platformprovider/kubernetes/resourcekey.go b/pkg/app/piped/platformprovider/kubernetes/resourcekey.go index 2d61ed3fb2..d3e83aac24 100644 --- a/pkg/app/piped/platformprovider/kubernetes/resourcekey.go +++ b/pkg/app/piped/platformprovider/kubernetes/resourcekey.go @@ -21,7 +21,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) -var builtInApiVersions = map[string]struct{}{ +var builtInAPIVersions = map[string]struct{}{ "admissionregistration.k8s.io/v1": {}, "admissionregistration.k8s.io/v1beta1": {}, "apiextensions.k8s.io/v1": {}, @@ -273,7 +273,7 @@ func DecodeResourceKey(key string) (ResourceKey, error) { } func IsKubernetesBuiltInResource(apiVersion string) bool { - _, ok := builtInApiVersions[apiVersion] + _, ok := builtInAPIVersions[apiVersion] // TODO: Change the way to detect whether an APIVersion is built-in or not // rather than depending on this fixed list. return ok diff --git a/pkg/app/piped/platformprovider/kubernetes/state.go b/pkg/app/piped/platformprovider/kubernetes/state.go index 10f8e063c8..913d794d0d 100644 --- a/pkg/app/piped/platformprovider/kubernetes/state.go +++ b/pkg/app/piped/platformprovider/kubernetes/state.go @@ -424,7 +424,6 @@ func determineIngressHealth(obj *unstructured.Unstructured) (status model.Kubern return } status = model.KubernetesResourceState_HEALTHY - return } v1Ingress := &networkingv1.Ingress{} diff --git a/pkg/app/piped/trigger/trigger.go b/pkg/app/piped/trigger/trigger.go index 9aed58f12c..e73b1f15bb 100644 --- a/pkg/app/piped/trigger/trigger.go +++ b/pkg/app/piped/trigger/trigger.go @@ -474,7 +474,7 @@ func (t *Trigger) GetLastTriggeredCommitGetter() LastTriggeredCommitGetter { return t.commitStore } -func (t *Trigger) notifyDeploymentTriggered(ctx context.Context, appCfg *config.GenericApplicationSpec, d *model.Deployment) { +func (t *Trigger) notifyDeploymentTriggered(_ context.Context, appCfg *config.GenericApplicationSpec, d *model.Deployment) { var mentions []string if n := appCfg.DeploymentNotification; n != nil { mentions = n.FindSlackAccounts(model.NotificationEventType_EVENT_DEPLOYMENT_TRIGGERED) diff --git a/pkg/app/server/apikeyverifier/verifier.go b/pkg/app/server/apikeyverifier/verifier.go index b16e67f6a2..d3145b90ff 100644 --- a/pkg/app/server/apikeyverifier/verifier.go +++ b/pkg/app/server/apikeyverifier/verifier.go @@ -86,7 +86,7 @@ func (v *Verifier) Verify(ctx context.Context, key string) (*model.APIKey, error return apiKey, nil } -func (v *Verifier) checkAPIKey(ctx context.Context, apiKey *model.APIKey, id, key string) error { +func (v *Verifier) checkAPIKey(_ context.Context, apiKey *model.APIKey, id, key string) error { if apiKey.Disabled { return fmt.Errorf("the api key %s was already disabled", id) } diff --git a/pkg/crypto/hybrid.go b/pkg/crypto/hybrid.go index c041703ebe..884d7d81b2 100644 --- a/pkg/crypto/hybrid.go +++ b/pkg/crypto/hybrid.go @@ -45,7 +45,8 @@ func NewHybridEncrypter(key []byte) (*HybridEncrypter, error) { // Encrypt performs a regular AES-GCM + RSA-OAEP encryption. // The output string is: -// RSA ciphertext length || RSA ciphertext || AES ciphertext +// +// RSA ciphertext length || RSA ciphertext || AES ciphertext // // The implementation of this function was brought from well known Bitnami's SealedSecret library. // https://github.com/bitnami-labs/sealed-secrets/blob/master/pkg/crypto/crypto.go#L35 diff --git a/pkg/git/client.go b/pkg/git/client.go index 980f0f5038..ea56e74072 100644 --- a/pkg/git/client.go +++ b/pkg/git/client.go @@ -268,6 +268,8 @@ func runGitCommand(ctx context.Context, execPath, dir string, envs []string, arg } // retryCommand retries a command a few times with a constant backoff. +// +//nolint:unparam func retryCommand(retries int, interval time.Duration, logger *zap.Logger, commander func() ([]byte, error)) (out []byte, err error) { for i := 0; i < retries; i++ { out, err = commander() diff --git a/pkg/git/client_test.go b/pkg/git/client_test.go index 340c2a1550..3c6caa3781 100644 --- a/pkg/git/client_test.go +++ b/pkg/git/client_test.go @@ -116,6 +116,7 @@ func (f *faker) clean() { os.RemoveAll(f.dir) } +//nolint:unparam func (f *faker) repoDir(org, repo string) string { return filepath.Join(f.dir, org, repo) }