Skip to content

Commit

Permalink
Fix automatically helm charts in the status: pending-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
dviejokfs committed Oct 16, 2023
1 parent f84031f commit 57404db
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
14 changes: 12 additions & 2 deletions controllers/ca/ca_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/kfsoftware/hlf-operator/controllers/hlfmetrics"
"github.com/kfsoftware/hlf-operator/pkg/status"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/release"
"k8s.io/kubernetes/pkg/api/v1/pod"
"sort"

Expand Down Expand Up @@ -906,13 +907,22 @@ func Reconcile(

cmdStatus := action.NewStatus(cfg)
exists := true
_, err = cmdStatus.Run(releaseName)
helmStatus, err := cmdStatus.Run(releaseName)
if err != nil {
if errors.Is(err, driver.ErrReleaseNotFound) {
// it doesn't exists
exists = false
} else {
// it doesnt exist
// it doesn't exist
return ctrl.Result{}, err
}
}
if exists && helmStatus.Info.Status == release.StatusPendingUpgrade {
rollbackStatus := action.NewRollback(cfg)
rollbackStatus.Version = helmStatus.Version - 1
err = rollbackStatus.Run(releaseName)
if err != nil {
// it doesn't exist
return ctrl.Result{}, err
}
}
Expand Down
16 changes: 13 additions & 3 deletions controllers/ordnode/ordnode_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"encoding/pem"
"fmt"
"helm.sh/helm/v3/pkg/release"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -138,13 +139,22 @@ func (r *FabricOrdererNodeReconciler) Reconcile(ctx context.Context, req ctrl.Re
}
cmdStatus := action.NewStatus(cfg)
exists := true
_, err = cmdStatus.Run(releaseName)
helmStatus, err := cmdStatus.Run(releaseName)
if err != nil {
if errors.Is(err, driver.ErrReleaseNotFound) {
// it doesn't exists
exists = false
} else {
// it doesnt exist
// it doesn't exist
return ctrl.Result{}, err
}
}
if exists && helmStatus.Info.Status == release.StatusPendingUpgrade {
rollbackStatus := action.NewRollback(cfg)
rollbackStatus.Version = helmStatus.Version - 1
err = rollbackStatus.Run(releaseName)
if err != nil {
// it doesn't exist
return ctrl.Result{}, err
}
}
Expand Down Expand Up @@ -386,7 +396,7 @@ func (r *FabricOrdererNodeReconciler) SetupWithManager(mgr ctrl.Manager) error {
For(&hlfv1alpha1.FabricOrdererNode{}).
Owns(&appsv1.Deployment{}).
WithOptions(controller.Options{
MaxConcurrentReconciles: 10,
MaxConcurrentReconciles: 1,
}).
Complete(r)
}
Expand Down
18 changes: 14 additions & 4 deletions controllers/peer/peer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"encoding/pem"
"fmt"
"helm.sh/helm/v3/pkg/release"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -356,14 +357,23 @@ func (r *FabricPeerReconciler) Reconcile(ctx context.Context, req ctrl.Request)

cmdStatus := action.NewStatus(cfg)
exists := true
_, err = cmdStatus.Run(releaseName)
helmStatus, err := cmdStatus.Run(releaseName)
if err != nil {
if errors.Is(err, driver.ErrReleaseNotFound) {
// it doesn't exists
exists = false
} else {
// it doesnt exist
r.setConditionStatus(ctx, fabricPeer, hlfv1alpha1.FailedStatus, false, err, false)
return r.updateCRStatusOrFailReconcile(ctx, r.Log, fabricPeer)
// it doesn't exist
return ctrl.Result{}, err
}
}
if exists && helmStatus.Info.Status == release.StatusPendingUpgrade {
rollbackStatus := action.NewRollback(cfg)
rollbackStatus.Version = helmStatus.Version - 1
err = rollbackStatus.Run(releaseName)
if err != nil {
// it doesn't exist
return ctrl.Result{}, err
}
}
log.Debugf("Release %s exists=%v", releaseName, exists)
Expand Down

0 comments on commit 57404db

Please sign in to comment.