Skip to content

Commit 0827335

Browse files
committed
Cleanup code
Signed-off-by: David VIEJO <[email protected]>
1 parent f9b6e76 commit 0827335

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

controllers/mainchannel/mainchannel_controller.go

+11-26
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (r *FabricMainChannelReconciler) Reconcile(ctx context.Context, req ctrl.Re
118118

119119
options, _ := r.setupResmgmtOptions(fabricMainChannel)
120120

121-
blockBytes, err := r.fetchConfigBlock(resClient, fabricMainChannel, options)
121+
blockBytes, err := r.fetchConfigBlock(resClient, fabricMainChannel)
122122
if err != nil {
123123
return r.handleReconcileError(ctx, fabricMainChannel, err)
124124
}
@@ -127,11 +127,11 @@ func (r *FabricMainChannelReconciler) Reconcile(ctx context.Context, req ctrl.Re
127127
return r.handleReconcileError(ctx, fabricMainChannel, err)
128128
}
129129

130-
if err := r.updateChannelConfig(ctx, fabricMainChannel, resClient, options, blockBytes, sdk, clientSet); err != nil {
130+
if err := r.updateChannelConfig(ctx, fabricMainChannel, resClient, options, sdk, clientSet); err != nil {
131131
return r.handleReconcileError(ctx, fabricMainChannel, err)
132132
}
133133
time.Sleep(3 * time.Second)
134-
if err := r.saveChannelConfig(ctx, fabricMainChannel, resClient, options); err != nil {
134+
if err := r.saveChannelConfig(ctx, fabricMainChannel, resClient); err != nil {
135135
return r.handleReconcileError(ctx, fabricMainChannel, err)
136136
}
137137

@@ -414,9 +414,7 @@ func (r *FabricMainChannelReconciler) queryConfigBlockFromOrdererWithRoundRobin(
414414
}
415415

416416
// Add any other options that were passed in (except orderer endpoints)
417-
for _, opt := range resmgmtOptions {
418-
ordererOpts = append(ordererOpts, opt)
419-
}
417+
ordererOpts = append(ordererOpts, resmgmtOptions...)
420418

421419
log.Infof("Attempting to query config block from orderer %s", endpoint)
422420
block, err := resClient.QueryConfigBlockFromOrderer(channelID, ordererOpts...)
@@ -432,14 +430,9 @@ func (r *FabricMainChannelReconciler) queryConfigBlockFromOrdererWithRoundRobin(
432430
return nil, fmt.Errorf("failed to query config block from all orderers, last error: %v", lastErr)
433431
}
434432

435-
func (r *FabricMainChannelReconciler) fetchOrdererChannelBlock(resClient *resmgmt.Client, fabricMainChannel *hlfv1alpha1.FabricMainChannel, resmgmtOptions []resmgmt.RequestOption) (*common.Block, error) {
433+
func (r *FabricMainChannelReconciler) fetchOrdererChannelBlock(resClient *resmgmt.Client, fabricMainChannel *hlfv1alpha1.FabricMainChannel) (*common.Block, error) {
436434
var ordererChannelBlock *common.Block
437435
var err error
438-
resmgmtOptions = append(resmgmtOptions, resmgmt.WithRetry(retry.Opts{
439-
Attempts: 5,
440-
InitialBackoff: 1000 * time.Millisecond,
441-
MaxBackoff: 10 * time.Second,
442-
}))
443436

444437
options, endpoints := r.setupResmgmtOptions(fabricMainChannel)
445438
ordererChannelBlock, err = r.queryConfigBlockFromOrdererWithRoundRobin(resClient, fabricMainChannel.Spec.Name, endpoints, options)
@@ -529,23 +522,15 @@ func (r *FabricMainChannelReconciler) setupResmgmtOptions(fabricMainChannel *hlf
529522

530523
var ordererEndpoints []string
531524
for _, ordOrg := range fabricMainChannel.Spec.OrdererOrganizations {
532-
for _, endpoint := range ordOrg.OrdererEndpoints {
533-
ordererEndpoints = append(ordererEndpoints, endpoint)
534-
// resmgmtOptions = append(resmgmtOptions)
535-
}
525+
ordererEndpoints = append(ordererEndpoints, ordOrg.OrdererEndpoints...)
536526
}
537527

538528
return resmgmtOptions, ordererEndpoints
539529
}
540530

541-
func (r *FabricMainChannelReconciler) fetchConfigBlock(resClient *resmgmt.Client, fabricMainChannel *hlfv1alpha1.FabricMainChannel, resmgmtOptions []resmgmt.RequestOption) ([]byte, error) {
531+
func (r *FabricMainChannelReconciler) fetchConfigBlock(resClient *resmgmt.Client, fabricMainChannel *hlfv1alpha1.FabricMainChannel) ([]byte, error) {
542532
var channelBlock *cb.Block
543533
var err error
544-
resmgmtOptions = append(resmgmtOptions, resmgmt.WithRetry(retry.Opts{
545-
Attempts: 5,
546-
InitialBackoff: 1000 * time.Millisecond,
547-
MaxBackoff: 10 * time.Second,
548-
}))
549534

550535
options, endpoints := r.setupResmgmtOptions(fabricMainChannel)
551536
channelBlock, err = r.queryConfigBlockFromOrdererWithRoundRobin(resClient, fabricMainChannel.Spec.Name, endpoints, options)
@@ -596,8 +581,8 @@ func (r *FabricMainChannelReconciler) joinOrderers(ctx context.Context, fabricMa
596581
return nil
597582
}
598583

599-
func (r *FabricMainChannelReconciler) updateChannelConfig(ctx context.Context, fabricMainChannel *hlfv1alpha1.FabricMainChannel, resClient *resmgmt.Client, resmgmtOptions []resmgmt.RequestOption, blockBytes []byte, sdk *fabsdk.FabricSDK, clientSet *kubernetes.Clientset) error {
600-
ordererChannelBlock, err := r.fetchOrdererChannelBlock(resClient, fabricMainChannel, resmgmtOptions)
584+
func (r *FabricMainChannelReconciler) updateChannelConfig(ctx context.Context, fabricMainChannel *hlfv1alpha1.FabricMainChannel, resClient *resmgmt.Client, resmgmtOptions []resmgmt.RequestOption, sdk *fabsdk.FabricSDK, clientSet *kubernetes.Clientset) error {
585+
ordererChannelBlock, err := r.fetchOrdererChannelBlock(resClient, fabricMainChannel)
601586
if err != nil {
602587
return err
603588
}
@@ -680,8 +665,8 @@ func (r *FabricMainChannelReconciler) updateChannelConfig(ctx context.Context, f
680665
return nil
681666
}
682667

683-
func (r *FabricMainChannelReconciler) saveChannelConfig(ctx context.Context, fabricMainChannel *hlfv1alpha1.FabricMainChannel, resClient *resmgmt.Client, resmgmtOptions []resmgmt.RequestOption) error {
684-
ordererChannelBlock, err := r.fetchOrdererChannelBlock(resClient, fabricMainChannel, resmgmtOptions)
668+
func (r *FabricMainChannelReconciler) saveChannelConfig(ctx context.Context, fabricMainChannel *hlfv1alpha1.FabricMainChannel, resClient *resmgmt.Client) error {
669+
ordererChannelBlock, err := r.fetchOrdererChannelBlock(resClient, fabricMainChannel)
685670
if err != nil {
686671
return err
687672
}

0 commit comments

Comments
 (0)