Skip to content

Commit 06fb386

Browse files
committed
Add OperatorCondition status sync and update operator upgradeable check
OperatorCondition controller will update its status to refect the changes on its spec regarding the operator conditions that are reported by the operators themselves. In turn, operators can read the status to confirm if OLM has processed the spec changes. OLM will not take actions on upgradeable condition if the status is stale using ObservedGeneration and Generation check. Upstream-commit: 4ae8df668dd098c204f757b8572fa608a9899bdc Upstream-repository: operator-lifecycle-manager Signed-off-by: Vu Dinh <[email protected]>
1 parent 6156d25 commit 06fb386

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

staging/operator-lifecycle-manager/pkg/controller/operators/olm/operatorconditions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ func (a *Operator) isOperatorUpgradeable(csv *v1alpha1.ClusterServiceVersion) (b
3636

3737
// Check for OperatorUpgradeable condition status
3838
if c := meta.FindStatusCondition(cond.Status.Conditions, operatorsv1.Upgradeable); c != nil {
39+
if c.ObservedGeneration < cond.ObjectMeta.Generation {
40+
return false, fmt.Errorf("The operatorcondition status %q=%q is outdated", c.Type, c.Status)
41+
}
3942
if c.Status == metav1.ConditionFalse {
4043
return false, fmt.Errorf("The operator is not upgradeable: %s", c.Message)
4144
}

staging/operator-lifecycle-manager/pkg/controller/operators/operatorcondition_controller.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
corev1 "k8s.io/api/core/v1"
1010
rbacv1 "k8s.io/api/rbac/v1"
1111
k8serrors "k8s.io/apimachinery/pkg/api/errors"
12+
meta "k8s.io/apimachinery/pkg/api/meta"
1213
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1314
"k8s.io/apimachinery/pkg/runtime"
1415
"k8s.io/apimachinery/pkg/types"
@@ -119,6 +120,12 @@ func (r *OperatorConditionReconciler) Reconcile(ctx context.Context, req ctrl.Re
119120
return ctrl.Result{Requeue: true}, err
120121
}
121122

123+
err = r.syncOperatorConditionStatus(operatorCondition)
124+
if err != nil {
125+
log.V(1).Error(err, "Error syncing OperatorCondition Status")
126+
return ctrl.Result{Requeue: true}, err
127+
}
128+
122129
return ctrl.Result{}, nil
123130
}
124131

@@ -252,6 +259,26 @@ func (r *OperatorConditionReconciler) ensureDeploymentEnvVars(operatorCondition
252259
return nil
253260
}
254261

262+
func (r *OperatorConditionReconciler) syncOperatorConditionStatus(operatorCondition *operatorsv1.OperatorCondition) error {
263+
r.log.V(4).Info("Sync operatorcondition status")
264+
currentGen := operatorCondition.ObjectMeta.GetGeneration()
265+
changed := false
266+
for _, cond := range operatorCondition.Spec.Conditions {
267+
if c := meta.FindStatusCondition(operatorCondition.Status.Conditions, cond.Type); c != nil {
268+
if cond.Status == c.Status && c.ObservedGeneration == currentGen {
269+
continue
270+
}
271+
}
272+
meta.SetStatusCondition(&operatorCondition.Status.Conditions, cond)
273+
changed = true
274+
}
275+
276+
if changed {
277+
return r.Client.Status().Update(context.TODO(), operatorCondition)
278+
}
279+
return nil
280+
}
281+
255282
func ensureEnvVarIsPresent(envVars []corev1.EnvVar, envVar corev1.EnvVar) ([]corev1.EnvVar, bool) {
256283
for i, each := range envVars {
257284
if each.Name == envVar.Name {

vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm/operatorconditions.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/operatorcondition_controller.go

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)