Skip to content

Commit

Permalink
feat: add golangci-lint check
Browse files Browse the repository at this point in the history
Signed-off-by: Abirdcfly <[email protected]>
  • Loading branch information
Abirdcfly committed Nov 8, 2022
1 parent db38e85 commit bab013f
Show file tree
Hide file tree
Showing 119 changed files with 534 additions and 740 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: golangci-lint

on:
push:
branches:
- main
pull_request:
permissions:
contents: read
pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
34 changes: 34 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
run:
timeout: 30m
modules-download-mode: "mod"

linters:
disable-all: true
enable:
# linters maintained by golang.org
- gofmt
- goimports
- govet
# linters enabled by default
# - errcheck
# - ineffassign
- gosimple
# - govet
# - staticcheck
# - typecheck
# - unused
# custom
# please keep this alphabetized

issues:
max-same-issues: 0

linters-settings: # please keep this alphabetized
gosimple:
checks: [
"all",
"-S1034"
]

severity:
default-severity: error
11 changes: 3 additions & 8 deletions api/v1beta1/ibpca.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,8 @@ func (s *IBPCASpec) HSMSet() bool {
}

func (s *IBPCASpec) DomainSet() bool {
if s.Domain != "" {
return true
}

return false
return s.Domain != ""
}

func (s *IBPCASpec) CAResourcesSet() bool {
Expand Down Expand Up @@ -240,10 +237,8 @@ func (s *IBPCASpec) GetCAConfigOverride() (CAConfig, error) {
}

func (c *IBPCAStatus) HasType() bool {
if c.CRStatus.Type != "" {
return true
}
return false

return c.CRStatus.Type != ""
}

// Override will look at requested images and use those to override default image
Expand Down
12 changes: 5 additions & 7 deletions api/v1beta1/ibpconsole.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (v *Versions) Override(requestedVersions *Versions, registryURL string, arc

if len(requestedVersions.CA) != 0 {
CAVersions := map[string]VersionCA{}
for key, _ := range requestedVersions.CA {
for key := range requestedVersions.CA {
var caConfig VersionCA
requestedCAVersion := requestedVersions.CA[key]
caConfig.Image.Override(&requestedCAVersion.Image, registryURL, arch)
Expand All @@ -93,7 +93,7 @@ func (v *Versions) Override(requestedVersions *Versions, registryURL string, arc

if len(requestedVersions.Peer) != 0 {
PeerVersions := map[string]VersionPeer{}
for key, _ := range requestedVersions.Peer {
for key := range requestedVersions.Peer {
var peerConfig VersionPeer
requestedPeerVersion := requestedVersions.Peer[key]
peerConfig.Image.Override(&requestedPeerVersion.Image, registryURL, arch)
Expand All @@ -106,7 +106,7 @@ func (v *Versions) Override(requestedVersions *Versions, registryURL string, arc

if len(requestedVersions.Orderer) != 0 {
OrdererVersions := map[string]VersionOrderer{}
for key, _ := range requestedVersions.Orderer {
for key := range requestedVersions.Orderer {
var ordererConfig VersionOrderer
requestedOrdererVersion := requestedVersions.Orderer[key]
ordererConfig.Image.Override(&requestedOrdererVersion.Image, registryURL, arch)
Expand All @@ -123,8 +123,6 @@ func init() {
}

func (c *IBPConsoleStatus) HasType() bool {
if c.CRStatus.Type != "" {
return true
}
return false

return c.CRStatus.Type != ""
}
11 changes: 3 additions & 8 deletions api/v1beta1/ibporderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,8 @@ func (s *IBPOrdererSpec) HSMSet() bool {
}

func (s *IBPOrdererSpec) DomainSet() bool {
if s.Domain != "" {
return true
}

return false
return s.Domain != ""
}

func (s *IBPOrdererSpec) IsPrecreateOrderer() bool {
Expand Down Expand Up @@ -277,8 +274,6 @@ func init() {
}

func (o *IBPOrdererStatus) HasType() bool {
if o.CRStatus.Type != "" {
return true
}
return false

return o.CRStatus.Type != ""
}
21 changes: 5 additions & 16 deletions api/v1beta1/ibppeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,8 @@ func (s *IBPPeer) IsHSMEnabled() bool {
}

func (s *IBPPeer) UsingCouchDB() bool {
if strings.ToLower(s.Spec.StateDb) == "couchdb" {
return true
}

return false
return strings.ToLower(s.Spec.StateDb) == "couchdb"
}

func (s *IBPPeer) GetPullSecrets() []corev1.LocalObjectReference {
Expand Down Expand Up @@ -252,19 +249,13 @@ func (s *IBPPeerSpec) HSMSet() bool {
}

func (s *IBPPeerSpec) DomainSet() bool {
if s.Domain != "" {
return true
}

return false
return s.Domain != ""
}

func (s *IBPPeerSpec) UsingLevelDB() bool {
if strings.ToLower(s.StateDb) == "leveldb" {
return true
}

return false
return strings.ToLower(s.StateDb) == "leveldb"
}

func (s *IBPPeerSpec) GetNumSecondsWarningPeriod() int64 {
Expand All @@ -277,10 +268,8 @@ func (s *IBPPeerSpec) GetNumSecondsWarningPeriod() int64 {
}

func (p *IBPPeerStatus) HasType() bool {
if p.CRStatus.Type != "" {
return true
}
return false

return p.CRStatus.Type != ""
}

func (i *PeerImages) Override(requested *PeerImages, registryURL string, arch string) {
Expand Down
6 changes: 3 additions & 3 deletions controllers/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ type Client interface {
List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
}

// 1. Only one existing instance (of the same type as 'instance') should have
// the name 'instance.GetName()'; if more than one is present, return error
// 2. If any instance of a different type share the same name, return error
// 1. Only one existing instance (of the same type as 'instance') should have
// the name 'instance.GetName()'; if more than one is present, return error
// 2. If any instance of a different type share the same name, return error
func ValidateCRName(k8sclient Client, name, namespace, kind string) error {
listOptions := &client.ListOptions{
Namespace: namespace,
Expand Down
4 changes: 2 additions & 2 deletions controllers/ibpca/ibpca_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,11 +656,11 @@ func (r *ReconcileIBPCA) UpdateFunc(e event.UpdateEvent) bool {
}
}

if newCA.Spec.Action.Restart == true {
if newCA.Spec.Action.Restart {
update.restartNeeded = true
}

if newCA.Spec.Action.Renew.TLSCert == true {
if newCA.Spec.Action.Renew.TLSCert {
update.renewTLSCert = true
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/ibpconsole/ibpconsole_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func (r *ReconcileIBPConsole) UpdateFunc(e event.UpdateEvent) bool {
log.Info(fmt.Sprintf("Spec update detected on IBPConsole custom resource: %s", oldConsole.Name))
r.update.specUpdated = true

if newConsole.Spec.Action.Restart == true {
if newConsole.Spec.Action.Restart {
r.update.restartNeeded = true
}

Expand Down
8 changes: 4 additions & 4 deletions controllers/ibppeer/ibppeer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ func (r *ReconcileIBPPeer) UpdateFunc(e event.UpdateEvent) bool {

update.mspUpdated = commoncontroller.MSPInfoUpdateDetected(oldPeer.Spec.Secret, newPeer.Spec.Secret)

if newPeer.Spec.Action.Restart == true {
if newPeer.Spec.Action.Restart {
update.restartNeeded = true
}

Expand Down Expand Up @@ -683,15 +683,15 @@ func (r *ReconcileIBPPeer) UpdateFunc(e event.UpdateEvent) bool {
update.migrateToV24 = true
}

if newPeer.Spec.Action.UpgradeDBs == true {
if newPeer.Spec.Action.UpgradeDBs {
update.upgradedbs = true
}

if newPeer.Spec.Action.Enroll.Ecert == true {
if newPeer.Spec.Action.Enroll.Ecert {
update.ecertEnroll = true
}

if newPeer.Spec.Action.Enroll.TLSCert == true {
if newPeer.Spec.Action.Enroll.TLSCert {
update.tlscertEnroll = true
}

Expand Down
5 changes: 1 addition & 4 deletions integration/actions/ca/ca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,8 @@ var _ = Describe("trigger CA actions", func() {
}

newPodName := pods[0].Name
if newPodName != podName {
return true
}

return false
return newPodName != podName
}).Should(Equal(true))
})

Expand Down
6 changes: 3 additions & 3 deletions integration/actions/orderer/orderer_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func GetOrderer(tlsCert, caHost string) *helper.Orderer {
Expect(err).NotTo(HaveOccurred())

nodes := []helper.Orderer{
helper.Orderer{
{
Name: cr.Name + "node1",
Namespace: namespace,
CR: cr.DeepCopy(),
Expand All @@ -225,7 +225,7 @@ func GetOrderer(tlsCert, caHost string) *helper.Orderer {
Client: kclient,
},
},
helper.Orderer{
{
Name: cr.Name + "node2",
Namespace: namespace,
CR: cr.DeepCopy(),
Expand All @@ -236,7 +236,7 @@ func GetOrderer(tlsCert, caHost string) *helper.Orderer {
Client: kclient,
},
},
helper.Orderer{
{
Name: cr.Name + "node3",
Namespace: namespace,
CR: cr.DeepCopy(),
Expand Down
24 changes: 4 additions & 20 deletions integration/actions/orderer/orderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ var _ = Describe("trigger orderer actions", func() {
}

newPodName := pods[0].Name
if newPodName != podNameNode1 {
return true
}

return false
return newPodName != podNameNode1
}).Should(Equal(true))
})

Expand Down Expand Up @@ -141,11 +137,7 @@ var _ = Describe("trigger orderer actions", func() {
}

newPodName := pods[0].Name
if newPodName != podNameNode1 {
return true
}

return false
return newPodName != podNameNode1
}).Should(Equal(true))
})

Expand Down Expand Up @@ -339,11 +331,7 @@ var _ = Describe("trigger orderer actions", func() {
}

newPodName := pods[0].Name
if newPodName != podNameNode2 {
return true
}

return false
return newPodName != podNameNode2
}).Should(Equal(true))
})

Expand Down Expand Up @@ -476,11 +464,7 @@ var _ = Describe("trigger orderer actions", func() {
}

newPodName := pods[0].Name
if newPodName != podNameNode3 {
return true
}

return false
return newPodName != podNameNode3
}).Should(Equal(true))
})

Expand Down
Loading

0 comments on commit bab013f

Please sign in to comment.