@@ -17,26 +17,54 @@ limitations under the License.
17
17
package etcd
18
18
19
19
import (
20
+ "strings"
21
+
20
22
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
21
23
"k8s.io/apiextensions-apiserver/test/integration/fixtures"
22
24
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23
25
"k8s.io/apimachinery/pkg/runtime/schema"
26
+ utilversion "k8s.io/component-base/version"
24
27
25
28
"k8s.io/kubernetes/test/utils/image"
26
29
)
27
30
28
- // GetEtcdStorageData returns etcd data for all persisted objects.
31
+ // GetSupportedEmulatedVersions provides the list of supported emulated versions in the etcd data.
32
+ // Tests aiming for full coverage of versions should test fixtures of all supported versions.
33
+ func GetSupportedEmulatedVersions () []string {
34
+ return []string {
35
+ utilversion .DefaultKubeEffectiveVersion ().BinaryVersion ().SubtractMinor (2 ).String (),
36
+ utilversion .DefaultKubeEffectiveVersion ().BinaryVersion ().SubtractMinor (1 ).String (),
37
+ utilversion .DefaultKubeEffectiveVersion ().BinaryVersion ().String (),
38
+ }
39
+ }
40
+
41
+ // GetEtcdStorageData returns etcd data for all persisted objects at the latest release version.
29
42
// It is exported so that it can be reused across multiple tests.
30
43
// It returns a new map on every invocation to prevent different tests from mutating shared state.
31
44
func GetEtcdStorageData () map [schema.GroupVersionResource ]StorageData {
32
- return GetEtcdStorageDataForNamespace ( "etcdstoragepathtestnamespace" )
45
+ return GetEtcdStorageDataServedAt ( utilversion . DefaultKubeBinaryVersion , false )
33
46
}
34
47
35
- // GetEtcdStorageDataForNamespace returns etcd data for all persisted objects.
48
+ // GetEtcdStorageDataServedAt returns etcd data for all persisted objects at a particular release version.
49
+ // It is exported so that it can be reused across multiple tests.
50
+ // It returns a new map on every invocation to prevent different tests from mutating shared state.
51
+ func GetEtcdStorageDataServedAt (version string , removeAlphas bool ) map [schema.GroupVersionResource ]StorageData {
52
+ return GetEtcdStorageDataForNamespaceServedAt ("etcdstoragepathtestnamespace" , version , removeAlphas )
53
+ }
54
+
55
+ // GetEtcdStorageDataForNamespace returns etcd data for all persisted objects at the latest release version.
36
56
// It is exported so that it can be reused across multiple tests.
37
57
// It returns a new map on every invocation to prevent different tests from mutating shared state.
38
58
// Namespaced objects keys are computed for the specified namespace.
39
59
func GetEtcdStorageDataForNamespace (namespace string ) map [schema.GroupVersionResource ]StorageData {
60
+ return GetEtcdStorageDataForNamespaceServedAt (namespace , utilversion .DefaultKubeBinaryVersion , false )
61
+ }
62
+
63
+ // GetEtcdStorageDataForNamespaceServedAt returns etcd data for all persisted objects at a particular release version.
64
+ // It is exported so that it can be reused across multiple tests.
65
+ // It returns a new map on every invocation to prevent different tests from mutating shared state.
66
+ // Namespaced objects keys are computed for the specified namespace.
67
+ func GetEtcdStorageDataForNamespaceServedAt (namespace string , version string , removeAlphas bool ) map [schema.GroupVersionResource ]StorageData {
40
68
image := image .GetE2EImage (image .BusyBox )
41
69
etcdStorageData := map [schema.GroupVersionResource ]StorageData {
42
70
// k8s.io/kubernetes/pkg/api/v1
@@ -465,22 +493,46 @@ func GetEtcdStorageDataForNamespace(namespace string) map[schema.GroupVersionRes
465
493
},
466
494
// --
467
495
468
- }
496
+ // k8s.io/kubernetes/pkg/apis/storage/v1
497
+ gvr ("storage.k8s.io" , "v1" , "csinodes" ): {
498
+ Stub : `{"metadata": {"name": "csini2"}, "spec": {"drivers": [{"name": "test-driver", "nodeID": "localhost", "topologyKeys": ["company.com/zone1", "company.com/zone2"]}]}}` ,
499
+ ExpectedEtcdPath : "/registry/csinodes/csini2" ,
500
+ },
501
+ // --
469
502
470
- // add csinodes
471
- // k8s.io/kubernetes/pkg/apis/storage/v1
472
- etcdStorageData [gvr ("storage.k8s.io" , "v1" , "csinodes" )] = StorageData {
473
- Stub : `{"metadata": {"name": "csini2"}, "spec": {"drivers": [{"name": "test-driver", "nodeID": "localhost", "topologyKeys": ["company.com/zone1", "company.com/zone2"]}]}}` ,
474
- ExpectedEtcdPath : "/registry/csinodes/csini2" ,
503
+ // k8s.io/kubernetes/pkg/apis/storage/v1
504
+ gvr ("storage.k8s.io" , "v1" , "csidrivers" ): {
505
+ Stub : `{"metadata": {"name": "csid2"}, "spec": {"attachRequired": true, "podInfoOnMount": true}}` ,
506
+ ExpectedEtcdPath : "/registry/csidrivers/csid2" ,
507
+ },
508
+ // --
475
509
}
476
510
477
- // add csidrivers
478
- // k8s.io/kubernetes/pkg/apis/storage/v1
479
- etcdStorageData [gvr ("storage.k8s.io" , "v1" , "csidrivers" )] = StorageData {
480
- Stub : `{"metadata": {"name": "csid2"}, "spec": {"attachRequired": true, "podInfoOnMount": true}}` ,
481
- ExpectedEtcdPath : "/registry/csidrivers/csid2" ,
511
+ // Delete types no longer served or not yet added at a particular emulated version.
512
+ // When adding a brand new type non-alpha type in the latest release, please ensure that
513
+ // it is removed in previous emulated versions otherwise emulated version tests will fail.
514
+ // TODO: derive this programatically from gvk --> instance --> APILifecycle info
515
+ switch version {
516
+ case "1.33" :
517
+ delete (etcdStorageData , gvr ("flowcontrol.apiserver.k8s.io" , "v1beta3" , "flowschemas" ))
518
+ delete (etcdStorageData , gvr ("flowcontrol.apiserver.k8s.io" , "v1beta3" , "prioritylevelconfigurations" ))
519
+ case "1.32" :
520
+ delete (etcdStorageData , gvr ("flowcontrol.apiserver.k8s.io" , "v1beta3" , "flowschemas" ))
521
+ delete (etcdStorageData , gvr ("flowcontrol.apiserver.k8s.io" , "v1beta3" , "prioritylevelconfigurations" ))
522
+ case "1.31" :
523
+ delete (etcdStorageData , gvr ("resource.k8s.io" , "v1beta1" , "deviceclasses" ))
524
+ delete (etcdStorageData , gvr ("resource.k8s.io" , "v1beta1" , "resourceclaims" ))
525
+ delete (etcdStorageData , gvr ("resource.k8s.io" , "v1beta1" , "resourceclaimtemplates" ))
526
+ delete (etcdStorageData , gvr ("resource.k8s.io" , "v1beta1" , "resourceslices" ))
482
527
}
483
528
529
+ if removeAlphas {
530
+ for key := range etcdStorageData {
531
+ if strings .Contains (key .Version , "alpha" ) {
532
+ delete (etcdStorageData , key )
533
+ }
534
+ }
535
+ }
484
536
return etcdStorageData
485
537
}
486
538
0 commit comments