-
Notifications
You must be signed in to change notification settings - Fork 35
Danbar/e2e rolling update 10 #356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+259
−31
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3ef9c59
Fix rolling update test 10: delete first strategy, new pod stays pending
danbar2 2c43073
CR
danbar2 07cd145
CR
danbar2 ac2cdce
CR + revert e2e setup cahnges should be in seperate PR
danbar2 5d0c9d6
add rolling update unit tests
danbar2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
operator/internal/controller/podclique/reconcilestatus_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| // /* | ||
| // Copyright 2025 The Grove Authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // */ | ||
|
|
||
| package podclique | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| apicommon "github.com/ai-dynamo/grove/operator/api/common" | ||
| grovecorev1alpha1 "github.com/ai-dynamo/grove/operator/api/core/v1alpha1" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/utils/ptr" | ||
| ) | ||
|
|
||
| // TestMutateUpdatedReplica tests the mutateUpdatedReplica function across different PodClique states | ||
| func TestMutateUpdatedReplica(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| pclq *grovecorev1alpha1.PodClique | ||
| existingPods []*corev1.Pod | ||
| expectedUpdatedReplicas int32 | ||
| }{ | ||
| { | ||
| name: "rolling update in progress - count pods with new hash", | ||
| pclq: &grovecorev1alpha1.PodClique{ | ||
| Status: grovecorev1alpha1.PodCliqueStatus{ | ||
| RollingUpdateProgress: &grovecorev1alpha1.PodCliqueRollingUpdateProgress{ | ||
| PodTemplateHash: "new-hash-v2", | ||
| UpdateStartedAt: metav1.Time{Time: time.Now()}, | ||
| UpdateEndedAt: nil, // Still in progress | ||
| }, | ||
| CurrentPodTemplateHash: ptr.To("old-hash-v1"), | ||
| }, | ||
| }, | ||
| existingPods: []*corev1.Pod{ | ||
| // 3 pods updated to new version | ||
| createPodWithHash("pod-1", "new-hash-v2"), | ||
| createPodWithHash("pod-2", "new-hash-v2"), | ||
| createPodWithHash("pod-3", "new-hash-v2"), | ||
| // 7 pods still on old version | ||
| createPodWithHash("pod-4", "old-hash-v1"), | ||
| createPodWithHash("pod-5", "old-hash-v1"), | ||
| createPodWithHash("pod-6", "old-hash-v1"), | ||
| createPodWithHash("pod-7", "old-hash-v1"), | ||
| createPodWithHash("pod-8", "old-hash-v1"), | ||
| createPodWithHash("pod-9", "old-hash-v1"), | ||
| createPodWithHash("pod-10", "old-hash-v1"), | ||
| }, | ||
| expectedUpdatedReplicas: 3, // Only the 3 pods with new hash | ||
| }, | ||
| { | ||
| name: "update just completed - use RollingUpdateProgress hash (edge case)", | ||
| pclq: &grovecorev1alpha1.PodClique{ | ||
| Status: grovecorev1alpha1.PodCliqueStatus{ | ||
| RollingUpdateProgress: &grovecorev1alpha1.PodCliqueRollingUpdateProgress{ | ||
| PodTemplateHash: "new-hash-v2", | ||
| UpdateStartedAt: metav1.Time{Time: time.Now().Add(-5 * time.Minute)}, | ||
| UpdateEndedAt: &metav1.Time{Time: time.Now()}, // Just completed | ||
| }, | ||
| // CurrentPodTemplateHash not updated yet - still has old hash | ||
| CurrentPodTemplateHash: ptr.To("old-hash-v1"), | ||
| }, | ||
| }, | ||
| existingPods: []*corev1.Pod{ | ||
| // All pods updated to new version | ||
| createPodWithHash("pod-1", "new-hash-v2"), | ||
| createPodWithHash("pod-2", "new-hash-v2"), | ||
| createPodWithHash("pod-3", "new-hash-v2"), | ||
| createPodWithHash("pod-4", "new-hash-v2"), | ||
| createPodWithHash("pod-5", "new-hash-v2"), | ||
| createPodWithHash("pod-6", "new-hash-v2"), | ||
| createPodWithHash("pod-7", "new-hash-v2"), | ||
| createPodWithHash("pod-8", "new-hash-v2"), | ||
| createPodWithHash("pod-9", "new-hash-v2"), | ||
| createPodWithHash("pod-10", "new-hash-v2"), | ||
| }, | ||
| expectedUpdatedReplicas: 10, // All 10 pods should be counted as updated | ||
| }, | ||
| { | ||
| name: "steady state - no rolling update", | ||
| pclq: &grovecorev1alpha1.PodClique{ | ||
| Status: grovecorev1alpha1.PodCliqueStatus{ | ||
| RollingUpdateProgress: nil, // No rolling update | ||
| CurrentPodTemplateHash: ptr.To("stable-hash"), | ||
| }, | ||
| }, | ||
| existingPods: []*corev1.Pod{ | ||
| createPodWithHash("pod-1", "stable-hash"), | ||
| createPodWithHash("pod-2", "stable-hash"), | ||
| createPodWithHash("pod-3", "stable-hash"), | ||
| createPodWithHash("pod-4", "stable-hash"), | ||
| createPodWithHash("pod-5", "stable-hash"), | ||
| }, | ||
| expectedUpdatedReplicas: 5, // All pods match current hash | ||
| }, | ||
| { | ||
| name: "never reconciled - empty hash", | ||
| pclq: &grovecorev1alpha1.PodClique{ | ||
| Status: grovecorev1alpha1.PodCliqueStatus{ | ||
| RollingUpdateProgress: nil, | ||
| CurrentPodTemplateHash: nil, // Never set | ||
| }, | ||
| }, | ||
| existingPods: []*corev1.Pod{ | ||
| createPodWithHash("pod-1", "some-hash"), | ||
| createPodWithHash("pod-2", "some-hash"), | ||
| }, | ||
| expectedUpdatedReplicas: 0, // Should not count any pods when hash is unknown - no rolling update | ||
| }, | ||
| { | ||
| name: "mixed state - some pods match, some don't", | ||
| pclq: &grovecorev1alpha1.PodClique{ | ||
| Status: grovecorev1alpha1.PodCliqueStatus{ | ||
| RollingUpdateProgress: nil, | ||
| CurrentPodTemplateHash: ptr.To("current-hash"), | ||
| }, | ||
| }, | ||
| existingPods: []*corev1.Pod{ | ||
| createPodWithHash("pod-1", "current-hash"), | ||
| createPodWithHash("pod-2", "current-hash"), | ||
| createPodWithHash("pod-3", "old-hash"), | ||
| createPodWithHash("pod-4", "old-hash"), | ||
| createPodWithHash("pod-5", "old-hash"), | ||
| }, | ||
| expectedUpdatedReplicas: 2, // Only pods with current hash | ||
| }, | ||
| { | ||
| name: "no pods exist", | ||
| pclq: &grovecorev1alpha1.PodClique{ | ||
| Status: grovecorev1alpha1.PodCliqueStatus{ | ||
| CurrentPodTemplateHash: ptr.To("some-hash"), | ||
| }, | ||
| }, | ||
| existingPods: []*corev1.Pod{}, | ||
| expectedUpdatedReplicas: 0, | ||
| }, | ||
| { | ||
| name: "rolling update progress exists but pods have different hash", | ||
| pclq: &grovecorev1alpha1.PodClique{ | ||
| Status: grovecorev1alpha1.PodCliqueStatus{ | ||
| RollingUpdateProgress: &grovecorev1alpha1.PodCliqueRollingUpdateProgress{ | ||
| PodTemplateHash: "target-hash", | ||
| UpdateStartedAt: metav1.Time{Time: time.Now()}, | ||
| }, | ||
| CurrentPodTemplateHash: ptr.To("old-hash"), | ||
| }, | ||
| }, | ||
| existingPods: []*corev1.Pod{ | ||
| createPodWithHash("pod-1", "completely-different-hash"), | ||
| createPodWithHash("pod-2", "another-hash"), | ||
| }, | ||
| expectedUpdatedReplicas: 0, // None match the target hash | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| // Call the function | ||
| mutateUpdatedReplica(tt.pclq, tt.existingPods) | ||
|
|
||
| // Assert the result | ||
| assert.Equal(t, tt.expectedUpdatedReplicas, tt.pclq.Status.UpdatedReplicas, | ||
| "UpdatedReplicas should match expected value") | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // createPodWithHash creates a test pod with the specified template hash label | ||
| func createPodWithHash(name string, templateHash string) *corev1.Pod { | ||
| return &corev1.Pod{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: name, | ||
| Labels: map[string]string{ | ||
| apicommon.LabelPodTemplateHash: templateHash, | ||
| }, | ||
| }, | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.