diff --git a/cmd/kubeadm/app/util/config/common.go b/cmd/kubeadm/app/util/config/common.go index dd4340360118a..f417a39fba1d1 100644 --- a/cmd/kubeadm/app/util/config/common.go +++ b/cmd/kubeadm/app/util/config/common.go @@ -64,7 +64,7 @@ func MarshalKubeadmConfigObject(obj runtime.Object, gv schema.GroupVersion) ([]b // 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, allowExperimental bool) error { +func validateSupportedVersion(gvk schema.GroupVersionKind, 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 @@ -91,18 +91,18 @@ func validateSupportedVersion(gv schema.GroupVersion, allowDeprecated, allowExpe "kubeadm.k8s.io/v1beta3": {}, } - gvString := gv.String() + gvString := gvk.GroupVersion().String() if useKubeadmVersion := oldKnownAPIVersions[gvString]; useKubeadmVersion != "" { - return errors.Errorf("your configuration file uses an old API spec: %q. Please use kubeadm %s instead and run 'kubeadm config migrate --old-config old.yaml --new-config new.yaml', which will write the new, similar spec using a newer API version.", gv.String(), useKubeadmVersion) + return errors.Errorf("your configuration file uses an old API spec: %q (kind: %q). Please use kubeadm %s instead and run 'kubeadm config migrate --old-config old.yaml --new-config new.yaml', which will write the new, similar spec using a newer API version.", gvString, gvk.Kind, useKubeadmVersion) } if _, present := deprecatedAPIVersions[gvString]; present && !allowDeprecated { - 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.String()) + klog.Warningf("your configuration file uses a deprecated API spec: %q (kind: %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.", gvString, gvk.Kind) } 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 errors.Errorf("experimental API spec: %q (kind: %q) is not allowed. You can use the --%s flag if the command supports it.", gvString, gvk.Kind, options.AllowExperimentalAPI) } return nil @@ -225,7 +225,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, true); err != nil { + if err := validateSupportedVersion(gvk, true, true); err != nil { continue } diff --git a/cmd/kubeadm/app/util/config/common_test.go b/cmd/kubeadm/app/util/config/common_test.go index c17d7a7ea7e6a..538c03e096213 100644 --- a/cmd/kubeadm/app/util/config/common_test.go +++ b/cmd/kubeadm/app/util/config/common_test.go @@ -43,69 +43,77 @@ const KubeadmGroupName = "kubeadm.k8s.io" func TestValidateSupportedVersion(t *testing.T) { tests := []struct { - gv schema.GroupVersion + gvk schema.GroupVersionKind allowDeprecated bool allowExperimental bool expectedErr bool }{ { - gv: schema.GroupVersion{ + gvk: schema.GroupVersionKind{ Group: KubeadmGroupName, Version: "v1alpha1", + Kind: "InitConfiguration", }, expectedErr: true, }, { - gv: schema.GroupVersion{ + gvk: schema.GroupVersionKind{ Group: KubeadmGroupName, Version: "v1alpha2", + Kind: "InitConfiguration", }, expectedErr: true, }, { - gv: schema.GroupVersion{ + gvk: schema.GroupVersionKind{ Group: KubeadmGroupName, Version: "v1alpha3", + Kind: "InitConfiguration", }, expectedErr: true, }, { - gv: schema.GroupVersion{ + gvk: schema.GroupVersionKind{ Group: KubeadmGroupName, Version: "v1beta1", + Kind: "InitConfiguration", }, expectedErr: true, }, { - gv: schema.GroupVersion{ + gvk: schema.GroupVersionKind{ Group: KubeadmGroupName, Version: "v1beta2", + Kind: "InitConfiguration", }, expectedErr: true, }, { - gv: schema.GroupVersion{ + gvk: schema.GroupVersionKind{ Group: KubeadmGroupName, Version: "v1beta3", + Kind: "ClusterConfiguration", }, }, { - gv: schema.GroupVersion{ + gvk: schema.GroupVersionKind{ Group: "foo.k8s.io", Version: "v1", + Kind: "InitConfiguration", }, }, { - gv: schema.GroupVersion{ + gvk: schema.GroupVersionKind{ Group: KubeadmGroupName, Version: "v1beta4", + Kind: "ResetConfiguration", }, }, } 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, rt.allowExperimental) + t.Run(fmt.Sprintf("%s/allowDeprecated:%t", rt.gvk.GroupVersion(), rt.allowDeprecated), func(t *testing.T) { + err := validateSupportedVersion(rt.gvk, rt.allowDeprecated, rt.allowExperimental) if rt.expectedErr && err == nil { t.Error("unexpected success") } else if !rt.expectedErr && err != nil { diff --git a/cmd/kubeadm/app/util/config/initconfiguration.go b/cmd/kubeadm/app/util/config/initconfiguration.go index 8d2af14e39439..1566b8b1b5fea 100644 --- a/cmd/kubeadm/app/util/config/initconfiguration.go +++ b/cmd/kubeadm/app/util/config/initconfiguration.go @@ -322,7 +322,7 @@ func documentMapToInitConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecat fileContent := gvkmap[gvk] // first, check if this GVK is supported and possibly not deprecated - if err := validateSupportedVersion(gvk.GroupVersion(), allowDeprecated, allowExperimental); err != nil { + if err := validateSupportedVersion(gvk, allowDeprecated, allowExperimental); err != nil { return nil, err } diff --git a/cmd/kubeadm/app/util/config/joinconfiguration.go b/cmd/kubeadm/app/util/config/joinconfiguration.go index 1f2bc099cb6ca..6aa4f4c5b7444 100644 --- a/cmd/kubeadm/app/util/config/joinconfiguration.go +++ b/cmd/kubeadm/app/util/config/joinconfiguration.go @@ -106,7 +106,7 @@ func documentMapToJoinConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecat } // check if this version is supported and possibly not deprecated - if err := validateSupportedVersion(gvk.GroupVersion(), allowDeprecated, allowExperimental); err != nil { + if err := validateSupportedVersion(gvk, allowDeprecated, allowExperimental); err != nil { return nil, err } diff --git a/cmd/kubeadm/app/util/config/resetconfiguration.go b/cmd/kubeadm/app/util/config/resetconfiguration.go index 63994ff193960..06616bc18e3e0 100644 --- a/cmd/kubeadm/app/util/config/resetconfiguration.go +++ b/cmd/kubeadm/app/util/config/resetconfiguration.go @@ -110,7 +110,7 @@ func documentMapToResetConfiguration(gvkmap kubeadmapi.DocumentMap, allowDepreca } // check if this version is supported and possibly not deprecated - if err := validateSupportedVersion(gvk.GroupVersion(), allowDeprecated, allowExperimental); err != nil { + if err := validateSupportedVersion(gvk, allowDeprecated, allowExperimental); err != nil { return nil, err } diff --git a/cmd/kubeadm/app/util/config/upgradeconfiguration.go b/cmd/kubeadm/app/util/config/upgradeconfiguration.go index 09ac4753e221f..d35a884164167 100644 --- a/cmd/kubeadm/app/util/config/upgradeconfiguration.go +++ b/cmd/kubeadm/app/util/config/upgradeconfiguration.go @@ -45,7 +45,7 @@ func documentMapToUpgradeConfiguration(gvkmap kubeadmapi.DocumentMap, allowDepre for gvk, bytes := range gvkmap { // check if this version is supported and possibly not deprecated - if err := validateSupportedVersion(gvk.GroupVersion(), allowDeprecated, true); err != nil { + if err := validateSupportedVersion(gvk, allowDeprecated, true); err != nil { return nil, err }