Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
squash: remove reconciliation during CLI display operations (#2642)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Nisbet authored Sep 24, 2021
1 parent 9c87fc7 commit 019c295
Showing 1 changed file with 14 additions and 29 deletions.
43 changes: 14 additions & 29 deletions tool/gravity/cli/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ import (
"github.com/gravitational/gravity/lib/ops"
"github.com/gravitational/gravity/lib/storage"
libenviron "github.com/gravitational/gravity/lib/system/environ"
"github.com/gravitational/gravity/lib/update"
clusterupdate "github.com/gravitational/gravity/lib/update/cluster"
"github.com/gravitational/gravity/lib/utils"

"github.com/fatih/color"
"github.com/gravitational/trace"
"github.com/sirupsen/logrus"
)

func initUpdateOperationPlan(localEnv, updateEnv *localenv.LocalEnvironment) error {
Expand Down Expand Up @@ -132,28 +130,29 @@ func displayClusterOperationPlan(localEnv *localenv.LocalEnvironment, opKey ops.
return outputOrFollowPlan(localEnv, getClusterOperationPlanFunc(localEnv, opKey), opts)
}

func getUpdateOperationPlanFunc(localEnv *localenv.LocalEnvironment, environ LocalEnvironmentFactory, opKey ops.SiteOperationKey) fsm.GetPlanFunc {
func getUpdateOperationPlanFunc(environ LocalEnvironmentFactory, opKey ops.SiteOperationKey) (fsm.GetPlanFunc, error) {
updateEnv, err := environ.NewUpdateEnv()
if err != nil {
return nil, trace.Wrap(err)
}

return func() (*storage.OperationPlan, error) {
updateEnv, err := environ.NewUpdateEnv()
if err != nil {
return nil, trace.Wrap(err)
}
plan, err := fsm.GetOperationPlan(updateEnv.Backend, opKey)
if err != nil {
return nil, trace.Wrap(err)
}
reconciledPlan, err := tryReconcilePlan(context.TODO(), localEnv, updateEnv, *plan)
if err != nil {
logrus.WithError(err).Warn("Failed to reconcile plan.")
} else {
plan = reconciledPlan
}

return plan, nil
}
}, nil
}

func displayUpdateOperationPlan(localEnv *localenv.LocalEnvironment, environ LocalEnvironmentFactory, opKey ops.SiteOperationKey, opts displayPlanOptions) error {
return outputOrFollowPlan(localEnv, getUpdateOperationPlanFunc(localEnv, environ, opKey), opts)
f, err := getUpdateOperationPlanFunc(environ, opKey)
if err != nil {
return trace.Wrap(err)
}

return outputOrFollowPlan(localEnv, f, opts)
}

func getInstallOperationPlanFunc(opKey ops.SiteOperationKey) fsm.GetPlanFunc {
Expand Down Expand Up @@ -294,20 +293,6 @@ func outputPhaseError(phase storage.OperationPhase) error {
return nil
}

func tryReconcilePlan(ctx context.Context, localEnv, updateEnv *localenv.LocalEnvironment, plan storage.OperationPlan) (*storage.OperationPlan, error) {
clusterEnv, err := localEnv.NewClusterEnvironment(localenv.WithEtcdTimeout(1 * time.Second))
if err != nil {
return nil, trace.Wrap(err)
}
reconciler := update.NewDefaultReconciler(clusterEnv.Backend, updateEnv.Backend,
plan.ClusterName, plan.OperationID, logrus.WithField("operation-id", plan.OperationID))
reconciledPlan, err := reconciler.ReconcilePlan(ctx, plan)
if err != nil {
return nil, trace.Wrap(err)
}
return reconciledPlan, nil
}

func getPlanFromWizardBackend(opKey ops.SiteOperationKey) (*storage.OperationPlan, error) {
wizardEnv, err := localenv.NewLocalWizardEnvironment()
if err != nil {
Expand Down

0 comments on commit 019c295

Please sign in to comment.