Skip to content

Commit

Permalink
test/e2e: retry ytsaurus update
Browse files Browse the repository at this point in the history
  • Loading branch information
koct9i committed Nov 4, 2024
1 parent 1de2ce3 commit 00cf875
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
14 changes: 14 additions & 0 deletions test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (

"k8s.io/apimachinery/pkg/types"

clientgoretry "k8s.io/client-go/util/retry"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/envtest"
Expand Down Expand Up @@ -177,6 +179,18 @@ func NewYtsaurusStatusTracker() func(*ytv1.Ytsaurus) bool {
}
}

func UpdateYtsaurus(ctx context.Context, ytsaurus *ytv1.Ytsaurus) {
var current ytv1.Ytsaurus
name := client.ObjectKeyFromObject(ytsaurus)
err := clientgoretry.RetryOnConflict(clientgoretry.DefaultRetry, func() error {
Expect(k8sClient.Get(ctx, name, &current)).To(Succeed())
// Fetch current resource version: any status update changes it too.
ytsaurus.SetResourceVersion(current.GetResourceVersion())
return k8sClient.Update(ctx, ytsaurus)
})
Expect(err).ToNot(HaveOccurred())
}

func ExpectYtsaurus(ctx context.Context, name types.NamespacedName) Assertion {
var ytsaurus ytv1.Ytsaurus
Expect(k8sClient.Get(ctx, name, &ytsaurus)).Should(Succeed())
Expand Down
25 changes: 11 additions & 14 deletions test/e2e/ytsaurus_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,13 @@ func runImpossibleUpdateAndRollback(ytsaurus *ytv1.Ytsaurus, ytClient yt.Client)
By("Run cluster impossible update")
Expect(k8sClient.Get(ctx, name, ytsaurus)).Should(Succeed())
ytsaurus.Spec.CoreImage = testutil.CoreImageSecond
Expect(k8sClient.Update(ctx, ytsaurus)).Should(Succeed())
UpdateYtsaurus(ctx, ytsaurus)

EventuallyYtsaurus(ctx, name, reactionTimeout).Should(HaveClusterUpdateState(ytv1.UpdateStateImpossibleToStart))

By("Set previous core image")
Eventually(func(g Gomega) {
g.Expect(k8sClient.Get(ctx, name, ytsaurus)).Should(Succeed())
ytsaurus.Spec.CoreImage = testutil.CoreImageFirst
g.Expect(k8sClient.Update(ctx, ytsaurus)).Should(Succeed())
}, reactionTimeout, pollInterval).Should(Succeed())
ytsaurus.Spec.CoreImage = testutil.CoreImageFirst
UpdateYtsaurus(ctx, ytsaurus)

By("Wait for running")
EventuallyYtsaurus(ctx, name, upgradeTimeout).Should(HaveClusterStateRunning())
Expand Down Expand Up @@ -349,7 +346,7 @@ var _ = Describe("Basic test for Ytsaurus controller", func() {
ytsaurus.Spec.UpdateSelector = ytv1.UpdateSelectorNothing
// We want change in all yson configs, new discovery instance will trigger that.
ytsaurus.Spec.Discovery.InstanceCount += 1
Expect(k8sClient.Update(ctx, ytsaurus)).Should(Succeed())
UpdateYtsaurus(ctx, ytsaurus)

By("Ensure cluster doesn't start updating for 5 seconds")
ConsistentlyYtsaurus(ctx, name, 5*time.Second).Should(HaveClusterStateRunning())
Expand All @@ -363,7 +360,7 @@ var _ = Describe("Basic test for Ytsaurus controller", func() {
Expect(k8sClient.Get(ctx, name, ytsaurus)).Should(Succeed())
ytsaurus.Spec.UpdateSelector = ytv1.UpdateSelectorEverything
ytsaurus.Spec.Discovery.InstanceCount += 1
Expect(k8sClient.Update(ctx, ytsaurus)).Should(Succeed())
UpdateYtsaurus(ctx, ytsaurus)
EventuallyYtsaurus(ctx, name, reactionTimeout).Should(HaveObservedGeneration())
ExpectYtsaurus(ctx, name).Should(HaveClusterUpdatingComponents())

Expand Down Expand Up @@ -393,7 +390,7 @@ var _ = Describe("Basic test for Ytsaurus controller", func() {
Expect(k8sClient.Get(ctx, name, ytsaurus)).Should(Succeed())
ytsaurus.Spec.UpdateSelector = ytv1.UpdateSelectorExecNodesOnly
ytsaurus.Spec.Discovery.InstanceCount += 1
Expect(k8sClient.Update(ctx, ytsaurus)).Should(Succeed())
UpdateYtsaurus(ctx, ytsaurus)
EventuallyYtsaurus(ctx, name, reactionTimeout).Should(HaveObservedGeneration())
ExpectYtsaurus(ctx, name).Should(HaveClusterUpdatingComponents("ExecNode"))

Expand All @@ -412,7 +409,7 @@ var _ = Describe("Basic test for Ytsaurus controller", func() {
Expect(k8sClient.Get(ctx, name, ytsaurus)).Should(Succeed())
ytsaurus.Spec.UpdateSelector = ytv1.UpdateSelectorTabletNodesOnly
ytsaurus.Spec.Discovery.InstanceCount += 1
Expect(k8sClient.Update(ctx, ytsaurus)).Should(Succeed())
UpdateYtsaurus(ctx, ytsaurus)
EventuallyYtsaurus(ctx, name, reactionTimeout).Should(HaveObservedGeneration())
ExpectYtsaurus(ctx, name).Should(HaveClusterUpdatingComponents("TabletNode"))

Expand Down Expand Up @@ -443,7 +440,7 @@ var _ = Describe("Basic test for Ytsaurus controller", func() {
Expect(k8sClient.Get(ctx, name, ytsaurus)).Should(Succeed())
ytsaurus.Spec.UpdateSelector = ytv1.UpdateSelectorMasterOnly
ytsaurus.Spec.Discovery.InstanceCount += 1
Expect(k8sClient.Update(ctx, ytsaurus)).Should(Succeed())
UpdateYtsaurus(ctx, ytsaurus)
EventuallyYtsaurus(ctx, name, reactionTimeout).Should(HaveObservedGeneration())
ExpectYtsaurus(ctx, name).Should(HaveClusterUpdatingComponents("Master"))

Expand All @@ -461,7 +458,7 @@ var _ = Describe("Basic test for Ytsaurus controller", func() {
Expect(k8sClient.Get(ctx, name, ytsaurus)).Should(Succeed())
ytsaurus.Spec.UpdateSelector = ytv1.UpdateSelectorStatelessOnly
ytsaurus.Spec.Discovery.InstanceCount += 1
Expect(k8sClient.Update(ctx, ytsaurus)).Should(Succeed())
UpdateYtsaurus(ctx, ytsaurus)
EventuallyYtsaurus(ctx, name, reactionTimeout).Should(HaveObservedGeneration())
ExpectYtsaurus(ctx, name).Should(HaveClusterUpdatingComponents(
"Discovery",
Expand Down Expand Up @@ -523,7 +520,7 @@ var _ = Describe("Basic test for Ytsaurus controller", func() {
ytsaurus.Spec.PrimaryMasters.HostAddresses = []string{
getKindControlPlaneName(),
}
Expect(k8sClient.Update(ctx, ytsaurus)).Should(Succeed())
UpdateYtsaurus(ctx, ytsaurus)

By("Waiting PossibilityCheck")
EventuallyYtsaurus(ctx, ytsaurusKey, reactionTimeout).Should(HaveClusterUpdateState(ytv1.UpdateStatePossibilityCheck))
Expand Down Expand Up @@ -1259,7 +1256,7 @@ func getSimpleUpdateScenario(namespace, newImage string) func(ctx context.Contex
checkPodLabels(ctx, namespace)

ytsaurus.Spec.CoreImage = newImage
Expect(k8sClient.Update(ctx, ytsaurus)).Should(Succeed())
UpdateYtsaurus(ctx, ytsaurus)

EventuallyYtsaurus(ctx, name, reactionTimeout).Should(HaveObservedGeneration())
ExpectYtsaurus(ctx, name).Should(HaveClusterUpdateFlow(ytv1.UpdateFlowFull))
Expand Down

0 comments on commit 00cf875

Please sign in to comment.