From 10243308f913b0c67cb93ad2a7424f3eb5582b90 Mon Sep 17 00:00:00 2001 From: David VIEJO Date: Fri, 25 Oct 2024 14:29:26 +0200 Subject: [PATCH] Update kubectl-hlf + timeout on followerchannel + mainchannel after failure Signed-off-by: David VIEJO --- .../followerchannel_controller.go | 2 +- .../mainchannel/mainchannel_controller.go | 37 +++++-------------- kubectl-hlf/cmd/chaincode/getlatest.go | 12 ++++-- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/controllers/followerchannel/followerchannel_controller.go b/controllers/followerchannel/followerchannel_controller.go index 72d2baef..4e0c5ab4 100644 --- a/controllers/followerchannel/followerchannel_controller.go +++ b/controllers/followerchannel/followerchannel_controller.go @@ -401,7 +401,7 @@ func (r *FabricFollowerChannelReconciler) updateCRStatusOrFailReconcile(ctx cont } if p.Status.Status == hlfv1alpha1.FailedStatus { return reconcile.Result{ - RequeueAfter: 1 * time.Minute, + RequeueAfter: 5 * time.Minute, }, nil } return reconcile.Result{ diff --git a/controllers/mainchannel/mainchannel_controller.go b/controllers/mainchannel/mainchannel_controller.go index 663b781d..9750175a 100644 --- a/controllers/mainchannel/mainchannel_controller.go +++ b/controllers/mainchannel/mainchannel_controller.go @@ -21,7 +21,6 @@ import ( "github.com/hyperledger/fabric-config/protolator" "github.com/hyperledger/fabric-protos-go/common" cb "github.com/hyperledger/fabric-protos-go/common" - mspa "github.com/hyperledger/fabric-protos-go/msp" sb "github.com/hyperledger/fabric-protos-go/orderer/smartbft" "github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt" fab2 "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab" @@ -722,7 +721,7 @@ func (r *FabricMainChannelReconciler) updateCRStatusOrFailReconcile(ctx context. } if p.Status.Status == hlfv1alpha1.FailedStatus { return reconcile.Result{ - RequeueAfter: 1 * time.Minute, + RequeueAfter: 5 * time.Minute, }, nil } return reconcile.Result{}, nil @@ -1383,10 +1382,7 @@ func updateOrdererChannelConfigTx(currentConfigTX configtx.ConfigTx, newConfigTx return errors.Wrapf(err, "failed to get application configuration") } log.Infof("New config tx: %v", newConfigTx.Orderer) - err = currentConfigTX.Orderer().SetConfiguration(newConfigTx.Orderer) - if err != nil { - return errors.Wrapf(err, "failed to set orderer configuration") - } + currentConfig, err := currentConfigTX.Orderer().Configuration() if err != nil { return errors.Wrapf(err, "failed to get current orderer configuration") @@ -1433,6 +1429,10 @@ func updateOrdererChannelConfigTx(currentConfigTX configtx.ConfigTx, newConfigTx } } } else if newConfigTx.Orderer.OrdererType == orderer.ConsensusTypeBFT { + err = currentConfigTX.Orderer().SetConfiguration(newConfigTx.Orderer) + if err != nil { + return errors.Wrapf(err, "failed to set orderer configuration") + } var consenterMapping []*cb.Consenter for _, consenter := range newConfigTx.Orderer.ConsenterMapping { consenterMapping = append(consenterMapping, &cb.Consenter{ @@ -1449,31 +1449,14 @@ func updateOrdererChannelConfigTx(currentConfigTX configtx.ConfigTx, newConfigTx if err != nil { return errors.Wrapf(err, "failed to set consenter mapping") } - - var identities []*mspa.MSPPrincipal - var pols []*cb.SignaturePolicy - for i, consenter := range consenterMapping { - if consenter == nil { - return fmt.Errorf("consenter %d in the mapping is empty", i) - } - pols = append(pols, &cb.SignaturePolicy{ - Type: &cb.SignaturePolicy_SignedBy{ - SignedBy: int32(i), - }, - }) - identities = append(identities, &mspa.MSPPrincipal{ - PrincipalClassification: mspa.MSPPrincipal_IDENTITY, - Principal: protoutil.MarshalOrPanic(&mspa.SerializedIdentity{Mspid: consenter.MspId, IdBytes: consenter.Identity}), - }) - } - } - err = currentConfigTX.Orderer().SetConfiguration(newConfigTx.Orderer) - if err != nil { - return errors.Wrapf(err, "failed to set orderer configuration") } // update if ord.OrdererType == "BFT" { + err = currentConfigTX.Orderer().SetConfiguration(newConfigTx.Orderer) + if err != nil { + return errors.Wrapf(err, "failed to set orderer configuration") + } log.Infof("updateOrdererChannelConfigTx: Orderer type: %s", ord.OrdererType) // update policies but blockValidation err = currentConfigTX.Orderer().SetPolicy("Admins", newConfigTx.Orderer.Policies["Admins"]) diff --git a/kubectl-hlf/cmd/chaincode/getlatest.go b/kubectl-hlf/cmd/chaincode/getlatest.go index 17268de9..96f5a9ef 100644 --- a/kubectl-hlf/cmd/chaincode/getlatest.go +++ b/kubectl-hlf/cmd/chaincode/getlatest.go @@ -1,14 +1,15 @@ package chaincode import ( + "io" + "io/ioutil" + "strconv" + "github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt" "github.com/hyperledger/fabric-sdk-go/pkg/core/config" "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk" "github.com/pkg/errors" "github.com/spf13/cobra" - "io" - "io/ioutil" - "strconv" ) type getLatestInfoCmd struct { @@ -46,9 +47,14 @@ func (c *getLatestInfoCmd) run(out io.Writer, stdErr io.Writer) error { if err != nil { return err } + resmgmtOptions := []resmgmt.RequestOption{} + if c.peer != "" { + resmgmtOptions = append(resmgmtOptions, resmgmt.WithTargetEndpoints(c.peer)) + } committedCCs, err := resClient.LifecycleQueryCommittedCC( c.channelName, resmgmt.LifecycleQueryCommittedCCRequest{Name: c.name}, + resmgmtOptions..., ) if err != nil { return err