Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: remove BoolTrue and BoolFalse variable #68

Merged
merged 2 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions api/v1beta1/common_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import (
corev1 "k8s.io/api/core/v1"
)

var BoolTrue = true
var BoolFalse = false

// Service is the overrides to be used for Service of the component
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
type Service struct {
Expand Down
20 changes: 2 additions & 18 deletions api/v1beta1/ibporderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,27 +236,11 @@ func (s *IBPOrdererSpec) DomainSet() bool {
}

func (s *IBPOrdererSpec) IsPrecreateOrderer() bool {
if s.IsPrecreate == nil {
return false
}

if *s.IsPrecreate == BoolTrue {
return true
}

return false
return s.IsPrecreate != nil && *s.IsPrecreate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is great - much clearer. Thanks for letting us know about the pointer package!

This line is much cleaner than the old function. No need to update the PR, but I wonder if using the BoolDeref() here would make the intent even clearer. E.g.:

return pointer.BoolDeref(s.IsPrecreate, false)

It would be really good to establish a common pattern for comparisons with maybe-null boolean attributes, and carry this forward.

}

func (s *IBPOrdererSpec) IsUsingChannelLess() bool {
if s.UseChannelLess == nil {
return false
}

if *s.UseChannelLess == BoolTrue {
return true
}

return false
return s.UseChannelLess != nil && *s.UseChannelLess
}

func (s *IBPOrdererSpec) GetNumSecondsWarningPeriod() int64 {
Expand Down
3 changes: 2 additions & 1 deletion controllers/ibporderer/ibporderer_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/utils/pointer"

current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
orderermocks "github.com/IBM-Blockchain/fabric-operator/controllers/ibporderer/mocks"
Expand Down Expand Up @@ -640,7 +641,7 @@ var _ = Describe("ReconcileIBPOrderer", func() {
Name: instance.Name,
},
}
newOrderer.Spec.DisableNodeOU = &current.BoolTrue
newOrderer.Spec.DisableNodeOU = pointer.Bool(true)

e = event.UpdateEvent{
ObjectOld: oldOrderer,
Expand Down
5 changes: 3 additions & 2 deletions controllers/ibppeer/ibppeer_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/utils/pointer"

current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
peermocks "github.com/IBM-Blockchain/fabric-operator/controllers/ibppeer/mocks"
Expand All @@ -41,7 +42,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
yaml "sigs.k8s.io/yaml"
"sigs.k8s.io/yaml"
)

var _ = Describe("ReconcileIBPPeer", func() {
Expand Down Expand Up @@ -606,7 +607,7 @@ var _ = Describe("ReconcileIBPPeer", func() {
Name: instance.Name,
},
}
newPeer.Spec.DisableNodeOU = &current.BoolTrue
newPeer.Spec.DisableNodeOU = pointer.Bool(true)

e = event.UpdateEvent{
ObjectOld: oldPeer,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
k8s.io/apimachinery v0.21.5
k8s.io/client-go v0.21.5
k8s.io/code-generator v0.21.5
k8s.io/utils v0.0.0-20210527160623-6fdb442a123b
sigs.k8s.io/controller-runtime v0.9.0
sigs.k8s.io/yaml v1.2.0
)
Expand Down Expand Up @@ -142,7 +143,6 @@ require (
k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027 // indirect
k8s.io/klog/v2 v2.8.0 // indirect
k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7 // indirect
k8s.io/utils v0.0.0-20210527160623-6fdb442a123b // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
)

Expand Down
3 changes: 2 additions & 1 deletion integration/e2ev2/orderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"

current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
Expand Down Expand Up @@ -302,7 +303,7 @@ var _ = Describe("orderer", func() {
result.Into(ibporderer)

// Disable node ou
ibporderer.Spec.DisableNodeOU = &current.BoolTrue
ibporderer.Spec.DisableNodeOU = pointer.Bool(true)
bytes, err := json.Marshal(ibporderer)
Expect(err).NotTo(HaveOccurred())

Expand Down
3 changes: 2 additions & 1 deletion integration/e2ev2/peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/utils/pointer"

current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
"github.com/IBM-Blockchain/fabric-operator/pkg/apis/common"
Expand Down Expand Up @@ -154,7 +155,7 @@ var _ = Describe("peer", func() {
result.Into(peer)

// Disable node ou
peer.Spec.DisableNodeOU = &current.BoolTrue
peer.Spec.DisableNodeOU = pointer.Bool(true)
bytes, err = json.Marshal(peer)
Expect(err).NotTo(HaveOccurred())
})
Expand Down
5 changes: 3 additions & 2 deletions integration/init/orderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
)

const (
Expand Down Expand Up @@ -86,7 +87,7 @@ var _ = Describe("Orderer init", func() {
TLS: msp,
},
},
DisableNodeOU: &current.BoolTrue,
DisableNodeOU: pointer.Bool(true),
},
}
instance.Namespace = namespace
Expand Down Expand Up @@ -211,7 +212,7 @@ var _ = Describe("Orderer init", func() {
TLS: enrollment,
},
},
DisableNodeOU: &current.BoolTrue,
DisableNodeOU: pointer.Bool(true),
},
}
instance.Namespace = namespace
Expand Down
7 changes: 4 additions & 3 deletions integration/init/peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"path/filepath"

current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
operatorconfig "github.com/IBM-Blockchain/fabric-operator/operatorconfig"
"github.com/IBM-Blockchain/fabric-operator/operatorconfig"
"github.com/IBM-Blockchain/fabric-operator/pkg/initializer/common/enroller"
initializer "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/peer"
peerinit "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/peer"
Expand All @@ -37,6 +37,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
)

const (
Expand Down Expand Up @@ -98,7 +99,7 @@ var _ = Describe("Peer init", func() {
TLS: msp,
},
},
DisableNodeOU: &current.BoolTrue,
DisableNodeOU: pointer.Bool(true),
},
}
instance.Namespace = namespace
Expand Down Expand Up @@ -220,7 +221,7 @@ var _ = Describe("Peer init", func() {
TLS: enrollment,
},
},
DisableNodeOU: &current.BoolTrue,
DisableNodeOU: pointer.Bool(true),
},
}
instance.Namespace = namespace
Expand Down
13 changes: 7 additions & 6 deletions integration/orderer/orderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"fmt"
"time"

"k8s.io/utils/pointer"
"sigs.k8s.io/yaml"

current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
Expand Down Expand Up @@ -939,7 +940,7 @@ func GetOrderer() (*Orderer, []Orderer) {
},
},
ConfigOverride: &runtime.RawExtension{Raw: configBytes},
DisableNodeOU: &current.BoolTrue,
DisableNodeOU: pointer.Bool(true),
FabricVersion: integration.FabricVersion + "-1",
},
}
Expand Down Expand Up @@ -1022,7 +1023,7 @@ func GetOrderer2() (*Orderer, []Orderer) {
Limits: defaultLimitsProxy,
},
},
DisableNodeOU: &current.BoolTrue,
DisableNodeOU: pointer.Bool(true),
FabricVersion: integration.FabricVersion + "-1",
},
}
Expand Down Expand Up @@ -1117,7 +1118,7 @@ func GetOrderer3() (*Orderer, []Orderer) {
Region: "us-south2",
},
},
DisableNodeOU: &current.BoolTrue,
DisableNodeOU: pointer.Bool(true),
FabricVersion: integration.FabricVersion + "-1",
},
}
Expand Down Expand Up @@ -1200,7 +1201,7 @@ func GetOrderer4() (*Orderer, []Orderer) {
Limits: defaultLimitsProxy,
},
},
DisableNodeOU: &current.BoolTrue,
DisableNodeOU: pointer.Bool(true),
FabricVersion: integration.FabricVersion + "-1",
},
}
Expand Down Expand Up @@ -1268,7 +1269,7 @@ func GetOrderer5() (*Orderer, []Orderer) {
},
OrdererType: "etcdraft",
SystemChannelName: "testchainid",
UseChannelLess: &current.BoolTrue,
UseChannelLess: pointer.Bool(true),
OrgName: "orderermsp",
MSPID: "orderermsp",
ImagePullSecrets: []string{"regcred"},
Expand Down Expand Up @@ -1297,7 +1298,7 @@ func GetOrderer5() (*Orderer, []Orderer) {
Limits: defaultLimitsProxy,
},
},
DisableNodeOU: &current.BoolTrue,
DisableNodeOU: pointer.Bool(true),
FabricVersion: integration.FabricVersion24 + "-1",
},
}
Expand Down
5 changes: 3 additions & 2 deletions integration/peer/peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/utils/pointer"
"sigs.k8s.io/yaml"
)

Expand Down Expand Up @@ -813,7 +814,7 @@ func GetPeer1() *Peer {
MSP: testMSPSpec,
},
ConfigOverride: &runtime.RawExtension{Raw: configBytes},
DisableNodeOU: &current.BoolTrue,
DisableNodeOU: pointer.Bool(true),
FabricVersion: integration.FabricVersion + "-1",
},
}
Expand Down Expand Up @@ -867,7 +868,7 @@ func GetPeer2() *Peer {
Secret: &current.SecretSpec{
MSP: testMSPSpec,
},
DisableNodeOU: &current.BoolTrue,
DisableNodeOU: pointer.Bool(true),
FabricVersion: integration.FabricVersion + "-1",
},
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/offering/base/orderer/orderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -461,7 +462,7 @@ func (o *Orderer) CreateNodeCR(instance *current.IBPOrderer, number int) error {
if instance.Spec.IsUsingChannelLess() {
node.Spec.UseChannelLess = instance.Spec.UseChannelLess
} else {
node.Spec.IsPrecreate = &current.BoolTrue
node.Spec.IsPrecreate = pointer.Bool(true)
}
node.Spec.NodeNumber = &number
node.Spec.ClusterSize = 1
Expand Down