Skip to content

Commit

Permalink
Update kubectl-hlf + timeout on followerchannel + mainchannel after f…
Browse files Browse the repository at this point in the history
…ailure

Signed-off-by: David VIEJO <[email protected]>
  • Loading branch information
dviejokfs committed Oct 25, 2024
1 parent befc615 commit 1024330
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
2 changes: 1 addition & 1 deletion controllers/followerchannel/followerchannel_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
37 changes: 10 additions & 27 deletions controllers/mainchannel/mainchannel_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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{
Expand All @@ -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"])
Expand Down
12 changes: 9 additions & 3 deletions kubectl-hlf/cmd/chaincode/getlatest.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1024330

Please sign in to comment.