Skip to content

Commit 6c94adc

Browse files
committed
expand etcd storage tests to test for 1.31..1.33
1 parent dc476e9 commit 6c94adc

File tree

4 files changed

+119
-24
lines changed

4 files changed

+119
-24
lines changed

test/integration/controlplane/transformation/kms_transformation_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,6 @@ resources:
618618
endpoint: unix:///@encrypt-all-kms-provider.sock
619619
`
620620

621-
// KUBE_APISERVER_SERVE_REMOVED_APIS_FOR_ONE_RELEASE allows for APIs pending removal to not block tests
622-
t.Setenv("KUBE_APISERVER_SERVE_REMOVED_APIS_FOR_ONE_RELEASE", "true")
623-
624621
t.Run("encrypt all resources", func(t *testing.T) {
625622
_ = mock.NewBase64Plugin(t, "@encrypt-all-kms-provider.sock")
626623
// To ensure we are checking all REST resources

test/integration/etcd/data.go

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,54 @@ limitations under the License.
1717
package etcd
1818

1919
import (
20+
"strings"
21+
2022
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2123
"k8s.io/apiextensions-apiserver/test/integration/fixtures"
2224
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2325
"k8s.io/apimachinery/pkg/runtime/schema"
26+
utilversion "k8s.io/component-base/version"
2427

2528
"k8s.io/kubernetes/test/utils/image"
2629
)
2730

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.
2942
// It is exported so that it can be reused across multiple tests.
3043
// It returns a new map on every invocation to prevent different tests from mutating shared state.
3144
func GetEtcdStorageData() map[schema.GroupVersionResource]StorageData {
32-
return GetEtcdStorageDataForNamespace("etcdstoragepathtestnamespace")
45+
return GetEtcdStorageDataServedAt(utilversion.DefaultKubeBinaryVersion, false)
3346
}
3447

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.
3656
// It is exported so that it can be reused across multiple tests.
3757
// It returns a new map on every invocation to prevent different tests from mutating shared state.
3858
// Namespaced objects keys are computed for the specified namespace.
3959
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 {
4068
image := image.GetE2EImage(image.BusyBox)
4169
etcdStorageData := map[schema.GroupVersionResource]StorageData{
4270
// k8s.io/kubernetes/pkg/api/v1
@@ -465,22 +493,46 @@ func GetEtcdStorageDataForNamespace(namespace string) map[schema.GroupVersionRes
465493
},
466494
// --
467495

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+
// --
469502

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+
// --
475509
}
476510

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"))
482527
}
483528

529+
if removeAlphas {
530+
for key := range etcdStorageData {
531+
if strings.Contains(key.Version, "alpha") {
532+
delete(etcdStorageData, key)
533+
}
534+
}
535+
}
484536
return etcdStorageData
485537
}
486538

test/integration/etcd/etcd_storage_path_test.go

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ import (
3939
"k8s.io/apimachinery/pkg/runtime/serializer/recognizer"
4040
utiljson "k8s.io/apimachinery/pkg/util/json"
4141
"k8s.io/apimachinery/pkg/util/sets"
42+
"k8s.io/apimachinery/pkg/util/version"
4243
"k8s.io/apiserver/pkg/util/feature"
4344
"k8s.io/client-go/dynamic"
4445
featuregatetesting "k8s.io/component-base/featuregate/testing"
46+
componentbaseversion "k8s.io/component-base/version"
47+
"k8s.io/kubernetes/cmd/kube-apiserver/app/options"
4548
)
4649

4750
// Only add kinds to this list when this a virtual resource with get and create verbs that doesn't actually
@@ -75,13 +78,32 @@ var allowMissingTestdataFixtures = map[schema.GroupVersionKind]bool{
7578
// It will also fail when a type gets moved to a different location. Be very careful in this situation because
7679
// it essentially means that you will be break old clusters unless you create some migration path for the old data.
7780
func TestEtcdStoragePath(t *testing.T) {
78-
// KUBE_APISERVER_SERVE_REMOVED_APIS_FOR_ONE_RELEASE allows for APIs pending removal to not block tests
79-
t.Setenv("KUBE_APISERVER_SERVE_REMOVED_APIS_FOR_ONE_RELEASE", "true")
81+
supportedVersions := GetSupportedEmulatedVersions()
82+
for _, v := range supportedVersions {
83+
t.Run(v, func(t *testing.T) {
84+
testEtcdStoragePathWithVersion(t, v)
85+
})
86+
}
87+
}
8088

81-
featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, "AllAlpha", true)
82-
featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, "AllBeta", true)
89+
func testEtcdStoragePathWithVersion(t *testing.T, v string) {
90+
if v == componentbaseversion.DefaultKubeBinaryVersion {
91+
featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, "AllAlpha", true)
92+
featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, "AllBeta", true)
93+
} else {
94+
// Only test for beta and GA APIs with emulated version.
95+
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, feature.DefaultFeatureGate, version.MustParse(v))
96+
featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, "AllBeta", true)
97+
registerEffectiveEmulationVersion(t)
98+
}
99+
100+
apiServer := StartRealAPIServerOrDie(t, func(opts *options.ServerRunOptions) {
101+
// Disable alphas when emulating previous versions.
102+
if v != componentbaseversion.DefaultKubeBinaryVersion {
103+
opts.Options.APIEnablement.RuntimeConfig["api/alpha"] = "false"
104+
}
105+
})
83106

84-
apiServer := StartRealAPIServerOrDie(t)
85107
defer apiServer.Cleanup()
86108
defer dumpEtcdKVOnFailure(t, apiServer.KV)
87109

@@ -91,7 +113,14 @@ func TestEtcdStoragePath(t *testing.T) {
91113
t.Fatal(err)
92114
}
93115

94-
etcdStorageData := GetEtcdStorageData()
116+
var etcdStorageData map[schema.GroupVersionResource]StorageData
117+
if v == componentbaseversion.DefaultKubeBinaryVersion {
118+
etcdStorageData = GetEtcdStorageDataForNamespaceServedAt("etcdstoragepathtestnamespace", v, false)
119+
} else {
120+
// Drop alphas from etcd data fixtures when emulating previous versions
121+
// as alphas are not supported with emulation.
122+
etcdStorageData = GetEtcdStorageDataForNamespaceServedAt("etcdstoragepathtestnamespace", v, true)
123+
}
95124

96125
kindSeen := sets.NewString()
97126
pathSeen := map[string][]schema.GroupVersionResource{}

test/integration/etcd/server.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,19 @@ import (
3636
"k8s.io/apimachinery/pkg/runtime/schema"
3737
utilerrors "k8s.io/apimachinery/pkg/util/errors"
3838
"k8s.io/apimachinery/pkg/util/json"
39+
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3940
"k8s.io/apimachinery/pkg/util/wait"
4041
genericapiserveroptions "k8s.io/apiserver/pkg/server/options"
42+
"k8s.io/apiserver/pkg/util/feature"
4143
cacheddiscovery "k8s.io/client-go/discovery/cached/memory"
4244
"k8s.io/client-go/dynamic"
4345
clientset "k8s.io/client-go/kubernetes"
4446
restclient "k8s.io/client-go/rest"
4547
"k8s.io/client-go/restmapper"
4648
utiltesting "k8s.io/client-go/util/testing"
49+
"k8s.io/component-base/featuregate"
50+
featuregatetesting "k8s.io/component-base/featuregate/testing"
51+
utilversion "k8s.io/component-base/version"
4752
"k8s.io/kubernetes/cmd/kube-apiserver/app"
4853
"k8s.io/kubernetes/cmd/kube-apiserver/app/options"
4954
"k8s.io/kubernetes/test/integration"
@@ -62,11 +67,23 @@ AwEHoUQDQgAEH6cuzP8XuD5wal6wf9M6xDljTOPLX2i8uIp/C/ASqiIGUeeKQtX0
6267
/IR3qCXyThP/dbCiHrF3v1cuhBOHY8CLVg==
6368
-----END EC PRIVATE KEY-----`
6469

70+
func registerEffectiveEmulationVersion(t *testing.T) {
71+
featureGate := feature.DefaultMutableFeatureGate
72+
featureGate.AddMetrics()
73+
74+
effectiveVersion := utilversion.DefaultKubeEffectiveVersion()
75+
effectiveVersion.SetEmulationVersion(featureGate.EmulationVersion())
76+
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, featureGate, effectiveVersion.EmulationVersion())
77+
featuregate.DefaultComponentGlobalsRegistry.Reset()
78+
utilruntime.Must(featuregate.DefaultComponentGlobalsRegistry.Register(featuregate.DefaultKubeComponent, effectiveVersion, featureGate))
79+
}
80+
6581
// StartRealAPIServerOrDie starts an API server that is appropriate for use in tests that require one of every resource
6682
func StartRealAPIServerOrDie(t *testing.T, configFuncs ...func(*options.ServerRunOptions)) *APIServer {
6783
tCtx := ktesting.Init(t)
6884

69-
certDir, err := os.MkdirTemp("", t.Name())
85+
// Strip out "/" in subtests
86+
certDir, err := os.MkdirTemp("", strings.ReplaceAll(t.Name(), "/", ""))
7087
if err != nil {
7188
t.Fatal(err)
7289
}

0 commit comments

Comments
 (0)