@@ -38,7 +38,6 @@ import (
38
38
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
39
39
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
40
40
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/projection"
41
- "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/comparison"
42
41
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
43
42
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
44
43
registryapi "github.com/operator-framework/operator-registry/pkg/api"
@@ -328,7 +327,7 @@ var _ = Describe("Subscription", func() {
328
327
subscriptionCleanup , _ := createSubscription (GinkgoT (), crc , generatedNamespace .GetName (), "manual-subscription" , testPackageName , stableChannel , operatorsv1alpha1 .ApprovalManual )
329
328
defer subscriptionCleanup ()
330
329
331
- subscription , err := fetchSubscription (crc , generatedNamespace .GetName (), "manual-subscription" , subscriptionStateUpgradePendingChecker ( ))
330
+ subscription , err := fetchSubscription (crc , generatedNamespace .GetName (), "manual-subscription" , subscriptionHasCondition ( operatorsv1alpha1 . SubscriptionInstallPlanPending , corev1 . ConditionTrue , string ( operatorsv1alpha1 . InstallPlanPhaseRequiresApproval ), "" ))
332
331
require .NoError (GinkgoT (), err )
333
332
require .NotNil (GinkgoT (), subscription )
334
333
@@ -1029,29 +1028,7 @@ var _ = Describe("Subscription", func() {
1029
1028
})
1030
1029
1031
1030
It ("can reconcile InstallPlan status" , func () {
1032
- By (`TestSubscriptionInstallPlanStatus ensures that a Subscription has the appropriate status conditions for possible referenced` )
1033
- By (`InstallPlan states.` )
1034
- By (` BySteps:` )
1035
- By (`- Utilize the namespace and OG targeting that namespace created in the BeforeEach clause` )
1036
- By (`- Create CatalogSource, cs, in ns` )
1037
- By (`- Create Subscription to a package of cs in ns, sub` )
1038
- By (`- Wait for the package from sub to install successfully with no remaining InstallPlan status conditions` )
1039
- By (`- Store conditions for later comparision` )
1040
- By (`- Get the InstallPlan` )
1041
- By (`- Set the InstallPlan's approval mode to Manual` )
1042
- By (`- Set the InstallPlan's phase to None` )
1043
- By (`- Wait for sub to have status condition SubscriptionInstallPlanPending true and reason InstallPlanNotYetReconciled` )
1044
- By (`- Get the latest IntallPlan and set the phase to InstallPlanPhaseRequiresApproval` )
1045
- By (`- Wait for sub to have status condition SubscriptionInstallPlanPending true and reason RequiresApproval` )
1046
- By (`- Get the latest InstallPlan and set the phase to InstallPlanPhaseInstalling` )
1047
- By (`- Wait for sub to have status condition SubscriptionInstallPlanPending true and reason Installing` )
1048
- By (`- Get the latest InstallPlan and set the phase to InstallPlanPhaseFailed and remove all status conditions` )
1049
- By (`- Wait for sub to have status condition SubscriptionInstallPlanFailed true and reason InstallPlanFailed` )
1050
- By (`- Get the latest InstallPlan and set status condition of type Installed to false with reason InstallComponentFailed` )
1051
- By (`- Wait for sub to have status condition SubscriptionInstallPlanFailed true and reason InstallComponentFailed` )
1052
- By (`- Delete the referenced InstallPlan` )
1053
- By (`- Wait for sub to have status condition SubscriptionInstallPlanMissing true` )
1054
- By (`- Ensure original non-InstallPlan status conditions remain after InstallPlan transitions` )
1031
+ By (`TestSubscriptionInstallPlanStatus ensures that a Subscription has the appropriate status conditions for possible referenced InstallPlan states.` )
1055
1032
c := newKubeClient ()
1056
1033
crc := newCRClient ()
1057
1034
@@ -1099,6 +1076,7 @@ var _ = Describe("Subscription", func() {
1099
1076
ref := sub .Status .InstallPlanRef
1100
1077
Expect (ref ).ToNot (BeNil ())
1101
1078
1079
+ By (`Get the InstallPlan` )
1102
1080
plan := & operatorsv1alpha1.InstallPlan {}
1103
1081
plan .SetNamespace (ref .Namespace )
1104
1082
plan .SetName (ref .Name )
@@ -1151,14 +1129,14 @@ var _ = Describe("Subscription", func() {
1151
1129
return true
1152
1130
}
1153
1131
1154
- By ( ` Sometimes the transition from installing to complete can be so quick that the test does not capture` )
1155
- By ( ` the condition in the subscription before it is removed. To mitigate this, we check if the installplan` )
1156
- By ( ` has transitioned to complete and exit out the fetch subscription loop if so.` )
1157
- By ( ` This is a mitigation. We should probably fix this test appropriately.` )
1158
- By ( ` issue: https://github.com/operator-framework/operator-lifecycle-manager/issues/2667` )
1132
+ // Sometimes the transition from installing to complete can be so quick that the test does not capture
1133
+ // the condition in the subscription before it is removed. To mitigate this, we check if the installplan
1134
+ // has transitioned to complete and exit out the fetch subscription loop if so.
1135
+ // This is a mitigation. We should probably fix this test appropriately.
1136
+ // issue: https://github.com/operator-framework/operator-lifecycle-manager/issues/2667
1159
1137
ip , err := crc .OperatorsV1alpha1 ().InstallPlans (generatedNamespace .GetName ()).Get (context .TODO (), plan .Name , metav1.GetOptions {})
1160
1138
if err != nil {
1161
- By ( ` retry on failure` )
1139
+ // retry on failure
1162
1140
return false
1163
1141
}
1164
1142
isInstallPlanComplete := ip .Status .Phase == operatorsv1alpha1 .InstallPlanPhaseComplete
@@ -1210,16 +1188,13 @@ var _ = Describe("Subscription", func() {
1210
1188
Expect (err ).ToNot (HaveOccurred ())
1211
1189
Expect (sub ).ToNot (BeNil ())
1212
1190
1213
- By (`Ensure original non-InstallPlan status conditions remain after InstallPlan transitions` )
1214
- hashEqual := comparison .NewHashEqualitor ()
1191
+ By (`Ensure InstallPlan-related status conditions match what we're expecting` )
1215
1192
for _ , cond := range conds {
1216
1193
switch condType := cond .Type ; condType {
1217
1194
case operatorsv1alpha1 .SubscriptionInstallPlanPending , operatorsv1alpha1 .SubscriptionInstallPlanFailed :
1218
1195
require .FailNowf (GinkgoT (), "failed" , "subscription contains unexpected installplan condition: %v" , cond )
1219
1196
case operatorsv1alpha1 .SubscriptionInstallPlanMissing :
1220
1197
require .Equal (GinkgoT (), operatorsv1alpha1 .ReferencedInstallPlanNotFound , cond .Reason )
1221
- default :
1222
- require .True (GinkgoT (), hashEqual (cond , sub .Status .GetCondition (condType )), "non-installplan status condition changed" )
1223
1198
}
1224
1199
}
1225
1200
})
@@ -3218,27 +3193,53 @@ func subscriptionHasCurrentCSV(currentCSV string) subscriptionStateChecker {
3218
3193
}
3219
3194
3220
3195
func subscriptionHasCondition (condType operatorsv1alpha1.SubscriptionConditionType , status corev1.ConditionStatus , reason , message string ) subscriptionStateChecker {
3196
+ var lastCond operatorsv1alpha1.SubscriptionCondition
3197
+ lastTime := time .Now ()
3198
+ // if status/reason/message meet expectations, then subscription state is considered met/true
3199
+ // IFF this is the result of a recent change of status/reason/message
3200
+ // else, cache the current status/reason/message for next loop/comparison
3221
3201
return func (subscription * operatorsv1alpha1.Subscription ) bool {
3222
3202
cond := subscription .Status .GetCondition (condType )
3223
3203
if cond .Status == status && cond .Reason == reason && cond .Message == message {
3224
- fmt .Printf ("subscription condition met %v\n " , cond )
3204
+ if lastCond .Status != cond .Status && lastCond .Reason != cond .Reason && lastCond .Message == cond .Message {
3205
+ GinkgoT ().Logf ("waited %s subscription condition met %v\n " , time .Since (lastTime ), cond )
3206
+ lastTime = time .Now ()
3207
+ lastCond = cond
3208
+ }
3225
3209
return true
3226
3210
}
3227
3211
3228
- fmt .Printf ("subscription condition not met: %v\n " , cond )
3212
+ if lastCond .Status != cond .Status && lastCond .Reason != cond .Reason && lastCond .Message == cond .Message {
3213
+ GinkgoT ().Logf ("waited %s subscription condition not met: %v\n " , time .Since (lastTime ), cond )
3214
+ lastTime = time .Now ()
3215
+ lastCond = cond
3216
+ }
3229
3217
return false
3230
3218
}
3231
3219
}
3232
3220
3233
3221
func subscriptionDoesNotHaveCondition (condType operatorsv1alpha1.SubscriptionConditionType ) subscriptionStateChecker {
3222
+ var lastStatus corev1.ConditionStatus
3223
+ lastTime := time .Now ()
3224
+ // if status meets expectations, then subscription state is considered met/true
3225
+ // IFF this is the result of a recent change of status
3226
+ // else, cache the current status for next loop/comparison
3234
3227
return func (subscription * operatorsv1alpha1.Subscription ) bool {
3235
3228
cond := subscription .Status .GetCondition (condType )
3236
3229
if cond .Status == corev1 .ConditionUnknown {
3237
- fmt .Printf ("subscription condition not found\n " )
3230
+ if cond .Status != lastStatus {
3231
+ GinkgoT ().Logf ("waited %s subscription condition not found\n " , time .Since (lastTime ))
3232
+ lastStatus = cond .Status
3233
+ lastTime = time .Now ()
3234
+ }
3238
3235
return true
3239
3236
}
3240
3237
3241
- fmt .Printf ("subscription condition found: %v\n " , cond )
3238
+ if cond .Status != lastStatus {
3239
+ GinkgoT ().Logf ("waited %s subscription condition found: %v\n " , time .Since (lastTime ), cond )
3240
+ lastStatus = cond .Status
3241
+ lastTime = time .Now ()
3242
+ }
3242
3243
return false
3243
3244
}
3244
3245
}
@@ -3365,6 +3366,35 @@ func createSubscriptionForCatalogWithSpec(t GinkgoTInterface, crc versioned.Inte
3365
3366
return buildSubscriptionCleanupFunc (crc , subscription )
3366
3367
}
3367
3368
3369
+ func waitForSubscriptionToDelete (namespace , name string , c versioned.Interface ) error {
3370
+ var lastState operatorsv1alpha1.SubscriptionState
3371
+ var lastReason operatorsv1alpha1.ConditionReason
3372
+ lastTime := time .Now ()
3373
+
3374
+ ctx .Ctx ().Logf ("waiting for subscription %s/%s to delete" , namespace , name )
3375
+ err := wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
3376
+ sub , err := c .OperatorsV1alpha1 ().Subscriptions (namespace ).Get (context .TODO (), name , metav1.GetOptions {})
3377
+ if apierrors .IsNotFound (err ) {
3378
+ ctx .Ctx ().Logf ("subscription %s/%s deleted" , namespace , name )
3379
+ return true , nil
3380
+ }
3381
+ if err != nil {
3382
+ ctx .Ctx ().Logf ("error getting subscription %s/%s: %v" , namespace , name , err )
3383
+ }
3384
+ if sub != nil {
3385
+ state , reason := sub .Status .State , sub .Status .Reason
3386
+ if state != lastState || reason != lastReason {
3387
+ ctx .Ctx ().Logf ("waited %s for subscription %s/%s status: %s (%s)" , time .Since (lastTime ), namespace , name , state , reason )
3388
+ lastState , lastReason = state , reason
3389
+ lastTime = time .Now ()
3390
+ }
3391
+ }
3392
+ return false , nil
3393
+ })
3394
+
3395
+ return err
3396
+ }
3397
+
3368
3398
func checkDeploymentHasPodConfigNodeSelector (t GinkgoTInterface , client operatorclient.ClientInterface , csv * operatorsv1alpha1.ClusterServiceVersion , nodeSelector map [string ]string ) error {
3369
3399
resolver := install.StrategyResolver {}
3370
3400
0 commit comments