Repository: kubernetes/kubernetes
File: test/integration/etcd/data.go (Go)

Code before:
func GetEtcdStorageData() map[schema.GroupVersionResource]StorageData {
	return GetEtcdStorageDataForNamespace("etcdstoragepathtestnamespace")
}

// GetServedEtcdStorageData returns etcd for all persisted objects that
// are served at the latest release.
func GetServedEtcdStorageDataForNamespace(namespace string) map[schema.GroupVersionResource]StorageData {
	data := GetEtcdStorageDataForNamespace(namespace)
	removed := GetRemovedEtcdStorageDataForNamespace(namespace)
	for k := range removed {
		delete(data, k)
	}
	return data
}

// GetRemovedEtcdStorageData returns etcd storage information for
// APIs that have been removed at the latest release but may still emulated
// with older emulated versions
func GetRemovedEtcdStorageData() map[schema.GroupVersionResource]StorageData {
	return GetRemovedEtcdStorageDataForNamespace("etcdstoragepathtestnamespace")
}

func GetRemovedEtcdStorageDataForNamespace(namespace string) map[schema.GroupVersionResource]StorageData {
	return map[schema.GroupVersionResource]StorageData{
		// k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta3
		gvr("flowcontrol.apiserver.k8s.io", "v1beta3", "flowschemas"): {
			Stub:             `{"metadata": {"name": "fs-2"}, "spec": {"priorityLevelConfiguration": {"name": "name1"}}}`,
			ExpectedEtcdPath: "/registry/flowschemas/fs-2",
			ExpectedGVK:      gvkP("flowcontrol.apiserver.k8s.io", "v1", "FlowSchema"),
		},
		// --

		// k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta3
		gvr("flowcontrol.apiserver.k8s.io", "v1beta3", "prioritylevelconfigurations"): {
			Stub:             `{"metadata": {"name": "conf4"}, "spec": {"type": "Limited", "limited": {"nominalConcurrencyShares":3, "limitResponse": {"type": "Reject"}}}}`,
			ExpectedEtcdPath: "/registry/prioritylevelconfigurations/conf4",
			ExpectedGVK:      gvkP("flowcontrol.apiserver.k8s.io", "v1", "PriorityLevelConfiguration"),
		},
		// --
	}
}

// GetEtcdStorageDataForNamespace returns etcd data for all persisted objects.
// It is exported so that it can be reused across multiple tests.
// It returns a new map on every invocation to prevent different tests from mutating shared state.
// Namespaced objects keys are computed for the specified namespace.
func GetEtcdStorageDataForNamespace(namespace string) map[schema.GroupVersionResource]StorageData {
	image := image.GetE2EImage(image.BusyBox)
	etcdStorageData := map[schema.GroupVersionResource]StorageData{
		// k8s.io/kubernetes/pkg/api/v1
		gvr("", "v1", "configmaps"): {

Review comment (suggestion):
We're not dropping serving code for this yet, because someone could emulate 1.31 which still serves this? But we also can't serve this to test it correctly in the etcd storage test? That's a really unfortunate combination, and is exactly what I *don't* want to see happen with emulate-version ... code stays in tree but goes untested.

Code after:
// GetSupportedEmulatedVersions provides the list of supported emulated versions in the etcd data.
// Tests aiming for full coverage of versions should test fixtures of all supported versions.
func GetSupportedEmulatedVersions() []string {
	return []string{
		utilversion.DefaultKubeEffectiveVersion().BinaryVersion().SubtractMinor(2).String(),
		utilversion.DefaultKubeEffectiveVersion().BinaryVersion().SubtractMinor(1).String(),
		utilversion.DefaultKubeEffectiveVersion().BinaryVersion().String(),
	}
}

// GetEtcdStorageData returns etcd data for all persisted objects at the latest release version.
// It is exported so that it can be reused across multiple tests.
// It returns a new map on every invocation to prevent different tests from mutating shared state.
func GetEtcdStorageData() map[schema.GroupVersionResource]StorageData {
	return GetEtcdStorageDataServedAt(utilversion.DefaultKubeBinaryVersion, false)
}

// GetEtcdStorageDataServedAt returns etcd data for all persisted objects at a particular release version.
// It is exported so that it can be reused across multiple tests.
// It returns a new map on every invocation to prevent different tests from mutating shared state.
func GetEtcdStorageDataServedAt(version string, removeAlphas bool) map[schema.GroupVersionResource]StorageData {
	return GetEtcdStorageDataForNamespaceServedAt("etcdstoragepathtestnamespace", version, removeAlphas)
}

// GetEtcdStorageDataForNamespace returns etcd data for all persisted objects at the latest release version.
// It is exported so that it can be reused across multiple tests.
// It returns a new map on every invocation to prevent different tests from mutating shared state.
// Namespaced objects keys are computed for the specified namespace.
func GetEtcdStorageDataForNamespace(namespace string) map[schema.GroupVersionResource]StorageData {
	return GetEtcdStorageDataForNamespaceServedAt(namespace, utilversion.DefaultKubeBinaryVersion, false)
}

// GetEtcdStorageDataForNamespaceServedAt returns etcd data for all persisted objects at a particular release version.
// It is exported so that it can be reused across multiple tests.
// It returns a new map on every invocation to prevent different tests from mutating shared state.
// Namespaced objects keys are computed for the specified namespace.
func GetEtcdStorageDataForNamespaceServedAt(namespace string, version string, removeAlphas bool) map[schema.GroupVersionResource]StorageData {
	image := image.GetE2EImage(image.BusyBox)
	etcdStorageData := map[schema.GroupVersionResource]StorageData{
		// k8s.io/kubernetes/pkg/api/v1
		gvr("", "v1", "configmaps"): {
			Stub:             `{"data": {"foo": "bar"}, "metadata": {"name": "cm1"}}`,
			ExpectedEtcdPath: "/registry/configmaps/" + namespace + "/cm1",
		},
		gvr("", "v1", "services"): {
			Stub:             `{"metadata": {"name": "service1"}, "spec": {"type": "LoadBalancer", "ports": [{"port": 10000, "targetPort": 11000}], "selector": {"test": "data"}}}`,
			ExpectedEtcdPath: "/registry/services/specs/" + namespace + "/service1",
		},
		gvr("", "v1", "podtemplates"): {
			Stub:             `{"metadata": {"name": "pt1name"}, "template": {"metadata": {"labels": {"pt": "01"}}, "spec": {"containers": [{"image": "` + image + `", "name": "container9"}]}}}`,
			ExpectedEtcdPath: "/registry/podtemplates/" + namespace + "/pt1name",