Skip to content

Commit aa1a285

Browse files
committed
Replaced base_snapshot_name with base_snapshot_id in the
GetMetadataRequest Kubernetes SnapshotMetadata API. The iterator package now accepts both the previous snapshot name or CSI handle with preference given to the handle.
1 parent c75a630 commit aa1a285

File tree

17 files changed

+783
-591
lines changed

17 files changed

+783
-591
lines changed

.github/workflows/integration-test.yaml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
name: Intergration test
2+
name: Integration test
33

44
on:
55
pull_request
@@ -26,8 +26,8 @@ jobs:
2626
2727
- name: Build csi-snapshot-metadata container image
2828
run: |
29-
# make build-csi-snapshot-metadata
30-
# minikube image build -f ./cmd/csi-snapshot-metadata/Dockerfile -t gcr.io/k8s-staging-sig-storage/csi-snapshot-metadata:test .
29+
make build-csi-snapshot-metadata
30+
minikube image build -f ./cmd/csi-snapshot-metadata/Dockerfile -t gcr.io/k8s-staging-sig-storage/csi-snapshot-metadata:test .
3131
3232
- name: Deploy snapshot-controller
3333
run: |
@@ -46,7 +46,7 @@ jobs:
4646
4747
git clone https://github.com/kubernetes-csi/csi-driver-host-path.git ~/csi-driver-host-path
4848
49-
CSI_SNAPSHOT_METADATA_REGISTRY="gcr.io/k8s-staging-sig-storage" UPDATE_RBAC_RULES="false" CSI_SNAPSHOT_METADATA_TAG="main" SNAPSHOT_METADATA_TESTS=true HOSTPATHPLUGIN_REGISTRY="gcr.io/k8s-staging-sig-storage" HOSTPATHPLUGIN_TAG="canary" ~/csi-driver-host-path/deploy/kubernetes-latest/deploy.sh
49+
CSI_SNAPSHOT_METADATA_REGISTRY="gcr.io/k8s-staging-sig-storage" UPDATE_RBAC_RULES="false" CSI_SNAPSHOT_METADATA_TAG="test" SNAPSHOT_METADATA_TESTS=true HOSTPATHPLUGIN_REGISTRY="gcr.io/k8s-staging-sig-storage" HOSTPATHPLUGIN_TAG="canary" ~/csi-driver-host-path/deploy/kubernetes-latest/deploy.sh
5050
5151
kubectl apply -f ./deploy/example/csi-driver/testdata/
5252
@@ -160,12 +160,23 @@ jobs:
160160
kubectl cp ./snapshot-metadata-lister default/backup-app-client:/snapshot-metadata-lister -c run-client
161161
kubectl cp ./snapshot-metadata-verifier default/backup-app-client:/snapshot-metadata-verifier -c run-client
162162
163-
echo "Execute external-snapshot-metadata-client to list changed blocks between snap-1 and snap-2"
163+
echo "Execute external-snapshot-metadata-client to list changed blocks between snap-1 and snap-2 using snapshot names"
164164
kubectl exec backup-app-client -- /snapshot-metadata-lister -max-results 10 -previous-snapshot snap-1 -snapshot snap-2 -starting-offset 0 -namespace default -kubeconfig=""
165165
166-
echo "Execute external-snapshot-metadata-client to verify the data between snap-1 and snap-2"
166+
VSC_NAME=`kubectl get volumesnapshot snap-1 -o jsonpath="{.status.boundVolumeSnapshotContentName}"`
167+
echo "VolumeSnapshotContent for VolumeSnapshot snap-1 is [$VSC_NAME]"
168+
SNAP_HANDLE=`kubectl get volumesnapshotcontent $VSC_NAME -o jsonpath="{.status.snapshotHandle}"`
169+
echo "CSI snapshot handle of VolumeSnapshot snap-1 is [$SNAP_HANDLE]"
170+
171+
echo "Execute external-snapshot-metadata-client to list changed blocks between snap-1 and snap-2 using the CSI handle"
172+
kubectl exec backup-app-client -- /snapshot-metadata-lister -max-results 10 -previous-snapshot-id "$SNAP_HANDLE" -snapshot snap-2 -starting-offset 0 -namespace default -kubeconfig=""
173+
174+
echo "Execute external-snapshot-metadata-client to verify the data between snap-1 and snap-2 using snapshot names"
167175
kubectl exec backup-app-client -- /snapshot-metadata-verifier -max-results 10 -previous-snapshot snap-1 -snapshot snap-2 -starting-offset 0 -namespace default -kubeconfig="" -source-device-path /dev/source -target-device-path /dev/target
168176
177+
echo "Execute external-snapshot-metadata-client to verify the data between snap-1 and snap-2 using the CSI handle"
178+
kubectl exec backup-app-client -- /snapshot-metadata-verifier -max-results 10 -previous-snapshot-id "$SNAP_HANDLE" -snapshot snap-2 -starting-offset 0 -namespace default -kubeconfig="" -source-device-path /dev/source -target-device-path /dev/target
179+
169180
echo "Write more data into source-device to test negative case"
170181
kubectl exec -i backup-app-client -- sh -c "dd if=/dev/urandom of=/dev/source bs=4K count=6 oflag=direct"
171182

examples/snapshot-metadata-lister/main.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,26 @@ const (
3838
3939
%[1]s -n Namespace -s Snapshot [Additional flags ...]
4040
41-
2. Display changed block metadata between two snapshots
41+
2. Display changed block metadata between two snapshots, using the previous snapshot object name
4242
4343
%[1]s -n Namespace -s Snapshot -p PreviousSnapshot [Additional flags ...]
4444
45-
3. Display the full help message
45+
3. Display changed block metadata between two snapshots, using the CSI handle of the previous snapshot
46+
47+
%[1]s -n Namespace -s Snapshot -P PreviousSnapshotID [Additional flags ...]
48+
49+
4. Display the full help message
4650
4751
%[1]s -h
4852
`
4953
usageFmt = `This command displays metadata on the content of a VolumeSnapshot object.
5054
If a previous VolumeSnapshot object is also specified then the metadata
5155
describes the content changes between the two snapshots, which must both
52-
be from the same PersistentVolume.
56+
be from the same PersistentVolume. The previous VolumeSnapshot object can
57+
be specified either by name or by its CSI snapshot handle, obtained from
58+
the Status.SnapshotHandle field of its associated VolumeSnapshotContent
59+
object. The CSI handle takes precedence over the name, in case both are
60+
specified.
5361
5462
The command is usually invoked in a Pod in the cluster, as the gRPC client
5563
needs to resolve the DNS address in the SnapshotMetadataService CR.
@@ -75,6 +83,7 @@ func parseFlags() {
7583

7684
stringFlag(&args.Namespace, "namespace", "n", "", "The Namespace containing the VolumeSnapshot objects.")
7785
stringFlag(&args.SnapshotName, "snapshot", "s", "", "The name of the VolumeSnapshot for which metadata is to be displayed.")
86+
stringFlag(&args.PrevSnapshotID, "previous-snapshot-id", "P", "", "The CSI handle of an earlier VolumeSnapshot against which changed block metadata is to be displayed.")
7887
stringFlag(&args.PrevSnapshotName, "previous-snapshot", "p", "", "The name of an earlier VolumeSnapshot against which changed block metadata is to be displayed.")
7988
stringFlag(&outputFormat, "output-format", "o", "table", "The format of the output. Possible values: \"table\" or \"json\".")
8089

examples/snapshot-metadata-verifier/main.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,26 @@ const (
3838
3939
%[1]s -n Namespace -s Snapshot -src /dev/source -tgt /dev/target [Additional flags ...]
4040
41-
2. Verify changed block metadata between two snapshots
41+
2. Verify changed block metadata between two snapshots, using the previous snapshot object name
4242
4343
%[1]s -n Namespace -s Snapshot -p PreviousSnapshot -src /dev/source -tgt /dev/target [Additional flags ...]
4444
45-
3. Display the full help message
45+
3. Verify changed block metadata between two snapshots, using the CSI handle of the previous snapshot
46+
47+
%[1]s -n Namespace -s Snapshot -P PreviousSnapshotID -src /dev/source -tgt /dev/target [Additional flags ...]
48+
49+
50+
4. Display the full help message
4651
4752
%[1]s -h
4853
`
4954
usageFmt = `This command verifies allocated blocks of a VolumeSnapshot object.
5055
If a previous VolumeSnapshot object is also specified then changed blocks between
5156
the two snapshots, which must both be from the same PersistentVolume, are verified.
57+
The previous VolumeSnapshot object can be specified either by name or by its CSI
58+
snapshot handle, obtained from the Status.SnapshotHandle field of its associated
59+
VolumeSnapshotContent object. The CSI handle takes precedence over the name, in
60+
case both are specified.
5261
5362
The command is usually invoked in a Pod in the cluster, as the gRPC client
5463
needs to resolve the DNS address in the SnapshotMetadataService CR.
@@ -73,10 +82,11 @@ func parseFlags() {
7382
}
7483

7584
stringFlag(&args.Namespace, "namespace", "n", "", "The Namespace containing the VolumeSnapshot objects.")
76-
stringFlag(&args.SnapshotName, "snapshot", "s", "", "The name of the VolumeSnapshot for which metadata is to be displayed.")
77-
stringFlag(&args.PrevSnapshotName, "previous-snapshot", "p", "", "The name of an earlier VolumeSnapshot against which changed block metadata is to be displayed.")
85+
stringFlag(&args.SnapshotName, "snapshot", "s", "", "The name of the VolumeSnapshot for which metadata is to be verified.")
86+
stringFlag(&args.PrevSnapshotID, "previous-snapshot-id", "P", "", "The CSI handle of an earlier VolumeSnapshot against which changed block metadata is to be verified.")
87+
stringFlag(&args.PrevSnapshotName, "previous-snapshot", "p", "", "The name of an earlier VolumeSnapshot against which changed block metadata is to be verified.")
7888
stringFlag(&sourceDevicePath, "source-device-path", "src", "", "Path of the source device. This device should be the PVC in block mode restored from the snapshot which is passed as the '-snapshot' flag.")
79-
stringFlag(&targetDevicePath, "target-device-path", "tgt", "", "Path of the target device. This device should be a PVC in block mode restored from the snapshot which is passed as the '-previous-snapshot' flag or a fresh PVC in block mode in case the flag is not passed.")
89+
stringFlag(&targetDevicePath, "target-device-path", "tgt", "", "Path of the target device. This device should be a PVC in block mode restored from the snapshot which is passed as the '-previous-snapshot' or '-previous-snapshot-id' flags, or a fresh PVC in block mode in case the flags are not passed.")
8090

8191
if home := homedir.HomeDir(); home != "" {
8292
flag.StringVar(&kubeConfig, "kubeconfig", filepath.Join(home, ".kube", "config"), "Path to the kubeconfig file.")

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ require (
2020
k8s.io/apiserver v0.34.0
2121
k8s.io/client-go v0.34.0
2222
k8s.io/klog/v2 v2.130.1
23+
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397
2324
)
2425

2526
require (
@@ -71,7 +72,6 @@ require (
7172
gopkg.in/yaml.v3 v3.0.1 // indirect
7273
k8s.io/component-base v0.34.0 // indirect
7374
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect
74-
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 // indirect
7575
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
7676
sigs.k8s.io/randfill v1.0.0 // indirect
7777
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect

0 commit comments

Comments
 (0)