Skip to content

Commit

Permalink
Allow operator upgrade when no MCH's present (stolostron#1032)
Browse files Browse the repository at this point in the history
Signed-off-by: Jakob Gray <[email protected]>
  • Loading branch information
JakobGray authored May 10, 2023
1 parent 75d0194 commit 44d59b4
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,28 +198,44 @@ func main() {
os.Exit(1)
}

ctx := context.Background()

// Force OperatorCondition Upgradeable to False
//
// We have to at least default the condition to False or
// OLM will use the Readiness condition via our readiness probe instead:
// https://olm.operatorframework.io/docs/advanced-tasks/communicating-operator-conditions-to-olm/#setting-defaults
//
// We want to force it to False to ensure that the final decision about whether
// the operator can be upgraded stays within the hyperconverged controller.
setupLog.Info("Setting OperatorCondition.")
upgradeableCondition, err := utils.NewOperatorCondition(uncachedClient, operatorsapiv2.Upgradeable)
ctx := context.Background()

if err != nil {
setupLog.Error(err, "Cannot create the Upgradeable Operator Condition")
os.Exit(1)
}
err = upgradeableCondition.Set(ctx, metav1.ConditionFalse, utils.UpgradeableInitReason, utils.UpgradeableInitMessage)

mchList := &operatorv1.MultiClusterHubList{}
err = uncachedClient.List(context.TODO(), mchList)
if err != nil {
setupLog.Error(err, "unable to create uncached client")
setupLog.Error(err, "Could not set List multiclusterhubs")
os.Exit(1)
}

if len(mchList.Items) == 0 {
// If there is no MCH then no upgrade logic is needed.
err = upgradeableCondition.Set(ctx, metav1.ConditionTrue, utils.UpgradeableAllowReason, utils.UpgradeableAllowMessage)
if err != nil {
setupLog.Error(err, "Could not set Operator Condition")
os.Exit(1)
}
} else {
// We want to force it to False to ensure that the final decision about whether
// the operator can be upgraded stays within the controller.
err = upgradeableCondition.Set(ctx, metav1.ConditionFalse, utils.UpgradeableInitReason, utils.UpgradeableInitMessage)
if err != nil {
setupLog.Error(err, "unable to create uncached client")
os.Exit(1)
}
}

// re-create the condition, this time with the final client
upgradeableCondition, err = utils.NewOperatorCondition(mgr.GetClient(), operatorsapiv2.Upgradeable)
if err != nil {
Expand Down

0 comments on commit 44d59b4

Please sign in to comment.