diff --git a/.github/workflows/golangci.yaml b/.github/workflows/golangci.yaml new file mode 100644 index 00000000..2f6d1c30 --- /dev/null +++ b/.github/workflows/golangci.yaml @@ -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 diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 00000000..7a63027f --- /dev/null +++ b/.golangci.yaml @@ -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 diff --git a/api/v1beta1/ibpca.go b/api/v1beta1/ibpca.go index 9bddaf48..91f79e72 100644 --- a/api/v1beta1/ibpca.go +++ b/api/v1beta1/ibpca.go @@ -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 { @@ -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 diff --git a/api/v1beta1/ibpconsole.go b/api/v1beta1/ibpconsole.go index 52175b28..b35e3631 100644 --- a/api/v1beta1/ibpconsole.go +++ b/api/v1beta1/ibpconsole.go @@ -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) @@ -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) @@ -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) @@ -123,8 +123,6 @@ func init() { } func (c *IBPConsoleStatus) HasType() bool { - if c.CRStatus.Type != "" { - return true - } - return false + + return c.CRStatus.Type != "" } diff --git a/api/v1beta1/ibporderer.go b/api/v1beta1/ibporderer.go index b61e3efa..c12dec68 100644 --- a/api/v1beta1/ibporderer.go +++ b/api/v1beta1/ibporderer.go @@ -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 { @@ -277,8 +274,6 @@ func init() { } func (o *IBPOrdererStatus) HasType() bool { - if o.CRStatus.Type != "" { - return true - } - return false + + return o.CRStatus.Type != "" } diff --git a/api/v1beta1/ibppeer.go b/api/v1beta1/ibppeer.go index 6fe512de..03b5670a 100644 --- a/api/v1beta1/ibppeer.go +++ b/api/v1beta1/ibppeer.go @@ -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 { @@ -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 { @@ -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) { diff --git a/controllers/common/common.go b/controllers/common/common.go index e7b366d7..52e9b703 100644 --- a/controllers/common/common.go +++ b/controllers/common/common.go @@ -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, diff --git a/controllers/ibpca/ibpca_controller.go b/controllers/ibpca/ibpca_controller.go index 937c618e..890a858d 100644 --- a/controllers/ibpca/ibpca_controller.go +++ b/controllers/ibpca/ibpca_controller.go @@ -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 } diff --git a/controllers/ibpconsole/ibpconsole_controller.go b/controllers/ibpconsole/ibpconsole_controller.go index a2252c39..6be4ebfc 100644 --- a/controllers/ibpconsole/ibpconsole_controller.go +++ b/controllers/ibpconsole/ibpconsole_controller.go @@ -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 } diff --git a/controllers/ibppeer/ibppeer_controller.go b/controllers/ibppeer/ibppeer_controller.go index bb11c4af..32c392d3 100644 --- a/controllers/ibppeer/ibppeer_controller.go +++ b/controllers/ibppeer/ibppeer_controller.go @@ -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 } @@ -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 } diff --git a/integration/actions/ca/ca_test.go b/integration/actions/ca/ca_test.go index ae47a614..22e4403f 100644 --- a/integration/actions/ca/ca_test.go +++ b/integration/actions/ca/ca_test.go @@ -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)) }) diff --git a/integration/actions/orderer/orderer_suite_test.go b/integration/actions/orderer/orderer_suite_test.go index cad59b43..1980417f 100644 --- a/integration/actions/orderer/orderer_suite_test.go +++ b/integration/actions/orderer/orderer_suite_test.go @@ -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(), @@ -225,7 +225,7 @@ func GetOrderer(tlsCert, caHost string) *helper.Orderer { Client: kclient, }, }, - helper.Orderer{ + { Name: cr.Name + "node2", Namespace: namespace, CR: cr.DeepCopy(), @@ -236,7 +236,7 @@ func GetOrderer(tlsCert, caHost string) *helper.Orderer { Client: kclient, }, }, - helper.Orderer{ + { Name: cr.Name + "node3", Namespace: namespace, CR: cr.DeepCopy(), diff --git a/integration/actions/orderer/orderer_test.go b/integration/actions/orderer/orderer_test.go index 2990db1b..bd0136ee 100644 --- a/integration/actions/orderer/orderer_test.go +++ b/integration/actions/orderer/orderer_test.go @@ -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)) }) @@ -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)) }) @@ -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)) }) @@ -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)) }) diff --git a/integration/actions/peer/peer_test.go b/integration/actions/peer/peer_test.go index 444d75fe..5b53952d 100644 --- a/integration/actions/peer/peer_test.go +++ b/integration/actions/peer/peer_test.go @@ -78,11 +78,8 @@ var _ = Describe("trigger peer actions", func() { } newPodName := pods[0].Name - if newPodName != podName { - return true - } - return false + return newPodName != podName }).Should(Equal(true)) }) @@ -111,11 +108,8 @@ var _ = Describe("trigger peer actions", func() { } newPodName := pods[0].Name - if newPodName != podName { - return true - } - return false + return newPodName != podName }).Should(Equal(true)) }) @@ -232,11 +226,8 @@ var _ = Describe("trigger peer actions", func() { } newPodName := pods[0].Name - if newPodName != podName { - return true - } - return false + return newPodName != podName }).Should(Equal(true)) }) @@ -524,10 +515,8 @@ var _ = Describe("trigger peer actions", func() { _, err = kclient.BatchV1().Jobs(namespace). Get(context.TODO(), migrationJobName, metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) }) @@ -551,10 +540,8 @@ var _ = Describe("trigger peer actions", func() { Eventually(func() bool { _, err := kclient.BatchV1().Jobs(namespace). Get(context.TODO(), migrationJobName, metav1.GetOptions{}) - if err != nil { - return true - } - return false + + return err != nil }).Should(Equal(true)) }) diff --git a/integration/autorenew/autorenew_suite_test.go b/integration/autorenew/autorenew_suite_test.go index 6fdf88f5..71f9c0eb 100644 --- a/integration/autorenew/autorenew_suite_test.go +++ b/integration/autorenew/autorenew_suite_test.go @@ -296,7 +296,7 @@ func GetOrderer(tlsCert, caHost string) *helper.Orderer { cr.Spec.NumSecondsWarningPeriod = 31535970 nodes := []helper.Orderer{ - helper.Orderer{ + { Name: cr.Name + "node1", Namespace: namespace, CR: cr.DeepCopy(), diff --git a/integration/ca/ca_test.go b/integration/ca/ca_test.go index 0e6f86b6..abaccffa 100644 --- a/integration/ca/ca_test.go +++ b/integration/ca/ca_test.go @@ -111,10 +111,8 @@ var _ = Describe("Interaction between IBP-Operator and Kubernetes cluster", func By("creating config map that contains spec", func() { Eventually(func() bool { _, err := kclient.CoreV1().ConfigMaps(namespace).Get(context.TODO(), ca.Name+"-spec", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) }) @@ -436,11 +434,8 @@ var _ = Describe("Interaction between IBP-Operator and Kubernetes cluster", func } newPodName := pods[0].Name - if newPodName == oldPodName { - return true - } - return false + return newPodName == oldPodName }).Should(Equal(true)) }) }) @@ -490,11 +485,8 @@ var _ = Describe("Interaction between IBP-Operator and Kubernetes cluster", func } newPodName := pods[0].Name - if newPodName == oldPodName { - return false - } - return true + return newPodName != oldPodName }).Should(Equal(true)) }) }) @@ -688,7 +680,7 @@ func GetCA3() *CA { caJson, err := util.ConvertToJsonMessage(caOverrides) Expect(err).NotTo(HaveOccurred()) - var replicas int32 + var replicas int32 //nolint:gosimple replicas = 3 name := "ibpca3" cr := ¤t.IBPCA{ diff --git a/integration/console/console_test.go b/integration/console/console_test.go index 3c137f04..a0dca052 100644 --- a/integration/console/console_test.go +++ b/integration/console/console_test.go @@ -484,7 +484,7 @@ func GetConsole() *Console { }, Versions: ¤t.Versions{ CA: map[string]current.VersionCA{ - integration.FabricCAVersion: current.VersionCA{ + integration.FabricCAVersion: { Default: true, Version: integration.FabricCAVersion, Image: current.CAImages{ @@ -496,7 +496,7 @@ func GetConsole() *Console { }, }, Peer: map[string]current.VersionPeer{ - integration.FabricVersion: current.VersionPeer{ + integration.FabricVersion: { Default: true, Version: integration.FabricVersion, Image: current.PeerImages{ @@ -512,7 +512,7 @@ func GetConsole() *Console { }, }, Orderer: map[string]current.VersionOrderer{ - integration.FabricVersion: current.VersionOrderer{ + integration.FabricVersion: { Default: true, Version: integration.FabricVersion, Image: current.OrdererImages{ @@ -579,7 +579,7 @@ func GetConsole2() *Console { }, Versions: ¤t.Versions{ CA: map[string]current.VersionCA{ - integration.FabricCAVersion: current.VersionCA{ + integration.FabricCAVersion: { Default: true, Version: integration.FabricCAVersion, Image: current.CAImages{ @@ -591,7 +591,7 @@ func GetConsole2() *Console { }, }, Peer: map[string]current.VersionPeer{ - integration.FabricVersion: current.VersionPeer{ + integration.FabricVersion: { Default: true, Version: integration.FabricVersion, Image: current.PeerImages{ @@ -607,7 +607,7 @@ func GetConsole2() *Console { }, }, Orderer: map[string]current.VersionOrderer{ - integration.FabricVersion: current.VersionOrderer{ + integration.FabricVersion: { Default: true, Version: integration.FabricVersion, Image: current.OrdererImages{ diff --git a/integration/e2ev2/console_test.go b/integration/e2ev2/console_test.go index 72af43ca..20f6bf6a 100644 --- a/integration/e2ev2/console_test.go +++ b/integration/e2ev2/console_test.go @@ -91,11 +91,8 @@ var _ = Describe("console", func() { } newPodName := pods[0].Name - if newPodName != podName { - return true - } - return false + return newPodName != podName }).Should(Equal(true)) }) @@ -166,7 +163,7 @@ func GetConsole() *Console { }, Versions: ¤t.Versions{ CA: map[string]current.VersionCA{ - integration.FabricCAVersion: current.VersionCA{ + integration.FabricCAVersion: { Default: true, Version: integration.FabricCAVersion, Image: current.CAImages{ @@ -178,7 +175,7 @@ func GetConsole() *Console { }, }, Peer: map[string]current.VersionPeer{ - integration.FabricVersion: current.VersionPeer{ + integration.FabricVersion: { Default: true, Version: integration.FabricVersion, Image: current.PeerImages{ @@ -194,7 +191,7 @@ func GetConsole() *Console { }, }, Orderer: map[string]current.VersionOrderer{ - integration.FabricVersion: current.VersionOrderer{ + integration.FabricVersion: { Default: true, Version: integration.FabricVersion, Image: current.OrdererImages{ diff --git a/integration/e2ev2/orderer_test.go b/integration/e2ev2/orderer_test.go index 8dad45cf..72f4147b 100644 --- a/integration/e2ev2/orderer_test.go +++ b/integration/e2ev2/orderer_test.go @@ -147,11 +147,8 @@ var _ = Describe("orderer", func() { } newPodName := pods[0].Name - if newPodName != podName { - return true - } - return false + return newPodName != podName }).Should(Equal(true)) }) }) @@ -203,11 +200,8 @@ var _ = Describe("orderer", func() { } newPodName := pods[0].Name - if newPodName == podName { - return false - } - return true + return newPodName != podName }).Should(Equal(true)) Eventually(node1.PodIsRunning).Should((Equal(true))) @@ -288,10 +282,8 @@ var _ = Describe("orderer", func() { _, err := kclient.CoreV1(). Secrets(namespace). Get(context.TODO(), fmt.Sprintf("ecert-%s-admincerts", node1.Name), metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) }) @@ -336,11 +328,8 @@ var _ = Describe("orderer", func() { } newPodName := pods[0].Name - if newPodName != podName { - return true - } - return false + return newPodName != podName }).Should(Equal(true)) }) }) @@ -352,7 +341,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(), diff --git a/integration/e2ev2/peer_test.go b/integration/e2ev2/peer_test.go index 1f4bde2b..218be894 100644 --- a/integration/e2ev2/peer_test.go +++ b/integration/e2ev2/peer_test.go @@ -193,11 +193,8 @@ var _ = Describe("peer", func() { } newPodName := pods[0].Name - if newPodName != podName { - return true - } - return false + return newPodName != podName }).Should(Equal(true)) }) }) diff --git a/integration/helper/ca.go b/integration/helper/ca.go index 94b8c146..e105fde6 100644 --- a/integration/helper/ca.go +++ b/integration/helper/ca.go @@ -90,11 +90,8 @@ func (ca *CA) HealthCheck(url string, cert []byte) bool { } _, err := client.Get(url) - if err != nil { - return false - } - return true + return err == nil } func (ca *CA) ConnectionProfile() (*current.CAConnectionProfile, error) { diff --git a/integration/helper/crspecs.go b/integration/helper/crspecs.go index cf8a3b72..cf28649d 100644 --- a/integration/helper/crspecs.go +++ b/integration/helper/crspecs.go @@ -276,13 +276,13 @@ func OrdererCR(namespace, domain, ordererUsername, tlsCert, caHost string) (*cur OrdererInitTag: integration.InitTag, }, ClusterSecret: []*current.SecretSpec{ - ¤t.SecretSpec{ + { Enrollment: enrollment, }, - ¤t.SecretSpec{ + { Enrollment: enrollment, }, - ¤t.SecretSpec{ + { Enrollment: enrollment, }, }, diff --git a/integration/init/init_test.go b/integration/init/init_test.go index b1f22a87..c431c542 100644 --- a/integration/init/init_test.go +++ b/integration/init/init_test.go @@ -131,11 +131,11 @@ func SetupServer(homeDir string, parentURL string, port int, tlsConfig *tls.Serv "org2dept1": nil, } profiles := map[string]*cfconfig.SigningProfile{ - "tls": &cfconfig.SigningProfile{ + "tls": { Usage: []string{"signing", "key encipherment", "server auth", "client auth", "key agreement"}, ExpiryString: "8760h", }, - "ca": &cfconfig.SigningProfile{ + "ca": { Usage: []string{"cert sign", "crl sign"}, ExpiryString: "8760h", CAConstraint: cfconfig.CAConstraint{ diff --git a/integration/migration/fabric/orderer_test.go b/integration/migration/fabric/orderer_test.go index 342a3f07..2841a268 100644 --- a/integration/migration/fabric/orderer_test.go +++ b/integration/migration/fabric/orderer_test.go @@ -155,7 +155,7 @@ func GetOrderer() *helper.Orderer { OrdererInitTag: integration.InitTag, }, ClusterSecret: []*current.SecretSpec{ - ¤t.SecretSpec{ + { Enrollment: enrollment, }, }, @@ -164,7 +164,7 @@ func GetOrderer() *helper.Orderer { } nodes := []helper.Orderer{ - helper.Orderer{ + { Name: cr.Name + "node1", Namespace: namespace, CR: cr.DeepCopy(), diff --git a/integration/migration/fabric/peer_test.go b/integration/migration/fabric/peer_test.go index 11f8e62e..14913901 100644 --- a/integration/migration/fabric/peer_test.go +++ b/integration/migration/fabric/peer_test.go @@ -99,10 +99,8 @@ var _ = Describe("Fabric peer migration", func() { _, err = kclient.BatchV1().Jobs(namespace). Get(context.TODO(), dbmigrationJobName, metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) }) diff --git a/integration/migration/migration_test.go b/integration/migration/migration_test.go index e57d8974..9d5e931b 100644 --- a/integration/migration/migration_test.go +++ b/integration/migration/migration_test.go @@ -149,12 +149,12 @@ var _ = PDescribe("migrating", func() { Spec: corev1.ServiceSpec{ Type: corev1.ServiceTypeNodePort, Ports: []corev1.ServicePort{ - corev1.ServicePort{ + { Name: "http", Port: int32(7054), NodePort: httpNodePort, }, - corev1.ServicePort{ + { Name: "operations", Port: int32(9443), NodePort: operationNodePort, @@ -170,11 +170,11 @@ var _ = PDescribe("migrating", func() { ingress := &networkingv1.Ingress{ Spec: networkingv1.IngressSpec{ Rules: []networkingv1.IngressRule{ - networkingv1.IngressRule{ + { IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: "camigration-service", @@ -246,10 +246,8 @@ var _ = PDescribe("migrating", func() { Eventually(func() bool { secret, err = kclient.CoreV1().Secrets(namespace).Get(context.TODO(), "camigration-oldstate", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) Expect(secret.Data["camigration-service"]).NotTo(Equal("")) @@ -265,10 +263,8 @@ var _ = PDescribe("migrating", func() { Eventually(func() bool { service, err = kclient.CoreV1().Services(namespace).Get(context.TODO(), "camigration", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) Expect(service.Spec.Ports[0].NodePort).To(Equal(httpNodePort)) @@ -284,10 +280,8 @@ var _ = PDescribe("migrating", func() { Eventually(func() bool { ingress, err = kclient.NetworkingV1().Ingresses(namespace).Get(context.TODO(), "camigration", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) Expect(ingress.Spec.Rules[0].HTTP.Paths[0].Backend.Service.Name).To(Equal("camigration")) @@ -353,12 +347,12 @@ var _ = PDescribe("migrating", func() { Spec: corev1.ServiceSpec{ Type: corev1.ServiceTypeNodePort, Ports: []corev1.ServicePort{ - corev1.ServicePort{ + { Name: "http", Port: int32(7054), NodePort: httpNodePort, }, - corev1.ServicePort{ + { Name: "operations", Port: int32(9443), NodePort: operationNodePort, @@ -374,11 +368,11 @@ var _ = PDescribe("migrating", func() { ingress := &networkingv1.Ingress{ Spec: networkingv1.IngressSpec{ Rules: []networkingv1.IngressRule{ - networkingv1.IngressRule{ + { IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: "consolemigration-service", @@ -459,10 +453,8 @@ var _ = PDescribe("migrating", func() { Eventually(func() bool { _, err := kclient.CoreV1().Services(namespace).Get(context.TODO(), "consolemigration-service", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(false)) By("creating a secret with state of current resources before migration", func() { @@ -471,10 +463,8 @@ var _ = PDescribe("migrating", func() { Eventually(func() bool { secret, err = kclient.CoreV1().Secrets(namespace).Get(context.TODO(), "consolemigration-oldstate", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) Expect(secret.Data["consolemigration-service"]).NotTo(Equal("")) @@ -490,10 +480,8 @@ var _ = PDescribe("migrating", func() { Eventually(func() bool { service, err = kclient.CoreV1().Services(namespace).Get(context.TODO(), "consolemigration", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) Expect(service.Spec.Ports[0].NodePort).To(Equal(httpNodePort)) @@ -506,10 +494,8 @@ var _ = PDescribe("migrating", func() { Eventually(func() bool { ingress, err = kclient.NetworkingV1().Ingresses(namespace).Get(context.TODO(), "consolemigration", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) Expect(ingress.Spec.Rules[0].HTTP.Paths[0].Backend.Service.Name).To(Equal("consolemigration")) @@ -588,22 +574,22 @@ var _ = PDescribe("migrating", func() { Spec: corev1.ServiceSpec{ Type: corev1.ServiceTypeNodePort, Ports: []corev1.ServicePort{ - corev1.ServicePort{ + { Name: "peer-api", Port: int32(7051), NodePort: peerApiNodePort, }, - corev1.ServicePort{ + { Name: "operations", Port: int32(9443), NodePort: operationNodePort, }, - corev1.ServicePort{ + { Name: "grpcweb-debug", Port: int32(8080), NodePort: grpcwebDebugNodePort, }, - corev1.ServicePort{ + { Name: "grpcweb", Port: int32(7443), NodePort: grpcwebNodePort, @@ -619,11 +605,11 @@ var _ = PDescribe("migrating", func() { ingress := &networkingv1.Ingress{ Spec: networkingv1.IngressSpec{ Rules: []networkingv1.IngressRule{ - networkingv1.IngressRule{ + { IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: "peermigration-service", @@ -675,10 +661,8 @@ var _ = PDescribe("migrating", func() { secret := &corev1.Secret{} err := client.Get(context.TODO(), namespacedName, secret) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) mspSecret = &initsecret.Secret{} @@ -696,10 +680,8 @@ var _ = PDescribe("migrating", func() { Eventually(func() bool { secret, err = kclient.CoreV1().Secrets(namespace).Get(context.TODO(), "peermigration-oldstate", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) Expect(secret.Data["peermigration-service"]).NotTo(Equal("")) @@ -709,70 +691,56 @@ var _ = PDescribe("migrating", func() { By("creating ecert ca certs secret", func() { Eventually(func() bool { _, err := kclient.CoreV1().Secrets(namespace).Get(context.TODO(), "ecert-peermigration-cacerts", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) }) By("creating ecert keystore secret", func() { Eventually(func() bool { _, err := kclient.CoreV1().Secrets(namespace).Get(context.TODO(), "ecert-peermigration-keystore", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) }) By("creating ecert signcert secret", func() { Eventually(func() bool { _, err := kclient.CoreV1().Secrets(namespace).Get(context.TODO(), "ecert-peermigration-signcert", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) }) By("creating ecert admin cert secret", func() { Eventually(func() bool { _, err := kclient.CoreV1().Secrets(namespace).Get(context.TODO(), "ecert-peermigration-admincerts", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) }) By("creating tls ca certs secret", func() { Eventually(func() bool { _, err := kclient.CoreV1().Secrets(namespace).Get(context.TODO(), "tls-peermigration-cacerts", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) }) By("creating tls keystore certs secret", func() { Eventually(func() bool { _, err := kclient.CoreV1().Secrets(namespace).Get(context.TODO(), "tls-peermigration-keystore", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) }) By("creating tls signcert secret", func() { Eventually(func() bool { _, err := kclient.CoreV1().Secrets(namespace).Get(context.TODO(), "tls-peermigration-signcert", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) }) @@ -782,10 +750,8 @@ var _ = PDescribe("migrating", func() { Eventually(func() bool { service, err = kclient.CoreV1().Services(namespace).Get(context.TODO(), "peermigration", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) Expect(service.Spec.Ports[0].NodePort).To(Equal(peerApiNodePort)) @@ -803,10 +769,8 @@ var _ = PDescribe("migrating", func() { Eventually(func() bool { ingress, err = kclient.NetworkingV1().Ingresses(namespace).Get(context.TODO(), "peermigration", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) Expect(ingress.Spec.Rules[0].HTTP.Paths[0].Backend.Service.Name).To(Equal("peermigration")) @@ -888,10 +852,8 @@ var _ = PDescribe("migrating", func() { secret := &corev1.Secret{} err := client.Get(context.TODO(), namespacedName, secret) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) mspSecret = &initsecret.Secret{} @@ -908,11 +870,11 @@ var _ = PDescribe("migrating", func() { ingress := &networkingv1.Ingress{ Spec: networkingv1.IngressSpec{ Rules: []networkingv1.IngressRule{ - networkingv1.IngressRule{ + { IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: "camigration-service", @@ -957,10 +919,8 @@ var _ = PDescribe("migrating", func() { Eventually(func() bool { _, err := kclient.CoreV1().ConfigMaps(namespace).Get(context.TODO(), "orderer-migrationnode1-config", metav1.GetOptions{}) - if err != nil { - return true - } - return false + + return err != nil }).Should(Equal(true)) }) }) @@ -974,7 +934,7 @@ func CreateServiceWithRetry(service *corev1.Service, retryNumber int) (int32, in } if strings.Contains(err.Error(), "provided port is already allocated") { fmt.Fprintf(GinkgoWriter, "encountered port error: %s, trying again\n", err) - for i, _ := range service.Spec.Ports { + for i := range service.Spec.Ports { service.Spec.Ports[i].NodePort = RandomNodePort() } CreateServiceWithRetry(service, retryNumber-1) @@ -992,7 +952,7 @@ func CreatePeerServiceWithRetry(service *corev1.Service, retryNumber int) (int32 } if strings.Contains(err.Error(), "provided port is already allocated") { fmt.Fprintf(GinkgoWriter, "encountered port error: %s, trying again\n", err) - for i, _ := range service.Spec.Ports { + for i := range service.Spec.Ports { service.Spec.Ports[i].NodePort = RandomNodePort() } CreatePeerServiceWithRetry(service, retryNumber-1) diff --git a/integration/operatorrestart/operatorrestart_suite_test.go b/integration/operatorrestart/operatorrestart_suite_test.go index 2aa5adcd..2a6e537a 100644 --- a/integration/operatorrestart/operatorrestart_suite_test.go +++ b/integration/operatorrestart/operatorrestart_suite_test.go @@ -340,7 +340,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(), diff --git a/integration/orderer/orderer_test.go b/integration/orderer/orderer_test.go index b5f0b811..ed7934b0 100644 --- a/integration/orderer/orderer_test.go +++ b/integration/orderer/orderer_test.go @@ -188,10 +188,8 @@ var _ = Describe("Interaction between IBP-Operator and Kubernetes cluster", func for _, node := range orderer1nodes { Eventually(func() bool { _, err := kclient.CoreV1().ConfigMaps(namespace).Get(context.TODO(), node.Name+"-spec", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) } }) @@ -364,11 +362,7 @@ var _ = Describe("Interaction between IBP-Operator and Kubernetes cluster", func ordererConfig, err := config.ReadOrdererFromBytes(configBytes) Expect(err).NotTo(HaveOccurred()) - if ordererConfig.FileLedger.Location == "/temp" { - return true - } - - return false + return ordererConfig.FileLedger.Location == "/temp" }).Should(Equal(true)) }) } @@ -499,10 +493,8 @@ var _ = Describe("Interaction between IBP-Operator and Kubernetes cluster", func for _, node := range orderer5nodes { Eventually(func() bool { _, err := kclient.CoreV1().ConfigMaps(namespace).Get(context.TODO(), node.Name+"-spec", metav1.GetOptions{}) - if err != nil { - return false - } - return true + + return err == nil }).Should(Equal(true)) } }) @@ -819,11 +811,8 @@ var _ = Describe("Interaction between IBP-Operator and Kubernetes cluster", func } newPodName := pods[0].Name - if newPodName == oldPodName { - return true - } - return false + return newPodName == oldPodName }).Should(Equal(true)) }) }) @@ -868,11 +857,8 @@ var _ = Describe("Interaction between IBP-Operator and Kubernetes cluster", func } newPodName := pods[0].Name - if newPodName == oldPodName { - return false - } - return true + return newPodName != oldPodName }).Should(Equal(true)) }) }) @@ -925,7 +911,7 @@ func GetOrderer() (*Orderer, []Orderer) { OrdererInitTag: integration.InitTag, }, ClusterSecret: []*current.SecretSpec{ - ¤t.SecretSpec{ + { MSP: testMSPSpec, }, }, @@ -947,7 +933,7 @@ func GetOrderer() (*Orderer, []Orderer) { cr.Name = name nodes := []Orderer{ - Orderer{ + { Name: name + "node1", CR: cr.DeepCopy(), NodeName: fmt.Sprintf("%s%s%d", name, baseorderer.NODE, 1), @@ -1001,13 +987,13 @@ func GetOrderer2() (*Orderer, []Orderer) { OrdererInitTag: integration.InitTag, }, ClusterSecret: []*current.SecretSpec{ - ¤t.SecretSpec{ + { MSP: testMSPSpec, }, - ¤t.SecretSpec{ + { MSP: testMSPSpec, }, - ¤t.SecretSpec{ + { MSP: testMSPSpec, }, }, @@ -1030,7 +1016,7 @@ func GetOrderer2() (*Orderer, []Orderer) { cr.Name = name nodes := []Orderer{ - Orderer{ + { Name: name + "node1", CR: cr.DeepCopy(), NodeName: fmt.Sprintf("%s%s%d", name, baseorderer.NODE, 1), @@ -1040,7 +1026,7 @@ func GetOrderer2() (*Orderer, []Orderer) { Client: kclient, }, }, - Orderer{ + { Name: name + "node2", CR: cr.DeepCopy(), NodeName: fmt.Sprintf("%s%s%d", name, baseorderer.NODE, 1), @@ -1050,7 +1036,7 @@ func GetOrderer2() (*Orderer, []Orderer) { Client: kclient, }, }, - Orderer{ + { Name: name + "node3", CR: cr.DeepCopy(), NodeName: fmt.Sprintf("%s%s%d", name, baseorderer.NODE, 1), @@ -1109,11 +1095,11 @@ func GetOrderer3() (*Orderer, []Orderer) { MSP: testMSPSpec, }, ClusterLocation: []current.IBPOrdererClusterLocation{ - current.IBPOrdererClusterLocation{ + { Zone: "dal1", Region: "us-south1", }, - current.IBPOrdererClusterLocation{ + { Zone: "dal2", Region: "us-south2", }, @@ -1125,7 +1111,7 @@ func GetOrderer3() (*Orderer, []Orderer) { cr.Name = name nodes := []Orderer{ - Orderer{ + { Name: name + "node1", CR: cr.DeepCopy(), NodeName: fmt.Sprintf("%s%s%d", name, baseorderer.NODE, 1), @@ -1179,13 +1165,13 @@ func GetOrderer4() (*Orderer, []Orderer) { OrdererInitTag: integration.InitTag, }, ClusterSecret: []*current.SecretSpec{ - ¤t.SecretSpec{ + { MSP: testMSPSpec, }, - ¤t.SecretSpec{ + { MSP: testMSPSpec, }, - ¤t.SecretSpec{ + { MSP: testMSPSpec, }, }, @@ -1208,7 +1194,7 @@ func GetOrderer4() (*Orderer, []Orderer) { cr.Name = name nodes := []Orderer{ - Orderer{ + { Name: name + "node1", CR: cr.DeepCopy(), NodeName: fmt.Sprintf("%s%s%d", name, baseorderer.NODE, 1), @@ -1218,7 +1204,7 @@ func GetOrderer4() (*Orderer, []Orderer) { Client: kclient, }, }, - Orderer{ + { Name: name + "node2", CR: cr.DeepCopy(), NodeName: fmt.Sprintf("%s%s%d", name, baseorderer.NODE, 1), @@ -1228,7 +1214,7 @@ func GetOrderer4() (*Orderer, []Orderer) { Client: kclient, }, }, - Orderer{ + { Name: name + "node3", CR: cr.DeepCopy(), NodeName: fmt.Sprintf("%s%s%d", name, baseorderer.NODE, 1), @@ -1284,7 +1270,7 @@ func GetOrderer5() (*Orderer, []Orderer) { OrdererInitTag: integration.InitTag, }, ClusterSecret: []*current.SecretSpec{ - ¤t.SecretSpec{ + { MSP: testMSPSpec, }, }, @@ -1305,7 +1291,7 @@ func GetOrderer5() (*Orderer, []Orderer) { cr.Name = name nodes := []Orderer{ - Orderer{ + { Name: name + "node1", CR: cr.DeepCopy(), NodeName: fmt.Sprintf("%s%s%d", name, baseorderer.NODE, 1), @@ -1388,11 +1374,8 @@ func (orderer *Orderer) allInitSecretsExist() bool { name = prefix + "-keystore" _, err = kclient.CoreV1().Secrets(namespace).Get(context.TODO(), name, metav1.GetOptions{}) - if err != nil { - return false - } - return true + return err == nil } func (o *Orderer) DeploymentExists() bool { diff --git a/integration/peer/peer_test.go b/integration/peer/peer_test.go index 48ae1d55..c150b114 100644 --- a/integration/peer/peer_test.go +++ b/integration/peer/peer_test.go @@ -205,10 +205,7 @@ var _ = Describe("Interaction between IBP-Operator and Kubernetes cluster", func By("creating config map that contains spec", func() { Eventually(func() bool { _, err := kclient.CoreV1().ConfigMaps(namespace).Get(context.TODO(), peer.Name+"-spec", metav1.GetOptions{}) - if err != nil { - return false - } - return true + return err == nil }).Should(Equal(true)) }) @@ -614,11 +611,7 @@ var _ = Describe("Interaction between IBP-Operator and Kubernetes cluster", func } newPodName := pods[0].Name - if newPodName == oldPodName { - return true - } - - return false + return newPodName == oldPodName }).Should(Equal(true)) }) }) @@ -661,11 +654,7 @@ var _ = Describe("Interaction between IBP-Operator and Kubernetes cluster", func } newPodName := pods[0].Name - if newPodName == oldPodName { - return false - } - - return true + return newPodName == oldPodName }).Should(Equal(true)) }) }) @@ -718,10 +707,10 @@ func GetPeer1() *Peer { ID: "testPeerID", DeliveryClient: v1.DeliveryClient{ AddressOverrides: []v1.AddressOverride{ - v1.AddressOverride{ + { CACertsFile: caCert, }, - v1.AddressOverride{ + { CACertsFile: signCert, }, }, diff --git a/integration/restartmgr/restartmgr_suite_test.go b/integration/restartmgr/restartmgr_suite_test.go index 28fa1f91..4b66cd7b 100644 --- a/integration/restartmgr/restartmgr_suite_test.go +++ b/integration/restartmgr/restartmgr_suite_test.go @@ -290,7 +290,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(), diff --git a/integration/restartmgr/restartmgr_test.go b/integration/restartmgr/restartmgr_test.go index 75e06f51..104660fa 100644 --- a/integration/restartmgr/restartmgr_test.go +++ b/integration/restartmgr/restartmgr_test.go @@ -100,11 +100,7 @@ var _ = Describe("restart manager", func() { } newPodName := pods[0].Name - if newPodName == podName { - return false - } - - return true + return newPodName != podName }).Should(Equal(true)) }) @@ -155,11 +151,7 @@ var _ = Describe("restart manager", func() { } newPodName := pods[0].Name - if newPodName == podName { - return true - } - - return false + return newPodName == podName }).Should(Equal(true)) }) @@ -194,10 +186,7 @@ var _ = Describe("restart manager", func() { Eventually(func() bool { _, err := kclient.CoreV1().ConfigMaps(namespace).Get(context.TODO(), "operator-config", metav1.GetOptions{}) - if err != nil { - return false - } - return true + return err == nil }).Should(Equal(true)) }) @@ -226,11 +215,7 @@ var _ = Describe("restart manager", func() { } newPodName := pods[0].Name - if newPodName == podName { - return true - } - - return false + return newPodName == podName }, 5*time.Second).Should(Equal(true)) }) @@ -313,10 +298,7 @@ var _ = Describe("restart manager", func() { Eventually(func() bool { _, err := kclient.CoreV1().ConfigMaps(namespace).Get(context.TODO(), "operator-config", metav1.GetOptions{}) - if err != nil { - return false - } - return true + return err == nil }).Should(Equal(true)) }) @@ -340,11 +322,7 @@ var _ = Describe("restart manager", func() { } newPodName := pods[0].Name - if newPodName == podName { - return true - } - - return false + return newPodName == podName }).Should(Equal(true)) }) @@ -435,10 +413,7 @@ var _ = Describe("restart manager", func() { Eventually(func() bool { _, err := kclient.CoreV1().ConfigMaps(namespace).Get(context.TODO(), "operator-config", metav1.GetOptions{}) - if err != nil { - return false - } - return true + return err == nil }).Should(Equal(true)) }) @@ -470,11 +445,7 @@ var _ = Describe("restart manager", func() { } newPodName := pods[0].Name - if newPodName == podName { - return true - } - - return false + return newPodName == podName }).Should(Equal(true)) }) diff --git a/operatorconfig/operator.go b/operatorconfig/operator.go index 2b848d25..601f1be2 100644 --- a/operatorconfig/operator.go +++ b/operatorconfig/operator.go @@ -59,7 +59,7 @@ func LoadFromConfigMap(nn k8sclient.ObjectKey, key string, client Client, operat func load(config []byte, operator *Operator) error { // If no config bytes passed, we can assume that a config file (config map) for operator // does not exist and we can skip the unmarshal step. - if config != nil && len(config) > 0 { + if len(config) > 0 { if err := yaml.Unmarshal(config, operator); err != nil { return err } diff --git a/pkg/apis/deployer/deployer.go b/pkg/apis/deployer/deployer.go index 1b4eb7e1..9e17c94c 100644 --- a/pkg/apis/deployer/deployer.go +++ b/pkg/apis/deployer/deployer.go @@ -401,7 +401,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) @@ -414,7 +414,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) @@ -427,7 +427,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) diff --git a/pkg/certificate/certificate.go b/pkg/certificate/certificate.go index 34c0bc98..06950f12 100644 --- a/pkg/certificate/certificate.go +++ b/pkg/certificate/certificate.go @@ -92,7 +92,7 @@ func (c *CertificateManager) GetDurationToNextRenewalForCert(certName string, ce } renewDate := expireDate.Add(-time.Duration(numSecondsBeforeExpire) * time.Second) // Subtract num seconds from expire date - duration := renewDate.Sub(time.Now()) // Get duration between now and the renew date (negative duration means renew date < time.Now()) + duration := time.Until(renewDate) // Get duration between now and the renew date (negative duration means renew date < time.Now()) if duration < 0 { return time.Duration(0), nil } @@ -116,7 +116,7 @@ func (c *CertificateManager) Expires(cert []byte, numSecondsBeforeExpire int64) } // Checks if the duration between time.Now() and the expiration date is less than or equal to the numSecondsBeforeExpire - if expireDate.Sub(time.Now()) <= time.Duration(numSecondsBeforeExpire)*time.Second { + if time.Until(expireDate) <= time.Duration(numSecondsBeforeExpire)*time.Second { return true, expireDate, nil } @@ -245,7 +245,7 @@ func (c *CertificateManager) RenewCert(certType common.SecretType, instance Inst var certReenroller Reenroller if certType == common.ECERT && hsmEnabled && !instance.UsingHSMProxy() { - log.Info(fmt.Sprintf("Certificate manager renewing ecert, non-proxy HSM enabled")) + log.Info("Certificate manager renewing ecert, non-proxy HSM enabled") hsmConfig, err := config.ReadHSMConfig(c.Client, instance) if err != nil { return err @@ -312,7 +312,7 @@ func (c *CertificateManager) RenewCert(certType common.SecretType, instance Inst func (c *CertificateManager) UpdateSignCert(name string, cert []byte, instance v1.Object) error { // Cert might not be returned from reenroll call, for example if the reenroll happens in a job which handles // updating the secret when using HSM (non-proxy) - if cert == nil || len(cert) == 0 { + if len(cert) == 0 { return nil } @@ -332,7 +332,7 @@ func (c *CertificateManager) UpdateKey(name string, key []byte, instance v1.Obje // Need to ensure the value passed in for key is valid before updating. // Otherwise, an empty key will end up in the secret overriding a valid key, which // will cause runtime errors on nodes - if key == nil || len(key) == 0 { + if len(key) == 0 { return nil } diff --git a/pkg/certificate/reenroller/hsmdaemonreenroller.go b/pkg/certificate/reenroller/hsmdaemonreenroller.go index 8718ce74..dd602b62 100644 --- a/pkg/certificate/reenroller/hsmdaemonreenroller.go +++ b/pkg/certificate/reenroller/hsmdaemonreenroller.go @@ -258,7 +258,7 @@ func (r *HSMDaemonReenroller) initHSMJob(instance Instance, hsmConfig *config.HS ImagePullSecrets: util.AppendImagePullSecretIfMissing(instance.GetPullSecrets(), hsmConfig.BuildPullSecret()), RestartPolicy: corev1.RestartPolicyNever, InitContainers: []corev1.Container{ - corev1.Container{ + { Name: HSMClient, Image: hsmConfig.Library.Image, ImagePullPolicy: corev1.PullAlways, @@ -272,7 +272,7 @@ func (r *HSMDaemonReenroller) initHSMJob(instance Instance, hsmConfig *config.HS RunAsNonRoot: &f, }, VolumeMounts: []corev1.VolumeMount{ - corev1.VolumeMount{ + { Name: "shared", MountPath: mountPath, }, @@ -292,7 +292,7 @@ func (r *HSMDaemonReenroller) initHSMJob(instance Instance, hsmConfig *config.HS }, }, Containers: []corev1.Container{ - corev1.Container{ + { Name: CertGen, Image: instance.EnrollerImage(), ImagePullPolicy: corev1.PullAlways, @@ -310,22 +310,22 @@ func (r *HSMDaemonReenroller) initHSMJob(instance Instance, hsmConfig *config.HS fmt.Sprintf(config.DAEMON_CHECK_CMD+" && /usr/local/bin/enroller node reenroll %s %s %s %s %s %s %s %s %s %t", r.HomeDir, "/tmp/fabric-ca-client-config.yaml", r.Config.CAHost, r.Config.CAPort, r.Config.CAName, instance.GetName(), instance.GetNamespace(), r.Config.EnrollID, fmt.Sprintf("%s/cert.pem", r.HomeDir), r.NewKey), }, VolumeMounts: []corev1.VolumeMount{ - corev1.VolumeMount{ + { Name: "tlscertfile", MountPath: fmt.Sprintf("%s/tlsCert.pem", r.HomeDir), SubPath: "tlsCert.pem", }, - corev1.VolumeMount{ + { Name: "certfile", MountPath: fmt.Sprintf("%s/cert.pem", r.HomeDir), SubPath: "cert.pem", }, - corev1.VolumeMount{ + { Name: "clientconfig", MountPath: fmt.Sprintf("/tmp/%s", "fabric-ca-client-config.yaml"), SubPath: "fabric-ca-client-config.yaml", }, - corev1.VolumeMount{ + { Name: "shared", MountPath: "/hsm/lib", SubPath: "hsm", @@ -338,7 +338,7 @@ func (r *HSMDaemonReenroller) initHSMJob(instance Instance, hsmConfig *config.HS }, }, Volumes: []corev1.Volume{ - corev1.Volume{ + { Name: "shared", VolumeSource: corev1.VolumeSource{ EmptyDir: &corev1.EmptyDirVolumeSource{ @@ -346,7 +346,7 @@ func (r *HSMDaemonReenroller) initHSMJob(instance Instance, hsmConfig *config.HS }, }, }, - corev1.Volume{ + { Name: "tlscertfile", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ @@ -354,7 +354,7 @@ func (r *HSMDaemonReenroller) initHSMJob(instance Instance, hsmConfig *config.HS }, }, }, - corev1.Volume{ + { Name: "certfile", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ @@ -362,7 +362,7 @@ func (r *HSMDaemonReenroller) initHSMJob(instance Instance, hsmConfig *config.HS }, }, }, - corev1.Volume{ + { Name: "clientconfig", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ diff --git a/pkg/certificate/reenroller/hsmreenroller.go b/pkg/certificate/reenroller/hsmreenroller.go index 3da83588..bf4dbfdf 100644 --- a/pkg/certificate/reenroller/hsmreenroller.go +++ b/pkg/certificate/reenroller/hsmreenroller.go @@ -368,7 +368,7 @@ func (r *HSMReenroller) initHSMJob(instance Instance, hsmConfig *config.HSMConfi ImagePullSecrets: util.AppendImagePullSecretIfMissing(instance.GetPullSecrets(), hsmConfig.BuildPullSecret()), RestartPolicy: corev1.RestartPolicyNever, InitContainers: []corev1.Container{ - corev1.Container{ + { Name: "hsm-client", Image: hsmConfig.Library.Image, ImagePullPolicy: corev1.PullAlways, @@ -382,7 +382,7 @@ func (r *HSMReenroller) initHSMJob(instance Instance, hsmConfig *config.HSMConfi RunAsNonRoot: &f, }, VolumeMounts: []corev1.VolumeMount{ - corev1.VolumeMount{ + { Name: "shared", MountPath: mountPath, }, @@ -402,7 +402,7 @@ func (r *HSMReenroller) initHSMJob(instance Instance, hsmConfig *config.HSMConfi }, }, Containers: []corev1.Container{ - corev1.Container{ + { Name: "init", Image: instance.EnrollerImage(), ImagePullPolicy: corev1.PullAlways, @@ -416,22 +416,22 @@ func (r *HSMReenroller) initHSMJob(instance Instance, hsmConfig *config.HSMConfi fmt.Sprintf("/usr/local/bin/enroller node reenroll %s %s %s %s %s %s %s %s %s %t", r.HomeDir, "/tmp/fabric-ca-client-config.yaml", r.Config.CAHost, r.Config.CAPort, r.Config.CAName, instance.GetName(), instance.GetNamespace(), r.Config.EnrollID, fmt.Sprintf("%s/cert.pem", r.HomeDir), r.NewKey), }, VolumeMounts: []corev1.VolumeMount{ - corev1.VolumeMount{ + { Name: "tlscertfile", MountPath: fmt.Sprintf("%s/tlsCert.pem", r.HomeDir), SubPath: "tlsCert.pem", }, - corev1.VolumeMount{ + { Name: "certfile", MountPath: fmt.Sprintf("%s/cert.pem", r.HomeDir), SubPath: "cert.pem", }, - corev1.VolumeMount{ + { Name: "clientconfig", MountPath: fmt.Sprintf("/tmp/%s", "fabric-ca-client-config.yaml"), SubPath: "fabric-ca-client-config.yaml", }, - corev1.VolumeMount{ + { Name: "shared", MountPath: "/hsm/lib", SubPath: "hsm", @@ -440,7 +440,7 @@ func (r *HSMReenroller) initHSMJob(instance Instance, hsmConfig *config.HSMConfi }, }, Volumes: []corev1.Volume{ - corev1.Volume{ + { Name: "shared", VolumeSource: corev1.VolumeSource{ EmptyDir: &corev1.EmptyDirVolumeSource{ @@ -448,7 +448,7 @@ func (r *HSMReenroller) initHSMJob(instance Instance, hsmConfig *config.HSMConfi }, }, }, - corev1.Volume{ + { Name: "tlscertfile", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ @@ -456,7 +456,7 @@ func (r *HSMReenroller) initHSMJob(instance Instance, hsmConfig *config.HSMConfi }, }, }, - corev1.Volume{ + { Name: "certfile", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ @@ -464,7 +464,7 @@ func (r *HSMReenroller) initHSMJob(instance Instance, hsmConfig *config.HSMConfi }, }, }, - corev1.Volume{ + { Name: "clientconfig", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ diff --git a/pkg/certificate/reenroller/reenroller_suite_test.go b/pkg/certificate/reenroller/reenroller_suite_test.go index 94698fe5..1657e67c 100644 --- a/pkg/certificate/reenroller/reenroller_suite_test.go +++ b/pkg/certificate/reenroller/reenroller_suite_test.go @@ -59,7 +59,6 @@ var _ = BeforeSuite(func() { server = httptest.NewTLSServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { // Test request parameters Expect(req.URL.String()).To(Equal("/cainfo")) - return })) serverURL = server.URL diff --git a/pkg/initializer/ca/ca.go b/pkg/initializer/ca/ca.go index c57d552a..7b9b197d 100644 --- a/pkg/initializer/ca/ca.go +++ b/pkg/initializer/ca/ca.go @@ -241,11 +241,8 @@ func (ca *CA) IsPostgresReachable(db lib.CAConfigDB) bool { defer cancel() err = sqldb.PingContext(ctx) - if err != nil { - return false - } - return true + return err == nil } // ViperUnmarshal as this is what fabric-ca uses when it reads it's configuration @@ -421,10 +418,8 @@ func (ca *CA) IsBeingUpdated() { } func (ca *CA) IsHSMEnabled() bool { - if ca.Config.UsingPKCS11() { - return true - } - return false + + return ca.Config.UsingPKCS11() } func (ca *CA) HealthCheck(parentURL, certPath string) error { diff --git a/pkg/initializer/ca/config/db.go b/pkg/initializer/ca/config/db.go index de78e207..3ead97a8 100644 --- a/pkg/initializer/ca/config/db.go +++ b/pkg/initializer/ca/config/db.go @@ -119,7 +119,7 @@ func (c *Config) DBMountPath() { } certFiles := c.ServerConfig.CAConfig.DB.TLS.CertFiles - for index, _ := range certFiles { + for index := range certFiles { certFiles[index] = filepath.Join(c.MountPath, fmt.Sprintf("db-certfile%d.pem", index)) } c.ServerConfig.CAConfig.DB.TLS.CertFiles = certFiles diff --git a/pkg/initializer/ca/config/intermediate.go b/pkg/initializer/ca/config/intermediate.go index 3f7067b4..8be08dc3 100644 --- a/pkg/initializer/ca/config/intermediate.go +++ b/pkg/initializer/ca/config/intermediate.go @@ -69,7 +69,7 @@ func (c *Config) IntermediateMountPath() { } certFiles := c.ServerConfig.CAConfig.Intermediate.TLS.CertFiles - for index, _ := range certFiles { + for index := range certFiles { certFiles[index] = filepath.Join(c.MountPath, fmt.Sprintf("parent-certfile%d.pem", index)) } c.ServerConfig.CAConfig.Intermediate.TLS.CertFiles = certFiles diff --git a/pkg/initializer/ca/config/operations.go b/pkg/initializer/ca/config/operations.go index 088974e8..7894d865 100644 --- a/pkg/initializer/ca/config/operations.go +++ b/pkg/initializer/ca/config/operations.go @@ -74,7 +74,7 @@ func (c *Config) OperationsMountPath() { c.ServerConfig.Operations.TLS.KeyFile = filepath.Join(c.MountPath, "operations-key.pem") certFiles := c.ServerConfig.Operations.TLS.ClientCACertFiles - for index, _ := range certFiles { + for index := range certFiles { certFiles[index] = filepath.Join(c.MountPath, fmt.Sprintf("operations-certfile%d.pem", index)) } c.ServerConfig.Operations.TLS.ClientCACertFiles = certFiles diff --git a/pkg/initializer/ca/config/tls.go b/pkg/initializer/ca/config/tls.go index 254b02a9..9268c5c0 100644 --- a/pkg/initializer/ca/config/tls.go +++ b/pkg/initializer/ca/config/tls.go @@ -76,7 +76,7 @@ func (c *Config) TLSMountPath() { c.ServerConfig.TLS.KeyFile = filepath.Join(c.MountPath, "tls-key.pem") certFiles := c.ServerConfig.TLS.ClientAuth.CertFiles - for index, _ := range certFiles { + for index := range certFiles { certFiles[index] = filepath.Join(c.MountPath, fmt.Sprintf("tls-certfile%d.pem", index)) } c.ServerConfig.TLS.ClientAuth.CertFiles = certFiles diff --git a/pkg/initializer/ca/hsm.go b/pkg/initializer/ca/hsm.go index 82036252..259e294c 100644 --- a/pkg/initializer/ca/hsm.go +++ b/pkg/initializer/ca/hsm.go @@ -424,7 +424,7 @@ func initHSMCAJob(instance *current.IBPCA, hsmConfig *config.HSMConfig, dbConfig ImagePullSecrets: util.AppendImagePullSecretIfMissing(instance.GetPullSecrets(), hsmConfig.BuildPullSecret()), RestartPolicy: corev1.RestartPolicyNever, InitContainers: []corev1.Container{ - corev1.Container{ + { Name: "hsm-client", Image: hsmConfig.Library.Image, ImagePullPolicy: corev1.PullAlways, @@ -438,7 +438,7 @@ func initHSMCAJob(instance *current.IBPCA, hsmConfig *config.HSMConfig, dbConfig RunAsNonRoot: &f, }, VolumeMounts: []corev1.VolumeMount{ - corev1.VolumeMount{ + { Name: "shared", MountPath: mountPath, }, @@ -458,7 +458,7 @@ func initHSMCAJob(instance *current.IBPCA, hsmConfig *config.HSMConfig, dbConfig }, }, Containers: []corev1.Container{ - corev1.Container{ + { Name: "init", Image: image.Format( instance.Spec.Images.EnrollerImage, @@ -476,12 +476,12 @@ func initHSMCAJob(instance *current.IBPCA, hsmConfig *config.HSMConfig, dbConfig }, Env: hsmConfig.GetEnvs(), VolumeMounts: []corev1.VolumeMount{ - corev1.VolumeMount{ + { Name: "shared", MountPath: "/hsm/lib", SubPath: "hsm", }, - corev1.VolumeMount{ + { Name: "caconfig", MountPath: fmt.Sprintf("/tmp/data/%s/%s/fabric-ca-server-config.yaml", instance.GetName(), typ), SubPath: "fabric-ca-server-config.yaml", @@ -490,7 +490,7 @@ func initHSMCAJob(instance *current.IBPCA, hsmConfig *config.HSMConfig, dbConfig }, }, Volumes: []corev1.Volume{ - corev1.Volume{ + { Name: "shared", VolumeSource: corev1.VolumeSource{ EmptyDir: &corev1.EmptyDirVolumeSource{ @@ -498,7 +498,7 @@ func initHSMCAJob(instance *current.IBPCA, hsmConfig *config.HSMConfig, dbConfig }, }, }, - corev1.Volume{ + { Name: "caconfig", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ @@ -535,7 +535,7 @@ func initHSMCAJob(instance *current.IBPCA, hsmConfig *config.HSMConfig, dbConfig Secret: &corev1.SecretVolumeSource{ SecretName: fmt.Sprintf("%s-%s-crypto", instance.GetName(), typ), Items: []corev1.KeyToPath{ - corev1.KeyToPath{ + { Key: "db-certfile0.pem", Path: "db-certfile0.pem", }, diff --git a/pkg/initializer/ca/hsmdaemon.go b/pkg/initializer/ca/hsmdaemon.go index d3d33e06..b5d854b7 100644 --- a/pkg/initializer/ca/hsmdaemon.go +++ b/pkg/initializer/ca/hsmdaemon.go @@ -284,7 +284,7 @@ func (h *HSMDaemon) initHSMCAJob(instance *current.IBPCA, dbConfig *v1.CAConfigD Secret: &corev1.SecretVolumeSource{ SecretName: fmt.Sprintf("%s-%s-crypto", instance.GetName(), typ), Items: []corev1.KeyToPath{ - corev1.KeyToPath{ + { Key: "db-certfile0.pem", Path: "db-certfile0.pem", }, diff --git a/pkg/initializer/ca/tls/tls_test.go b/pkg/initializer/ca/tls/tls_test.go index cd5b637d..729249c6 100644 --- a/pkg/initializer/ca/tls/tls_test.go +++ b/pkg/initializer/ca/tls/tls_test.go @@ -20,7 +20,6 @@ package tls_test import ( "crypto/x509" - "fmt" "io/ioutil" "os" "path/filepath" @@ -51,7 +50,7 @@ var _ = Describe("generating TLS crypto", func() { csr = &api.CSRInfo{ CN: "tls-ca", Names: []cfcsr.Name{ - cfcsr.Name{ + { C: "United States", ST: "North Carolina", L: "Raleigh", @@ -83,7 +82,7 @@ var _ = Describe("generating TLS crypto", func() { Expect(cert.Subject.OrganizationalUnit).To(Equal([]string{"Blockchain"})) Expect(cert.DNSNames[0]).To(Equal("localhost")) - Expect(fmt.Sprintf("%s", cert.IPAddresses[0])).To(Equal("127.0.0.1")) + Expect(cert.IPAddresses[0].String()).To(Equal("127.0.0.1")) Expect(cert.Subject).To(Equal(cert.Issuer)) }) diff --git a/pkg/initializer/common/config/hsmconfig_test.go b/pkg/initializer/common/config/hsmconfig_test.go index 42f9dbb0..c8937b09 100644 --- a/pkg/initializer/common/config/hsmconfig_test.go +++ b/pkg/initializer/common/config/hsmconfig_test.go @@ -34,7 +34,7 @@ var _ = Describe("HSM Config", func() { Type: "hsm", Version: "v1", MountPaths: []config.MountPath{ - config.MountPath{ + { Name: "hsmcrypto", Secret: "hsmcrypto", MountPath: "/hsm", @@ -49,7 +49,7 @@ var _ = Describe("HSM Config", func() { }, }, }, - config.MountPath{ + { Name: "hsmconfig", Secret: "hsmcrypto", MountPath: "/etc/Chrystoki.conf", diff --git a/pkg/initializer/common/enroller/hsmdaemonenroller.go b/pkg/initializer/common/enroller/hsmdaemonenroller.go index 8085d483..2b674699 100644 --- a/pkg/initializer/common/enroller/hsmdaemonenroller.go +++ b/pkg/initializer/common/enroller/hsmdaemonenroller.go @@ -79,7 +79,7 @@ func (e *HSMDaemonEnroller) PingCA(timeout time.Duration) error { // Enroll reaches out the CA to get back a signed certificate func (e *HSMDaemonEnroller) Enroll() (*config.Response, error) { - log.Info(fmt.Sprintf("Enrolling using HSM Daemon")) + log.Info("Enrolling using HSM Daemon") // Deleting CA client config is an unfortunate requirement since the ca client // config map was not properly deleted after a successfull reenrollment request. // This is problematic when recreating a resource with same name, as it will diff --git a/pkg/initializer/common/enroller/hsmenroller.go b/pkg/initializer/common/enroller/hsmenroller.go index 18f51f2d..acf8b6f7 100644 --- a/pkg/initializer/common/enroller/hsmenroller.go +++ b/pkg/initializer/common/enroller/hsmenroller.go @@ -344,7 +344,7 @@ func (e *HSMEnroller) initHSMJob(instance Instance, timeouts HSMEnrollJobTimeout ImagePullSecrets: util.AppendImagePullSecretIfMissing(instance.GetPullSecrets(), hsmConfig.BuildPullSecret()), RestartPolicy: corev1.RestartPolicyNever, InitContainers: []corev1.Container{ - corev1.Container{ + { Name: "hsm-client", Image: hsmConfig.Library.Image, ImagePullPolicy: corev1.PullAlways, @@ -358,7 +358,7 @@ func (e *HSMEnroller) initHSMJob(instance Instance, timeouts HSMEnrollJobTimeout RunAsNonRoot: &f, }, VolumeMounts: []corev1.VolumeMount{ - corev1.VolumeMount{ + { Name: "shared", MountPath: mountPath, }, @@ -378,7 +378,7 @@ func (e *HSMEnroller) initHSMJob(instance Instance, timeouts HSMEnrollJobTimeout }, }, Containers: []corev1.Container{ - corev1.Container{ + { Name: "init", Image: instance.EnrollerImage(), ImagePullPolicy: corev1.PullAlways, @@ -393,17 +393,17 @@ func (e *HSMEnroller) initHSMJob(instance Instance, timeouts HSMEnrollJobTimeout fmt.Sprintf("/usr/local/bin/enroller node enroll %s %s %s %s %s %s %s %s %s", e.CAClient.GetHomeDir(), "/tmp/fabric-ca-client-config.yaml", req.CAHost, req.CAPort, req.CAName, instance.GetName(), instance.GetNamespace(), req.EnrollID, req.EnrollSecret), }, VolumeMounts: []corev1.VolumeMount{ - corev1.VolumeMount{ + { Name: "tlscertfile", MountPath: fmt.Sprintf("%s/tlsCert.pem", e.CAClient.GetHomeDir()), SubPath: "tlsCert.pem", }, - corev1.VolumeMount{ + { Name: "clientconfig", MountPath: fmt.Sprintf("/tmp/%s", "fabric-ca-client-config.yaml"), SubPath: "fabric-ca-client-config.yaml", }, - corev1.VolumeMount{ + { Name: "shared", MountPath: "/hsm/lib", SubPath: "hsm", @@ -412,7 +412,7 @@ func (e *HSMEnroller) initHSMJob(instance Instance, timeouts HSMEnrollJobTimeout }, }, Volumes: []corev1.Volume{ - corev1.Volume{ + { Name: "shared", VolumeSource: corev1.VolumeSource{ EmptyDir: &corev1.EmptyDirVolumeSource{ @@ -420,7 +420,7 @@ func (e *HSMEnroller) initHSMJob(instance Instance, timeouts HSMEnrollJobTimeout }, }, }, - corev1.Volume{ + { Name: "tlscertfile", VolumeSource: corev1.VolumeSource{ Secret: &corev1.SecretVolumeSource{ @@ -428,7 +428,7 @@ func (e *HSMEnroller) initHSMJob(instance Instance, timeouts HSMEnrollJobTimeout }, }, }, - corev1.Volume{ + { Name: "clientconfig", VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ diff --git a/pkg/initializer/common/secretmanager/secretmanager.go b/pkg/initializer/common/secretmanager/secretmanager.go index d2d6f5ca..40a43f19 100644 --- a/pkg/initializer/common/secretmanager/secretmanager.go +++ b/pkg/initializer/common/secretmanager/secretmanager.go @@ -155,7 +155,7 @@ func (s *SecretManager) CreateIntermediateCertsSecret(name string, instance v1.O } func (s *SecretManager) CreateSignCert(name string, instance v1.Object, cert []byte) error { - if cert == nil || len(cert) == 0 { + if len(cert) == 0 { return nil } diff --git a/pkg/initializer/orderer/config/v2/orderer.go b/pkg/initializer/orderer/config/v2/orderer.go index c532446b..43b1153e 100644 --- a/pkg/initializer/orderer/config/v2/orderer.go +++ b/pkg/initializer/orderer/config/v2/orderer.go @@ -133,7 +133,6 @@ func (o *Orderer) SetBCCSPLibrary(library string) { func (o *Orderer) SetDefaultKeyStore() { // No-op - return } func (o *Orderer) GetBCCSPSection() *commonapi.BCCSP { diff --git a/pkg/initializer/orderer/config/v24/orderer.go b/pkg/initializer/orderer/config/v24/orderer.go index bcabd8e8..f30a2e71 100644 --- a/pkg/initializer/orderer/config/v24/orderer.go +++ b/pkg/initializer/orderer/config/v24/orderer.go @@ -132,7 +132,6 @@ func (o *Orderer) SetBCCSPLibrary(library string) { func (o *Orderer) SetDefaultKeyStore() { // No-op - return } func (o *Orderer) GetBCCSPSection() *commonapi.BCCSP { diff --git a/pkg/initializer/orderer/configtx/configtx.go b/pkg/initializer/orderer/configtx/configtx.go index 94e90ee8..08948251 100644 --- a/pkg/initializer/orderer/configtx/configtx.go +++ b/pkg/initializer/orderer/configtx/configtx.go @@ -32,7 +32,7 @@ import ( func GetGenesisDefaults() *TopLevel { return &TopLevel{ Profiles: map[string]*Profile{ - "Initial": &Profile{ + "Initial": { Orderer: &Orderer{ Organizations: []*Organization{}, OrdererType: "etcdraft", @@ -57,19 +57,19 @@ func GetGenesisDefaults() *TopLevel { "V1_4_2": true, }, Policies: map[string]*Policy{ - "Readers": &Policy{ + "Readers": { Type: "ImplicitMeta", Rule: "ANY Readers", }, - "Writers": &Policy{ + "Writers": { Type: "ImplicitMeta", Rule: "ANY Writers", }, - "Admins": &Policy{ + "Admins": { Type: "ImplicitMeta", Rule: "ANY Admins", }, - "BlockValidation": &Policy{ + "BlockValidation": { Type: "ImplicitMeta", Rule: "ANY Writers", }, @@ -77,21 +77,21 @@ func GetGenesisDefaults() *TopLevel { }, Consortiums: map[string]*Consortium{ - "SampleConsortium": &Consortium{}, + "SampleConsortium": {}, }, Capabilities: map[string]bool{ "V1_4_3": true, }, Policies: map[string]*Policy{ - "Readers": &Policy{ + "Readers": { Type: "ImplicitMeta", Rule: "ANY Readers", }, - "Writers": &Policy{ + "Writers": { Type: "ImplicitMeta", Rule: "ANY Writers", }, - "Admins": &Policy{ + "Admins": { Type: "ImplicitMeta", Rule: "MAJORITY Admins", }, diff --git a/pkg/initializer/orderer/configtx/profile_test.go b/pkg/initializer/orderer/configtx/profile_test.go index 196e8a46..36d4b119 100644 --- a/pkg/initializer/orderer/configtx/profile_test.go +++ b/pkg/initializer/orderer/configtx/profile_test.go @@ -40,7 +40,7 @@ var _ = Describe("profile", func() { Expect(err).NotTo(HaveOccurred()) mspConfig = map[string]*msp.MSPConfig{ - "testorg3": &msp.MSPConfig{}, + "testorg3": {}, } }) @@ -85,15 +85,15 @@ var _ = Describe("profile", func() { It("adds consortium", func() { profile.Policies = map[string]*configtx.Policy{ - channelconfig.AdminsPolicyKey: &configtx.Policy{ + channelconfig.AdminsPolicyKey: { Type: configtx.ImplicitMetaPolicyType, Rule: "ALL bar", }, - channelconfig.ReadersPolicyKey: &configtx.Policy{ + channelconfig.ReadersPolicyKey: { Type: configtx.ImplicitMetaPolicyType, Rule: "ALL bar", }, - channelconfig.WritersPolicyKey: &configtx.Policy{ + channelconfig.WritersPolicyKey: { Type: configtx.ImplicitMetaPolicyType, Rule: "ALL bar", }, @@ -125,15 +125,15 @@ var _ = Describe("profile", func() { It("adds org to consortium", func() { profile.Policies = map[string]*configtx.Policy{ - channelconfig.AdminsPolicyKey: &configtx.Policy{ + channelconfig.AdminsPolicyKey: { Type: configtx.ImplicitMetaPolicyType, Rule: "ALL bar", }, - channelconfig.ReadersPolicyKey: &configtx.Policy{ + channelconfig.ReadersPolicyKey: { Type: configtx.ImplicitMetaPolicyType, Rule: "ALL bar", }, - channelconfig.WritersPolicyKey: &configtx.Policy{ + channelconfig.WritersPolicyKey: { Type: configtx.ImplicitMetaPolicyType, Rule: "ALL bar", }, diff --git a/pkg/initializer/peer/config/v1/config_test.go b/pkg/initializer/peer/config/v1/config_test.go index 032681e0..e9177350 100644 --- a/pkg/initializer/peer/config/v1/config_test.go +++ b/pkg/initializer/peer/config/v1/config_test.go @@ -87,7 +87,7 @@ var _ = Describe("Peer configuration", func() { }, DeliveryClient: v1.DeliveryClient{ AddressOverrides: []v1.AddressOverride{ - v1.AddressOverride{ + { From: "old", To: "new", CACertsFile: certB64, @@ -449,10 +449,10 @@ var _ = Describe("Peer configuration", func() { // Handlers By("setting Handlers.AuthFilters", func() { Expect(peerConfig.Handlers.AuthFilters).To(Equal([]v1.HandlerConfig{ - v1.HandlerConfig{ + { Name: "DefaultAuth", }, - v1.HandlerConfig{ + { Name: "ExpirationCheck", }, })) @@ -460,7 +460,7 @@ var _ = Describe("Peer configuration", func() { By("setting Handlers.Decorators", func() { Expect(peerConfig.Handlers.Decorators).To(Equal([]v1.HandlerConfig{ - v1.HandlerConfig{ + { Name: "DefaultDecorator", }, })) @@ -535,7 +535,7 @@ var _ = Describe("Peer configuration", func() { Expect(core.Peer.ID).To(Equal("jdoe")) addressOverrides := []v1.AddressOverride{ - v1.AddressOverride{ + { From: "address_old", To: "address_new", CACertsFile: certB64, diff --git a/pkg/initializer/peer/config/v2/config.go b/pkg/initializer/peer/config/v2/config.go index 7d66fc2e..15213f22 100644 --- a/pkg/initializer/peer/config/v2/config.go +++ b/pkg/initializer/peer/config/v2/config.go @@ -138,7 +138,6 @@ func (c *Core) SetPKCS11Defaults(usingHSMProxy bool) { func (c *Core) SetDefaultKeyStore() { // No-op - return } func (c *Core) GetMaxNameLength() *int { diff --git a/pkg/initializer/peer/config/v2/config_test.go b/pkg/initializer/peer/config/v2/config_test.go index aff372ef..3f058e16 100644 --- a/pkg/initializer/peer/config/v2/config_test.go +++ b/pkg/initializer/peer/config/v2/config_test.go @@ -87,7 +87,7 @@ var _ = Describe("Peer configuration", func() { StartupTimeout: startupTimeout, ExecuteTimeout: executeTimeout, ExternalBuilders: []v2core.ExternalBuilder{ - v2core.ExternalBuilder{ + { Path: "/scripts", Name: "go-builder", EnvironmentWhiteList: []string{"ENV1=Value1"}, diff --git a/pkg/initializer/peer/initializer.go b/pkg/initializer/peer/initializer.go index 1f401dbb..3f3a3e66 100644 --- a/pkg/initializer/peer/initializer.go +++ b/pkg/initializer/peer/initializer.go @@ -152,9 +152,8 @@ func (i *Initializer) CoreConfigMap() *CoreConfigMap { } func (i *Initializer) Update(overrides CoreConfig, peer IBPPeer) (*Response, error) { - var err error - err = peer.OverrideConfig(overrides) + err := peer.OverrideConfig(overrides) if err != nil { return nil, err } diff --git a/pkg/initializer/peer/peer_suite_test.go b/pkg/initializer/peer/peer_suite_test.go index 41ed6174..0b17b3fe 100644 --- a/pkg/initializer/peer/peer_suite_test.go +++ b/pkg/initializer/peer/peer_suite_test.go @@ -41,7 +41,6 @@ var _ = BeforeSuite(func() { server = httptest.NewTLSServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { // Test request parameters Expect(req.URL.String()).To(Equal("/cainfo")) - return })) }) diff --git a/pkg/k8s/controllerclient/client.go b/pkg/k8s/controllerclient/client.go index 1045cf48..cdc94aab 100644 --- a/pkg/k8s/controllerclient/client.go +++ b/pkg/k8s/controllerclient/client.go @@ -86,7 +86,7 @@ func (c *ClientImpl) Create(ctx context.Context, obj k8sclient.Object, opts ...C c.GlobalConfig.Apply(obj) - if opts != nil && len(opts) > 0 { + if len(opts) > 0 { if err := setControllerReference(opts[0].Owner, obj, opts[0].Scheme); err != nil { return err } @@ -105,7 +105,7 @@ func (c *ClientImpl) Patch(ctx context.Context, obj k8sclient.Object, patch k8sc c.GlobalConfig.Apply(obj) - if opts != nil && len(opts) > 0 { + if len(opts) > 0 { if opts[0].Resilient != nil { return c.ResilientPatch(ctx, obj, opts[0].Resilient, opts[0].Opts...) } @@ -166,7 +166,7 @@ func (c *ClientImpl) resilientPatch(ctx context.Context, obj k8sclient.Object, s func (c *ClientImpl) PatchStatus(ctx context.Context, obj k8sclient.Object, patch k8sclient.Patch, opts ...PatchOption) error { var patchOpts []k8sclient.PatchOption - if opts != nil && len(opts) > 0 { + if len(opts) > 0 { if opts[0].Resilient != nil { return c.ResilientPatchStatus(ctx, obj, opts[0].Resilient, opts[0].Opts...) } @@ -228,7 +228,7 @@ func (c *ClientImpl) Update(ctx context.Context, obj k8sclient.Object, opts ...U c.GlobalConfig.Apply(obj) - if opts != nil && len(opts) > 0 { + if len(opts) > 0 { if err := setControllerReference(opts[0].Owner, obj, opts[0].Scheme); err != nil { return err } @@ -263,7 +263,7 @@ func (c *ClientImpl) Delete(ctx context.Context, obj k8sclient.Object, opts ...k // CreateOrUpdate does not support k8sclient.CreateOption or k8sclient.UpdateOption being passed as variadic parameters, // if want to use opts use Create or Update methods func (c *ClientImpl) CreateOrUpdate(ctx context.Context, obj k8sclient.Object, opts ...CreateOrUpdateOption) error { - if opts != nil && len(opts) > 0 { + if len(opts) > 0 { if err := setControllerReference(opts[0].Owner, obj, opts[0].Scheme); err != nil { return err } diff --git a/pkg/manager/resources/configmap/manager.go b/pkg/manager/resources/configmap/manager.go index 6cc278a1..6ec8e5e8 100644 --- a/pkg/manager/resources/configmap/manager.go +++ b/pkg/manager/resources/configmap/manager.go @@ -52,7 +52,7 @@ func (m *Manager) GetName(instance v1.Object) string { if m.Name != "" { return fmt.Sprintf("%s-%s", instance.GetName(), m.Name) } - return fmt.Sprintf("%s", instance.GetName()) + return instance.GetName() } func (m *Manager) Reconcile(instance v1.Object, update bool) error { @@ -145,11 +145,8 @@ func (m *Manager) Get(instance v1.Object) (client.Object, error) { func (m *Manager) Exists(instance v1.Object) bool { _, err := m.Get(instance) - if err != nil { - return false - } - return true + return err == nil } func (m *Manager) Delete(instance v1.Object) error { diff --git a/pkg/manager/resources/container/container_test.go b/pkg/manager/resources/container/container_test.go index 1ad5810a..19f1b2e8 100644 --- a/pkg/manager/resources/container/container_test.go +++ b/pkg/manager/resources/container/container_test.go @@ -41,7 +41,7 @@ var _ = Describe("container", func() { Context("env vars", func() { BeforeEach(func() { cont.Env = []corev1.EnvVar{ - corev1.EnvVar{ + { Name: "env1", Value: "1.0", }, diff --git a/pkg/manager/resources/deployment/deployment.go b/pkg/manager/resources/deployment/deployment.go index d131c967..65762118 100644 --- a/pkg/manager/resources/deployment/deployment.go +++ b/pkg/manager/resources/deployment/deployment.go @@ -126,7 +126,7 @@ func (d *Deployment) SetServiceAccountName(name string) { } func (d *Deployment) SetImagePullSecrets(pullSecrets []string) { - if pullSecrets != nil && len(pullSecrets) > 0 { + if len(pullSecrets) > 0 { d.Deployment.Spec.Template.Spec.ImagePullSecrets = []corev1.LocalObjectReference{} for _, pullSecret := range pullSecrets { diff --git a/pkg/manager/resources/deployment/manager.go b/pkg/manager/resources/deployment/manager.go index fa263332..a9edd5e0 100644 --- a/pkg/manager/resources/deployment/manager.go +++ b/pkg/manager/resources/deployment/manager.go @@ -415,5 +415,5 @@ func GetName(instanceName string, suffix ...string) string { return fmt.Sprintf("%s-%s", instanceName, suffix[0]) } } - return fmt.Sprintf("%s", instanceName) + return instanceName } diff --git a/pkg/manager/resources/deployment/manager_test.go b/pkg/manager/resources/deployment/manager_test.go index 06880878..0fd439e8 100644 --- a/pkg/manager/resources/deployment/manager_test.go +++ b/pkg/manager/resources/deployment/manager_test.go @@ -63,7 +63,7 @@ var _ = Describe("Deployment manager", func() { d.Spec = appsv1.DeploymentSpec{ Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ - Containers: []corev1.Container{corev1.Container{ + Containers: []corev1.Container{{ Name: "container", }}, }, @@ -167,7 +167,7 @@ var _ = Describe("Deployment manager", func() { }, Template: corev1.PodTemplateSpec{ Spec: corev1.PodSpec{ - Containers: []corev1.Container{corev1.Container{ + Containers: []corev1.Container{{ Name: "test-container", }}, }, diff --git a/pkg/manager/resources/ingress/manager.go b/pkg/manager/resources/ingress/manager.go index 213790f5..6b39d0e1 100644 --- a/pkg/manager/resources/ingress/manager.go +++ b/pkg/manager/resources/ingress/manager.go @@ -124,11 +124,8 @@ func (m *Manager) Exists(instance v1.Object) bool { ingress := &networkingv1.Ingress{} err := m.Client.Get(context.TODO(), types.NamespacedName{Name: name, Namespace: instance.GetNamespace()}, ingress) - if err != nil { - return false - } - return true + return err == nil } func (m *Manager) Delete(instance v1.Object) error { diff --git a/pkg/manager/resources/ingressv1beta1/manager.go b/pkg/manager/resources/ingressv1beta1/manager.go index 2bc5a52d..dd2f356d 100644 --- a/pkg/manager/resources/ingressv1beta1/manager.go +++ b/pkg/manager/resources/ingressv1beta1/manager.go @@ -124,11 +124,8 @@ func (m *Manager) Exists(instance v1.Object) bool { ingress := &networkingv1beta1.Ingress{} err := m.Client.Get(context.TODO(), types.NamespacedName{Name: name, Namespace: instance.GetNamespace()}, ingress) - if err != nil { - return false - } - return true + return err == nil } func (m *Manager) Delete(instance v1.Object) error { diff --git a/pkg/manager/resources/job/job.go b/pkg/manager/resources/job/job.go index fa33b3d4..98006a01 100644 --- a/pkg/manager/resources/job/job.go +++ b/pkg/manager/resources/job/job.go @@ -253,9 +253,8 @@ func (j *Job) WaitUntilActive(client controller.Client) error { } func (j *Job) WaitUntilFinished(client controller.Client) error { - var err error - err = wait.Poll(2*time.Second, j.Timeouts.WaitUntilFinished, func() (bool, error) { + err := wait.Poll(2*time.Second, j.Timeouts.WaitUntilFinished, func() (bool, error) { log.Info(fmt.Sprintf("Waiting for job pod '%s' to finish", j.GetName())) pods, err := j.getPods(client) @@ -290,9 +289,8 @@ func (j *Job) podsTerminated(pods *corev1.PodList) bool { } func (j *Job) WaitUntilContainerFinished(client controller.Client, contName string) error { - var err error - err = wait.Poll(2*time.Second, j.Timeouts.WaitUntilFinished, func() (bool, error) { + err := wait.Poll(2*time.Second, j.Timeouts.WaitUntilFinished, func() (bool, error) { log.Info(fmt.Sprintf("Waiting for job pod '%s' to finish", j.GetName())) pods, err := j.getPods(client) diff --git a/pkg/manager/resources/orderernode/manager.go b/pkg/manager/resources/orderernode/manager.go index 490ddbca..2f8a946b 100644 --- a/pkg/manager/resources/orderernode/manager.go +++ b/pkg/manager/resources/orderernode/manager.go @@ -203,11 +203,7 @@ func (m *Manager) Get(instance v1.Object) (client.Object, error) { func (m *Manager) Exists(instance v1.Object) bool { _, err := m.Get(instance) - if err != nil { - return false - } - - return true + return err == nil } func (m *Manager) Delete(instance v1.Object) error { @@ -275,7 +271,7 @@ func GetName(instanceName string, suffix ...string) string { return fmt.Sprintf("%s-%s", instanceName, suffix[0]) } } - return fmt.Sprintf("%s", instanceName) + return instanceName } func GetOrderernodeFromFile(file string) (*current.IBPOrderer, error) { diff --git a/pkg/manager/resources/pv/manager.go b/pkg/manager/resources/pv/manager.go index b3f11376..0d6a1b9b 100644 --- a/pkg/manager/resources/pv/manager.go +++ b/pkg/manager/resources/pv/manager.go @@ -114,11 +114,7 @@ func (m *Manager) Get(instance v1.Object) (client.Object, error) { func (m *Manager) Exists(instance v1.Object) bool { _, err := m.Get(instance) - if err != nil { - return false - } - - return true + return err == nil } func (m *Manager) Delete(instance v1.Object) error { diff --git a/pkg/manager/resources/pvc/manager.go b/pkg/manager/resources/pvc/manager.go index 3dd52b25..a32331fa 100644 --- a/pkg/manager/resources/pvc/manager.go +++ b/pkg/manager/resources/pvc/manager.go @@ -128,11 +128,7 @@ func (m *Manager) Get(instance v1.Object) (client.Object, error) { func (m *Manager) Exists(instance v1.Object) bool { _, err := m.Get(instance) - if err != nil { - return false - } - - return true + return err == nil } func (m *Manager) Delete(instance v1.Object) error { diff --git a/pkg/manager/resources/role/manager.go b/pkg/manager/resources/role/manager.go index b614812f..48f4e3e4 100644 --- a/pkg/manager/resources/role/manager.go +++ b/pkg/manager/resources/role/manager.go @@ -118,11 +118,8 @@ func (m *Manager) Get(instance v1.Object) (client.Object, error) { func (m *Manager) Exists(instance v1.Object) bool { _, err := m.Get(instance) - if err != nil { - return false - } - return true + return err == nil } func (m *Manager) Delete(instance v1.Object) error { diff --git a/pkg/manager/resources/rolebinding/manager.go b/pkg/manager/resources/rolebinding/manager.go index 889ad0a2..aaef59b0 100644 --- a/pkg/manager/resources/rolebinding/manager.go +++ b/pkg/manager/resources/rolebinding/manager.go @@ -127,11 +127,8 @@ func (m *Manager) Get(instance v1.Object) (client.Object, error) { func (m *Manager) Exists(instance v1.Object) bool { _, err := m.Get(instance) - if err != nil { - return false - } - return true + return err == nil } func (m *Manager) Delete(instance v1.Object) error { diff --git a/pkg/manager/resources/route/manager.go b/pkg/manager/resources/route/manager.go index 9efe8b43..cb1db6a2 100644 --- a/pkg/manager/resources/route/manager.go +++ b/pkg/manager/resources/route/manager.go @@ -129,11 +129,8 @@ func (m *Manager) Get(instance v1.Object) (client.Object, error) { func (m *Manager) Exists(instance v1.Object) bool { _, err := m.Get(instance) - if err != nil { - return false - } - return true + return err == nil } func (m *Manager) Delete(instance v1.Object) error { @@ -178,5 +175,5 @@ func GetName(instance v1.Object, suffix ...string) string { return fmt.Sprintf("%s-%s", instance.GetName(), suffix[0]) } } - return fmt.Sprintf("%s", instance.GetName()) + return instance.GetName() } diff --git a/pkg/manager/resources/service/manager.go b/pkg/manager/resources/service/manager.go index bbc9ce70..59bc4a37 100644 --- a/pkg/manager/resources/service/manager.go +++ b/pkg/manager/resources/service/manager.go @@ -129,11 +129,7 @@ func (m *Manager) Get(instance v1.Object) (client.Object, error) { func (m *Manager) Exists(instance v1.Object) bool { _, err := m.Get(instance) - if err != nil { - return false - } - - return true + return err == nil } func (m *Manager) Delete(instance v1.Object) error { @@ -178,5 +174,5 @@ func GetName(instanceName string, suffix ...string) string { return fmt.Sprintf("%s%s", instanceName, suffix[0]) } } - return fmt.Sprintf("%s", instanceName) + return instanceName } diff --git a/pkg/manager/resources/serviceaccount/manager.go b/pkg/manager/resources/serviceaccount/manager.go index 11a19954..25cd9289 100644 --- a/pkg/manager/resources/serviceaccount/manager.go +++ b/pkg/manager/resources/serviceaccount/manager.go @@ -119,11 +119,8 @@ func (m *Manager) Get(instance v1.Object) (client.Object, error) { func (m *Manager) Exists(instance v1.Object) bool { _, err := m.Get(instance) - if err != nil { - return false - } - return true + return err == nil } func (m *Manager) Delete(instance v1.Object) error { @@ -168,5 +165,5 @@ func GetName(instanceName string, suffix ...string) string { return fmt.Sprintf("%s-%s", instanceName, suffix[0]) } } - return fmt.Sprintf("%s", instanceName) + return instanceName } diff --git a/pkg/migrator/peer/fabric/v2/peer.go b/pkg/migrator/peer/fabric/v2/peer.go index 67be710e..9deb01a5 100644 --- a/pkg/migrator/peer/fabric/v2/peer.go +++ b/pkg/migrator/peer/fabric/v2/peer.go @@ -136,7 +136,7 @@ func (m *Migrate) UpdateConfig(instance metav1.Object, version string) error { core.VM.Endpoint = "" core.Chaincode.ExternalBuilders = []v2peer.ExternalBuilder{ - v2peer.ExternalBuilder{ + { Name: "ibp-builder", Path: "/usr/local", EnvironmentWhiteList: []string{ diff --git a/pkg/migrator/peer/fabric/v2/peer_test.go b/pkg/migrator/peer/fabric/v2/peer_test.go index 239acd5f..5732ba48 100644 --- a/pkg/migrator/peer/fabric/v2/peer_test.go +++ b/pkg/migrator/peer/fabric/v2/peer_test.go @@ -109,7 +109,7 @@ var _ = Describe("V2 peer migrator", func() { configMapManager.GetCoreConfigReturns(&corev1.ConfigMap{ BinaryData: map[string][]byte{ - "core.yaml": []byte{}, + "core.yaml": {}, }, }, nil) @@ -163,10 +163,10 @@ var _ = Describe("V2 peer migrator", func() { if strings.Contains(opts[0].(*k8sclient.ListOptions).LabelSelector.String(), "job-name") { pods := obj.(*corev1.PodList) pods.Items = []corev1.Pod{ - corev1.Pod{ + { Status: corev1.PodStatus{ ContainerStatuses: []corev1.ContainerStatus{ - corev1.ContainerStatus{ + { State: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{}, }, @@ -319,7 +319,7 @@ var _ = Describe("V2 peer migrator", func() { switch obj.(type) { case *current.IBPConsoleList: list := obj.(*current.IBPConsoleList) - list.Items = []current.IBPConsole{current.IBPConsole{}} + list.Items = []current.IBPConsole{{}} } return nil diff --git a/pkg/offering/base/ca/initialize.go b/pkg/offering/base/ca/initialize.go index b9d6f1d0..ddeb2684 100644 --- a/pkg/offering/base/ca/initialize.go +++ b/pkg/offering/base/ca/initialize.go @@ -500,11 +500,8 @@ func (i *Initialize) SecretExists(instance *current.IBPCA, name string) bool { s := &corev1.Secret{} err := i.Client.Get(context.TODO(), n, s) - if err != nil { - return false - } - return true + return err == nil } func ConfigToBytes(c *cav1.ServerConfig) ([]byte, error) { diff --git a/pkg/offering/base/ca/override/deployment_test.go b/pkg/offering/base/ca/override/deployment_test.go index 4cc396ed..0af09400 100644 --- a/pkg/offering/base/ca/override/deployment_test.go +++ b/pkg/offering/base/ca/override/deployment_test.go @@ -64,7 +64,7 @@ var _ = Describe("Deployment Overrides", func() { Type: "hsm", Version: "v1", MountPaths: []config.MountPath{ - config.MountPath{ + { Name: "hsmcrypto", Secret: "hsmcrypto", MountPath: "/hsm", @@ -87,7 +87,7 @@ var _ = Describe("Deployment Overrides", func() { }, }, }, - config.MountPath{ + { Name: "hsmconfig", Secret: "hsmcrypto", MountPath: "/etc/Chrystoki.conf", @@ -194,33 +194,33 @@ var _ = Describe("Deployment Overrides", func() { NodeAffinity: &corev1.NodeAffinity{ RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{ NodeSelectorTerms: []corev1.NodeSelectorTerm{ - corev1.NodeSelectorTerm{ + { MatchExpressions: []corev1.NodeSelectorRequirement{ - corev1.NodeSelectorRequirement{ + { Key: "kubernetes.io/arch", Operator: corev1.NodeSelectorOpIn, Values: instance.Spec.Arch, }, - corev1.NodeSelectorRequirement{ + { Key: "topology.kubernetes.io/zone", Operator: corev1.NodeSelectorOpIn, Values: []string{instance.Spec.Zone}, }, - corev1.NodeSelectorRequirement{ + { Key: "topology.kubernetes.io/region", Operator: corev1.NodeSelectorOpIn, Values: []string{instance.Spec.Region}, }, }, }, - corev1.NodeSelectorTerm{ + { MatchExpressions: []corev1.NodeSelectorRequirement{ - corev1.NodeSelectorRequirement{ + { Key: "failure-domain.beta.kubernetes.io/zone", Operator: corev1.NodeSelectorOpIn, Values: []string{instance.Spec.Zone}, }, - corev1.NodeSelectorRequirement{ + { Key: "failure-domain.beta.kubernetes.io/region", Operator: corev1.NodeSelectorOpIn, Values: []string{instance.Spec.Region}, @@ -233,12 +233,12 @@ var _ = Describe("Deployment Overrides", func() { } affinity.PodAntiAffinity = &corev1.PodAntiAffinity{ PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{ - corev1.WeightedPodAffinityTerm{ + { Weight: 100, PodAffinityTerm: corev1.PodAffinityTerm{ LabelSelector: &metav1.LabelSelector{ MatchExpressions: []metav1.LabelSelectorRequirement{ - metav1.LabelSelectorRequirement{ + { Key: "app", Operator: metav1.LabelSelectorOpIn, Values: []string{instance.Name}, @@ -248,12 +248,12 @@ var _ = Describe("Deployment Overrides", func() { TopologyKey: "topology.kubernetes.io/zone", }, }, - corev1.WeightedPodAffinityTerm{ + { Weight: 100, PodAffinityTerm: corev1.PodAffinityTerm{ LabelSelector: &metav1.LabelSelector{ MatchExpressions: []metav1.LabelSelectorRequirement{ - metav1.LabelSelectorRequirement{ + { Key: "app", Operator: metav1.LabelSelectorOpIn, Values: []string{instance.Name}, diff --git a/pkg/offering/base/ca/override/override.go b/pkg/offering/base/ca/override/override.go index a91f5a5f..7835bd85 100644 --- a/pkg/offering/base/ca/override/override.go +++ b/pkg/offering/base/ca/override/override.go @@ -83,10 +83,10 @@ func (o *Override) GetNodeAffinity(instance *current.IBPCA) *corev1.NodeAffinity region := instance.Spec.Region nodeSelectorTerms := []corev1.NodeSelectorTerm{ - corev1.NodeSelectorTerm{ + { MatchExpressions: []corev1.NodeSelectorRequirement{}, }, - corev1.NodeSelectorTerm{ + { MatchExpressions: []corev1.NodeSelectorRequirement{}, }, } @@ -111,12 +111,12 @@ func (o *Override) GetNodeAffinity(instance *current.IBPCA) *corev1.NodeAffinity func (o *Override) GetPodAntiAffinity(instance *current.IBPCA) *corev1.PodAntiAffinity { antiaffinity := &corev1.PodAntiAffinity{ PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{ - corev1.WeightedPodAffinityTerm{ + { Weight: 100, PodAffinityTerm: corev1.PodAffinityTerm{ LabelSelector: &metav1.LabelSelector{ MatchExpressions: []metav1.LabelSelectorRequirement{ - metav1.LabelSelectorRequirement{ + { Key: "app", Operator: metav1.LabelSelectorOpIn, Values: []string{instance.GetName()}, @@ -126,12 +126,12 @@ func (o *Override) GetPodAntiAffinity(instance *current.IBPCA) *corev1.PodAntiAf TopologyKey: "topology.kubernetes.io/zone", }, }, - corev1.WeightedPodAffinityTerm{ + { Weight: 100, PodAffinityTerm: corev1.PodAffinityTerm{ LabelSelector: &metav1.LabelSelector{ MatchExpressions: []metav1.LabelSelectorRequirement{ - metav1.LabelSelectorRequirement{ + { Key: "app", Operator: metav1.LabelSelectorOpIn, Values: []string{instance.GetName()}, @@ -150,7 +150,7 @@ func (o *Override) GetPodAntiAffinity(instance *current.IBPCA) *corev1.PodAntiAf PodAffinityTerm: corev1.PodAffinityTerm{ LabelSelector: &metav1.LabelSelector{ MatchExpressions: []metav1.LabelSelectorRequirement{ - metav1.LabelSelectorRequirement{ + { Key: "app", Operator: metav1.LabelSelectorOpIn, Values: []string{instance.GetName()}, diff --git a/pkg/offering/base/console/override/deployercm_test.go b/pkg/offering/base/console/override/deployercm_test.go index a261b082..516d93cd 100644 --- a/pkg/offering/base/console/override/deployercm_test.go +++ b/pkg/offering/base/console/override/deployercm_test.go @@ -56,7 +56,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, Versions: ¤t.Versions{ CA: map[string]current.VersionCA{ - "v1-0": current.VersionCA{ + "v1-0": { Default: true, Version: "v1-0", Image: current.CAImages{ @@ -66,7 +66,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { CATag: "1.0.0", }, }, - "v2-0": current.VersionCA{ + "v2-0": { Default: false, Version: "v2-0", Image: current.CAImages{ @@ -78,7 +78,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, }, Peer: map[string]current.VersionPeer{ - "v1-0": current.VersionPeer{ + "v1-0": { Default: true, Version: "v1-0", Image: current.PeerImages{ @@ -96,7 +96,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { CouchDBTag: "1.0.0", }, }, - "v2-0": current.VersionPeer{ + "v2-0": { Default: false, Version: "v2-0", Image: current.PeerImages{ @@ -118,7 +118,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, }, Orderer: map[string]current.VersionOrderer{ - "v1-0": current.VersionOrderer{ + "v1-0": { Default: true, Version: "v1-0", Image: current.OrdererImages{ @@ -130,7 +130,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { GRPCWebTag: "1.0.0", }, }, - "v2-0": current.VersionOrderer{ + "v2-0": { Default: false, Version: "v2-0", Image: current.OrdererImages{ @@ -208,7 +208,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { By("setting versions", func() { expectedVersions := ¤t.Versions{ CA: map[string]current.VersionCA{ - "v1-0": current.VersionCA{ + "v1-0": { Default: true, Version: "v1-0", Image: current.CAImages{ @@ -218,7 +218,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { CATag: "1.0.0", }, }, - "v2-0": current.VersionCA{ + "v2-0": { Default: false, Version: "v2-0", Image: current.CAImages{ @@ -230,7 +230,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, }, Peer: map[string]current.VersionPeer{ - "v1-0": current.VersionPeer{ + "v1-0": { Default: true, Version: "v1-0", Image: current.PeerImages{ @@ -248,7 +248,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { CouchDBTag: "1.0.0", }, }, - "v2-0": current.VersionPeer{ + "v2-0": { Default: false, Version: "v2-0", Image: current.PeerImages{ @@ -270,7 +270,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, }, Orderer: map[string]current.VersionOrderer{ - "v1-0": current.VersionOrderer{ + "v1-0": { Default: true, Version: "v1-0", Image: current.OrdererImages{ @@ -282,7 +282,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { GRPCWebTag: "1.0.0", }, }, - "v2-0": current.VersionOrderer{ + "v2-0": { Default: false, Version: "v2-0", Image: current.OrdererImages{ @@ -355,7 +355,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, Versions: ¤t.Versions{ CA: map[string]current.VersionCA{ - "v1-0": current.VersionCA{ + "v1-0": { Image: current.CAImages{ CAInitImage: "ghcr.io/ibm-blockchain/ca-init-image", CAInitTag: "1.0.0", @@ -365,7 +365,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, }, Peer: map[string]current.VersionPeer{ - "v1-0": current.VersionPeer{ + "v1-0": { Image: current.PeerImages{ PeerInitImage: "ghcr.io/ibm-blockchain/peer-init-image", PeerInitTag: "1.0.0", @@ -383,7 +383,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, }, Orderer: map[string]current.VersionOrderer{ - "v1-0": current.VersionOrderer{ + "v1-0": { Image: current.OrdererImages{ OrdererInitImage: "ghcr.io/ibm-blockchain/orderer-init-image", OrdererInitTag: "1.0.0", @@ -402,7 +402,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { It("keeps images as passed", func() { expectedVersions := ¤t.Versions{ CA: map[string]current.VersionCA{ - "v1-0": current.VersionCA{ + "v1-0": { Image: current.CAImages{ CAInitImage: "ghcr.io/ibm-blockchain/ca-init-image", CAInitTag: "1.0.0-amd64", @@ -412,7 +412,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, }, Peer: map[string]current.VersionPeer{ - "v1-0": current.VersionPeer{ + "v1-0": { Image: current.PeerImages{ PeerInitImage: "ghcr.io/ibm-blockchain/peer-init-image", PeerInitTag: "1.0.0-amd64", @@ -430,7 +430,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, }, Orderer: map[string]current.VersionOrderer{ - "v1-0": current.VersionOrderer{ + "v1-0": { Image: current.OrdererImages{ OrdererInitImage: "ghcr.io/ibm-blockchain/orderer-init-image", OrdererInitTag: "1.0.0-amd64", @@ -444,7 +444,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { } versions := &deployer.Versions{ CA: map[string]deployer.VersionCA{ - "1.4": deployer.VersionCA{ + "1.4": { Image: deployer.CAImages{ CAInitImage: "ca-init-image", CAInitTag: "1.0.0", @@ -456,7 +456,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, }, Peer: map[string]deployer.VersionPeer{ - "1.4": deployer.VersionPeer{ + "1.4": { Image: deployer.PeerImages{ PeerInitImage: "peer-init-image", PeerInitTag: "1.0.0", @@ -480,7 +480,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, }, Orderer: map[string]deployer.VersionOrderer{ - "1.4": deployer.VersionOrderer{ + "1.4": { Image: deployer.OrdererImages{ OrdererInitImage: "orderer-init-image", OrdererInitTag: "1.0.0", @@ -554,7 +554,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { RegistryURL: "ghcr.io/ibm-blockchain/", Versions: ¤t.Versions{ CA: map[string]current.VersionCA{ - "v1-0": current.VersionCA{ + "v1-0": { Image: current.CAImages{ CAInitImage: "ca-init-image", CAInitTag: "1.0.0", @@ -564,7 +564,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, }, Peer: map[string]current.VersionPeer{ - "v1-0": current.VersionPeer{ + "v1-0": { Image: current.PeerImages{ PeerInitImage: "peer-init-image", PeerInitTag: "1.0.0", @@ -582,7 +582,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, }, Orderer: map[string]current.VersionOrderer{ - "v1-0": current.VersionOrderer{ + "v1-0": { Image: current.OrdererImages{ OrdererInitImage: "orderer-init-image", OrdererInitTag: "1.0.0", @@ -601,7 +601,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { It("prepends registry url to images", func() { expectedVersions := ¤t.Versions{ CA: map[string]current.VersionCA{ - "v1-0": current.VersionCA{ + "v1-0": { Image: current.CAImages{ CAInitImage: "ghcr.io/ibm-blockchain/ca-init-image", CAInitTag: "1.0.0-amd64", @@ -611,7 +611,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, }, Peer: map[string]current.VersionPeer{ - "v1-0": current.VersionPeer{ + "v1-0": { Image: current.PeerImages{ PeerInitImage: "ghcr.io/ibm-blockchain/peer-init-image", PeerInitTag: "1.0.0-amd64", @@ -629,7 +629,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, }, Orderer: map[string]current.VersionOrderer{ - "v1-0": current.VersionOrderer{ + "v1-0": { Image: current.OrdererImages{ OrdererInitImage: "ghcr.io/ibm-blockchain/orderer-init-image", OrdererInitTag: "1.0.0-amd64", @@ -643,7 +643,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { } versions := &deployer.Versions{ CA: map[string]deployer.VersionCA{ - "1.4": deployer.VersionCA{ + "1.4": { Image: deployer.CAImages{ CAInitImage: "ca-init-image", CAInitTag: "1.0.0", @@ -655,7 +655,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, }, Peer: map[string]deployer.VersionPeer{ - "1.4": deployer.VersionPeer{ + "1.4": { Image: deployer.PeerImages{ PeerInitImage: "peer-init-image", PeerInitTag: "1.0.0", @@ -679,7 +679,7 @@ var _ = Describe("Base Console Deployer Config Map Overrides", func() { }, }, Orderer: map[string]deployer.VersionOrderer{ - "1.4": deployer.VersionOrderer{ + "1.4": { Image: deployer.OrdererImages{ OrdererInitImage: "orderer-init-image", OrdererInitTag: "1.0.0", diff --git a/pkg/offering/base/console/override/deployment.go b/pkg/offering/base/console/override/deployment.go index 1156de8d..2c1dab8c 100644 --- a/pkg/offering/base/console/override/deployment.go +++ b/pkg/offering/base/console/override/deployment.go @@ -351,7 +351,7 @@ func (o *Override) CreateCouchdbContainer() container.Container { Image: "", ImagePullPolicy: "Always", Env: []corev1.EnvVar{ - corev1.EnvVar{ + { Name: "LICENSE", Value: "accept", }, @@ -368,7 +368,7 @@ func (o *Override) CreateCouchdbContainer() container.Container { }, }, Ports: []corev1.ContainerPort{ - corev1.ContainerPort{ + { Name: "http", ContainerPort: 5984, }, diff --git a/pkg/offering/base/console/override/deployment_test.go b/pkg/offering/base/console/override/deployment_test.go index d1caf41d..fb0cdc2a 100644 --- a/pkg/offering/base/console/override/deployment_test.go +++ b/pkg/offering/base/console/override/deployment_test.go @@ -160,7 +160,7 @@ var _ = Describe("Base Console Deployment Overrides", func() { By("image pull secret", func() { Expect(deployment.Spec.Template.Spec.ImagePullSecrets).To(Equal([]corev1.LocalObjectReference{ - corev1.LocalObjectReference{ + { Name: instanceWithTags.Spec.ImagePullSecrets[0], }, })) diff --git a/pkg/offering/base/orderer/node.go b/pkg/offering/base/orderer/node.go index 623de0bb..004ac824 100644 --- a/pkg/offering/base/orderer/node.go +++ b/pkg/offering/base/orderer/node.go @@ -39,7 +39,7 @@ import ( v2ordererconfig "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/orderer/config/v2" v24ordererconfig "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/orderer/config/v24" "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/validator" - controllerclient "github.com/IBM-Blockchain/fabric-operator/pkg/k8s/controllerclient" + "github.com/IBM-Blockchain/fabric-operator/pkg/k8s/controllerclient" "github.com/IBM-Blockchain/fabric-operator/pkg/manager/resources" resourcemanager "github.com/IBM-Blockchain/fabric-operator/pkg/manager/resources/manager" "github.com/IBM-Blockchain/fabric-operator/pkg/offering/base/orderer/override" @@ -629,11 +629,8 @@ func (n *Node) ConfigExists(instance *current.IBPOrderer) bool { cm := &corev1.ConfigMap{} err := n.Client.Get(context.TODO(), namespacedName, cm) - if err != nil { - return false - } - return true + return err == nil } func (n *Node) InitializeUpdateConfigOverride(instance *current.IBPOrderer, initOrderer *initializer.Orderer) error { @@ -819,7 +816,7 @@ func (n *Node) GetLabels(instance v1.Object) map[string]string { return map[string]string{ "app": instance.GetName(), "creator": label, - "orderingservice": fmt.Sprintf("%s", instance.GetName()), + "orderingservice": instance.GetName(), "app.kubernetes.io/name": label, "app.kubernetes.io/instance": label + "orderer", "app.kubernetes.io/managed-by": label + "-operator", @@ -827,7 +824,7 @@ func (n *Node) GetLabels(instance v1.Object) map[string]string { } func (n *Node) Delete(instance *current.IBPOrderer) error { - log.Info(fmt.Sprintf("Deleting node '%s'", n.Name)) + log.Info("Deleting node '%s'", n.Name) err := n.ServiceManager.Delete(instance) if err != nil { return errors.Wrapf(err, "failed to delete service '%s'", n.ServiceManager.GetName(instance)) diff --git a/pkg/offering/base/orderer/orderer.go b/pkg/offering/base/orderer/orderer.go index fae32ae3..b1da65ef 100644 --- a/pkg/offering/base/orderer/orderer.go +++ b/pkg/offering/base/orderer/orderer.go @@ -183,9 +183,8 @@ func (o *Orderer) Initialize(instance *current.IBPOrderer, update Update) error } func (o *Orderer) ReconcileManagers(instance *current.IBPOrderer, update Update, genesisBlock []byte) error { - var b64GenesisBlock string - b64GenesisBlock = util.BytesToBase64(genesisBlock) + b64GenesisBlock := util.BytesToBase64(genesisBlock) for k := 0; k < instance.Spec.ClusterSize; k++ { nodenumber := k + 1 diff --git a/pkg/offering/base/orderer/override/deployment.go b/pkg/offering/base/orderer/override/deployment.go index 266d1c57..9edb77e4 100644 --- a/pkg/offering/base/orderer/override/deployment.go +++ b/pkg/offering/base/orderer/override/deployment.go @@ -325,11 +325,8 @@ func (o *Override) AdminSecretExists(instance *current.IBPOrderer) bool { err := o.Client.Get(context.TODO(), types.NamespacedName{ Name: fmt.Sprintf("ecert-%s-admincerts", instance.Name), Namespace: instance.Namespace}, secret) - if err != nil { - return false - } - return true + return err == nil } func hsmInitContainer(instance *current.IBPOrderer, hsmConfig *config.HSMConfig) *container.Container { @@ -354,7 +351,7 @@ func hsmInitContainer(instance *current.IBPOrderer, hsmConfig *config.HSMConfig) RunAsNonRoot: &f, }, VolumeMounts: []corev1.VolumeMount{ - corev1.VolumeMount{ + { Name: "shared", MountPath: mountPath, }, diff --git a/pkg/offering/base/orderer/override/deployment_test.go b/pkg/offering/base/orderer/override/deployment_test.go index 4980503b..9c26f5c3 100644 --- a/pkg/offering/base/orderer/override/deployment_test.go +++ b/pkg/offering/base/orderer/override/deployment_test.go @@ -70,7 +70,7 @@ var _ = Describe("Base Orderer Deployment Overrides", func() { Type: "hsm", Version: "v1", MountPaths: []config.MountPath{ - config.MountPath{ + { Name: "hsmcrypto", Secret: "hsmcrypto", MountPath: "/hsm", @@ -93,7 +93,7 @@ var _ = Describe("Base Orderer Deployment Overrides", func() { }, }, }, - config.MountPath{ + { Name: "hsmconfig", Secret: "hsmcrypto", MountPath: "/etc/Chrystoki.conf", @@ -231,7 +231,7 @@ var _ = Describe("Base Orderer Deployment Overrides", func() { Expect(err).NotTo(HaveOccurred()) By("setting pull secret", func() { - Expect(deployment.Spec.Template.Spec.ImagePullSecrets).To(Equal([]corev1.LocalObjectReference{corev1.LocalObjectReference{ + Expect(deployment.Spec.Template.Spec.ImagePullSecrets).To(Equal([]corev1.LocalObjectReference{{ Name: instance.Spec.ImagePullSecrets[0], }})) }) diff --git a/pkg/offering/base/orderer/override/override_test.go b/pkg/offering/base/orderer/override/override_test.go index aeb92dc4..82fb3c75 100644 --- a/pkg/offering/base/orderer/override/override_test.go +++ b/pkg/offering/base/orderer/override/override_test.go @@ -106,11 +106,11 @@ var _ = Describe("K8S Orderer Overrides", func() { ClusterSize: 2, NodeNumber: &nodenum, ClusterLocation: []current.IBPOrdererClusterLocation{ - current.IBPOrdererClusterLocation{ + { Zone: "dal1", Region: "us-south1", }, - current.IBPOrdererClusterLocation{ + { Zone: "dal2", Region: "us-south2", }, diff --git a/pkg/offering/base/peer/override/deployment.go b/pkg/offering/base/peer/override/deployment.go index ab6233e9..709e1d15 100644 --- a/pkg/offering/base/peer/override/deployment.go +++ b/pkg/offering/base/peer/override/deployment.go @@ -176,7 +176,7 @@ func (o *Override) CreateDeployment(instance *current.IBPPeer, k8sDep *appsv1.De var certsData string count := 0 - for key, _ := range tlsCACertsSecret.Data { + for key := range tlsCACertsSecret.Data { v := fmt.Sprintf("/certs/msp/tlscacerts/%s", key) if count == 0 { certsData = certsData + v @@ -200,7 +200,7 @@ func (o *Override) CreateDeployment(instance *current.IBPPeer, k8sDep *appsv1.De var certsData string count := 0 - for key, _ := range tlsCAInterCertsSecret.Data { + for key := range tlsCAInterCertsSecret.Data { v := fmt.Sprintf("/certs/msp/tlsintermediatecerts/%s", key) if count == 0 { certsData = certsData + v @@ -821,22 +821,16 @@ func (o *Override) AdminSecretExists(instance *current.IBPPeer) bool { err := o.Client.Get(context.TODO(), types.NamespacedName{ Name: fmt.Sprintf("ecert-%s-admincerts", instance.Name), Namespace: instance.Namespace}, secret) - if err != nil { - return false - } - return true + return err == nil } func (o *Override) OrdererCACertsSecretExists(instance *current.IBPPeer) bool { err := o.Client.Get(context.TODO(), types.NamespacedName{ Name: fmt.Sprintf("%s-orderercacerts", instance.Name), Namespace: instance.Namespace}, &corev1.Secret{}) - if err != nil { - return false - } - return true + return err == nil } func (o *Override) GetTLSCACertsSecret(instance *current.IBPPeer, secretName string) (*corev1.Secret, error) { @@ -872,7 +866,7 @@ func hsmInitContainer(instance *current.IBPPeer, hsmConfig *config.HSMConfig) *c RunAsNonRoot: &f, }, VolumeMounts: []corev1.VolumeMount{ - corev1.VolumeMount{ + { Name: "shared", MountPath: mountPath, }, diff --git a/pkg/offering/base/peer/override/deployment_test.go b/pkg/offering/base/peer/override/deployment_test.go index b7762457..46622e44 100644 --- a/pkg/offering/base/peer/override/deployment_test.go +++ b/pkg/offering/base/peer/override/deployment_test.go @@ -80,7 +80,7 @@ var _ = Describe("Base Peer Deployment Overrides", func() { Type: "hsm", Version: "v1", MountPaths: []config.MountPath{ - config.MountPath{ + { Name: "hsmcrypto", Secret: "hsmcrypto", MountPath: "/hsm", @@ -103,7 +103,7 @@ var _ = Describe("Base Peer Deployment Overrides", func() { }, }, }, - config.MountPath{ + { Name: "hsmconfig", Secret: "hsmcrypto", MountPath: "/etc/Chrystoki.conf", @@ -653,9 +653,8 @@ var _ = Describe("Base Peer Deployment Overrides", func() { Context("update", func() { BeforeEach(func() { - var err error - err = overrider.CreateCouchDBContainers(instance, deployment) + err := overrider.CreateCouchDBContainers(instance, deployment) Expect(err).NotTo(HaveOccurred()) }) diff --git a/pkg/offering/base/peer/peer.go b/pkg/offering/base/peer/peer.go index dbc8be50..7929eeef 100644 --- a/pkg/offering/base/peer/peer.go +++ b/pkg/offering/base/peer/peer.go @@ -38,7 +38,7 @@ import ( initializer "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/peer" peerconfig "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/peer/config/v1" "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/validator" - controllerclient "github.com/IBM-Blockchain/fabric-operator/pkg/k8s/controllerclient" + "github.com/IBM-Blockchain/fabric-operator/pkg/k8s/controllerclient" "github.com/IBM-Blockchain/fabric-operator/pkg/manager/resources" jobv1 "github.com/IBM-Blockchain/fabric-operator/pkg/manager/resources/job" resourcemanager "github.com/IBM-Blockchain/fabric-operator/pkg/manager/resources/manager" @@ -1077,11 +1077,8 @@ func (p *Peer) ConfigExists(instance *current.IBPPeer) bool { cm := &corev1.ConfigMap{} err := p.Client.Get(context.TODO(), namespacedName, cm) - if err != nil { - return false - } - return true + return err == nil } func (p *Peer) CheckCSRHosts(instance *current.IBPPeer, hosts []string) bool { diff --git a/pkg/offering/common/override.go b/pkg/offering/common/override.go index 29a4e941..318ed330 100644 --- a/pkg/offering/common/override.go +++ b/pkg/offering/common/override.go @@ -25,10 +25,10 @@ import ( func GetNodeSelectorTerms(arch []string, zone, region string) []corev1.NodeSelectorTerm { nodeSelectorTerms := []corev1.NodeSelectorTerm{ - corev1.NodeSelectorTerm{ + { MatchExpressions: []corev1.NodeSelectorRequirement{}, }, - corev1.NodeSelectorTerm{ + { MatchExpressions: []corev1.NodeSelectorRequirement{}, }, } @@ -88,12 +88,12 @@ func AddRegionSelector(region string, nodeSelectorTerms *[]corev1.NodeSelectorTe func GetPodAntiAffinity(orgName string) *corev1.PodAntiAffinity { return &corev1.PodAntiAffinity{ PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{ - corev1.WeightedPodAffinityTerm{ + { Weight: 100, PodAffinityTerm: corev1.PodAffinityTerm{ LabelSelector: &metav1.LabelSelector{ MatchExpressions: []metav1.LabelSelectorRequirement{ - metav1.LabelSelectorRequirement{ + { Key: "orgname", Operator: metav1.LabelSelectorOpIn, Values: []string{orgName}, diff --git a/pkg/offering/common/reconcilechecks/fabricversion.go b/pkg/offering/common/reconcilechecks/fabricversion.go index 8816e5bf..4c2b3fef 100644 --- a/pkg/offering/common/reconcilechecks/fabricversion.go +++ b/pkg/offering/common/reconcilechecks/fabricversion.go @@ -67,6 +67,7 @@ func FabricVersionHelper(instance Instance, versions *deployer.Versions, update } //go:generate counterfeiter -o mocks/image.go -fake-name Image . Image + // Image defines the contract with the image checks type Image interface { UpdateRequired(images.Update) bool @@ -74,6 +75,7 @@ type Image interface { } //go:generate counterfeiter -o mocks/version.go -fake-name Version . Version + // Version defines the contract with the version checks type Version interface { Normalize(images.FabricVersionInstance) string diff --git a/pkg/offering/common/secret.go b/pkg/offering/common/secret.go index 3aea14e4..d746d6c1 100644 --- a/pkg/offering/common/secret.go +++ b/pkg/offering/common/secret.go @@ -130,7 +130,7 @@ func getCACertBytes(prefix common.SecretType, client k8sclient.Client, instance } if secret.Data == nil || len(secret.Data) == 0 { - return nil, errors.New(fmt.Sprintf("%s cacert secret is blank", prefix)) + return nil, fmt.Errorf("%s cacert secret is blank", prefix) } var certs [][]byte diff --git a/pkg/offering/k8s/ca/override/ingress.go b/pkg/offering/k8s/ca/override/ingress.go index 067b47c0..98caebe5 100644 --- a/pkg/offering/k8s/ca/override/ingress.go +++ b/pkg/offering/k8s/ca/override/ingress.go @@ -60,12 +60,12 @@ func (o *Override) CommonIngress(instance *current.IBPCA, ingress *networkingv1. pathType := networkingv1.PathTypeImplementationSpecific ingress.Spec = networkingv1.IngressSpec{ Rules: []networkingv1.IngressRule{ - networkingv1.IngressRule{ + { Host: apihost, IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), @@ -81,12 +81,12 @@ func (o *Override) CommonIngress(instance *current.IBPCA, ingress *networkingv1. }, }, }, - networkingv1.IngressRule{ + { Host: operationshost, IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), @@ -104,10 +104,10 @@ func (o *Override) CommonIngress(instance *current.IBPCA, ingress *networkingv1. }, }, TLS: []networkingv1.IngressTLS{ - networkingv1.IngressTLS{ + { Hosts: []string{apihost}, }, - networkingv1.IngressTLS{ + { Hosts: []string{operationshost}, }, }, diff --git a/pkg/offering/k8s/ca/override/ingress_test.go b/pkg/offering/k8s/ca/override/ingress_test.go index d631d7a2..8c646d64 100644 --- a/pkg/offering/k8s/ca/override/ingress_test.go +++ b/pkg/offering/k8s/ca/override/ingress_test.go @@ -66,7 +66,7 @@ var _ = Describe("K8s CA Ingress Overrides", func() { IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), @@ -87,7 +87,7 @@ var _ = Describe("K8s CA Ingress Overrides", func() { IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), diff --git a/pkg/offering/k8s/ca/override/ingressv1beta1.go b/pkg/offering/k8s/ca/override/ingressv1beta1.go index bbe4d422..5f70e8d8 100644 --- a/pkg/offering/k8s/ca/override/ingressv1beta1.go +++ b/pkg/offering/k8s/ca/override/ingressv1beta1.go @@ -60,12 +60,12 @@ func (o *Override) CommonIngressv1beta1(instance *current.IBPCA, ingress *networ ingress.Spec = networkingv1beta1.IngressSpec{ Rules: []networkingv1beta1.IngressRule{ - networkingv1beta1.IngressRule{ + { Host: apihost, IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("http"), @@ -76,12 +76,12 @@ func (o *Override) CommonIngressv1beta1(instance *current.IBPCA, ingress *networ }, }, }, - networkingv1beta1.IngressRule{ + { Host: operationshost, IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("operations"), @@ -94,10 +94,10 @@ func (o *Override) CommonIngressv1beta1(instance *current.IBPCA, ingress *networ }, }, TLS: []networkingv1beta1.IngressTLS{ - networkingv1beta1.IngressTLS{ + { Hosts: []string{apihost}, }, - networkingv1beta1.IngressTLS{ + { Hosts: []string{operationshost}, }, }, diff --git a/pkg/offering/k8s/ca/override/ingressv1beta1_test.go b/pkg/offering/k8s/ca/override/ingressv1beta1_test.go index e9f3f413..22f15c51 100644 --- a/pkg/offering/k8s/ca/override/ingressv1beta1_test.go +++ b/pkg/offering/k8s/ca/override/ingressv1beta1_test.go @@ -66,7 +66,7 @@ var _ = Describe("K8s CA Ingress Overrides", func() { IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("http"), @@ -82,7 +82,7 @@ var _ = Describe("K8s CA Ingress Overrides", func() { IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("operations"), diff --git a/pkg/offering/k8s/console/override/deployercm_test.go b/pkg/offering/k8s/console/override/deployercm_test.go index 1127960c..9b19a8d9 100644 --- a/pkg/offering/k8s/console/override/deployercm_test.go +++ b/pkg/offering/k8s/console/override/deployercm_test.go @@ -59,7 +59,7 @@ var _ = Describe("K8S Console Deployer Config Map Overrides", func() { }, Versions: ¤t.Versions{ CA: map[string]current.VersionCA{ - "1.4.6-1": current.VersionCA{ + "1.4.6-1": { Default: true, Version: "1.4.6-1", Image: current.CAImages{ @@ -71,7 +71,7 @@ var _ = Describe("K8S Console Deployer Config Map Overrides", func() { }, }, Peer: map[string]current.VersionPeer{ - "1.4.6-1": current.VersionPeer{ + "1.4.6-1": { Default: true, Version: "1.4.6-1", Image: current.PeerImages{ @@ -89,7 +89,7 @@ var _ = Describe("K8S Console Deployer Config Map Overrides", func() { CouchDBTag: "1.4.6", }, }, - "2.1.0-1": current.VersionPeer{ + "2.1.0-1": { Default: true, Version: "2.1.0-1", Image: current.PeerImages{ @@ -107,7 +107,7 @@ var _ = Describe("K8S Console Deployer Config Map Overrides", func() { }, }, Orderer: map[string]current.VersionOrderer{ - "1.4.6-1": current.VersionOrderer{ + "1.4.6-1": { Default: true, Version: "1.4.6-1", Image: current.OrdererImages{ @@ -185,7 +185,7 @@ var _ = Describe("K8S Console Deployer Config Map Overrides", func() { By("setting versions", func() { expectedVersions := ¤t.Versions{ CA: map[string]current.VersionCA{ - "1.4.6-1": current.VersionCA{ + "1.4.6-1": { Default: true, Version: "1.4.6-1", Image: current.CAImages{ @@ -197,7 +197,7 @@ var _ = Describe("K8S Console Deployer Config Map Overrides", func() { }, }, Peer: map[string]current.VersionPeer{ - "1.4.6-1": current.VersionPeer{ + "1.4.6-1": { Default: true, Version: "1.4.6-1", Image: current.PeerImages{ @@ -215,7 +215,7 @@ var _ = Describe("K8S Console Deployer Config Map Overrides", func() { CouchDBTag: "1.4.6", }, }, - "2.1.0-1": current.VersionPeer{ + "2.1.0-1": { Default: true, Version: "2.1.0-1", Image: current.PeerImages{ @@ -233,7 +233,7 @@ var _ = Describe("K8S Console Deployer Config Map Overrides", func() { }, }, Orderer: map[string]current.VersionOrderer{ - "1.4.6-1": current.VersionOrderer{ + "1.4.6-1": { Default: true, Version: "1.4.6-1", Image: current.OrdererImages{ diff --git a/pkg/offering/k8s/console/override/ingress.go b/pkg/offering/k8s/console/override/ingress.go index 34620789..4af7b01c 100644 --- a/pkg/offering/k8s/console/override/ingress.go +++ b/pkg/offering/k8s/console/override/ingress.go @@ -58,12 +58,12 @@ func (o *Override) CommonIngress(instance *current.IBPConsole, ingress *networki pathType := networkingv1.PathTypeImplementationSpecific ingress.Spec = networkingv1.IngressSpec{ Rules: []networkingv1.IngressRule{ - networkingv1.IngressRule{ + { Host: consolehost, IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), @@ -81,7 +81,7 @@ func (o *Override) CommonIngress(instance *current.IBPConsole, ingress *networki }, }, TLS: []networkingv1.IngressTLS{ - networkingv1.IngressTLS{ + { Hosts: []string{consolehost}, }, }, diff --git a/pkg/offering/k8s/console/override/ingress_test.go b/pkg/offering/k8s/console/override/ingress_test.go index b6266e39..89c97a94 100644 --- a/pkg/offering/k8s/console/override/ingress_test.go +++ b/pkg/offering/k8s/console/override/ingress_test.go @@ -66,7 +66,7 @@ var _ = Describe("K8s Console Ingress Overrides", func() { IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), diff --git a/pkg/offering/k8s/console/override/ingressv1beta1.go b/pkg/offering/k8s/console/override/ingressv1beta1.go index 14c38c24..e051aa70 100644 --- a/pkg/offering/k8s/console/override/ingressv1beta1.go +++ b/pkg/offering/k8s/console/override/ingressv1beta1.go @@ -58,12 +58,12 @@ func (o *Override) CommonIngressv1beta1(instance *current.IBPConsole, ingress *n ingress.Spec = networkingv1beta1.IngressSpec{ Rules: []networkingv1beta1.IngressRule{ - networkingv1beta1.IngressRule{ + { Host: consolehost, IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("optools"), @@ -76,7 +76,7 @@ func (o *Override) CommonIngressv1beta1(instance *current.IBPConsole, ingress *n }, }, TLS: []networkingv1beta1.IngressTLS{ - networkingv1beta1.IngressTLS{ + { Hosts: []string{consolehost}, }, }, diff --git a/pkg/offering/k8s/console/override/ingressv1beta1_test.go b/pkg/offering/k8s/console/override/ingressv1beta1_test.go index 09c2d264..c3a77831 100644 --- a/pkg/offering/k8s/console/override/ingressv1beta1_test.go +++ b/pkg/offering/k8s/console/override/ingressv1beta1_test.go @@ -66,7 +66,7 @@ var _ = Describe("K8s Console Ingress Overrides", func() { IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("optools"), diff --git a/pkg/offering/k8s/orderer/override/ingress.go b/pkg/offering/k8s/orderer/override/ingress.go index a790c249..48457dc8 100644 --- a/pkg/offering/k8s/orderer/override/ingress.go +++ b/pkg/offering/k8s/orderer/override/ingress.go @@ -62,12 +62,12 @@ func (o *Override) CommonIngress(instance *current.IBPOrderer, ingress *networki pathType := networkingv1.PathTypeImplementationSpecific ingress.Spec = networkingv1.IngressSpec{ Rules: []networkingv1.IngressRule{ - networkingv1.IngressRule{ + { Host: apihost, IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), @@ -83,12 +83,12 @@ func (o *Override) CommonIngress(instance *current.IBPOrderer, ingress *networki }, }, }, - networkingv1.IngressRule{ + { Host: operationshost, IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), @@ -104,12 +104,12 @@ func (o *Override) CommonIngress(instance *current.IBPOrderer, ingress *networki }, }, }, - networkingv1.IngressRule{ + { Host: grpcwebhost, IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), @@ -127,13 +127,13 @@ func (o *Override) CommonIngress(instance *current.IBPOrderer, ingress *networki }, }, TLS: []networkingv1.IngressTLS{ - networkingv1.IngressTLS{ + { Hosts: []string{apihost}, }, - networkingv1.IngressTLS{ + { Hosts: []string{operationshost}, }, - networkingv1.IngressTLS{ + { Hosts: []string{grpcwebhost}, }, }, @@ -142,12 +142,12 @@ func (o *Override) CommonIngress(instance *current.IBPOrderer, ingress *networki if currentVer.EqualWithoutTag(version.V2_4_1) || currentVer.GreaterThan(version.V2_4_1) { adminhost := instance.Namespace + "-" + instance.Name + "-admin" + "." + instance.Spec.Domain adminIngressRule := []networkingv1.IngressRule{ - networkingv1.IngressRule{ + { Host: adminhost, IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), @@ -166,7 +166,7 @@ func (o *Override) CommonIngress(instance *current.IBPOrderer, ingress *networki } admintls := []networkingv1.IngressTLS{ - networkingv1.IngressTLS{ + { Hosts: []string{adminhost}, }, } diff --git a/pkg/offering/k8s/orderer/override/ingress_test.go b/pkg/offering/k8s/orderer/override/ingress_test.go index 28b20dc2..1d699b16 100644 --- a/pkg/offering/k8s/orderer/override/ingress_test.go +++ b/pkg/offering/k8s/orderer/override/ingress_test.go @@ -68,7 +68,7 @@ var _ = Describe("K8s Orderer Ingress Overrides", func() { IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), @@ -89,7 +89,7 @@ var _ = Describe("K8s Orderer Ingress Overrides", func() { IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), @@ -110,7 +110,7 @@ var _ = Describe("K8s Orderer Ingress Overrides", func() { IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), diff --git a/pkg/offering/k8s/orderer/override/ingressv1beta1.go b/pkg/offering/k8s/orderer/override/ingressv1beta1.go index fdff959a..7ddd3efd 100644 --- a/pkg/offering/k8s/orderer/override/ingressv1beta1.go +++ b/pkg/offering/k8s/orderer/override/ingressv1beta1.go @@ -61,12 +61,12 @@ func (o *Override) CommonIngressv1beta1(instance *current.IBPOrderer, ingress *n ingress.Spec = networkingv1beta1.IngressSpec{ Rules: []networkingv1beta1.IngressRule{ - networkingv1beta1.IngressRule{ + { Host: apihost, IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("orderer-grpc"), @@ -77,12 +77,12 @@ func (o *Override) CommonIngressv1beta1(instance *current.IBPOrderer, ingress *n }, }, }, - networkingv1beta1.IngressRule{ + { Host: operationshost, IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("operations"), @@ -93,12 +93,12 @@ func (o *Override) CommonIngressv1beta1(instance *current.IBPOrderer, ingress *n }, }, }, - networkingv1beta1.IngressRule{ + { Host: grpcwebhost, IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("grpcweb"), @@ -111,13 +111,13 @@ func (o *Override) CommonIngressv1beta1(instance *current.IBPOrderer, ingress *n }, }, TLS: []networkingv1beta1.IngressTLS{ - networkingv1beta1.IngressTLS{ + { Hosts: []string{apihost}, }, - networkingv1beta1.IngressTLS{ + { Hosts: []string{operationshost}, }, - networkingv1beta1.IngressTLS{ + { Hosts: []string{grpcwebhost}, }, }, diff --git a/pkg/offering/k8s/orderer/override/ingressv1beta1_test.go b/pkg/offering/k8s/orderer/override/ingressv1beta1_test.go index 7c1411e2..33560976 100644 --- a/pkg/offering/k8s/orderer/override/ingressv1beta1_test.go +++ b/pkg/offering/k8s/orderer/override/ingressv1beta1_test.go @@ -68,7 +68,7 @@ var _ = Describe("K8s Orderer Ingress Overrides", func() { IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("orderer-grpc"), @@ -84,7 +84,7 @@ var _ = Describe("K8s Orderer Ingress Overrides", func() { IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("operations"), @@ -100,7 +100,7 @@ var _ = Describe("K8s Orderer Ingress Overrides", func() { IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("grpcweb"), diff --git a/pkg/offering/k8s/peer/override/ingress.go b/pkg/offering/k8s/peer/override/ingress.go index 357552e6..144de43b 100644 --- a/pkg/offering/k8s/peer/override/ingress.go +++ b/pkg/offering/k8s/peer/override/ingress.go @@ -60,12 +60,12 @@ func (o *Override) CommonIngress(instance *current.IBPPeer, ingress *networkingv pathType := networkingv1.PathTypeImplementationSpecific ingress.Spec = networkingv1.IngressSpec{ Rules: []networkingv1.IngressRule{ - networkingv1.IngressRule{ + { Host: apihost, IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), @@ -81,12 +81,12 @@ func (o *Override) CommonIngress(instance *current.IBPPeer, ingress *networkingv }, }, }, - networkingv1.IngressRule{ + { Host: operationshost, IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), @@ -102,12 +102,12 @@ func (o *Override) CommonIngress(instance *current.IBPPeer, ingress *networkingv }, }, }, - networkingv1.IngressRule{ + { Host: grpcwebhost, IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), @@ -125,13 +125,13 @@ func (o *Override) CommonIngress(instance *current.IBPPeer, ingress *networkingv }, }, TLS: []networkingv1.IngressTLS{ - networkingv1.IngressTLS{ + { Hosts: []string{apihost}, }, - networkingv1.IngressTLS{ + { Hosts: []string{operationshost}, }, - networkingv1.IngressTLS{ + { Hosts: []string{grpcwebhost}, }, }, diff --git a/pkg/offering/k8s/peer/override/ingress_test.go b/pkg/offering/k8s/peer/override/ingress_test.go index 26cb984c..6a0a3c8d 100644 --- a/pkg/offering/k8s/peer/override/ingress_test.go +++ b/pkg/offering/k8s/peer/override/ingress_test.go @@ -124,7 +124,7 @@ func VerifyIngressCommonOverrides(instance *current.IBPPeer, ingress *networking IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), @@ -145,7 +145,7 @@ func VerifyIngressCommonOverrides(instance *current.IBPPeer, ingress *networking IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), @@ -166,7 +166,7 @@ func VerifyIngressCommonOverrides(instance *current.IBPPeer, ingress *networking IngressRuleValue: networkingv1.IngressRuleValue{ HTTP: &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { Backend: networkingv1.IngressBackend{ Service: &networkingv1.IngressServiceBackend{ Name: instance.GetName(), diff --git a/pkg/offering/k8s/peer/override/ingressv1beta1.go b/pkg/offering/k8s/peer/override/ingressv1beta1.go index 99155c95..413f948a 100644 --- a/pkg/offering/k8s/peer/override/ingressv1beta1.go +++ b/pkg/offering/k8s/peer/override/ingressv1beta1.go @@ -60,12 +60,12 @@ func (o *Override) CommonIngressv1beta1(instance *current.IBPPeer, ingress *netw ingress.Spec = networkingv1beta1.IngressSpec{ Rules: []networkingv1beta1.IngressRule{ - networkingv1beta1.IngressRule{ + { Host: apihost, IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("peer-api"), @@ -76,12 +76,12 @@ func (o *Override) CommonIngressv1beta1(instance *current.IBPPeer, ingress *netw }, }, }, - networkingv1beta1.IngressRule{ + { Host: operationshost, IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("operations"), @@ -92,12 +92,12 @@ func (o *Override) CommonIngressv1beta1(instance *current.IBPPeer, ingress *netw }, }, }, - networkingv1beta1.IngressRule{ + { Host: grpcwebhost, IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("grpcweb"), @@ -110,13 +110,13 @@ func (o *Override) CommonIngressv1beta1(instance *current.IBPPeer, ingress *netw }, }, TLS: []networkingv1beta1.IngressTLS{ - networkingv1beta1.IngressTLS{ + { Hosts: []string{apihost}, }, - networkingv1beta1.IngressTLS{ + { Hosts: []string{operationshost}, }, - networkingv1beta1.IngressTLS{ + { Hosts: []string{grpcwebhost}, }, }, diff --git a/pkg/offering/k8s/peer/override/ingressv1beta1_test.go b/pkg/offering/k8s/peer/override/ingressv1beta1_test.go index ac14462d..4f02ff4a 100644 --- a/pkg/offering/k8s/peer/override/ingressv1beta1_test.go +++ b/pkg/offering/k8s/peer/override/ingressv1beta1_test.go @@ -124,7 +124,7 @@ func VerifyIngressCommonOverridesv1beta1(instance *current.IBPPeer, ingress *net IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("peer-api"), @@ -140,7 +140,7 @@ func VerifyIngressCommonOverridesv1beta1(instance *current.IBPPeer, ingress *net IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("operations"), @@ -156,7 +156,7 @@ func VerifyIngressCommonOverridesv1beta1(instance *current.IBPPeer, ingress *net IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ Paths: []networkingv1beta1.HTTPIngressPath{ - networkingv1beta1.HTTPIngressPath{ + { Backend: networkingv1beta1.IngressBackend{ ServiceName: instance.GetName(), ServicePort: intstr.FromString("grpcweb"), diff --git a/pkg/offering/k8s/peer/peer.go b/pkg/offering/k8s/peer/peer.go index 40ae583b..dbda9450 100644 --- a/pkg/offering/k8s/peer/peer.go +++ b/pkg/offering/k8s/peer/peer.go @@ -162,7 +162,7 @@ func (p *Peer) Reconcile(instance *current.IBPPeer, update basepeer.Update) (com "job-name": fmt.Sprintf("%s-dbmigration", instance.GetName()), }, instance) if jobRunning { - log.Info(fmt.Sprintf("Requeuing request until job completes")) + log.Info("Requeuing request until job completes") return common.Result{ Result: reconcile.Result{ Requeue: true, diff --git a/pkg/offering/offering.go b/pkg/offering/offering.go index bdd75265..b049d725 100644 --- a/pkg/offering/offering.go +++ b/pkg/offering/offering.go @@ -19,7 +19,6 @@ package offering import ( - "errors" "fmt" "strings" ) @@ -42,5 +41,5 @@ func GetType(oType string) (Type, error) { case "k8s": return K8S, nil } - return "", errors.New(fmt.Sprintf("Cluster Type %s not supported", oType)) + return "", fmt.Errorf("Cluster Type %s not supported", oType) } diff --git a/pkg/offering/openshift/console/override/deployercm_test.go b/pkg/offering/openshift/console/override/deployercm_test.go index 51ddfc20..17f27a6b 100644 --- a/pkg/offering/openshift/console/override/deployercm_test.go +++ b/pkg/offering/openshift/console/override/deployercm_test.go @@ -56,7 +56,7 @@ var _ = Describe("Openshift Console Deployer Config Map Overrides", func() { }, Versions: ¤t.Versions{ CA: map[string]current.VersionCA{ - "1.4.6-1": current.VersionCA{ + "1.4.6-1": { Default: true, Version: "1.4.6-1", Image: current.CAImages{ @@ -68,7 +68,7 @@ var _ = Describe("Openshift Console Deployer Config Map Overrides", func() { }, }, Peer: map[string]current.VersionPeer{ - "1.4.6-1": current.VersionPeer{ + "1.4.6-1": { Default: true, Version: "1.4.6-1", Image: current.PeerImages{ @@ -90,7 +90,7 @@ var _ = Describe("Openshift Console Deployer Config Map Overrides", func() { }, }, Orderer: map[string]current.VersionOrderer{ - "1.4.6-1": current.VersionOrderer{ + "1.4.6-1": { Default: true, Version: "1.4.6-1", Image: current.OrdererImages{ @@ -168,7 +168,7 @@ var _ = Describe("Openshift Console Deployer Config Map Overrides", func() { By("setting versions", func() { expectedVersions := ¤t.Versions{ CA: map[string]current.VersionCA{ - "1.4.6-1": current.VersionCA{ + "1.4.6-1": { Default: true, Version: "1.4.6-1", Image: current.CAImages{ @@ -180,7 +180,7 @@ var _ = Describe("Openshift Console Deployer Config Map Overrides", func() { }, }, Peer: map[string]current.VersionPeer{ - "1.4.6-1": current.VersionPeer{ + "1.4.6-1": { Default: true, Version: "1.4.6-1", Image: current.PeerImages{ @@ -202,7 +202,7 @@ var _ = Describe("Openshift Console Deployer Config Map Overrides", func() { }, }, Orderer: map[string]current.VersionOrderer{ - "1.4.6-1": current.VersionOrderer{ + "1.4.6-1": { Default: true, Version: "1.4.6-1", Image: current.OrdererImages{ diff --git a/pkg/offering/openshift/peer/peer.go b/pkg/offering/openshift/peer/peer.go index db87625d..dae26ee5 100644 --- a/pkg/offering/openshift/peer/peer.go +++ b/pkg/offering/openshift/peer/peer.go @@ -183,7 +183,7 @@ func (p *Peer) Reconcile(instance *current.IBPPeer, update basepeer.Update) (com "job-name": fmt.Sprintf("%s-dbmigration", instance.GetName()), }, instance) if jobRunning { - log.Info(fmt.Sprintf("Requeuing request until job completes")) + log.Info("Requeuing request until job completes") return common.Result{ Result: reconcile.Result{ Requeue: true, diff --git a/pkg/restart/staggerrestarts/staggerrestarts.go b/pkg/restart/staggerrestarts/staggerrestarts.go index fe5bafb7..1da99494 100644 --- a/pkg/restart/staggerrestarts/staggerrestarts.go +++ b/pkg/restart/staggerrestarts/staggerrestarts.go @@ -63,8 +63,8 @@ func New(client k8sclient.Client, timeout time.Duration) *StaggerRestartsService // Restart is called by the restart manager. // For CA/Peer/Orderer: adds component to the queue for restart. -// For Console: restarts the component directly as there is only one ibpconsole -// instance per network. We bypass the queue logic for ibpconsoles. +// For Console: restarts the component directly as there is only one ibpconsole +// instance per network. We bypass the queue logic for ibpconsoles. func (s *StaggerRestartsService) Restart(instance Instance, reason string) error { switch instance.(type) { case *current.IBPConsole: diff --git a/pkg/util/util.go b/pkg/util/util.go index f5671b0d..9f25bb8e 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -653,16 +653,12 @@ func GetResourceVerFromSecret(client Client, name, namespace string) (string, er func JoinMaps(m1, m2 map[string][]byte) map[string][]byte { joined := map[string][]byte{} - if m1 != nil { - for k, v := range m1 { - joined[k] = v - } + for k, v := range m1 { + joined[k] = v } - if m2 != nil { - for k, v := range m2 { - joined[k] = v - } + for k, v := range m2 { + joined[k] = v } return joined @@ -847,11 +843,7 @@ func IntermediateSecretExists(client Client, namespace, secretName string) bool err := client.Get(context.TODO(), types.NamespacedName{ Name: secretName, Namespace: namespace}, &corev1.Secret{}) - if err != nil { - return false - } - - return true + return err == nil } func IsSecretTLSCert(secretName string) bool { diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go index 30e385ea..7b20f60a 100644 --- a/pkg/util/util_test.go +++ b/pkg/util/util_test.go @@ -369,7 +369,7 @@ var _ = Describe("Util", func() { BeforeEach(func() { pullSecrets = []corev1.LocalObjectReference{ - corev1.LocalObjectReference{ + { Name: "pullsecret1", }, } diff --git a/version/version.go b/version/version.go index 066aabfc..8af7bc26 100644 --- a/version/version.go +++ b/version/version.go @@ -93,11 +93,7 @@ func GetMajorReleaseVersion(version string) string { } func stripVersionPrefix(version string) string { - version = strings.ToLower(version) - if strings.HasPrefix(version, "v") { - version = strings.TrimPrefix(version, "v") - } - return version + return strings.TrimPrefix(strings.ToLower(version), "v") } func newVersion(version string) *Version {