Skip to content

Commit f929ef7

Browse files
committed
fix: use server-side apply in crd e2e test when changing the subscription to point to a new channel to avoid transient object modified errors
1 parent f5f6915 commit f929ef7

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

test/e2e/crd_e2e_test.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"time"
77

8+
"k8s.io/apimachinery/pkg/types"
9+
810
"github.com/blang/semver"
911
. "github.com/onsi/ginkgo"
1012
. "github.com/onsi/gomega"
@@ -15,6 +17,7 @@ import (
1517
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
1618
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1719
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20+
"sigs.k8s.io/controller-runtime/pkg/client"
1821
)
1922

2023
var _ = Describe("CRD Versions", func() {
@@ -304,8 +307,21 @@ var _ = Describe("CRD Versions", func() {
304307

305308
// update channel on sub
306309
sub.Spec.Channel = alphaChannel
307-
_, err = crc.OperatorsV1alpha1().Subscriptions(testNamespace).Update(context.TODO(), sub, metav1.UpdateOptions{})
308-
Expect(err).ToNot(HaveOccurred(), "could not update subscription")
310+
sub.TypeMeta.APIVersion = "operators.coreos.com/v1alpha1"
311+
sub.TypeMeta.Kind = "Subscription"
312+
sub.ManagedFields = []metav1.ManagedFieldsEntry{}
313+
314+
// use server-side apply to apply the update to the subscription point to the alpha channel
315+
forceApply := true
316+
opts := metav1.PatchOptions{
317+
Force: &forceApply,
318+
FieldManager: "operator-lifecycle-manager-registry-reconciler",
319+
}
320+
newSub, err := client.Apply.Data(sub)
321+
Expect(err).ToNot(HaveOccurred(), "could not serialize updated subscription to bytes")
322+
323+
_, err = crc.OperatorsV1alpha1().Subscriptions(testNamespace).Patch(context.TODO(), sub.GetName(), types.ApplyPatchType, newSub, opts)
324+
Expect(err).ToNot(HaveOccurred(), "could not patch subscription with updated channel")
309325

310326
subscriptionAtLatestWithDifferentInstallPlan := func(v *operatorsv1alpha1.Subscription) bool {
311327
return subscriptionStateAtLatestChecker(v) && v.Status.InstallPlanRef != nil && v.Status.InstallPlanRef.Name != fetchedInstallPlan.Name

0 commit comments

Comments
 (0)