New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kubeadm: add v1beta4 to scheme; add --allow-experimental-api flag #118866
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,4 +142,7 @@ const ( | |
|
||
// CleanupTmpDir flag indicates whether reset will cleanup the tmp dir | ||
CleanupTmpDir = "cleanup-tmp-dir" | ||
|
||
// AllowExperimentalAPI flag can be used to allow experimental / work in progress APIs | ||
AllowExperimentalAPI = "allow-experimental-api" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. flag naming is similar to upgrade apply, where we have --allow-foo flags |
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ import ( | |
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" | ||
kubeadmscheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme" | ||
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3" | ||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options" | ||
"k8s.io/kubernetes/cmd/kubeadm/app/componentconfigs" | ||
"k8s.io/kubernetes/cmd/kubeadm/app/constants" | ||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util" | ||
|
@@ -54,7 +55,7 @@ func MarshalKubeadmConfigObject(obj runtime.Object) ([]byte, error) { | |
|
||
// validateSupportedVersion checks if the supplied GroupVersion is not on the lists of old unsupported or deprecated GVs. | ||
// If it is, an error is returned. | ||
func validateSupportedVersion(gv schema.GroupVersion, allowDeprecated bool) error { | ||
func validateSupportedVersion(gv schema.GroupVersion, allowDeprecated, allowExperimental bool) error { | ||
// The support matrix will look something like this now and in the future: | ||
// v1.10 and earlier: v1alpha1 | ||
// v1.11: v1alpha1 read-only, writes only v1alpha2 config | ||
|
@@ -72,6 +73,13 @@ func validateSupportedVersion(gv schema.GroupVersion, allowDeprecated bool) erro | |
"kubeadm.k8s.io/v1beta2": "v1.22", | ||
} | ||
|
||
// v1.28: v1beta4 is released as experimental | ||
experimentalAPIVersions := map[string]string{ | ||
// TODO: https://github.com/kubernetes/kubeadm/issues/2890 | ||
// remove this from experimental once v1beta4 is released | ||
"kubeadm.k8s.io/v1beta4": "v1.28", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. task tracked in #118866 |
||
} | ||
|
||
// Deprecated API versions are supported by us, but can only be used for migration. | ||
deprecatedAPIVersions := map[string]struct{}{} | ||
|
||
|
@@ -85,6 +93,10 @@ func validateSupportedVersion(gv schema.GroupVersion, allowDeprecated bool) erro | |
klog.Warningf("your configuration file uses a deprecated API spec: %q. Please use 'kubeadm config migrate --old-config old.yaml --new-config new.yaml', which will write the new, similar spec using a newer API version.", gv) | ||
} | ||
|
||
if _, present := experimentalAPIVersions[gvString]; present && !allowExperimental { | ||
return errors.Errorf("experimental API spec: %q is not allowed. You can use the --%s flag if the command supports it.", gv, options.AllowExperimentalAPI) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
@@ -205,7 +217,7 @@ func validateKnownGVKs(gvks []schema.GroupVersionKind) error { | |
|
||
// Skip legacy known GVs so that they don't return errors. | ||
// This makes the function return errors only for GVs that where never known. | ||
if err := validateSupportedVersion(gvk.GroupVersion(), true); err != nil { | ||
if err := validateSupportedVersion(gvk.GroupVersion(), true, true); err != nil { | ||
continue | ||
} | ||
|
||
|
@@ -229,7 +241,7 @@ func validateKnownGVKs(gvks []schema.GroupVersionKind) error { | |
|
||
// MigrateOldConfig migrates an old configuration from a byte slice into a new one (returned again as a byte slice). | ||
// Only kubeadm kinds are migrated. | ||
func MigrateOldConfig(oldConfig []byte) ([]byte, error) { | ||
func MigrateOldConfig(oldConfig []byte, allowExperimental bool) ([]byte, error) { | ||
newConfig := [][]byte{} | ||
|
||
gvkmap, err := kubeadmutil.SplitYAMLDocuments(oldConfig) | ||
|
@@ -248,7 +260,7 @@ func MigrateOldConfig(oldConfig []byte) ([]byte, error) { | |
|
||
// Migrate InitConfiguration and ClusterConfiguration if there are any in the config | ||
if kubeadmutil.GroupVersionKindsHasInitConfiguration(gvks...) || kubeadmutil.GroupVersionKindsHasClusterConfiguration(gvks...) { | ||
o, err := documentMapToInitConfiguration(gvkmap, true, true) | ||
o, err := documentMapToInitConfiguration(gvkmap, true, allowExperimental, true) | ||
if err != nil { | ||
return []byte{}, err | ||
} | ||
|
@@ -261,7 +273,7 @@ func MigrateOldConfig(oldConfig []byte) ([]byte, error) { | |
|
||
// Migrate JoinConfiguration if there is any | ||
if kubeadmutil.GroupVersionKindsHasJoinConfiguration(gvks...) { | ||
o, err := documentMapToJoinConfiguration(gvkmap, true, true) | ||
o, err := documentMapToJoinConfiguration(gvkmap, true, allowExperimental, true) | ||
if err != nil { | ||
return []byte{}, err | ||
} | ||
|
@@ -277,7 +289,7 @@ func MigrateOldConfig(oldConfig []byte) ([]byte, error) { | |
|
||
// ValidateConfig takes a byte slice containing a kubeadm configuration and performs conversion | ||
// to internal types and validation. | ||
func ValidateConfig(oldConfig []byte) error { | ||
func ValidateConfig(oldConfig []byte, allowExperimental bool) error { | ||
gvkmap, err := kubeadmutil.SplitYAMLDocuments(oldConfig) | ||
if err != nil { | ||
return err | ||
|
@@ -294,14 +306,14 @@ func ValidateConfig(oldConfig []byte) error { | |
|
||
// Validate InitConfiguration and ClusterConfiguration if there are any in the config | ||
if kubeadmutil.GroupVersionKindsHasInitConfiguration(gvks...) || kubeadmutil.GroupVersionKindsHasClusterConfiguration(gvks...) { | ||
if _, err := documentMapToInitConfiguration(gvkmap, true, true); err != nil { | ||
if _, err := documentMapToInitConfiguration(gvkmap, true, allowExperimental, true); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// Validate JoinConfiguration if there is any | ||
if kubeadmutil.GroupVersionKindsHasJoinConfiguration(gvks...) { | ||
if _, err := documentMapToJoinConfiguration(gvkmap, true, true); err != nil { | ||
if _, err := documentMapToJoinConfiguration(gvkmap, true, allowExperimental, true); err != nil { | ||
return err | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,9 +34,10 @@ const KubeadmGroupName = "kubeadm.k8s.io" | |
|
||
func TestValidateSupportedVersion(t *testing.T) { | ||
tests := []struct { | ||
gv schema.GroupVersion | ||
allowDeprecated bool | ||
expectedErr bool | ||
gv schema.GroupVersion | ||
allowDeprecated bool | ||
allowExperimental bool | ||
expectedErr bool | ||
}{ | ||
{ | ||
gv: schema.GroupVersion{ | ||
|
@@ -85,11 +86,25 @@ func TestValidateSupportedVersion(t *testing.T) { | |
Version: "v1", | ||
}, | ||
}, | ||
{ | ||
gv: schema.GroupVersion{ | ||
Group: KubeadmGroupName, | ||
Version: "v1beta4", | ||
}, | ||
allowExperimental: true, | ||
}, | ||
{ | ||
gv: schema.GroupVersion{ | ||
Group: KubeadmGroupName, | ||
Version: "v1beta4", | ||
}, | ||
expectedErr: true, | ||
Comment on lines
+90
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there are no /cmd/kubeadm/test integration tests currently, only unit tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to see what can be done with the migration unit test
|
||
}, | ||
} | ||
|
||
for _, rt := range tests { | ||
t.Run(fmt.Sprintf("%s/allowDeprecated:%t", rt.gv, rt.allowDeprecated), func(t *testing.T) { | ||
err := validateSupportedVersion(rt.gv, rt.allowDeprecated) | ||
err := validateSupportedVersion(rt.gv, rt.allowDeprecated, rt.allowExperimental) | ||
if rt.expectedErr && err == nil { | ||
t.Error("unexpected success") | ||
} else if !rt.expectedErr && err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is tracked in the tasklist of #118866
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens now is that kubeadm still uses v1beta3 by default, until we adjust the priority here.