Skip to content

Commit 86eda22

Browse files
committed
Update OperatorCondition Role and e2e test case
1. Operator can create/update/patch OperatorCondition but not its status. 2. Update the e2e test case to update OperatorCondition's spec directly instead of its status Signed-off-by: Vu Dinh <[email protected]>
1 parent f934d5c commit 86eda22

File tree

5 files changed

+148
-25
lines changed

5 files changed

+148
-25
lines changed

pkg/controller/operators/olm/operatorconditions.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
1111
"github.com/operator-framework/api/pkg/operators/v1alpha1"
12+
"github.com/sirupsen/logrus"
1213
)
1314

1415
func (a *Operator) isOperatorUpgradeable(csv *v1alpha1.ClusterServiceVersion) (bool, error) {
@@ -24,19 +25,27 @@ func (a *Operator) isOperatorUpgradeable(csv *v1alpha1.ClusterServiceVersion) (b
2425
return false, err
2526
}
2627

28+
logger := a.logger.WithFields(logrus.Fields{
29+
"name": csv.GetName(),
30+
"namespace": csv.GetNamespace(),
31+
})
32+
2733
// Check condition overrides
2834
for _, override := range cond.Spec.Overrides {
2935
if override.Type == operatorsv1.Upgradeable {
3036
if override.Status == metav1.ConditionTrue {
37+
logger.Infof("Upgradeable condition is overridden to true: %s", override.Message)
3138
return true, nil
3239
}
40+
logger.Infof("Upgradeable condition is overridden to false: %s", override.Message)
3341
return false, fmt.Errorf("The operator is not upgradeable: %s", override.Message)
3442
}
3543
}
3644

3745
// Check for OperatorUpgradeable condition status
3846
if c := meta.FindStatusCondition(cond.Status.Conditions, operatorsv1.Upgradeable); c != nil {
3947
if c.ObservedGeneration < cond.ObjectMeta.Generation {
48+
logger.Debugf("Upgradeable condition's generation doesn't match: %d/%d", c.ObservedGeneration, cond.ObjectMeta.Generation)
4049
return false, fmt.Errorf("The operatorcondition status %q=%q is outdated", c.Type, c.Status)
4150
}
4251
if c.Status == metav1.ConditionFalse {

pkg/controller/operators/operatorcondition_controller.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,10 @@ func (r *OperatorConditionReconciler) ensureOperatorConditionRole(operatorCondit
137137
Namespace: operatorCondition.GetNamespace(),
138138
},
139139
Rules: []rbacv1.PolicyRule{
140-
{
141-
Verbs: []string{"get"},
142-
APIGroups: []string{"operators.coreos.com"},
143-
Resources: []string{"operatorconditions"},
144-
ResourceNames: []string{operatorCondition.GetName()},
145-
},
146140
{
147141
Verbs: []string{"get", "update", "patch"},
148142
APIGroups: []string{"operators.coreos.com"},
149-
Resources: []string{"operatorconditions/status"},
143+
Resources: []string{"operatorconditions"},
150144
ResourceNames: []string{operatorCondition.GetName()},
151145
},
152146
},

pkg/controller/operators/operatorcondition_controller_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,10 @@ var _ = Describe("OperatorCondition", func() {
9999
BlockOwnerDeletion: &falseBool,
100100
}))
101101
Expect(role.Rules).Should(Equal([]rbacv1.PolicyRule{
102-
{
103-
Verbs: []string{"get"},
104-
APIGroups: []string{"operators.coreos.com"},
105-
Resources: []string{"operatorconditions"},
106-
ResourceNames: []string{namespacedName.Name},
107-
},
108102
{
109103
Verbs: []string{"get", "update", "patch"},
110104
APIGroups: []string{"operators.coreos.com"},
111-
Resources: []string{"operatorconditions/status"},
105+
Resources: []string{"operatorconditions"},
112106
ResourceNames: []string{namespacedName.Name},
113107
},
114108
}))

test/e2e/operator_condition_e2e_test.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var _ = Describe("Operator Condition", func() {
2626
By("This test proves that an operator can upgrade successfully when" +
2727
"Upgrade condition type is set in OperatorCondition CR. Plus, an operator" +
2828
"chooses not to use OperatorCondition, the upgrade process will proceed as" +
29-
" asexpected. The overrides specification in OperatorCondition can be used to" +
29+
" as expected. The overrides specification in OperatorCondition can be used to" +
3030
" override the status condition. The overrides spec will remain in place until" +
3131
"they are unset.")
3232
c := newKubeClient()
@@ -99,14 +99,17 @@ var _ = Describe("Operator Condition", func() {
9999
Message: "test",
100100
LastTransitionTime: metav1.Now(),
101101
}
102+
103+
var currentGen int64
102104
Eventually(func() error {
103105
cond, err = crc.OperatorsV1().OperatorConditions(testNamespace).Get(context.TODO(), csvA.GetName(), metav1.GetOptions{})
104106
if err != nil {
105107
return err
106108
}
107-
108-
meta.SetStatusCondition(&cond.Status.Conditions, upgradeableFalseCondition)
109-
_, err = crc.OperatorsV1().OperatorConditions(testNamespace).UpdateStatus(context.TODO(), cond, metav1.UpdateOptions{})
109+
currentGen = cond.ObjectMeta.GetGeneration()
110+
upgradeableFalseCondition.ObservedGeneration = currentGen
111+
meta.SetStatusCondition(&cond.Spec.Conditions, upgradeableFalseCondition)
112+
_, err = crc.OperatorsV1().OperatorConditions(testNamespace).Update(context.TODO(), cond, metav1.UpdateOptions{})
110113
return err
111114

112115
}, pollInterval, pollDuration).Should(Succeed())
@@ -142,11 +145,13 @@ var _ = Describe("Operator Condition", func() {
142145
}
143146
Eventually(func() error {
144147
cond, err = crc.OperatorsV1().OperatorConditions(testNamespace).Get(context.TODO(), csvA.GetName(), metav1.GetOptions{})
145-
if err != nil {
148+
if err != nil || currentGen == cond.ObjectMeta.GetGeneration() {
146149
return err
147150
}
148-
meta.SetStatusCondition(&cond.Status.Conditions, upgradeableTrueCondition)
149-
_, err = crc.OperatorsV1().OperatorConditions(testNamespace).UpdateStatus(context.TODO(), cond, metav1.UpdateOptions{})
151+
currentGen = cond.ObjectMeta.GetGeneration()
152+
upgradeableTrueCondition.ObservedGeneration = cond.ObjectMeta.GetGeneration()
153+
meta.SetStatusCondition(&cond.Spec.Conditions, upgradeableTrueCondition)
154+
_, err = crc.OperatorsV1().OperatorConditions(testNamespace).Update(context.TODO(), cond, metav1.UpdateOptions{})
150155
return err
151156
}, pollInterval, pollDuration).Should(Succeed())
152157

@@ -157,11 +162,13 @@ var _ = Describe("Operator Condition", func() {
157162
// Get the OperatorCondition for csvB and report that it is not upgradeable
158163
Eventually(func() error {
159164
cond, err = crc.OperatorsV1().OperatorConditions(testNamespace).Get(context.TODO(), csvB.GetName(), metav1.GetOptions{})
160-
if err != nil {
165+
if err != nil || currentGen == cond.ObjectMeta.GetGeneration() {
161166
return err
162167
}
163-
meta.SetStatusCondition(&cond.Status.Conditions, upgradeableFalseCondition)
164-
_, err = crc.OperatorsV1().OperatorConditions(testNamespace).UpdateStatus(context.TODO(), cond, metav1.UpdateOptions{})
168+
currentGen = cond.ObjectMeta.GetGeneration()
169+
upgradeableFalseCondition.ObservedGeneration = currentGen
170+
meta.SetStatusCondition(&cond.Spec.Conditions, upgradeableFalseCondition)
171+
_, err = crc.OperatorsV1().OperatorConditions(testNamespace).Update(context.TODO(), cond, metav1.UpdateOptions{})
165172
return err
166173
}, pollInterval, pollDuration).Should(Succeed())
167174

@@ -189,7 +196,7 @@ var _ = Describe("Operator Condition", func() {
189196
// Get the OperatorCondition for csvB and override the upgradeable false condition
190197
Eventually(func() error {
191198
cond, err = crc.OperatorsV1().OperatorConditions(testNamespace).Get(context.TODO(), csvB.GetName(), metav1.GetOptions{})
192-
if err != nil {
199+
if err != nil || currentGen == cond.ObjectMeta.GetGeneration() {
193200
return err
194201
}
195202
// Set Condition overrides to True

vendor/github.com/operator-framework/api/crds/operators.coreos.com_operatorconditions.yaml

Lines changed: 119 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)