-
Notifications
You must be signed in to change notification settings - Fork 4.8k
OCPNODE-4055: Add e2e testcase for additional storage support feature #31399
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
BhargaviGudi
wants to merge
1
commit into
openshift:main
Choose a base branch
from
BhargaviGudi:additionalImageStore
base: main
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.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,246 @@ | ||
| package node | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
| "time" | ||
|
|
||
| g "github.com/onsi/ginkgo/v2" | ||
| o "github.com/onsi/gomega" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/util/wait" | ||
| "k8s.io/kubernetes/test/e2e/framework" | ||
|
|
||
| machineconfigv1 "github.com/openshift/api/machineconfiguration/v1" | ||
| mcclient "github.com/openshift/client-go/machineconfiguration/clientset/versioned" | ||
| exutil "github.com/openshift/origin/test/extended/util" | ||
| ) | ||
|
|
||
| // Additional Storage E2E Tests - trigger MCO reconciliation (MCP rollouts) | ||
| // and run in the disruptive-longrunning suite. | ||
| var _ = g.Describe("[Skipped:Disconnected][apigroup:config.openshift.io][apigroup:machineconfiguration.openshift.io][Jira:Node/CRI-O][sig-node][Feature:AdditionalStorageSupport][OCPFeatureGate:AdditionalStorageConfig][Serial][Disruptive][Suite:openshift/disruptive-longrunning] Additional Storage E2E Tests", func() { | ||
| defer g.GinkgoRecover() | ||
|
|
||
| var oc = exutil.NewCLI("additional-storage-e2e") | ||
|
|
||
| g.BeforeEach(func(ctx context.Context) { | ||
| SkipOnMicroShift(oc) | ||
| EnsureNodesReady(ctx, oc) | ||
|
|
||
| enabled, reason := IsAdditionalStorageConfigEnabled(ctx, oc) | ||
| if !enabled { | ||
| g.Skip(reason) | ||
| } | ||
| }) | ||
|
|
||
| // This test verifies configuration for all three storage types (image, layer, artifact) | ||
| // and performs functional testing for image stores (pre-population and fallback). | ||
| // Artifact stores are tested with filesystem operations, and layer stores are verified | ||
| // via storage.conf :ref suffix configuration. | ||
| g.It("should verify configuration of all storage types and functionally test image stores", func(ctx context.Context) { | ||
| mcClient, err := mcclient.NewForConfig(oc.KubeFramework().ClientConfig()) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| // SETUP: Create single-node MachineConfigPool for faster rollouts | ||
| g.By("Getting worker node for test") | ||
| testNode := GetFirstReadyWorkerNode(oc) | ||
|
|
||
| mcpName := "combined-func-test" | ||
| var mcpConfig *CustomMCPConfig | ||
|
|
||
| g.By("Creating single-node MachineConfigPool for test isolation") | ||
| mcpConfig, err = CreateCustomMCPForNode(ctx, oc, mcClient, mcpName, testNode) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| framework.Logf("Custom MCP %s created, targeting node %s", mcpName, testNode) | ||
|
|
||
| testNamespace := oc.Namespace() | ||
|
|
||
| // Phase 1: Setup directories and prepare for testing | ||
| g.By("Phase 1: Creating storage directories") | ||
| imageStorePath := "/var/lib/combined-imagestore" | ||
| artifactStorePath := "/var/lib/combined-artifactstore" | ||
| layerStorePath := "/var/lib/stargz-store/store" | ||
| allDirs := []string{imageStorePath, artifactStorePath, layerStorePath} | ||
|
|
||
| g.DeferCleanup(cleanupDirectoriesOnNode, oc, testNode, allDirs) | ||
| g.DeferCleanup(func() { | ||
| cleanupCtx := context.Background() | ||
| delErr := mcClient.MachineconfigurationV1().ContainerRuntimeConfigs().Delete( | ||
| cleanupCtx, "combined-func-test", metav1.DeleteOptions{}) | ||
| if delErr != nil && !apierrors.IsNotFound(delErr) { | ||
| framework.Logf("Warning: failed to delete ContainerRuntimeConfig %s: %v", "combined-func-test", delErr) | ||
| } | ||
| if mcpConfig != nil { | ||
| cleanupErr := CleanupCustomMCP(cleanupCtx, mcpConfig) | ||
| if cleanupErr != nil { | ||
| framework.Logf("Warning: failed to cleanup custom MCP: %v", cleanupErr) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| err = createDirectoriesOnNode(oc, testNode, allDirs) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| // Pre-populate test image in image store | ||
| testImage := "registry.k8s.io/e2e-test-images/agnhost:2.59" | ||
| framework.Logf("Pre-populating image %s to %s on node %s", testImage, imageStorePath, testNode) | ||
|
|
||
| _, err = ExecOnNodeWithChroot(ctx, oc, testNode, "podman", "--root", imageStorePath, "pull", testImage) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| lsOutput, err := ExecOnNodeWithChroot(ctx, oc, testNode, "podman", "--root", imageStorePath, "images", "--format", "{{.Repository}}:{{.Tag}}") | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| o.Expect(lsOutput).To(o.ContainSubstring(testImage)) | ||
| framework.Logf("Image pre-populated successfully: %s", lsOutput) | ||
|
|
||
| // Phase 2: Create ContainerRuntimeConfig with all three storage types | ||
| g.By("Phase 2: Creating ContainerRuntimeConfig with all three storage types") | ||
| ctrcfg := &machineconfigv1.ContainerRuntimeConfig{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "combined-func-test", | ||
| }, | ||
| Spec: machineconfigv1.ContainerRuntimeConfigSpec{ | ||
| MachineConfigPoolSelector: &metav1.LabelSelector{ | ||
| MatchLabels: map[string]string{ | ||
| "machineconfiguration.openshift.io/pool": mcpName, | ||
| }, | ||
| }, | ||
| ContainerRuntimeConfig: &machineconfigv1.ContainerRuntimeConfiguration{ | ||
| AdditionalLayerStores: []machineconfigv1.AdditionalLayerStore{ | ||
| {Path: machineconfigv1.StorePath(layerStorePath)}, | ||
| }, | ||
| AdditionalImageStores: []machineconfigv1.AdditionalImageStore{ | ||
| {Path: machineconfigv1.StorePath(imageStorePath)}, | ||
| }, | ||
| AdditionalArtifactStores: []machineconfigv1.AdditionalArtifactStore{ | ||
| {Path: machineconfigv1.StorePath(artifactStorePath)}, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| g.By("Applying ContainerRuntimeConfig and waiting for MCP rollout") | ||
| err = ApplyContainerRuntimeConfigAndWaitForMCP(ctx, mcClient, ctrcfg, mcpName, 15*time.Minute) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| // CONFIGURATION VERIFICATION - verify configs without usage | ||
|
|
||
| // Phase 3: Verify storage configuration | ||
| g.By("Phase 3: Verifying storage.conf and CRI-O configuration") | ||
| storageConfOutput, err := ExecOnNodeWithChroot(ctx, oc, testNode, "cat", "/etc/containers/storage.conf") | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| // Verify image stores | ||
| o.Expect(storageConfOutput).To(o.ContainSubstring(imageStorePath)) | ||
| framework.Logf("Image stores verified in storage.conf") | ||
|
|
||
| // Verify layer stores with :ref suffix (MCO automatically appends :ref) | ||
| expectedPathWithRef := layerStorePath + ":ref" | ||
| o.Expect(storageConfOutput).To(o.ContainSubstring("additionallayerstores"), | ||
| "storage.conf should contain additionallayerstores on node %s", testNode) | ||
| o.Expect(storageConfOutput).To(o.ContainSubstring(expectedPathWithRef), | ||
| "storage.conf should contain %s with :ref suffix on node %s", expectedPathWithRef, testNode) | ||
| framework.Logf("Layer stores verified in storage.conf with path %s (MCO added :ref)", expectedPathWithRef) | ||
|
|
||
| g.By("Verifying CRI-O config contains artifact stores") | ||
| crioOutput, err := ExecOnNodeWithChroot(ctx, oc, testNode, "cat", "/etc/crio/crio.conf.d/01-ctrcfg-additionalArtifactStores") | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| expectedArtifactConfig := fmt.Sprintf(`additional_artifact_stores = ["%s"]`, artifactStorePath) | ||
| o.Expect(crioOutput).To(o.ContainSubstring(expectedArtifactConfig)) | ||
| framework.Logf("Artifact stores verified in CRI-O config") | ||
|
|
||
| g.By("Verifying CRI-O is active with new configuration") | ||
| crioStatus, err := ExecOnNodeWithChroot(ctx, oc, testNode, "systemctl", "is-active", "crio") | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| o.Expect(strings.TrimSpace(crioStatus)).To(o.Equal("active")) | ||
| framework.Logf("CRI-O is active") | ||
|
|
||
| // FUNCTIONAL VERIFICATION - actually use the stores | ||
|
|
||
| // Phase 4: Test image store functionality - prepopulation and fallback | ||
| g.By("Phase 4a: Functionally testing additionalImageStores - verify pre-populated image accessible") | ||
|
|
||
| // Ensure image is NOT in primary CRI-O store to guarantee additional store is used | ||
| framework.Logf("Removing %s from primary CRI-O store to ensure additional store is tested", testImage) | ||
| imageList, _ := ExecOnNodeWithChroot(ctx, oc, testNode, "crictl", "images", "-q", testImage) | ||
| if imageList != "" { | ||
| _, err = ExecOnNodeWithChroot(ctx, oc, testNode, "crictl", "rmi", testImage) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| } | ||
|
|
||
| // Check storage.conf has the image store path | ||
| storageConf, err := ExecOnNodeWithChroot(ctx, oc, testNode, "cat", "/etc/containers/storage.conf") | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| o.Expect(storageConf).To(o.ContainSubstring(imageStorePath)) | ||
| framework.Logf("Image store path verified in storage.conf") | ||
|
|
||
| // Test prepopulated image by creating a pod | ||
| // Use ImagePullPolicy: Never to force using only local stores (proves additional store is used) | ||
| g.By("Phase 4b: Creating pod using prepopulated image") | ||
| testPod1 := createTestPod("imagestore-prepop-pod", testNamespace, testImage, testNode, corev1.PullNever) | ||
| startTime1 := time.Now() | ||
| _ = createPodAndWaitForRunning(ctx, oc, testPod1) | ||
|
BhargaviGudi marked this conversation as resolved.
|
||
| pod1Time := time.Since(startTime1) | ||
| framework.Logf("Pod using prepopulated image started in %v", pod1Time) | ||
|
|
||
| // Test fallback to registry | ||
| g.By("Phase 5: Testing fallback to registry when image removed from additional store") | ||
| err = oc.AdminKubeClient().CoreV1().Pods(testNamespace).Delete(ctx, testPod1.Name, metav1.DeleteOptions{}) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| err = wait.PollUntilContextTimeout(ctx, 2*time.Second, 2*time.Minute, true, func(ctx context.Context) (bool, error) { | ||
| _, err := oc.AdminKubeClient().CoreV1().Pods(testNamespace).Get(ctx, testPod1.Name, metav1.GetOptions{}) | ||
| if apierrors.IsNotFound(err) { | ||
| return true, nil | ||
| } | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| return false, nil | ||
| }) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| // Remove image from additional store | ||
| _, err = ExecOnNodeWithChroot(ctx, oc, testNode, "podman", "--root", imageStorePath, "rmi", testImage) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| framework.Logf("Removed image from additional store to test fallback") | ||
|
|
||
| // Create second pod - should fall back to registry | ||
| // Use ImagePullPolicy: Always to force registry pull (proves fallback works) | ||
| testPod2 := createTestPod("imagestore-fallback-pod", testNamespace, testImage, testNode, corev1.PullAlways) | ||
| startTime2 := time.Now() | ||
| _ = createPodAndWaitForRunning(ctx, oc, testPod2) | ||
| g.DeferCleanup(deletePodAndWait, ctx, oc, testNamespace, testPod2.Name) | ||
| pod2Time := time.Since(startTime2) | ||
| framework.Logf("Pod using registry fallback started in %v", pod2Time) | ||
|
|
||
| // Verify pod pulled from registry | ||
| var foundSuccessfullyPulled bool | ||
| err = wait.PollUntilContextTimeout(ctx, 2*time.Second, 2*time.Minute, true, func(ctx context.Context) (bool, error) { | ||
| events, err := oc.AdminKubeClient().CoreV1().Events(testNamespace).List(ctx, metav1.ListOptions{ | ||
| FieldSelector: fmt.Sprintf("involvedObject.name=%s", testPod2.Name), | ||
| }) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| for _, event := range events.Items { | ||
| if event.Reason == "Pulled" && strings.Contains(event.Message, "Successfully pulled") { | ||
| foundSuccessfullyPulled = true | ||
| framework.Logf("SUCCESS: Image pulled from registry - %s", event.Message) | ||
| return true, nil | ||
| } | ||
| } | ||
| return false, nil | ||
| }) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| o.Expect(foundSuccessfullyPulled).To(o.BeTrue()) | ||
| framework.Logf("Phase 5 PASSED: Fallback to registry works when image not in additional store") | ||
|
|
||
| framework.Logf("Test PASSED: Configuration verified for all storage types and image stores functionally tested") | ||
| }) | ||
| }) | ||
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
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.