Skip to content

Commit

Permalink
Feat/small feats (#209)
Browse files Browse the repository at this point in the history
* NetworkConfig: filter the peers to be added per organization

* Filter peers by org, global peers and global CAs

* Add `FabricChaincodeTemplate` CRD

* update

* Add support for FabricChaincodeTemplateRef in FabricChaincodeSpec

Signed-off-by: David VIEJO <[email protected]>

* update

* Update helm chart in pipelien

Signed-off-by: David VIEJO <[email protected]>

* Update

Signed-off-by: David VIEJO <[email protected]>

* update

Signed-off-by: David VIEJO <[email protected]>

* Update

Signed-off-by: David VIEJO <[email protected]>

* update

* fabric-config 0.1.0 -> 0.2.1

Add ports 443 for the peer

* Upgrade to go 1.21

* Add adminURL in the network config if available

* Update pipelines to 1.21

* Add command to get the next sequence and version for a chaincode based on chaincode definition

Signed-off-by: David VIEJO <[email protected]>

* update

Signed-off-by: David VIEJO <[email protected]>

* update

Signed-off-by: David VIEJO <[email protected]>

* update

Signed-off-by: David VIEJO <[email protected]>

---------

Signed-off-by: David VIEJO <[email protected]>
Signed-off-by: David Viejo <[email protected]>
  • Loading branch information
dviejokfs authored Feb 5, 2024
1 parent 68842cd commit b34e3ec
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 41 deletions.
85 changes: 57 additions & 28 deletions controllers/ca/ca_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,32 @@ func Reconcile(
// it doesn't exist
return ctrl.Result{}, err
}
} else if exists && helmStatus.Info.Status == release.StatusPendingRollback {
historyAction := action.NewHistory(cfg)
history, err := historyAction.Run(releaseName)
if err != nil {
return ctrl.Result{}, err
}
if len(history) > 0 {
// find the last deployed revision
// and rollback to it
// sort history by revision number descending using raw go
sort.Slice(history, func(i, j int) bool {
return history[i].Version > history[j].Version
})
for _, historyItem := range history {
if historyItem.Info.Status == release.StatusDeployed {
rollbackStatus := action.NewRollback(cfg)
rollbackStatus.Version = historyItem.Version
err = rollbackStatus.Run(releaseName)
if err != nil {
// it doesn't exist
return ctrl.Result{}, err
}
break
}
}
}
}
log.Debugf("Release %s exists=%v", releaseName, exists)
clientSet, err := utils.GetClientKubeWithConf(r.Config)
Expand Down Expand Up @@ -969,35 +995,38 @@ func Reconcile(
Status: "True",
LastTransitionTime: v1.Time{},
})
c, err := GetConfig(hlf, clientSet, releaseName, req.Namespace)
if err != nil {
return ctrl.Result{}, err
}
inrec, err := json.Marshal(c)
if err != nil {
return ctrl.Result{}, err
}
var inInterface map[string]interface{}
err = json.Unmarshal(inrec, &inInterface)
if err != nil {
return ctrl.Result{}, err
}
cmd := action.NewUpgrade(cfg)
cmd.Timeout = r.Timeout
cmd.Wait = r.Wait
cmd.MaxHistory = r.MaxHistory
settings := cli.New()
chartPath, err := cmd.LocateChart(r.ChartPath, settings)
ch, err := loader.Load(chartPath)
if err != nil {
return ctrl.Result{}, err
}
release, err := cmd.Run(releaseName, ch, inInterface)
if err != nil {
setConditionStatus(hlf, hlfv1alpha1.FailedStatus, false, err, false)
return r.updateCRStatusOrFailReconcile(ctx, r.Log, hlf)
if helmStatus.Info.Status != release.StatusPendingUpgrade {
c, err := GetConfig(hlf, clientSet, releaseName, req.Namespace)
if err != nil {
return ctrl.Result{}, err
}
inrec, err := json.Marshal(c)
if err != nil {
return ctrl.Result{}, err
}
var inInterface map[string]interface{}
err = json.Unmarshal(inrec, &inInterface)
if err != nil {
return ctrl.Result{}, err
}
cmd := action.NewUpgrade(cfg)
cmd.Timeout = r.Timeout
cmd.Wait = r.Wait
cmd.MaxHistory = r.MaxHistory

settings := cli.New()
chartPath, err := cmd.LocateChart(r.ChartPath, settings)
ch, err := loader.Load(chartPath)
if err != nil {
return ctrl.Result{}, err
}
release, err := cmd.Run(releaseName, ch, inInterface)
if err != nil {
setConditionStatus(hlf, hlfv1alpha1.FailedStatus, false, err, false)
return r.updateCRStatusOrFailReconcile(ctx, r.Log, hlf)
}
log.Debugf("Chart upgraded %s", release.Name)
}
log.Debugf("Chart upgraded %s", release.Name)
if !reflect.DeepEqual(fca.Status, hlf.Status) {
if err := r.Status().Update(ctx, fca); err != nil {
log.Debugf("Error updating the status: %v", err)
Expand Down
3 changes: 3 additions & 0 deletions controllers/chaincode/chaincode_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,9 @@ func (r *FabricChaincodeReconciler) Reconcile(ctx context.Context, req ctrl.Requ
FailureThreshold: 3,
},
}
if fabricChaincode.Spec.Resources != nil {
container.Resources = *fabricChaincode.Spec.Resources
}
if fabricChaincode.Spec.Command != nil {
container.Command = fabricChaincode.Spec.Command
}
Expand Down
5 changes: 4 additions & 1 deletion controllers/followerchannel/followerchannel_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"strings"
"time"
)

// FabricFollowerChannelReconciler reconciles a FabricFollowerChannel object
Expand Down Expand Up @@ -385,7 +386,9 @@ func (r *FabricFollowerChannelReconciler) updateCRStatusOrFailReconcile(ctx cont
log.Error(err, fmt.Sprintf("%v failed to update the application status", ErrClientK8s))
return reconcile.Result{}, err
}
return reconcile.Result{}, nil
return reconcile.Result{
RequeueAfter: 1 * time.Minute,
}, nil
}

func (r *FabricFollowerChannelReconciler) setConditionStatus(ctx context.Context, p *hlfv1alpha1.FabricFollowerChannel, conditionType hlfv1alpha1.DeploymentStatus, statusFlag bool, err error, statusUnknown bool) (update bool) {
Expand Down
4 changes: 3 additions & 1 deletion controllers/mainchannel/mainchannel_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,9 @@ func (r *FabricMainChannelReconciler) updateCRStatusOrFailReconcile(ctx context.
log.Error(err, fmt.Sprintf("%v failed to update the application status", ErrClientK8s))
return reconcile.Result{}, err
}
return reconcile.Result{}, nil
return reconcile.Result{
RequeueAfter: 1 * time.Minute,
}, nil
}

func (r *FabricMainChannelReconciler) setConditionStatus(ctx context.Context, p *hlfv1alpha1.FabricMainChannel, conditionType hlfv1alpha1.DeploymentStatus, statusFlag bool, err error, statusUnknown bool) (update bool) {
Expand Down
30 changes: 29 additions & 1 deletion controllers/ordnode/ordnode_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"helm.sh/helm/v3/pkg/release"
"os"
"reflect"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -162,6 +163,32 @@ func (r *FabricOrdererNodeReconciler) Reconcile(ctx context.Context, req ctrl.Re
// it doesn't exist
return ctrl.Result{}, err
}
} else if exists && helmStatus.Info.Status == release.StatusPendingRollback {
historyAction := action.NewHistory(cfg)
history, err := historyAction.Run(releaseName)
if err != nil {
return ctrl.Result{}, err
}
if len(history) > 0 {
// find the last deployed revision
// and rollback to it
// sort history by revision number descending using raw go
sort.Slice(history, func(i, j int) bool {
return history[i].Version > history[j].Version
})
for _, historyItem := range history {
if historyItem.Info.Status == release.StatusDeployed {
rollbackStatus := action.NewRollback(cfg)
rollbackStatus.Version = historyItem.Version
err = rollbackStatus.Run(releaseName)
if err != nil {
// it doesn't exist
return ctrl.Result{}, err
}
break
}
}
}
}
log.Printf("Release %s exists=%v", releaseName, exists)
clientSet, err := utils.GetClientKubeWithConf(r.Config)
Expand Down Expand Up @@ -216,7 +243,7 @@ func (r *FabricOrdererNodeReconciler) Reconcile(ctx context.Context, req ctrl.Re
lastTimeCertsRenewed = &newTime
log.Infof("Certs updated, last time updated: %v", lastTimeCertsRenewed)
requeueAfter = time.Minute * 1
} else {
} else if helmStatus.Info.Status != release.StatusPendingUpgrade {
c, err := getConfig(fabricOrdererNode, clientSet, releaseName, req.Namespace, false)
if err != nil {
return ctrl.Result{}, err
Expand Down Expand Up @@ -478,6 +505,7 @@ func (r *FabricOrdererNodeReconciler) upgradeChart(
cmd.Wait = r.Wait
cmd.Timeout = r.Timeout
cmd.MaxHistory = r.MaxHistory

release, err := cmd.Run(releaseName, ch, inInterface)
if err != nil {
return err
Expand Down
38 changes: 33 additions & 5 deletions controllers/peer/peer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"helm.sh/helm/v3/pkg/release"
"os"
"reflect"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -378,6 +379,32 @@ func (r *FabricPeerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
// it doesn't exist
return ctrl.Result{}, err
}
} else if exists && helmStatus.Info.Status == release.StatusPendingRollback {
historyAction := action.NewHistory(cfg)
history, err := historyAction.Run(releaseName)
if err != nil {
return ctrl.Result{}, err
}
if len(history) > 0 {
// find the last deployed revision
// and rollback to it
// sort history by revision number descending using raw go
sort.Slice(history, func(i, j int) bool {
return history[i].Version > history[j].Version
})
for _, historyItem := range history {
if historyItem.Info.Status == release.StatusDeployed {
rollbackStatus := action.NewRollback(cfg)
rollbackStatus.Version = historyItem.Version
err = rollbackStatus.Run(releaseName)
if err != nil {
// it doesn't exist
return ctrl.Result{}, err
}
break
}
}
}
}
log.Debugf("Release %s exists=%v", releaseName, exists)
clientSet, err := utils.GetClientKubeWithConf(r.Config)
Expand Down Expand Up @@ -449,11 +476,12 @@ func (r *FabricPeerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
r.setConditionStatus(ctx, fabricPeer, hlfv1alpha1.FailedStatus, false, err, false)
return r.updateCRStatusOrFailReconcile(ctx, r.Log, fabricPeer)
}

err = r.upgradeChart(cfg, err, ns, releaseName, c)
if err != nil {
r.setConditionStatus(ctx, fabricPeer, hlfv1alpha1.FailedStatus, false, err, false)
return r.updateCRStatusOrFailReconcile(ctx, r.Log, fabricPeer)
if helmStatus.Info.Status != release.StatusPendingUpgrade {
err = r.upgradeChart(cfg, err, ns, releaseName, c)
if err != nil {
r.setConditionStatus(ctx, fabricPeer, hlfv1alpha1.FailedStatus, false, err, false)
return r.updateCRStatusOrFailReconcile(ctx, r.Log, fabricPeer)
}
}
requeueAfter = time.Minute * 10
}
Expand Down
1 change: 1 addition & 0 deletions kubectl-hlf/cmd/chaincode/chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func NewChaincodeCmd(stdOut io.Writer, stdErr io.Writer) *cobra.Command {
newCalculatePackageIDCMD(stdOut, stdErr),
newGetLatestInfoCMD(stdOut, stdErr),
newCheckCommitReadiness(stdOut, stdErr),
newGetNextCMD(stdOut, stdErr),
)
return consortiumCmd
}
Loading

0 comments on commit b34e3ec

Please sign in to comment.