Skip to content

Commit

Permalink
compare pods full upd
Browse files Browse the repository at this point in the history
  • Loading branch information
l0kix2 committed Apr 17, 2024
1 parent 87244e0 commit 6918385
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions test/e2e/ytsaurus_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"

"go.ytsaurus.tech/yt/go/mapreduce"
"go.ytsaurus.tech/yt/go/mapreduce/spec"
Expand All @@ -29,6 +31,8 @@ import (
"github.com/ytsaurus/yt-k8s-operator/pkg/components"
"github.com/ytsaurus/yt-k8s-operator/pkg/consts"
"github.com/ytsaurus/yt-k8s-operator/pkg/ytconfig"

ctrlcli "sigs.k8s.io/controller-runtime/pkg/client"
)

const (
Expand Down Expand Up @@ -271,6 +275,7 @@ var _ = Describe("Basic test for Ytsaurus controller", func() {
DeferCleanup(deleteYtsaurus, ytsaurus)
name := types.NamespacedName{Name: ytsaurus.GetName(), Namespace: namespace}
deployAndCheck(ytsaurus, namespace)
podsBeforeUpdate := getComponentPods(ctx, namespace)

By("Run cluster update with strategy blocked")
Expect(k8sClient.Get(ctx, name, ytsaurus)).Should(Succeed())
Expand All @@ -281,18 +286,43 @@ var _ = Describe("Basic test for Ytsaurus controller", func() {

By("Ensure cluster doesn't start updating for 5 seconds")
ConsistentlyYtsaurus(ctx, name, 5*time.Second).Should(HaveClusterState(ytv1.ClusterStateRunning))
// TODO: check pods
podsAfterBlockedUpdate := getComponentPods(ctx, namespace)
Expect(podsBeforeUpdate).To(
Equal(podsAfterBlockedUpdate),
"pods shouldn't be recreated when update is blocked",
)

By("Update cluster update with strategy full")
Expect(k8sClient.Get(ctx, name, ytsaurus)).Should(Succeed())
ytsaurus.Spec.UpdateStrategy = ytv1.UpdateStrategyFull
ytsaurus.Spec.Discovery.InstanceCount += 1
timeBeforeUpdate := time.Now()
updateAndCheck(ytsaurus, namespace)
EventuallyYtsaurus(ctx, name, reactionTimeout).Should(HaveClusterState(ytv1.ClusterStateUpdating))

By("Wait cluster update with full update complete")
EventuallyYtsaurus(ctx, name, upgradeTimeout).Should(HaveClusterState(ytv1.ClusterStateRunning))
// check all created recently (or after smth)
podsAfterFullUpdate := getComponentPods(ctx, namespace)
for podName, podAfter := range podsAfterFullUpdate {
if podName == "ds-1" || podName == "ds-2" {
Expect(podAfter.CreationTimestamp.After(timeBeforeUpdate)).To(
BeTrue(),
"extra ds pods should be created after the full update",
)
continue
}
podBefore, ok := podsBeforeUpdate[podName]
Expect(ok).To(
BeTrue(),
fmt.Sprintf("unexpected new pod %s: %v", podName, podAfter),
)
Expect(podBefore.CreationTimestamp.Before(&podAfter.CreationTimestamp)).To(
BeTrue(),
fmt.Sprintf("expect pod %s be recreated, got %s -> %s",
podName, podBefore.CreationTimestamp, podAfter.CreationTimestamp,
),
)
}
},
)
It(
Expand Down Expand Up @@ -807,3 +837,24 @@ func runAndCheckSortOperation(ytClient yt.Client) mapreduce.Operation {
Expect(rows).Should(Equal(keys))
return op
}

func getComponentPods(ctx context.Context, namespace string) map[string]corev1.Pod {
podlist := corev1.PodList{}
noJobPodsReq, err := labels.NewRequirement("job-name", selection.DoesNotExist, []string{})
Expect(err).Should(Succeed())
selector := labels.NewSelector()
selector = selector.Add(*noJobPodsReq)
err = k8sClient.List(
ctx,
&podlist,
ctrlcli.InNamespace(namespace),
ctrlcli.MatchingLabelsSelector{Selector: selector},
)
Expect(err).Should(Succeed())

result := make(map[string]corev1.Pod)
for _, pod := range podlist.Items {
result[pod.Name] = pod
}
return result
}

0 comments on commit 6918385

Please sign in to comment.