@@ -43,37 +43,26 @@ func convertGroupSnapshotCRD(obj *unstructured.Unstructured, toVersion string) (
4343 return nil , statusErrorWithMessage ("conversion from a version to itself should not call the webhook: %s" , toVersion )
4444 }
4545
46- switch obj .GetAPIVersion () {
47- case "groupsnapshot.storage.k8s.io/v1beta1" :
48- switch toVersion {
49- case "groupsnapshot.storage.k8s.io/v1beta2" :
50- switch kind {
51- case "VolumeGroupSnapshotContent" :
52- if err := convertVolumeGroupSnapshotContentFromV1beta1ToV1beta2 (convertedObject ); err != nil {
53- return nil , statusErrorWithMessage ("%s" , err .Error ())
54- }
55- default :
56- return nil , statusErrorWithMessage ("unexpected conversion kind %q" , kind )
57- }
58- default :
59- return nil , statusErrorWithMessage ("unexpected conversion version %q" , toVersion )
46+ if kind != "VolumeGroupSnapshotContent" {
47+ return nil , statusErrorWithMessage ("unexpected conversion kind %q" , kind )
48+ }
49+
50+ const v1beta1Version = "groupsnapshot.storage.k8s.io/v1beta1"
51+ const v1beta2Version = "groupsnapshot.storage.k8s.io/v1beta2"
52+
53+ switch {
54+ case fromVersion == v1beta1Version && toVersion == v1beta2Version :
55+ if err := convertVolumeGroupSnapshotContentFromV1beta1ToV1beta2 (convertedObject ); err != nil {
56+ return nil , statusErrorWithMessage ("%s" , err .Error ())
6057 }
61- case "groupsnapshot.storage.k8s.io/v1beta2" :
62- switch toVersion {
63- case "groupsnapshot.storage.k8s.io/v1beta1" :
64- switch kind {
65- case "VolumeGroupSnapshotContent" :
66- if err := convertVolumeGroupSnapshotContentFromV1beta2ToV1beta1 (convertedObject ); err != nil {
67- return nil , statusErrorWithMessage ("%s" , err .Error ())
68- }
69- default :
70- return nil , statusErrorWithMessage ("unexpected conversion kind %q" , kind )
71- }
72- default :
73- return nil , statusErrorWithMessage ("unexpected conversion version %q" , toVersion )
58+
59+ case fromVersion == v1beta2Version && toVersion == v1beta1Version :
60+ if err := convertVolumeGroupSnapshotContentFromV1beta2ToV1beta1 (convertedObject ); err != nil {
61+ return nil , statusErrorWithMessage ("%s" , err .Error ())
7462 }
63+
7564 default :
76- return nil , statusErrorWithMessage ("unexpected conversion version %q " , fromVersion )
65+ return nil , statusErrorWithMessage ("unexpected conversion version from %q to %q " , fromVersion , toVersion )
7766 }
7867
7968 return convertedObject , statusSucceed ()
@@ -151,7 +140,7 @@ func convertVolumeGroupSnapshotContentFromV1beta2ToV1beta1(obj *unstructured.Uns
151140 delete (mapEntry , "readyToUse" )
152141 delete (mapEntry , "restoreSize" )
153142 } else {
154- return fmt .Errorf ("unexpected content in .status.volumeSnapshotInfoList[%q ]: expected map" , i )
143+ return fmt .Errorf ("unexpected content in .status.volumeSnapshotInfoList[%d ]: expected map" , i )
155144 }
156145 }
157146
0 commit comments