Skip to content

Commit

Permalink
Add peer/orderer config updates and handle upgrades (#112)
Browse files Browse the repository at this point in the history
#111

Signed-off-by: asararatnakar <[email protected]>
  • Loading branch information
asararatnakar authored Jun 2, 2023
1 parent bb938eb commit 44d341a
Show file tree
Hide file tree
Showing 52 changed files with 3,868 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
IMAGE ?= ghcr.io/hyperledger-labs/fabric-operator
TAG ?= $(shell git rev-parse --short HEAD)
ARCH ?= $(shell go env GOARCH)
OSS_GO_VER ?= 1.17.7
OSS_GO_VER ?= 1.20.3
BUILD_DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
OS = $(shell go env GOOS)

Expand Down
13 changes: 12 additions & 1 deletion api/v1beta1/ibporderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
config "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/orderer/config/v1"
v2config "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/orderer/config/v2"
v24config "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/orderer/config/v24"
v25config "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/orderer/config/v25"
"github.com/IBM-Blockchain/fabric-operator/pkg/util/image"
"github.com/IBM-Blockchain/fabric-operator/version"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -88,7 +89,17 @@ func (o *IBPOrderer) GetConfigOverride() (interface{}, error) {
switch version.GetMajorReleaseVersion(o.Spec.FabricVersion) {
case version.V2:
currentVer := version.String(o.Spec.FabricVersion)
if currentVer.EqualWithoutTag(version.V2_4_1) || currentVer.GreaterThan(version.V2_4_1) {
if currentVer.EqualWithoutTag(version.V2_5_1) || currentVer.GreaterThan(version.V2_5_1) {
if o.Spec.ConfigOverride == nil {
return &v25config.Orderer{}, nil
}

configOverride, err := v25config.ReadFrom(&o.Spec.ConfigOverride.Raw)
if err != nil {
return nil, err
}
return configOverride, nil
} else if currentVer.EqualWithoutTag(version.V2_4_1) || currentVer.GreaterThan(version.V2_4_1) {
if o.Spec.ConfigOverride == nil {
return &v24config.Orderer{}, nil
}
Expand Down
23 changes: 21 additions & 2 deletions api/v1beta1/ibppeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

config "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/peer/config/v1"
v2config "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/peer/config/v2"
v25config "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/peer/config/v25"
"github.com/IBM-Blockchain/fabric-operator/pkg/util/image"
"github.com/IBM-Blockchain/fabric-operator/version"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -99,15 +100,33 @@ func (p *IBPPeer) UsingCCLauncherImage() bool {
func (p *IBPPeer) EnrollerImage() string {
return image.Format(p.Spec.Images.EnrollerImage, p.Spec.Images.EnrollerTag)
}
func IsV25Peer(fabricVersion string) bool {
currentVer := version.String(fabricVersion)
if currentVer.EqualWithoutTag(version.V2_5_1) || currentVer.GreaterThan(version.V2_5_1) {
return true
}
return false
}

func (s *IBPPeer) GetConfigOverride() (interface{}, error) {
switch version.GetMajorReleaseVersion(s.Spec.FabricVersion) {
case version.V2:
isv25Peer := IsV25Peer(s.Spec.FabricVersion)
if s.Spec.ConfigOverride == nil {
return &v2config.Core{}, nil
if isv25Peer {
return &v25config.Core{}, nil
} else {
return &v2config.Core{}, nil
}
}

configOverride, err := v2config.ReadFrom(&s.Spec.ConfigOverride.Raw)
var configOverride interface{}
var err error
if isv25Peer {
configOverride, err = v25config.ReadFrom(&s.Spec.ConfigOverride.Raw)
} else {
configOverride, err = v2config.ReadFrom(&s.Spec.ConfigOverride.Raw)
}
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions controllers/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ type Client interface {
List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
}

// 1. Only one existing instance (of the same type as 'instance') should have
// the name 'instance.GetName()'; if more than one is present, return error
// 2. If any instance of a different type share the same name, return error
// 1. Only one existing instance (of the same type as 'instance') should have
// the name 'instance.GetName()'; if more than one is present, return error
// 2. If any instance of a different type share the same name, return error
func ValidateCRName(k8sclient Client, name, namespace, kind string) error {
listOptions := &client.ListOptions{
Namespace: namespace,
Expand Down
30 changes: 24 additions & 6 deletions controllers/ibporderer/ibporderer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,23 +746,41 @@ func (r *ReconcileIBPOrderer) UpdateFunc(e event.UpdateEvent) bool {
oldVer := version.String(oldOrderer.Spec.FabricVersion)
newVer := version.String(newOrderer.Spec.FabricVersion)

// check if this V1 -> V2.2.x/V2.4.x orderer migration
// check if this V1 -> V2.2.x/V2.4.x/v2.5.x orderer migration
if (oldOrderer.Spec.FabricVersion == "" ||
version.GetMajorReleaseVersion(oldOrderer.Spec.FabricVersion) == version.V1) &&
version.GetMajorReleaseVersion(newOrderer.Spec.FabricVersion) == version.V2 {
update.migrateToV2 = true
if newVer.EqualWithoutTag(version.V2_4_1) || newVer.GreaterThan(version.V2_4_1) {
if newVer.EqualWithoutTag(version.V2_5_1) || newVer.GreaterThan(version.V2_5_1) {
update.migrateToV25 = true
// Re-enrolling tls cert to include admin hostname in SAN (for orderers >=2.5.1)
update.tlscertReenrollNeeded = true
} else if newVer.EqualWithoutTag(version.V2_4_1) || newVer.GreaterThan(version.V2_4_1) {
update.migrateToV24 = true
// Re-enrolling tls cert to include admin hostname in SAN (for orderers >=2.4.1)
update.tlscertReenrollNeeded = true
}
}

// check if this V2.2.x -> V2.4.x/2.5.x orderer migration
if (version.GetMajorReleaseVersion(oldOrderer.Spec.FabricVersion) == version.V2) &&
oldVer.LessThan(version.V2_4_1) {
if newVer.EqualWithoutTag(version.V2_5_1) || newVer.GreaterThan(version.V2_5_1) {
update.migrateToV25 = true
// Re-enrolling tls cert to include admin hostname in SAN (for orderers >=2.4.1)
update.tlscertReenrollNeeded = true
} else if newVer.EqualWithoutTag(version.V2_4_1) || newVer.GreaterThan(version.V2_4_1) {
update.migrateToV24 = true
// Re-enrolling tls cert to include admin hostname in SAN (for orderers >=2.4.1)
update.tlscertReenrollNeeded = true
}
}

// check if this V2.2.x -> V2.4.x orderer migration
// check if this V2.4.x -> V2.5.x orderer migration
if (version.GetMajorReleaseVersion(oldOrderer.Spec.FabricVersion) == version.V2) &&
oldVer.LessThan(version.V2_4_1) &&
(newVer.EqualWithoutTag(version.V2_4_1) || newVer.GreaterThan(version.V2_4_1)) {
update.migrateToV24 = true
oldVer.LessThan(version.V2_5_1) &&
(newVer.EqualWithoutTag(version.V2_5_1) || newVer.GreaterThan(version.V2_5_1)) {
update.migrateToV25 = true
// Re-enrolling tls cert to include admin hostname in SAN (for orderers >=2.4.1)
update.tlscertReenrollNeeded = true
}
Expand Down
9 changes: 9 additions & 0 deletions controllers/ibporderer/predicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Update struct {
ecertCreated bool
migrateToV2 bool
migrateToV24 bool
migrateToV25 bool
nodeOUUpdated bool
imagesUpdated bool
fabricVersionUpdated bool
Expand All @@ -69,6 +70,7 @@ func (u *Update) Detected() bool {
u.ecertEnroll ||
u.migrateToV2 ||
u.migrateToV24 ||
u.migrateToV25 ||
u.nodeOUUpdated ||
u.imagesUpdated ||
u.fabricVersionUpdated
Expand Down Expand Up @@ -186,6 +188,10 @@ func (u *Update) MigrateToV24() bool {
return u.migrateToV24
}

func (u *Update) MigrateToV25() bool {
return u.migrateToV25
}

func (u *Update) NodeOUUpdated() bool {
return u.nodeOUUpdated
}
Expand Down Expand Up @@ -251,6 +257,9 @@ func (u *Update) GetUpdateStackWithTrues() string {
if u.migrateToV24 {
stack += "migrateToV24 "
}
if u.migrateToV25 {
stack += "migrateToV25 "
}
if u.nodeOUUpdated {
stack += "nodeOUUpdated "
}
Expand Down
24 changes: 18 additions & 6 deletions controllers/ibppeer/ibppeer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -671,16 +670,29 @@ func (r *ReconcileIBPPeer) UpdateFunc(e event.UpdateEvent) bool {
version.GetMajorReleaseVersion(oldPeer.Spec.FabricVersion) == version.V1) &&
version.GetMajorReleaseVersion(newPeer.Spec.FabricVersion) == version.V2 {
update.migrateToV2 = true
if newVer.EqualWithoutTag(version.V2_4_1) || newVer.GreaterThan(version.V2_4_1) {
if newVer.EqualWithoutTag(version.V2_5_1) || newVer.GreaterThan(version.V2_5_1) {
update.migrateToV24 = true
update.migrateToV25 = true
} else if newVer.EqualWithoutTag(version.V2_4_1) || newVer.GreaterThan(version.V2_4_1) {
update.migrateToV24 = true
}
}

// check if this V2.2.x -> V2.4.x peer migration
// check if this V2.2.x -> V2.4.x/V2.5.x peer migration
if (version.GetMajorReleaseVersion(oldPeer.Spec.FabricVersion) == version.V2) &&
oldVer.LessThan(version.V2_4_1) &&
(newVer.EqualWithoutTag(version.V2_4_1) || newVer.GreaterThan(version.V2_4_1)) {
oldVer.LessThan(version.V2_4_1) {
update.migrateToV24 = true
if newVer.EqualWithoutTag(version.V2_5_1) || newVer.GreaterThan(version.V2_5_1) {
update.migrateToV25 = true
}
}

// check if this V2.4.x -> V2.5.x peer migration
if (version.GetMajorReleaseVersion(oldPeer.Spec.FabricVersion) == version.V2) &&
oldVer.LessThan(version.V2_5_1) {
if newVer.EqualWithoutTag(version.V2_5_1) || newVer.GreaterThan(version.V2_5_1) {
update.migrateToV25 = true
}
}

if newPeer.Spec.Action.UpgradeDBs == true {
Expand Down Expand Up @@ -775,7 +787,7 @@ func (r *ReconcileIBPPeer) DeleteFunc(e event.DeleteEvent) bool {
// without proper controller references set and was not cleaned up on peer resource deletion.
log.Info(fmt.Sprintf("Deleting %s-init-config config map, if found", peer.GetName()))
if err := r.client.Delete(context.TODO(), &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
ObjectMeta: v1.ObjectMeta{
Name: fmt.Sprintf("%s-init-config", peer.GetName()),
Namespace: peer.GetNamespace(),
},
Expand Down
9 changes: 9 additions & 0 deletions controllers/ibppeer/predicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Update struct {
tlscertNewKeyReenroll bool
migrateToV2 bool
migrateToV24 bool
migrateToV25 bool
mspUpdated bool
ecertEnroll bool
tlscertEnroll bool
Expand Down Expand Up @@ -116,6 +117,10 @@ func (u *Update) MigrateToV24() bool {
return u.migrateToV24
}

func (u *Update) MigrateToV25() bool {
return u.migrateToV25
}

func (u *Update) UpgradeDBs() bool {
return u.upgradedbs
}
Expand Down Expand Up @@ -195,6 +200,7 @@ func (u *Update) Needed() bool {
u.tlscertNewKeyReenroll ||
u.migrateToV2 ||
u.migrateToV24 ||
u.migrateToV25 ||
u.mspUpdated ||
u.ecertEnroll ||
u.upgradedbs ||
Expand Down Expand Up @@ -239,6 +245,9 @@ func (u *Update) GetUpdateStackWithTrues() string {
if u.migrateToV24 {
stack += "migrateToV24 "
}
if u.migrateToV25 {
stack += "migrateToV25 "
}
if u.mspUpdated {
stack += "mspUpdated "
}
Expand Down
8 changes: 8 additions & 0 deletions defaultconfig/orderer/v24/orderer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ General:
# ServerTimeout is the duration the server waits for a response from
# a client before closing the connection.
ServerTimeout: 20s

# Since all nodes should be consistent it is recommended to keep
# the default value of 100MB for MaxRecvMsgSize & MaxSendMsgSize
# Max message size in bytes the GRPC server and client can receive
MaxRecvMsgSize: 104857600
# Max message size in bytes the GRPC server and client can send
MaxSendMsgSize: 104857600

# Cluster settings for ordering service nodes that communicate with other ordering service nodes
# such as Raft based ordering service.
Cluster:
Expand Down
Loading

0 comments on commit 44d341a

Please sign in to comment.