mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
Merge pull request #128279 from Jefftree/compat-133
Bump DefaultKubeBinaryVersion to 1.33
This commit is contained in:
commit
9d82148924
@ -34,8 +34,8 @@ import (
|
|||||||
func TestServerRunOptionsValidate(t *testing.T) {
|
func TestServerRunOptionsValidate(t *testing.T) {
|
||||||
testRegistry := featuregate.NewComponentGlobalsRegistry()
|
testRegistry := featuregate.NewComponentGlobalsRegistry()
|
||||||
featureGate := utilfeature.DefaultFeatureGate.DeepCopy()
|
featureGate := utilfeature.DefaultFeatureGate.DeepCopy()
|
||||||
effectiveVersion := utilversion.NewEffectiveVersion("1.30")
|
effectiveVersion := utilversion.NewEffectiveVersion("1.35")
|
||||||
effectiveVersion.SetEmulationVersion(version.MajorMinor(1, 32))
|
effectiveVersion.SetEmulationVersion(version.MajorMinor(1, 31))
|
||||||
testComponent := "test"
|
testComponent := "test"
|
||||||
utilruntime.Must(testRegistry.Register(testComponent, effectiveVersion, featureGate))
|
utilruntime.Must(testRegistry.Register(testComponent, effectiveVersion, featureGate))
|
||||||
|
|
||||||
@ -197,7 +197,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
|||||||
ComponentName: testComponent,
|
ComponentName: testComponent,
|
||||||
ComponentGlobalsRegistry: testRegistry,
|
ComponentGlobalsRegistry: testRegistry,
|
||||||
},
|
},
|
||||||
expectErr: "emulation version 1.32 is not between [1.29, 1.30.0]",
|
expectErr: "emulation version 1.31 is not between [1.32, 1.35.0]",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Test when ServerRunOptions is valid",
|
name: "Test when ServerRunOptions is valid",
|
||||||
|
@ -118,7 +118,7 @@ func TestVersionFlagOptions(t *testing.T) {
|
|||||||
func TestVersionFlagOptionsWithMapping(t *testing.T) {
|
func TestVersionFlagOptionsWithMapping(t *testing.T) {
|
||||||
r := testRegistry(t)
|
r := testRegistry(t)
|
||||||
utilruntime.Must(r.SetEmulationVersionMapping(testComponent, DefaultKubeComponent,
|
utilruntime.Must(r.SetEmulationVersionMapping(testComponent, DefaultKubeComponent,
|
||||||
func(from *version.Version) *version.Version { return from.OffsetMinor(3) }))
|
func(from *version.Version) *version.Version { return version.MajorMinor(1, from.Minor()+23) }))
|
||||||
emuVers := strings.Join(r.unsafeVersionFlagOptions(true), "\n")
|
emuVers := strings.Join(r.unsafeVersionFlagOptions(true), "\n")
|
||||||
expectedEmuVers := "test=2.8..2.8 (default=2.8)"
|
expectedEmuVers := "test=2.8..2.8 (default=2.8)"
|
||||||
if emuVers != expectedEmuVers {
|
if emuVers != expectedEmuVers {
|
||||||
|
@ -66,5 +66,5 @@ const (
|
|||||||
// DefaultKubeBinaryVersion is the hard coded k8 binary version based on the latest K8s release.
|
// DefaultKubeBinaryVersion is the hard coded k8 binary version based on the latest K8s release.
|
||||||
// It is supposed to be consistent with gitMajor and gitMinor, except for local tests, where gitMajor and gitMinor are "".
|
// It is supposed to be consistent with gitMajor and gitMinor, except for local tests, where gitMajor and gitMinor are "".
|
||||||
// Should update for each minor release!
|
// Should update for each minor release!
|
||||||
DefaultKubeBinaryVersion = "1.32"
|
DefaultKubeBinaryVersion = "1.33"
|
||||||
)
|
)
|
||||||
|
@ -25,6 +25,8 @@ import (
|
|||||||
apimachineryversion "k8s.io/apimachinery/pkg/version"
|
apimachineryversion "k8s.io/apimachinery/pkg/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var minimumKubeEmulationVersion *version.Version = version.MajorMinor(1, 31)
|
||||||
|
|
||||||
type EffectiveVersion interface {
|
type EffectiveVersion interface {
|
||||||
BinaryVersion() *version.Version
|
BinaryVersion() *version.Version
|
||||||
EmulationVersion() *version.Version
|
EmulationVersion() *version.Version
|
||||||
@ -121,8 +123,11 @@ func (m *effectiveVersion) Set(binaryVersion, emulationVersion, minCompatibility
|
|||||||
|
|
||||||
func (m *effectiveVersion) SetEmulationVersion(emulationVersion *version.Version) {
|
func (m *effectiveVersion) SetEmulationVersion(emulationVersion *version.Version) {
|
||||||
m.emulationVersion.Store(majorMinor(emulationVersion))
|
m.emulationVersion.Store(majorMinor(emulationVersion))
|
||||||
|
// set the default minCompatibilityVersion to be emulationVersion - 1
|
||||||
|
m.minCompatibilityVersion.Store(majorMinor(emulationVersion.SubtractMinor(1)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetMinCompatibilityVersion should be called after SetEmulationVersion
|
||||||
func (m *effectiveVersion) SetMinCompatibilityVersion(minCompatibilityVersion *version.Version) {
|
func (m *effectiveVersion) SetMinCompatibilityVersion(minCompatibilityVersion *version.Version) {
|
||||||
m.minCompatibilityVersion.Store(majorMinor(minCompatibilityVersion))
|
m.minCompatibilityVersion.Store(majorMinor(minCompatibilityVersion))
|
||||||
}
|
}
|
||||||
@ -134,15 +139,15 @@ func (m *effectiveVersion) Validate() []error {
|
|||||||
emulationVersion := m.emulationVersion.Load()
|
emulationVersion := m.emulationVersion.Load()
|
||||||
minCompatibilityVersion := m.minCompatibilityVersion.Load()
|
minCompatibilityVersion := m.minCompatibilityVersion.Load()
|
||||||
|
|
||||||
// emulationVersion can only be 1.{binaryMinor-1}...1.{binaryMinor}.
|
// emulationVersion can only be 1.{binaryMinor-3}...1.{binaryMinor}
|
||||||
maxEmuVer := binaryVersion
|
maxEmuVer := binaryVersion
|
||||||
minEmuVer := binaryVersion.SubtractMinor(1)
|
minEmuVer := binaryVersion.SubtractMinor(3)
|
||||||
if emulationVersion.GreaterThan(maxEmuVer) || emulationVersion.LessThan(minEmuVer) {
|
if emulationVersion.GreaterThan(maxEmuVer) || emulationVersion.LessThan(minEmuVer) {
|
||||||
errs = append(errs, fmt.Errorf("emulation version %s is not between [%s, %s]", emulationVersion.String(), minEmuVer.String(), maxEmuVer.String()))
|
errs = append(errs, fmt.Errorf("emulation version %s is not between [%s, %s]", emulationVersion.String(), minEmuVer.String(), maxEmuVer.String()))
|
||||||
}
|
}
|
||||||
// minCompatibilityVersion can only be 1.{binaryMinor-1} for alpha.
|
// minCompatibilityVersion can only be 1.{binaryMinor-3} to 1.{binaryMinor}
|
||||||
maxCompVer := binaryVersion.SubtractMinor(1)
|
maxCompVer := emulationVersion
|
||||||
minCompVer := binaryVersion.SubtractMinor(1)
|
minCompVer := binaryVersion.SubtractMinor(4)
|
||||||
if minCompatibilityVersion.GreaterThan(maxCompVer) || minCompatibilityVersion.LessThan(minCompVer) {
|
if minCompatibilityVersion.GreaterThan(maxCompVer) || minCompatibilityVersion.LessThan(minCompVer) {
|
||||||
errs = append(errs, fmt.Errorf("minCompatibilityVersion version %s is not between [%s, %s]", minCompatibilityVersion.String(), minCompVer.String(), maxCompVer.String()))
|
errs = append(errs, fmt.Errorf("minCompatibilityVersion version %s is not between [%s, %s]", minCompatibilityVersion.String(), minCompVer.String(), maxCompVer.String()))
|
||||||
}
|
}
|
||||||
@ -187,13 +192,15 @@ func DefaultKubeEffectiveVersion() MutableEffectiveVersion {
|
|||||||
return newEffectiveVersion(binaryVersion, false)
|
return newEffectiveVersion(binaryVersion, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateKubeEffectiveVersion validates the EmulationVersion is equal to the binary version at 1.31 for kube components.
|
// ValidateKubeEffectiveVersion validates the EmulationVersion is at least 1.31 and MinCompatibilityVersion
|
||||||
// emulationVersion is introduced in 1.31, so it is only allowed to be equal to the binary version at 1.31.
|
// is at least 1.30 for kube components.
|
||||||
func ValidateKubeEffectiveVersion(effectiveVersion EffectiveVersion) error {
|
func ValidateKubeEffectiveVersion(effectiveVersion EffectiveVersion) error {
|
||||||
binaryVersion := version.MajorMinor(effectiveVersion.BinaryVersion().Major(), effectiveVersion.BinaryVersion().Minor())
|
if !effectiveVersion.EmulationVersion().AtLeast(minimumKubeEmulationVersion) {
|
||||||
if binaryVersion.EqualTo(version.MajorMinor(1, 31)) && !effectiveVersion.EmulationVersion().EqualTo(binaryVersion) {
|
return fmt.Errorf("emulation version needs to be greater or equal to 1.31, got %s", effectiveVersion.EmulationVersion().String())
|
||||||
return fmt.Errorf("emulation version needs to be equal to binary version(%s) in compatibility-version alpha, got %s",
|
|
||||||
binaryVersion.String(), effectiveVersion.EmulationVersion().String())
|
|
||||||
}
|
}
|
||||||
|
if !effectiveVersion.MinCompatibilityVersion().AtLeast(minimumKubeEmulationVersion.SubtractMinor(1)) {
|
||||||
|
return fmt.Errorf("minCompatibilityVersion version needs to be greater or equal to 1.30, got %s", effectiveVersion.MinCompatibilityVersion().String())
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -43,9 +43,22 @@ func TestValidate(t *testing.T) {
|
|||||||
minCompatibilityVersion: "v1.31.0",
|
minCompatibilityVersion: "v1.31.0",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "emulation version two minor lower than binary not ok",
|
name: "emulation version two minor lower than binary ok",
|
||||||
binaryVersion: "v1.33.2",
|
binaryVersion: "v1.33.2",
|
||||||
emulationVersion: "v1.31.0",
|
emulationVersion: "v1.31.0",
|
||||||
|
minCompatibilityVersion: "v1.31.0",
|
||||||
|
expectErrors: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "emulation version three minor lower than binary ok",
|
||||||
|
binaryVersion: "v1.35.0",
|
||||||
|
emulationVersion: "v1.32.0",
|
||||||
|
minCompatibilityVersion: "v1.32.0",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "emulation version four minor lower than binary not ok",
|
||||||
|
binaryVersion: "v1.36.0",
|
||||||
|
emulationVersion: "v1.32.0",
|
||||||
minCompatibilityVersion: "v1.32.0",
|
minCompatibilityVersion: "v1.32.0",
|
||||||
expectErrors: true,
|
expectErrors: true,
|
||||||
},
|
},
|
||||||
@ -64,18 +77,25 @@ func TestValidate(t *testing.T) {
|
|||||||
expectErrors: true,
|
expectErrors: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "compatibility version same as binary not ok",
|
name: "compatibility version same as binary ok",
|
||||||
binaryVersion: "v1.32.2",
|
binaryVersion: "v1.32.2",
|
||||||
emulationVersion: "v1.32.0",
|
emulationVersion: "v1.32.0",
|
||||||
minCompatibilityVersion: "v1.32.0",
|
minCompatibilityVersion: "v1.32.0",
|
||||||
expectErrors: true,
|
expectErrors: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "compatibility version two minor lower than binary not ok",
|
name: "compatibility version two minor lower than binary ok",
|
||||||
binaryVersion: "v1.32.2",
|
binaryVersion: "v1.32.2",
|
||||||
emulationVersion: "v1.32.0",
|
emulationVersion: "v1.32.0",
|
||||||
minCompatibilityVersion: "v1.30.0",
|
minCompatibilityVersion: "v1.30.0",
|
||||||
expectErrors: true,
|
expectErrors: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "compatibility version three minor lower than binary ok",
|
||||||
|
binaryVersion: "v1.34.2",
|
||||||
|
emulationVersion: "v1.33.0",
|
||||||
|
minCompatibilityVersion: "v1.31.0",
|
||||||
|
expectErrors: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "compatibility version one minor higher than binary not ok",
|
name: "compatibility version one minor higher than binary not ok",
|
||||||
@ -84,6 +104,13 @@ func TestValidate(t *testing.T) {
|
|||||||
minCompatibilityVersion: "v1.33.0",
|
minCompatibilityVersion: "v1.33.0",
|
||||||
expectErrors: true,
|
expectErrors: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "emulation version lower than compatibility version not ok",
|
||||||
|
binaryVersion: "v1.34.2",
|
||||||
|
emulationVersion: "v1.32.0",
|
||||||
|
minCompatibilityVersion: "v1.33.0",
|
||||||
|
expectErrors: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
@ -105,3 +132,54 @@ func TestValidate(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidateKubeEffectiveVersion(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
emulationVersion string
|
||||||
|
minCompatibilityVersion string
|
||||||
|
expectErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "valid versions",
|
||||||
|
emulationVersion: "v1.31.0",
|
||||||
|
minCompatibilityVersion: "v1.31.0",
|
||||||
|
expectErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "emulationVersion too low",
|
||||||
|
emulationVersion: "v1.30.0",
|
||||||
|
minCompatibilityVersion: "v1.31.0",
|
||||||
|
expectErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "minCompatibilityVersion too low",
|
||||||
|
emulationVersion: "v1.31.0",
|
||||||
|
minCompatibilityVersion: "v1.29.0",
|
||||||
|
expectErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "both versions too low",
|
||||||
|
emulationVersion: "v1.30.0",
|
||||||
|
minCompatibilityVersion: "v1.30.0",
|
||||||
|
expectErr: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
|
||||||
|
effective := NewEffectiveVersion("1.32")
|
||||||
|
effective.SetEmulationVersion(version.MustParseGeneric(test.emulationVersion))
|
||||||
|
effective.SetMinCompatibilityVersion(version.MustParseGeneric(test.minCompatibilityVersion))
|
||||||
|
|
||||||
|
err := ValidateKubeEffectiveVersion(effective)
|
||||||
|
if test.expectErr && err == nil {
|
||||||
|
t.Error("expected error, but got nil")
|
||||||
|
}
|
||||||
|
if !test.expectErr && err != nil {
|
||||||
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -2975,20 +2975,6 @@ func TestEmulatedStorageVersion(t *testing.T) {
|
|||||||
expectedStorageVersion schema.GroupVersion
|
expectedStorageVersion schema.GroupVersion
|
||||||
}
|
}
|
||||||
cases := []testCase{
|
cases := []testCase{
|
||||||
{
|
|
||||||
name: "vap first ga release",
|
|
||||||
emulatedVersion: "1.30",
|
|
||||||
gvr: schema.GroupVersionResource{
|
|
||||||
Group: "admissionregistration.k8s.io",
|
|
||||||
Version: "v1",
|
|
||||||
Resource: "validatingadmissionpolicies",
|
|
||||||
},
|
|
||||||
object: validVap,
|
|
||||||
expectedStorageVersion: schema.GroupVersion{
|
|
||||||
Group: "admissionregistration.k8s.io",
|
|
||||||
Version: "v1beta1",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "vap after ga release",
|
name: "vap after ga release",
|
||||||
emulatedVersion: "1.31",
|
emulatedVersion: "1.31",
|
||||||
|
@ -618,9 +618,6 @@ resources:
|
|||||||
endpoint: unix:///@encrypt-all-kms-provider.sock
|
endpoint: unix:///@encrypt-all-kms-provider.sock
|
||||||
`
|
`
|
||||||
|
|
||||||
// KUBE_APISERVER_SERVE_REMOVED_APIS_FOR_ONE_RELEASE allows for APIs pending removal to not block tests
|
|
||||||
t.Setenv("KUBE_APISERVER_SERVE_REMOVED_APIS_FOR_ONE_RELEASE", "true")
|
|
||||||
|
|
||||||
t.Run("encrypt all resources", func(t *testing.T) {
|
t.Run("encrypt all resources", func(t *testing.T) {
|
||||||
_ = mock.NewBase64Plugin(t, "@encrypt-all-kms-provider.sock")
|
_ = mock.NewBase64Plugin(t, "@encrypt-all-kms-provider.sock")
|
||||||
// To ensure we are checking all REST resources
|
// To ensure we are checking all REST resources
|
||||||
|
@ -17,26 +17,54 @@ limitations under the License.
|
|||||||
package etcd
|
package etcd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||||
"k8s.io/apiextensions-apiserver/test/integration/fixtures"
|
"k8s.io/apiextensions-apiserver/test/integration/fixtures"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
utilversion "k8s.io/component-base/version"
|
||||||
|
|
||||||
"k8s.io/kubernetes/test/utils/image"
|
"k8s.io/kubernetes/test/utils/image"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetEtcdStorageData returns etcd data for all persisted objects.
|
// 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 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.
|
// It returns a new map on every invocation to prevent different tests from mutating shared state.
|
||||||
func GetEtcdStorageData() map[schema.GroupVersionResource]StorageData {
|
func GetEtcdStorageData() map[schema.GroupVersionResource]StorageData {
|
||||||
return GetEtcdStorageDataForNamespace("etcdstoragepathtestnamespace")
|
return GetEtcdStorageDataServedAt(utilversion.DefaultKubeBinaryVersion, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetEtcdStorageDataForNamespace returns etcd data for all persisted objects.
|
// 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 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.
|
// 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.
|
// Namespaced objects keys are computed for the specified namespace.
|
||||||
func GetEtcdStorageDataForNamespace(namespace string) map[schema.GroupVersionResource]StorageData {
|
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)
|
image := image.GetE2EImage(image.BusyBox)
|
||||||
etcdStorageData := map[schema.GroupVersionResource]StorageData{
|
etcdStorageData := map[schema.GroupVersionResource]StorageData{
|
||||||
// k8s.io/kubernetes/pkg/api/v1
|
// k8s.io/kubernetes/pkg/api/v1
|
||||||
@ -465,22 +493,46 @@ func GetEtcdStorageDataForNamespace(namespace string) map[schema.GroupVersionRes
|
|||||||
},
|
},
|
||||||
// --
|
// --
|
||||||
|
|
||||||
|
// k8s.io/kubernetes/pkg/apis/storage/v1
|
||||||
|
gvr("storage.k8s.io", "v1", "csinodes"): {
|
||||||
|
Stub: `{"metadata": {"name": "csini2"}, "spec": {"drivers": [{"name": "test-driver", "nodeID": "localhost", "topologyKeys": ["company.com/zone1", "company.com/zone2"]}]}}`,
|
||||||
|
ExpectedEtcdPath: "/registry/csinodes/csini2",
|
||||||
|
},
|
||||||
|
// --
|
||||||
|
|
||||||
|
// k8s.io/kubernetes/pkg/apis/storage/v1
|
||||||
|
gvr("storage.k8s.io", "v1", "csidrivers"): {
|
||||||
|
Stub: `{"metadata": {"name": "csid2"}, "spec": {"attachRequired": true, "podInfoOnMount": true}}`,
|
||||||
|
ExpectedEtcdPath: "/registry/csidrivers/csid2",
|
||||||
|
},
|
||||||
|
// --
|
||||||
}
|
}
|
||||||
|
|
||||||
// add csinodes
|
// Delete types no longer served or not yet added at a particular emulated version.
|
||||||
// k8s.io/kubernetes/pkg/apis/storage/v1
|
// When adding a brand new type non-alpha type in the latest release, please ensure that
|
||||||
etcdStorageData[gvr("storage.k8s.io", "v1", "csinodes")] = StorageData{
|
// it is removed in previous emulated versions otherwise emulated version tests will fail.
|
||||||
Stub: `{"metadata": {"name": "csini2"}, "spec": {"drivers": [{"name": "test-driver", "nodeID": "localhost", "topologyKeys": ["company.com/zone1", "company.com/zone2"]}]}}`,
|
// TODO: derive this programatically from gvk --> instance --> APILifecycle info
|
||||||
ExpectedEtcdPath: "/registry/csinodes/csini2",
|
switch version {
|
||||||
|
case "1.33":
|
||||||
|
delete(etcdStorageData, gvr("flowcontrol.apiserver.k8s.io", "v1beta3", "flowschemas"))
|
||||||
|
delete(etcdStorageData, gvr("flowcontrol.apiserver.k8s.io", "v1beta3", "prioritylevelconfigurations"))
|
||||||
|
case "1.32":
|
||||||
|
delete(etcdStorageData, gvr("flowcontrol.apiserver.k8s.io", "v1beta3", "flowschemas"))
|
||||||
|
delete(etcdStorageData, gvr("flowcontrol.apiserver.k8s.io", "v1beta3", "prioritylevelconfigurations"))
|
||||||
|
case "1.31":
|
||||||
|
delete(etcdStorageData, gvr("resource.k8s.io", "v1beta1", "deviceclasses"))
|
||||||
|
delete(etcdStorageData, gvr("resource.k8s.io", "v1beta1", "resourceclaims"))
|
||||||
|
delete(etcdStorageData, gvr("resource.k8s.io", "v1beta1", "resourceclaimtemplates"))
|
||||||
|
delete(etcdStorageData, gvr("resource.k8s.io", "v1beta1", "resourceslices"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// add csidrivers
|
if removeAlphas {
|
||||||
// k8s.io/kubernetes/pkg/apis/storage/v1
|
for key := range etcdStorageData {
|
||||||
etcdStorageData[gvr("storage.k8s.io", "v1", "csidrivers")] = StorageData{
|
if strings.Contains(key.Version, "alpha") {
|
||||||
Stub: `{"metadata": {"name": "csid2"}, "spec": {"attachRequired": true, "podInfoOnMount": true}}`,
|
delete(etcdStorageData, key)
|
||||||
ExpectedEtcdPath: "/registry/csidrivers/csid2",
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return etcdStorageData
|
return etcdStorageData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,9 +39,12 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime/serializer/recognizer"
|
"k8s.io/apimachinery/pkg/runtime/serializer/recognizer"
|
||||||
utiljson "k8s.io/apimachinery/pkg/util/json"
|
utiljson "k8s.io/apimachinery/pkg/util/json"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
|
"k8s.io/apimachinery/pkg/util/version"
|
||||||
"k8s.io/apiserver/pkg/util/feature"
|
"k8s.io/apiserver/pkg/util/feature"
|
||||||
"k8s.io/client-go/dynamic"
|
"k8s.io/client-go/dynamic"
|
||||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||||
|
componentbaseversion "k8s.io/component-base/version"
|
||||||
|
"k8s.io/kubernetes/cmd/kube-apiserver/app/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Only add kinds to this list when this a virtual resource with get and create verbs that doesn't actually
|
// 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{
|
|||||||
// It will also fail when a type gets moved to a different location. Be very careful in this situation because
|
// It will also fail when a type gets moved to a different location. Be very careful in this situation because
|
||||||
// it essentially means that you will be break old clusters unless you create some migration path for the old data.
|
// it essentially means that you will be break old clusters unless you create some migration path for the old data.
|
||||||
func TestEtcdStoragePath(t *testing.T) {
|
func TestEtcdStoragePath(t *testing.T) {
|
||||||
// KUBE_APISERVER_SERVE_REMOVED_APIS_FOR_ONE_RELEASE allows for APIs pending removal to not block tests
|
supportedVersions := GetSupportedEmulatedVersions()
|
||||||
t.Setenv("KUBE_APISERVER_SERVE_REMOVED_APIS_FOR_ONE_RELEASE", "true")
|
for _, v := range supportedVersions {
|
||||||
|
t.Run(v, func(t *testing.T) {
|
||||||
|
testEtcdStoragePathWithVersion(t, v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, "AllAlpha", true)
|
func testEtcdStoragePathWithVersion(t *testing.T, v string) {
|
||||||
featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, "AllBeta", true)
|
if v == componentbaseversion.DefaultKubeBinaryVersion {
|
||||||
|
featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, "AllAlpha", true)
|
||||||
|
featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, "AllBeta", true)
|
||||||
|
} else {
|
||||||
|
// Only test for beta and GA APIs with emulated version.
|
||||||
|
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, feature.DefaultFeatureGate, version.MustParse(v))
|
||||||
|
featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, "AllBeta", true)
|
||||||
|
registerEffectiveEmulationVersion(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
apiServer := StartRealAPIServerOrDie(t, func(opts *options.ServerRunOptions) {
|
||||||
|
// Disable alphas when emulating previous versions.
|
||||||
|
if v != componentbaseversion.DefaultKubeBinaryVersion {
|
||||||
|
opts.Options.APIEnablement.RuntimeConfig["api/alpha"] = "false"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
apiServer := StartRealAPIServerOrDie(t)
|
|
||||||
defer apiServer.Cleanup()
|
defer apiServer.Cleanup()
|
||||||
defer dumpEtcdKVOnFailure(t, apiServer.KV)
|
defer dumpEtcdKVOnFailure(t, apiServer.KV)
|
||||||
|
|
||||||
@ -91,7 +113,14 @@ func TestEtcdStoragePath(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
etcdStorageData := GetEtcdStorageData()
|
var etcdStorageData map[schema.GroupVersionResource]StorageData
|
||||||
|
if v == componentbaseversion.DefaultKubeBinaryVersion {
|
||||||
|
etcdStorageData = GetEtcdStorageDataForNamespaceServedAt("etcdstoragepathtestnamespace", v, false)
|
||||||
|
} else {
|
||||||
|
// Drop alphas from etcd data fixtures when emulating previous versions
|
||||||
|
// as alphas are not supported with emulation.
|
||||||
|
etcdStorageData = GetEtcdStorageDataForNamespaceServedAt("etcdstoragepathtestnamespace", v, true)
|
||||||
|
}
|
||||||
|
|
||||||
kindSeen := sets.NewString()
|
kindSeen := sets.NewString()
|
||||||
pathSeen := map[string][]schema.GroupVersionResource{}
|
pathSeen := map[string][]schema.GroupVersionResource{}
|
||||||
|
@ -36,14 +36,19 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||||
"k8s.io/apimachinery/pkg/util/json"
|
"k8s.io/apimachinery/pkg/util/json"
|
||||||
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
genericapiserveroptions "k8s.io/apiserver/pkg/server/options"
|
genericapiserveroptions "k8s.io/apiserver/pkg/server/options"
|
||||||
|
"k8s.io/apiserver/pkg/util/feature"
|
||||||
cacheddiscovery "k8s.io/client-go/discovery/cached/memory"
|
cacheddiscovery "k8s.io/client-go/discovery/cached/memory"
|
||||||
"k8s.io/client-go/dynamic"
|
"k8s.io/client-go/dynamic"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
"k8s.io/client-go/restmapper"
|
"k8s.io/client-go/restmapper"
|
||||||
utiltesting "k8s.io/client-go/util/testing"
|
utiltesting "k8s.io/client-go/util/testing"
|
||||||
|
"k8s.io/component-base/featuregate"
|
||||||
|
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||||
|
utilversion "k8s.io/component-base/version"
|
||||||
"k8s.io/kubernetes/cmd/kube-apiserver/app"
|
"k8s.io/kubernetes/cmd/kube-apiserver/app"
|
||||||
"k8s.io/kubernetes/cmd/kube-apiserver/app/options"
|
"k8s.io/kubernetes/cmd/kube-apiserver/app/options"
|
||||||
"k8s.io/kubernetes/test/integration"
|
"k8s.io/kubernetes/test/integration"
|
||||||
@ -62,11 +67,23 @@ AwEHoUQDQgAEH6cuzP8XuD5wal6wf9M6xDljTOPLX2i8uIp/C/ASqiIGUeeKQtX0
|
|||||||
/IR3qCXyThP/dbCiHrF3v1cuhBOHY8CLVg==
|
/IR3qCXyThP/dbCiHrF3v1cuhBOHY8CLVg==
|
||||||
-----END EC PRIVATE KEY-----`
|
-----END EC PRIVATE KEY-----`
|
||||||
|
|
||||||
|
func registerEffectiveEmulationVersion(t *testing.T) {
|
||||||
|
featureGate := feature.DefaultMutableFeatureGate
|
||||||
|
featureGate.AddMetrics()
|
||||||
|
|
||||||
|
effectiveVersion := utilversion.DefaultKubeEffectiveVersion()
|
||||||
|
effectiveVersion.SetEmulationVersion(featureGate.EmulationVersion())
|
||||||
|
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, featureGate, effectiveVersion.EmulationVersion())
|
||||||
|
featuregate.DefaultComponentGlobalsRegistry.Reset()
|
||||||
|
utilruntime.Must(featuregate.DefaultComponentGlobalsRegistry.Register(featuregate.DefaultKubeComponent, effectiveVersion, featureGate))
|
||||||
|
}
|
||||||
|
|
||||||
// StartRealAPIServerOrDie starts an API server that is appropriate for use in tests that require one of every resource
|
// StartRealAPIServerOrDie starts an API server that is appropriate for use in tests that require one of every resource
|
||||||
func StartRealAPIServerOrDie(t *testing.T, configFuncs ...func(*options.ServerRunOptions)) *APIServer {
|
func StartRealAPIServerOrDie(t *testing.T, configFuncs ...func(*options.ServerRunOptions)) *APIServer {
|
||||||
tCtx := ktesting.Init(t)
|
tCtx := ktesting.Init(t)
|
||||||
|
|
||||||
certDir, err := os.MkdirTemp("", t.Name())
|
// Strip out "/" in subtests
|
||||||
|
certDir, err := os.MkdirTemp("", strings.ReplaceAll(t.Name(), "/", ""))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ func TestAPIServerMetrics(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make a request to a deprecated API to ensure there's at least one data point
|
// Make a request to a deprecated API to ensure there's at least one data point
|
||||||
if _, err := client.FlowcontrolV1beta3().FlowSchemas().List(context.TODO(), metav1.ListOptions{}); err != nil {
|
if _, err := client.AdmissionregistrationV1beta1().ValidatingAdmissionPolicies().List(context.TODO(), metav1.ListOptions{}); err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user