mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	kubeadm: improve the error/warning messages of 'validateSupportedVersion' to include the checked resource kind
This commit is contained in:
		@@ -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.
 | 
					// validateSupportedVersion checks if the supplied GroupVersion is not on the lists of old unsupported or deprecated GVs.
 | 
				
			||||||
// If it is, an error is returned.
 | 
					// 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:
 | 
						// The support matrix will look something like this now and in the future:
 | 
				
			||||||
	// v1.10 and earlier: v1alpha1
 | 
						// v1.10 and earlier: v1alpha1
 | 
				
			||||||
	// v1.11: v1alpha1 read-only, writes only v1alpha2 config
 | 
						// v1.11: v1alpha1 read-only, writes only v1alpha2 config
 | 
				
			||||||
@@ -91,18 +91,18 @@ func validateSupportedVersion(gv schema.GroupVersion, allowDeprecated, allowExpe
 | 
				
			|||||||
		"kubeadm.k8s.io/v1beta3": {},
 | 
							"kubeadm.k8s.io/v1beta3": {},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gvString := gv.String()
 | 
						gvString := gvk.GroupVersion().String()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if useKubeadmVersion := oldKnownAPIVersions[gvString]; useKubeadmVersion != "" {
 | 
						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 {
 | 
						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 {
 | 
						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
 | 
						return nil
 | 
				
			||||||
@@ -225,7 +225,7 @@ func validateKnownGVKs(gvks []schema.GroupVersionKind) error {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		// Skip legacy known GVs so that they don't return errors.
 | 
							// Skip legacy known GVs so that they don't return errors.
 | 
				
			||||||
		// This makes the function return errors only for GVs that where never known.
 | 
							// 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
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,69 +43,77 @@ const KubeadmGroupName = "kubeadm.k8s.io"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestValidateSupportedVersion(t *testing.T) {
 | 
					func TestValidateSupportedVersion(t *testing.T) {
 | 
				
			||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
		gv                schema.GroupVersion
 | 
							gvk               schema.GroupVersionKind
 | 
				
			||||||
		allowDeprecated   bool
 | 
							allowDeprecated   bool
 | 
				
			||||||
		allowExperimental bool
 | 
							allowExperimental bool
 | 
				
			||||||
		expectedErr       bool
 | 
							expectedErr       bool
 | 
				
			||||||
	}{
 | 
						}{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			gv: schema.GroupVersion{
 | 
								gvk: schema.GroupVersionKind{
 | 
				
			||||||
				Group:   KubeadmGroupName,
 | 
									Group:   KubeadmGroupName,
 | 
				
			||||||
				Version: "v1alpha1",
 | 
									Version: "v1alpha1",
 | 
				
			||||||
 | 
									Kind:    "InitConfiguration",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			expectedErr: true,
 | 
								expectedErr: true,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			gv: schema.GroupVersion{
 | 
								gvk: schema.GroupVersionKind{
 | 
				
			||||||
				Group:   KubeadmGroupName,
 | 
									Group:   KubeadmGroupName,
 | 
				
			||||||
				Version: "v1alpha2",
 | 
									Version: "v1alpha2",
 | 
				
			||||||
 | 
									Kind:    "InitConfiguration",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			expectedErr: true,
 | 
								expectedErr: true,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			gv: schema.GroupVersion{
 | 
								gvk: schema.GroupVersionKind{
 | 
				
			||||||
				Group:   KubeadmGroupName,
 | 
									Group:   KubeadmGroupName,
 | 
				
			||||||
				Version: "v1alpha3",
 | 
									Version: "v1alpha3",
 | 
				
			||||||
 | 
									Kind:    "InitConfiguration",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			expectedErr: true,
 | 
								expectedErr: true,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			gv: schema.GroupVersion{
 | 
								gvk: schema.GroupVersionKind{
 | 
				
			||||||
				Group:   KubeadmGroupName,
 | 
									Group:   KubeadmGroupName,
 | 
				
			||||||
				Version: "v1beta1",
 | 
									Version: "v1beta1",
 | 
				
			||||||
 | 
									Kind:    "InitConfiguration",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			expectedErr: true,
 | 
								expectedErr: true,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			gv: schema.GroupVersion{
 | 
								gvk: schema.GroupVersionKind{
 | 
				
			||||||
				Group:   KubeadmGroupName,
 | 
									Group:   KubeadmGroupName,
 | 
				
			||||||
				Version: "v1beta2",
 | 
									Version: "v1beta2",
 | 
				
			||||||
 | 
									Kind:    "InitConfiguration",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			expectedErr: true,
 | 
								expectedErr: true,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			gv: schema.GroupVersion{
 | 
								gvk: schema.GroupVersionKind{
 | 
				
			||||||
				Group:   KubeadmGroupName,
 | 
									Group:   KubeadmGroupName,
 | 
				
			||||||
				Version: "v1beta3",
 | 
									Version: "v1beta3",
 | 
				
			||||||
 | 
									Kind:    "ClusterConfiguration",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			gv: schema.GroupVersion{
 | 
								gvk: schema.GroupVersionKind{
 | 
				
			||||||
				Group:   "foo.k8s.io",
 | 
									Group:   "foo.k8s.io",
 | 
				
			||||||
				Version: "v1",
 | 
									Version: "v1",
 | 
				
			||||||
 | 
									Kind:    "InitConfiguration",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			gv: schema.GroupVersion{
 | 
								gvk: schema.GroupVersionKind{
 | 
				
			||||||
				Group:   KubeadmGroupName,
 | 
									Group:   KubeadmGroupName,
 | 
				
			||||||
				Version: "v1beta4",
 | 
									Version: "v1beta4",
 | 
				
			||||||
 | 
									Kind:    "ResetConfiguration",
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, rt := range tests {
 | 
						for _, rt := range tests {
 | 
				
			||||||
		t.Run(fmt.Sprintf("%s/allowDeprecated:%t", rt.gv, rt.allowDeprecated), func(t *testing.T) {
 | 
							t.Run(fmt.Sprintf("%s/allowDeprecated:%t", rt.gvk.GroupVersion(), rt.allowDeprecated), func(t *testing.T) {
 | 
				
			||||||
			err := validateSupportedVersion(rt.gv, rt.allowDeprecated, rt.allowExperimental)
 | 
								err := validateSupportedVersion(rt.gvk, rt.allowDeprecated, rt.allowExperimental)
 | 
				
			||||||
			if rt.expectedErr && err == nil {
 | 
								if rt.expectedErr && err == nil {
 | 
				
			||||||
				t.Error("unexpected success")
 | 
									t.Error("unexpected success")
 | 
				
			||||||
			} else if !rt.expectedErr && err != nil {
 | 
								} else if !rt.expectedErr && err != nil {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -322,7 +322,7 @@ func documentMapToInitConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecat
 | 
				
			|||||||
		fileContent := gvkmap[gvk]
 | 
							fileContent := gvkmap[gvk]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// first, check if this GVK is supported and possibly not deprecated
 | 
							// 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
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -106,7 +106,7 @@ func documentMapToJoinConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecat
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// check if this version is supported and possibly not deprecated
 | 
							// 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
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -110,7 +110,7 @@ func documentMapToResetConfiguration(gvkmap kubeadmapi.DocumentMap, allowDepreca
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// check if this version is supported and possibly not deprecated
 | 
							// 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
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -45,7 +45,7 @@ func documentMapToUpgradeConfiguration(gvkmap kubeadmapi.DocumentMap, allowDepre
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	for gvk, bytes := range gvkmap {
 | 
						for gvk, bytes := range gvkmap {
 | 
				
			||||||
		// check if this version is supported and possibly not deprecated
 | 
							// 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
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user