Skip to content

Commit

Permalink
Enhance workaround for Subscription ResolutionFailed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanemerson committed Sep 10, 2024
1 parent fe3f7f0 commit c8d84c0
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func TestRollingUpgrade(t *testing.T) {
}

defer testKube.CleanupOLMTest(t, tutils.TestName(t), olm.SubName, olm.SubNamespace, olm.SubPackage)
testKube.CreateSubscriptionAndApproveInitialVersion(olm, sub)
testKube.CreateOperatorGroup(olm)
testKube.CreateSubscriptionAndApproveInitialVersion(sub)

replicas := 2
entriesPerCache := 100
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/upgrade/dropped_operand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func TestUpgradeFromDroppedOperand(t *testing.T) {
},
}
defer testKube.CleanupOLMTest(t, tutils.TestName(t), olm.SubName, olm.SubNamespace, olm.SubPackage)
testKube.CreateSubscriptionAndApproveInitialVersion(olm, sub)
testKube.CreateOperatorGroup(olm)
testKube.CreateSubscriptionAndApproveInitialVersion(sub)

replicas := 1
spec := tutils.DefaultSpec(t, testKube, func(i *ispnv1.Infinispan) {
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/upgrade/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ func TestUpgrade(t *testing.T) {
}

defer testKube.CleanupOLMTest(t, tutils.TestName(t), olm.SubName, olm.SubNamespace, olm.SubPackage)
testKube.CreateSubscriptionAndApproveInitialVersion(olm, sub)
testKube.CreateOperatorGroup(olm)
testKube.CreateSubscriptionAndApproveInitialVersion(sub)

// Create the Infinispan CR
replicas := 2
replicas := 1
spec := tutils.DefaultSpec(t, testKube, func(i *ispnv1.Infinispan) {
i.Spec.Replicas = int32(replicas)
i.Spec.Service.Container.EphemeralStorage = false
Expand Down
47 changes: 38 additions & 9 deletions test/e2e/utils/olm.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ func getChannel(env string, manifest *manifests.PackageManifest) manifests.Packa
return manifests.PackageChannel{}
}

func (k TestKubernetes) CreateSubscriptionAndApproveInitialVersion(olm OLMEnv, sub *coreos.Subscription) {
// Create OperatorGroup only if Subscription is created in non-global namespace
if olm.SubNamespace != "openshift-operators" && olm.SubNamespace != "operators" {
k.CreateOperatorGroup(olm.SubName, olm.SubNamespace, olm.SubNamespace)
}
func (k TestKubernetes) CreateSubscriptionAndApproveInitialVersion(sub *coreos.Subscription) {
k.CreateSubscription(sub)
// Approve the initial startingCSV InstallPlan
k.WaitForSubscriptionState(coreos.SubscriptionStateUpgradePending, sub)
Expand Down Expand Up @@ -183,17 +179,22 @@ func (k TestKubernetes) CleanupOLMTest(t *testing.T, testIdentifier, subName, su
}
}

func (k TestKubernetes) CreateOperatorGroup(name, namespace string, targetNamespaces ...string) {
func (k TestKubernetes) CreateOperatorGroup(olm OLMEnv) {
// Create OperatorGroup only if Subscription is created in non-global namespace
if olm.SubNamespace == "openshift-operators" || olm.SubNamespace == "operators" {
return
}

operatorGroup := &coreosv1.OperatorGroup{
TypeMeta: metav1.TypeMeta{
Kind: coreosv1.OperatorGroupKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Name: olm.SubName,
Namespace: olm.SubNamespace,
},
Spec: coreosv1.OperatorGroupSpec{
TargetNamespaces: targetNamespaces,
TargetNamespaces: []string{olm.SubNamespace},
},
}
err := k.Kubernetes.Client.Create(context.TODO(), operatorGroup)
Expand Down Expand Up @@ -361,7 +362,22 @@ func (k TestKubernetes) WaitForSubscription(sub *coreos.Subscription, predicate
// https://github.com/operator-framework/operator-lifecycle-manager/issues/2201
// https://issues.redhat.com/browse/OCPBUGS-5080
if condition.Type == "ResolutionFailed" && condition.Status == corev1.ConditionTrue {
fmt.Printf("CSV '%s' ResolutionFailed: %s\n", sub.Status.InstalledCSV, condition.Message)
fmt.Printf("Deleting Subscription '%s:%s'", sub.Name, sub.Namespace)
// Delete Subscription and CSV
k.DeleteSubscription(sub.Name, sub.Namespace)

csv := &coreos.ClusterServiceVersion{
ObjectMeta: metav1.ObjectMeta{
Name: sub.Status.InstalledCSV,
Namespace: sub.Namespace,
},
}
fmt.Printf("Deleting CSV '%s:%s'", csv.Name, csv.Namespace)
ExpectMaybeNotFound(k.Kubernetes.Client.Delete(context.TODO(), csv, DeleteOpts...))

// Restart OLM pods to clear the cache
fmt.Println("Restarting OLM and Catalog Operator")
olmNamespace := k.OLMNamespace()
ExpectNoError(
k.Kubernetes.Client.DeleteAllOf(
Expand All @@ -380,6 +396,19 @@ func (k TestKubernetes) WaitForSubscription(sub *coreos.Subscription, predicate
client.MatchingLabels(map[string]string{"app": "catalog-operator"}),
),
)

// Create new Subscription with the startingCSV set to the failed version
fmt.Println("Attempting to recreate Subscription")
startingCSV := sub.Status.InstalledCSV
sub = &coreos.Subscription{
ObjectMeta: metav1.ObjectMeta{
Name: sub.Name,
Namespace: sub.Namespace,
},
Spec: sub.Spec,
}
sub.Spec.StartingCSV = startingCSV
k.CreateSubscriptionAndApproveInitialVersion(sub)
err = poll()
break
}
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func TestMain(m *testing.M) {
// Defer in case a panic is encountered by one of the tests
defer testKube.CleanupOLMTest(nil, "webhook_test_main_defer", olm.SubName, olm.SubNamespace, olm.SubPackage)

testKube.CreateSubscriptionAndApproveInitialVersion(olm, sub)
testKube.CreateOperatorGroup(olm)
testKube.CreateSubscriptionAndApproveInitialVersion(sub)
testKube.WaitForDeployment("infinispan-operator-controller-manager", olm.SubNamespace)

// We must ensure that the Operator pods have the defined environment variables available
Expand Down

0 comments on commit c8d84c0

Please sign in to comment.