Skip to content

Commit b3cded1

Browse files
authored
Integrate golangci-lint to run aggregate linting checks for CI (#2536)
* Introduce golangci-lint support Introduce a root .golangci-lint.yaml file to the repository. This file is responsible for housing the golangci-lint configuration, and the various aggregate linters that are enabled/disabled. Signed-off-by: timflannagan <[email protected]> * .github/workflows: Run the golangci-lint action during the sanity checks Update the sanity workflow and add the golangci-lint action. Signed-off-by: timflannagan <[email protected]> * Fix linting violations outlined by golangci-lint Signed-off-by: timflannagan <[email protected]>
1 parent c6cc1d7 commit b3cded1

File tree

82 files changed

+463
-663
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+463
-663
lines changed

.github/workflows/sanity.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ jobs:
1313
- uses: actions/setup-go@v2
1414
with:
1515
go-version: '~1.16'
16-
- name: Install goimports
17-
run: go install golang.org/x/tools/cmd/goimports@latest
1816
- name: Run sanity checks
19-
run: make vendor && make lint && make diff
17+
run: make vendor && make diff
18+
- name: Run linting checks
19+
uses: "golangci/golangci-lint-action@v2"
20+
with:
21+
version: "v1.43"
22+
skip-go-installation: true
23+
skip-pkg-cache: true

.golangci.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
run:
2+
timeout: 5m
3+
skip-dirs:
4+
- pkg/lib
5+
- pkg/api
6+
- pkg/fakes
7+
- pkg/package-server/apis
8+
- test/e2e
9+
10+
linters:
11+
enable:
12+
- depguard
13+
- gofmt
14+
- goimports
15+
- importas
16+
- misspell
17+
- stylecheck
18+
- tparallel
19+
- unconvert
20+
- whitespace
21+
disable:
22+
- errcheck
23+
24+
issues:
25+
max-issues-per-linter: 0
26+
max-same-issues: 0
27+
28+
output:
29+
format: tab
30+
sort-results: true

cmd/catalog/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var (
6969
tlsCertPath = flag.String(
7070
"tls-cert", "", "Path to use for certificate key (requires tls-key)")
7171

72-
profiling = flag.Bool("profiling", false, "deprecated")
72+
_ = flag.Bool("profiling", false, "deprecated")
7373

7474
clientCAPath = flag.String("client-ca", "", "path to watch for client ca bundle")
7575

cmd/olm/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var (
6363
tlsCertPath = pflag.String(
6464
"tls-cert", "", "Path to use for certificate key (requires tls-key)")
6565

66-
profiling = pflag.Bool("profiling", false, "deprecated")
66+
_ = pflag.Bool("profiling", false, "deprecated")
6767

6868
clientCAPath = pflag.String("client-ca", "", "path to watch for client ca bundle")
6969

cmd/olm/manager.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ func Manager(ctx context.Context, debug bool) (ctrl.Manager, error) {
118118
if err = adoptionReconciler.SetupWithManager(mgr); err != nil {
119119
return nil, err
120120
}
121-
122121
}
123122
setupLog.Info("manager configured")
124123

pkg/controller/bundle/bundle_unpacker.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@ const (
384384
)
385385

386386
func (c *ConfigMapUnpacker) UnpackBundle(lookup *operatorsv1alpha1.BundleLookup, timeout time.Duration) (result *BundleUnpackResult, err error) {
387-
388387
result = newBundleUnpackResult(lookup)
389388

390389
// if bundle lookup failed condition already present, then there is nothing more to do
@@ -523,8 +522,8 @@ func (c *ConfigMapUnpacker) pendingContainerStatusMessages(job *batchv1.Job) (st
523522
podLabel := map[string]string{BundleUnpackPodLabel: job.GetName()}
524523
pods, listErr := c.podLister.Pods(job.GetNamespace()).List(k8slabels.SelectorFromValidatedSet(podLabel))
525524
if listErr != nil {
526-
c.logger.Errorf("Failed to list pods for job(%s): %v", job.GetName(), listErr)
527-
return "", fmt.Errorf("Failed to list pods for job(%s): %v", job.GetName(), listErr)
525+
c.logger.Errorf("failed to list pods for job(%s): %v", job.GetName(), listErr)
526+
return "", fmt.Errorf("failed to list pods for job(%s): %v", job.GetName(), listErr)
528527
}
529528

530529
// Ideally there should be just 1 pod running but inspect all pods in the pending phase
@@ -570,14 +569,14 @@ func (c *ConfigMapUnpacker) ensureConfigmap(csRef *corev1.ObjectReference, name
570569
if err != nil && apierrors.IsAlreadyExists(err) {
571570
cm, err = c.client.CoreV1().ConfigMaps(fresh.GetNamespace()).Get(context.TODO(), fresh.GetName(), metav1.GetOptions{})
572571
if err != nil {
573-
return nil, fmt.Errorf("Failed to retrieve configmap %s: %v", fresh.GetName(), err)
572+
return nil, fmt.Errorf("failed to retrieve configmap %s: %v", fresh.GetName(), err)
574573
}
575574
cm.SetLabels(map[string]string{
576575
install.OLMManagedLabelKey: install.OLMManagedLabelValue,
577576
})
578577
cm, err = c.client.CoreV1().ConfigMaps(cm.GetNamespace()).Update(context.TODO(), cm, metav1.UpdateOptions{})
579578
if err != nil {
580-
return nil, fmt.Errorf("Failed to update configmap %s: %v", cm.GetName(), err)
579+
return nil, fmt.Errorf("failed to update configmap %s: %v", cm.GetName(), err)
581580
}
582581
}
583582
}

pkg/controller/bundle/bundle_unpacker_test.go

Lines changed: 5 additions & 6 deletions
Large diffs are not rendered by default.

pkg/controller/install/apiservice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (i *StrategyDeploymentInstaller) createOrUpdateAPIService(caPEM []byte, des
4343
} else {
4444
csv, ok := i.owner.(*v1alpha1.ClusterServiceVersion)
4545
if !ok {
46-
return fmt.Errorf("APIServices require a CSV Owner.")
46+
return fmt.Errorf("failed to typecast the APIService owner: APIServices require a CSV owner")
4747
}
4848

4949
adoptable, err := IsAPIServiceAdoptable(i.strategyClient.GetOpLister(), csv, apiService)

pkg/controller/install/certresources.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ func (i *StrategyDeploymentInstaller) installCertRequirementsForDeployment(deplo
315315
logger.Warnf("could not update secret %s", secret.GetName())
316316
return nil, nil, err
317317
}
318-
319318
} else if k8serrors.IsNotFound(err) {
320319
// Create the secret
321320
ownerutil.AddNonBlockingOwner(secret, i.owner)

pkg/controller/install/certresources_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func selector(t *testing.T, selector string) *metav1.LabelSelector {
3737
return s
3838
}
3939

40-
var staticCerts *certs.KeyPair = nil
40+
var staticCerts *certs.KeyPair
4141

4242
// staticCertGenerator replaces the CertGenerator to get consistent keys for testing
4343
func staticCertGenerator(notAfter time.Time, organization string, ca *certs.KeyPair, hosts []string) (*certs.KeyPair, error) {
@@ -124,7 +124,6 @@ func TestInstallCertRequirementsForDeployment(t *testing.T) {
124124
assert.NoError(t, err)
125125
caHash := certs.PEMSHA256(caPEM)
126126
type fields struct {
127-
strategyClient wrappers.InstallStrategyDeploymentInterface
128127
owner ownerutil.Owner
129128
previousStrategy Strategy
130129
templateAnnotations map[string]string

0 commit comments

Comments
 (0)