-
Notifications
You must be signed in to change notification settings - Fork 483
feat(critest): Add image manager consistency and idempotency tests #1959
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
Open
SergeyKanzhelev
wants to merge
1
commit into
kubernetes-sigs:master
Choose a base branch
from
SergeyKanzhelev:imageTests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+269
−10
Open
Changes from all commits
Commits
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
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,161 @@ | ||
| /* | ||
| Copyright 2026 The Kubernetes 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 validate | ||
|
|
||
| import ( | ||
| "context" | ||
| "slices" | ||
| "sync" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| internalapi "k8s.io/cri-api/pkg/apis" | ||
| runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1" | ||
|
|
||
| "sigs.k8s.io/cri-tools/pkg/framework" | ||
| ) | ||
|
|
||
| var _ = framework.KubeDescribe("Image Consistency", func() { | ||
| f := framework.NewDefaultCRIFramework() | ||
|
|
||
| var c internalapi.ImageManagerService | ||
|
|
||
| BeforeEach(func() { | ||
| c = f.CRIClient.CRIImageClient | ||
| }) | ||
|
|
||
| // Test: Immediate call to ListImages (and other methods like GetImage) after removing the image must not have this image information | ||
| It("should not list or get image status immediately after removal [Conformance]", Serial, func() { | ||
| imageName := testImageWithTag | ||
|
|
||
| // Ensure image is absent before test | ||
| removeImage(c, imageName) | ||
|
|
||
| By("Pulling image: " + imageName) | ||
| framework.PullPublicImage(c, imageName, testImagePodSandbox) | ||
|
|
||
| By("Removing image: " + imageName) | ||
| removeImage(c, imageName) | ||
|
|
||
| By("Verifying image is not listed") | ||
| images := framework.ListImage(c, &runtimeapi.ImageFilter{}) | ||
| found := false | ||
| for _, img := range images { | ||
| if slices.Contains(img.GetRepoTags(), imageName) { | ||
| found = true | ||
| } | ||
| if found { | ||
| break | ||
| } | ||
| } | ||
| Expect(found).To(BeFalse(), "Image %q should not be listed after removal", imageName) | ||
|
|
||
| By("Verifying image status is nil") | ||
| imageStatus := framework.ImageStatus(c, imageName) | ||
| Expect(imageStatus).To(BeNil(), "Image status for %q should be nil after removal", imageName) | ||
| }) | ||
|
|
||
| It("should list and get image status immediately after pulling [Conformance]", Serial, func() { | ||
| imageName := testImageWithTag | ||
|
|
||
| // Ensure image is absent before test | ||
| removeImage(c, imageName) | ||
|
|
||
| By("Pulling image: " + imageName) | ||
| framework.PullPublicImage(c, imageName, testImagePodSandbox) | ||
| // Defer removal to ensure cleanup even if test fails | ||
| defer removeImage(c, imageName) | ||
|
|
||
| By("Verifying image is listed") | ||
| images := framework.ListImage(c, &runtimeapi.ImageFilter{}) | ||
| found := false | ||
| for _, img := range images { | ||
| if slices.Contains(img.GetRepoTags(), imageName) { | ||
| found = true | ||
| } | ||
| if found { | ||
| break | ||
| } | ||
| } | ||
| Expect(found).To(BeTrue(), "Image %q should be listed after pulling", imageName) | ||
|
|
||
| By("Verifying image status is not nil") | ||
| imageStatus := framework.ImageStatus(c, imageName) | ||
| Expect(imageStatus).NotTo(BeNil(), "Image status for %q should be available after pulling", imageName) | ||
| }) | ||
|
|
||
| // TODO: Implement ImageFsInfo tests | ||
| // | ||
| // It("ImageFsInfo usage should increase momentarily when an image is pulled", func() { | ||
| // // 1. Get initial ImageFsInfo. | ||
| // // 2. Pull a new, unique image (e.g., by digest) to ensure it's not cached. | ||
| // // 3. Immediately (or within a very short timeout) check that the ImageFsInfo usage has increased. | ||
| // // This validates that the runtime updates its stats promptly after a pull. | ||
| // }) | ||
| // | ||
| // It("ImageFsInfo usage should decrease eventually when an image is removed", func() { | ||
| // // 1. Pull a new, unique image. | ||
| // // 2. Get the ImageFsInfo after the pull. | ||
| // // 3. Remove the image. | ||
| // // 4. Poll (with a reasonable timeout) until the ImageFsInfo usage decreases. | ||
| // // This validates that the runtime reclaims space and updates its stats after removal, | ||
| // // acknowledging that the cleanup might be asynchronous. | ||
| // }) | ||
|
|
||
| It("should not fail on simultaneous RemoveImage calls [Conformance]", Serial, func() { | ||
| imageName := testImageWithTag | ||
| removeImage(c, imageName) // Ensure image is not present | ||
|
|
||
| By("Pulling an image to be removed") | ||
| imageID := framework.PullPublicImage(c, imageName, testImagePodSandbox) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SergeyKanzhelev Can we use image ID returned by CRI, not image reference? Just as image GC does. The behavior of CRI-O when deleting an image with its digest is a bit complicated and it may take some time to get consensus about how we fix it. |
||
|
|
||
| By("Concurrently removing the same image") | ||
| var wg sync.WaitGroup | ||
| // Channel to collect results from each goroutine | ||
| type removeResult struct { | ||
| err error | ||
| imageFound bool | ||
| } | ||
| results := make(chan removeResult, 5) | ||
|
|
||
| for range 5 { | ||
| wg.Go(func() { | ||
| // Use the specific image ID for removal to avoid ambiguity | ||
| remErr := c.RemoveImage(context.Background(), &runtimeapi.ImageSpec{Image: imageID}) | ||
|
|
||
| // Immediately check image status after removal attempt | ||
| status := framework.ImageStatus(c, imageID) | ||
| imageFound := (status != nil) | ||
|
|
||
| results <- removeResult{err: remErr, imageFound: imageFound} | ||
| }) | ||
| } | ||
| wg.Wait() | ||
| close(results) | ||
|
|
||
| // Verify results: all calls should succeed, and image should be gone immediately after each call | ||
| for res := range results { | ||
| Expect(res.err).NotTo(HaveOccurred(), "Concurrent RemoveImage calls should not return an error") | ||
| // Assert immediate disappearance of the image | ||
| Expect(res.imageFound).To(BeFalse(), "Image should be missing immediately after RemoveImage call returns") | ||
| } | ||
|
|
||
| By("Verifying the image is completely removed (final check)") | ||
| status := framework.ImageStatus(c, imageID) | ||
| Expect(status).To(BeNil(), "Image should be removed after all concurrent calls") | ||
| }) | ||
| }) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@haircommander @saschagrunert can it be that the failure in CI indicate an actual different behavior of CRI-O. In logs I seems to observe that the one of remove images finished, but after this image status still returns the image.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like an issue in CRI-O, I have to investigate this. Ref: cri-o/cri-o#9717