Skip to content

Commit

Permalink
Create RollingUpgradeContext (#234)
Browse files Browse the repository at this point in the history
* #2285: rollup CR statistic metrics in v2 (#218)

* #2285: rollup CR statistic metrics in v2

Signed-off-by: sbadla1 <sahil_badla@intuit.com>

* #2285: updated metric flags

Signed-off-by: sbadla1 <sahil_badla@intuit.com>

* #2285: updated metric flags

Signed-off-by: sbadla1 <sahil_badla@intuit.com>
Signed-off-by: sbadiger <shreyas_badiger@intuit.com>

* log cloud discovery failure

Signed-off-by: sbadiger <shreyas_badiger@intuit.com>

* Create RollingUpgrade Context

Signed-off-by: sbadiger <shreyas_badiger@intuit.com>

* rollingupgrade context

Signed-off-by: sbadiger <shreyas_badiger@intuit.com>

Co-authored-by: Sahil Badla <sahil_badla@intuit.com>
  • Loading branch information
shreyas-badiger and sahilbadla committed May 13, 2021
1 parent b8d0e72 commit b664fdd
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 156 deletions.
12 changes: 11 additions & 1 deletion controllers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,22 @@ func createRollingUpgradeReconciler(t *testing.T) *RollingUpgradeReconciler {
ScriptRunner: ScriptRunner{
Logger: logger,
},
Cloud: NewDiscoveredState(auth, logger),
}
return reconciler

}

func createRollingUpgradeContext(r *RollingUpgradeReconciler) *RollingUpgradeContext {
return &RollingUpgradeContext{
Logger: r.Logger,
Auth: r.Auth,
ScriptRunner: r.ScriptRunner,
Cloud: NewDiscoveredState(r.Auth, r.Logger),
RollingUpgrade: createRollingUpgrade(),
}

}

func createRollingUpgrade() *v1alpha1.RollingUpgrade {
return &v1alpha1.RollingUpgrade{
ObjectMeta: metav1.ObjectMeta{Name: "0", Namespace: "default"},
Expand Down
30 changes: 17 additions & 13 deletions controllers/rollingupgrade_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,13 @@ import (
type RollingUpgradeReconciler struct {
client.Client
logr.Logger
Scheme *runtime.Scheme
AdmissionMap sync.Map
CacheConfig *cache.Config
Auth *RollingUpgradeAuthenticator
Cloud *DiscoveredState
EventWriter *kubeprovider.EventWriter
maxParallel int
ScriptRunner ScriptRunner
DrainGroupMapper sync.Map
DrainErrorMapper sync.Map
Scheme *runtime.Scheme
AdmissionMap sync.Map
CacheConfig *cache.Config
EventWriter *kubeprovider.EventWriter
maxParallel int
ScriptRunner ScriptRunner
Auth *RollingUpgradeAuthenticator
}

type RollingUpgradeAuthenticator struct {
Expand Down Expand Up @@ -129,16 +126,23 @@ func (r *RollingUpgradeReconciler) Reconcile(ctx context.Context, req ctrl.Reque
rollingUpgrade.SetCurrentStatus(v1alpha1.StatusInit)
common.SetMetricRollupInitOrRunning(rollingUpgrade.Name)

r.Cloud = NewDiscoveredState(r.Auth, r.Logger)
if err := r.Cloud.Discover(); err != nil {
rollupCtx := &RollingUpgradeContext{
Logger: r.Logger,
Auth: r.Auth,
ScriptRunner: r.ScriptRunner,
RollingUpgrade: rollingUpgrade,
}
rollupCtx.Cloud = NewDiscoveredState(rollupCtx.Auth, rollupCtx.Logger)
if err := rollupCtx.Cloud.Discover(); err != nil {
r.Info("failed to discover the cloud", "name", rollingUpgrade.NamespacedName(), "scalingGroup", scalingGroupName)
rollingUpgrade.SetCurrentStatus(v1alpha1.StatusError)
// Set prometheus metric cr_status_failed
common.SetMetricRollupFailed(rollingUpgrade.Name)
return ctrl.Result{}, err
}

// process node rotation
if err := r.RotateNodes(rollingUpgrade); err != nil {
if err := rollupCtx.RotateNodes(); err != nil {
rollingUpgrade.SetCurrentStatus(v1alpha1.StatusError)
// Set prometheus metric cr_status_failed
common.SetMetricRollupFailed(rollingUpgrade.Name)
Expand Down
Loading

0 comments on commit b664fdd

Please sign in to comment.