@@ -116,9 +116,9 @@ func (r *FabricMainChannelReconciler) Reconcile(ctx context.Context, req ctrl.Re
116
116
return r .handleReconcileError (ctx , fabricMainChannel , err )
117
117
}
118
118
119
- resmgmtOptions := r .setupResmgmtOptions (fabricMainChannel )
119
+ options , _ := r .setupResmgmtOptions (fabricMainChannel )
120
120
121
- blockBytes , err := r .fetchConfigBlock (resClient , fabricMainChannel , resmgmtOptions )
121
+ blockBytes , err := r .fetchConfigBlock (resClient , fabricMainChannel , options )
122
122
if err != nil {
123
123
return r .handleReconcileError (ctx , fabricMainChannel , err )
124
124
}
@@ -127,11 +127,11 @@ func (r *FabricMainChannelReconciler) Reconcile(ctx context.Context, req ctrl.Re
127
127
return r .handleReconcileError (ctx , fabricMainChannel , err )
128
128
}
129
129
130
- if err := r .updateChannelConfig (ctx , fabricMainChannel , resClient , resmgmtOptions , blockBytes , sdk , clientSet ); err != nil {
130
+ if err := r .updateChannelConfig (ctx , fabricMainChannel , resClient , options , blockBytes , sdk , clientSet ); err != nil {
131
131
return r .handleReconcileError (ctx , fabricMainChannel , err )
132
132
}
133
133
time .Sleep (3 * time .Second )
134
- if err := r .saveChannelConfig (ctx , fabricMainChannel , resClient , resmgmtOptions ); err != nil {
134
+ if err := r .saveChannelConfig (ctx , fabricMainChannel , resClient , options ); err != nil {
135
135
return r .handleReconcileError (ctx , fabricMainChannel , err )
136
136
}
137
137
@@ -395,6 +395,43 @@ func (r *FabricMainChannelReconciler) joinInternalOrderers(ctx context.Context,
395
395
return nil
396
396
}
397
397
398
+ func (r * FabricMainChannelReconciler ) queryConfigBlockFromOrdererWithRoundRobin (resClient * resmgmt.Client , channelID string , ordererEndpoints []string , resmgmtOptions []resmgmt.RequestOption ) (* common.Block , error ) {
399
+ if len (ordererEndpoints ) == 0 {
400
+ return nil , fmt .Errorf ("no orderer endpoints available" )
401
+ }
402
+
403
+ // Try each orderer in sequence until one succeeds
404
+ var lastErr error
405
+ for _ , endpoint := range ordererEndpoints {
406
+ // Create options for this specific orderer
407
+ ordererOpts := []resmgmt.RequestOption {
408
+ resmgmt .WithOrdererEndpoint (endpoint ),
409
+ resmgmt .WithRetry (retry.Opts {
410
+ Attempts : 3 ,
411
+ InitialBackoff : 1 * time .Second ,
412
+ MaxBackoff : 10 * time .Second ,
413
+ }),
414
+ }
415
+
416
+ // Add any other options that were passed in (except orderer endpoints)
417
+ for _ , opt := range resmgmtOptions {
418
+ ordererOpts = append (ordererOpts , opt )
419
+ }
420
+
421
+ log .Infof ("Attempting to query config block from orderer %s" , endpoint )
422
+ block , err := resClient .QueryConfigBlockFromOrderer (channelID , ordererOpts ... )
423
+ if err != nil {
424
+ log .Warnf ("Failed to query config block from orderer %s: %v" , endpoint , err )
425
+ lastErr = err
426
+ continue
427
+ }
428
+ log .Infof ("Successfully queried config block from orderer %s" , endpoint )
429
+ return block , nil
430
+ }
431
+
432
+ return nil , fmt .Errorf ("failed to query config block from all orderers, last error: %v" , lastErr )
433
+ }
434
+
398
435
func (r * FabricMainChannelReconciler ) fetchOrdererChannelBlock (resClient * resmgmt.Client , fabricMainChannel * hlfv1alpha1.FabricMainChannel , resmgmtOptions []resmgmt.RequestOption ) (* common.Block , error ) {
399
436
var ordererChannelBlock * common.Block
400
437
var err error
@@ -403,7 +440,9 @@ func (r *FabricMainChannelReconciler) fetchOrdererChannelBlock(resClient *resmgm
403
440
InitialBackoff : 1000 * time .Millisecond ,
404
441
MaxBackoff : 10 * time .Second ,
405
442
}))
406
- ordererChannelBlock , err = resClient .QueryConfigBlockFromOrderer (fabricMainChannel .Spec .Name , resmgmtOptions ... )
443
+
444
+ options , endpoints := r .setupResmgmtOptions (fabricMainChannel )
445
+ ordererChannelBlock , err = r .queryConfigBlockFromOrdererWithRoundRobin (resClient , fabricMainChannel .Spec .Name , endpoints , options )
407
446
if err != nil {
408
447
return nil , errors .Wrapf (err , "failed to get block from channel %s" , fabricMainChannel .Spec .Name )
409
448
}
@@ -478,18 +517,25 @@ func (r *FabricMainChannelReconciler) handleReconcileError(ctx context.Context,
478
517
return r .updateCRStatusOrFailReconcile (ctx , r .Log , fabricMainChannel )
479
518
}
480
519
481
- func (r * FabricMainChannelReconciler ) setupResmgmtOptions (fabricMainChannel * hlfv1alpha1.FabricMainChannel ) []resmgmt.RequestOption {
520
+ func (r * FabricMainChannelReconciler ) setupResmgmtOptions (fabricMainChannel * hlfv1alpha1.FabricMainChannel ) ( []resmgmt.RequestOption , [] string ) {
482
521
resmgmtOptions := []resmgmt.RequestOption {
483
522
resmgmt .WithTimeout (fab2 .ResMgmt , 30 * time .Second ),
523
+ resmgmt .WithRetry (retry.Opts {
524
+ Attempts : 3 ,
525
+ InitialBackoff : 1 * time .Second ,
526
+ MaxBackoff : 10 * time .Second ,
527
+ }),
484
528
}
485
529
530
+ var ordererEndpoints []string
486
531
for _ , ordOrg := range fabricMainChannel .Spec .OrdererOrganizations {
487
532
for _ , endpoint := range ordOrg .OrdererEndpoints {
488
- resmgmtOptions = append (resmgmtOptions , resmgmt .WithOrdererEndpoint (endpoint ))
533
+ ordererEndpoints = append (ordererEndpoints , endpoint )
534
+ // resmgmtOptions = append(resmgmtOptions)
489
535
}
490
536
}
491
537
492
- return resmgmtOptions
538
+ return resmgmtOptions , ordererEndpoints
493
539
}
494
540
495
541
func (r * FabricMainChannelReconciler ) fetchConfigBlock (resClient * resmgmt.Client , fabricMainChannel * hlfv1alpha1.FabricMainChannel , resmgmtOptions []resmgmt.RequestOption ) ([]byte , error ) {
@@ -501,11 +547,8 @@ func (r *FabricMainChannelReconciler) fetchConfigBlock(resClient *resmgmt.Client
501
547
MaxBackoff : 10 * time .Second ,
502
548
}))
503
549
504
- channelBlock , err = resClient .QueryConfigBlockFromOrderer (fabricMainChannel .Spec .Name , resmgmtOptions ... )
505
- if err != nil {
506
- return nil , errors .Wrapf (err , "failed to query config block from orderer %s" , fabricMainChannel .Spec .Name )
507
- }
508
-
550
+ options , endpoints := r .setupResmgmtOptions (fabricMainChannel )
551
+ channelBlock , err = r .queryConfigBlockFromOrdererWithRoundRobin (resClient , fabricMainChannel .Spec .Name , endpoints , options )
509
552
if err != nil {
510
553
log .Infof ("Channel %s does not exist, creating it: %v" , fabricMainChannel .Spec .Name , err )
511
554
return r .createNewChannel (fabricMainChannel )
0 commit comments