Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions test/e2e/storage/drivers/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ func InitHostPathCSIDriver() storageframework.TestDriver {
// added when patching the deployment.
storageframework.CapVolumeLimits: true,
}
// DO NOT MERGE: pre-merge testing functionality when this env var is true in openshift/release
err := os.Setenv("CSI_PROW_ENABLE_SNAPSHOT_METADATA", "true")
if err != nil {
framework.Failf("failed to set CSI_PROW_ENABLE_SNAPSHOT_METADATA: %v", err)
}
// TODO: It can be removed after the VolumeGroupSnapshot feature is default enabled
if os.Getenv("CSI_PROW_ENABLE_GROUP_SNAPSHOT") == "true" {
capabilities[storageframework.CapVolumeGroupSnapshot] = true
Expand Down Expand Up @@ -376,6 +381,22 @@ func (h *hostpathCSIDriver) PrepareTest(ctx context.Context, f *framework.Framew
framework.Failf("deploying %s driver: %v", h.driverInfo.Name, err)
}

if h.driverInfo.Capabilities[storageframework.CapSnapshotMetadata] {
// Create snapshot metadata resources (CRD is already created by test runner script)
ginkgo.By("Creating snapshot metadata resources")
err = utils.CreateSnapshotMetadataResources(ctx, f, config.Driver.GetDriverInfo().Name, driverns)
if err != nil {
framework.Failf("failed to create snapshot metadata resources: %v", err)
}
ginkgo.DeferCleanup(func(ctx context.Context) {
Comment on lines +384 to +391

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 12 \
  'func CreateFromManifests|csi-snapshot-metadata-server-certs|CreateSnapshotMetadataResources|CleanupSnapshotMetadataResources' \
  test/e2e/storage test/e2e/testing-manifests

Repository: openshift/kubernetes

Length of output: 20683


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- csi.go ---'
sed -n '310,415p' test/e2e/storage/drivers/csi.go

printf '%s\n' '--- create.go ---'
sed -n '130,235p' test/e2e/storage/utils/create.go

printf '%s\n' '--- snapshot-metadata.go ---'
sed -n '219,290p' test/e2e/storage/utils/snapshot-metadata.go

printf '%s\n' '--- manifest workload and secret references ---'
sed -n '300,465p' test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpath-plugin.yaml

Repository: openshift/kubernetes

Length of output: 15313


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
import re

csi = Path("test/e2e/storage/drivers/csi.go").read_text()
create = Path("test/e2e/storage/utils/create.go").read_text()
snapshot = Path("test/e2e/storage/utils/snapshot-metadata.go").read_text()
manifest = Path("test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpath-plugin.yaml").read_text()

def body(text, signature):
    start = text.index(signature)
    brace = text.index("{", start)
    depth = 0
    for i in range(brace, len(text)):
        if text[i] == "{":
            depth += 1
        elif text[i] == "}":
            depth -= 1
            if depth == 0:
                return text[start:i+1]
    raise RuntimeError(signature)

create_body = body(create, "func CreateFromManifestsTCtx")
snapshot_body = body(snapshot, "func CreateSnapshotMetadataResources")
cleanup_body = body(snapshot, "func CleanupSnapshotMetadataResources")

print("CreateFromManifestsTCtx creates items after loading/patching:")
for token in ("LoadFromManifests", "PatchItemsTCtx", "CreateItem", "Wait"):
    print(f"  {token}: {token in create_body}")

print("CreateSnapshotMetadataResources write order:")
for token in ("createTLSSecret", "createSnapshotMetadataSVC", "createSnapshotMetdataServiceCR"):
    print(f"  {token}: offset {snapshot_body.find(token)}")
print("Cleanup registration relative to helper call:")
print("  helper call offset:", csi.find("utils.CreateSnapshotMetadataResources"))
print("  DeferCleanup offset:", csi.find("ginkgo.DeferCleanup", csi.find("utils.CreateSnapshotMetadataResources")))

print("Manifest Secret reference count:")
print("  volume secretName:", len(re.findall(r"secretName:\s*csi-snapshot-metadata-server-certs", manifest)))
print("  volume mount name:", len(re.findall(r"name:\s*csi-snapshot-metadata-server-certs", manifest)))

print("CleanupSnapshotMetadataResources returns an error:")
print("  return statements:", re.findall(r"(?m)^\s*return\b.*$", cleanup_body))
PY

Repository: openshift/kubernetes

Length of output: 738


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- snapshot resource creators ---'
sed -n '80,220p' test/e2e/storage/utils/snapshot-metadata.go

printf '%s\n' '--- corrected CreateFromManifests verifier ---'
python3 - <<'PY'
from pathlib import Path

text = Path("test/e2e/storage/utils/create.go").read_text()
start = text.index("func CreateFromManifestsTCtx")
end = text.index("// What is a subset", start)
body = text[start:end]

for token in ("LoadFromManifests", "PatchItemsTCtx", "patch(item)", "createItems"):
    print(f"{token}: {token in body}")

print("wait-like calls in CreateFromManifestsTCtx section:")
for line in body.splitlines():
    if any(token in line.lower() for token in ("wait", "poll", "observe")):
        print(line.strip())
PY

Repository: openshift/kubernetes

Length of output: 5245


Create snapshot-metadata resources before starting the driver and register cleanup early.

  • Create the TLS Secret before utils.CreateFromManifests. The StatefulSet references this Secret and reports FailedMount until it exists.
  • Register ginkgo.DeferCleanup before CreateSnapshotMetadataResources, or add rollback. A later creation failure leaves earlier resources behind. CleanupSnapshotMetadataResources always returns nil, so cleanup errors cannot reach the caller.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/e2e/storage/drivers/csi.go` around lines 384 - 391, Reorder
snapshot-metadata setup in the driver initialization flow: register DeferCleanup
before CreateSnapshotMetadataResources, create the TLS Secret before
utils.CreateFromManifests, and retain cleanup for any partial failure. Ensure
CleanupSnapshotMetadataResources is invoked for resources created before
subsequent setup errors.

Source: MCP tools

ginkgo.By("Cleaning up snapshot metadata resources")
err = utils.CleanupSnapshotMetadataResources(ctx, f, config.Driver.GetDriverInfo().Name, driverns)
if err != nil {
framework.Logf("Warning: failed to cleanup snapshot metadata resources: %v", err)
}
})
}

cleanupFunc := generateDriverCleanupFunc(
f,
h.driverInfo.Name,
Expand Down
15 changes: 1 addition & 14 deletions test/e2e/storage/testsuites/snapshot-metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const (
sourceDevicePvcName = "source-device"
targetDevicePvcName = "target-device"
installToolContainerName = "install-tool"
installToolImage = "golang:1.25.7"
installToolImage = "golang:1.26.1"
installToolCommand = "/bin/sh -c 'go install github.com/kubernetes-csi/external-snapshot-metadata/tools/snapshot-metadata-verifier@main && cp $(go env GOPATH)/bin/snapshot-metadata-verifier /output'"
sharedVolumeName = "shared-volume"
sharedVolumeMountPath = "/tools"
Expand Down Expand Up @@ -307,11 +307,6 @@ func (s *snapshotMetadataTestSuite) DefineTests(driver storageframework.TestDriv

config = smDriver.PrepareTest(ctx, f)

// Create snapshot metadata resources (CRD is already created by test runner script)
ginkgo.By("Creating snapshot metadata resources")
err = storageutils.CreateSnapshotMetadataResources(ctx, f, config.Driver.GetDriverInfo().Name, config.DriverNamespace.Name)
framework.ExpectNoError(err, "Failed to create snapshot metadata resources")

pattern.VolMode = v1.PersistentVolumeBlock
volume = storageframework.CreateVolumeResource(ctx, smDriver, config, pattern, s.GetTestSuiteInfo().SupportedSizeRange)
testPVC = volume.Pvc
Expand Down Expand Up @@ -359,14 +354,6 @@ func (s *snapshotMetadataTestSuite) DefineTests(driver storageframework.TestDriv
backupClientPod = nil
}

// Cleanup snapshot metadata resources
if config != nil {
ginkgo.By("Cleaning up snapshot metadata resources")
err := storageutils.CleanupSnapshotMetadataResources(ctx, f, config.Driver.GetDriverInfo().Name, config.DriverNamespace.Name)
if err != nil {
framework.Logf("Warning: failed to cleanup snapshot metadata resources: %v", err)
}
}
})

ginkgo.It("should verify GetMetadataDelta", func(ctx context.Context) {
Expand Down