Merge pull request #115944 from SataQiu/warning-for-externalid

Add field-level warning for deprecated spec.externalID of node
This commit is contained in:
Kubernetes Prow Robot 2023-02-24 06:15:47 -08:00 committed by GitHub
commit 0753f02851
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -123,7 +123,7 @@ func (nodeStrategy) Validate(ctx context.Context, obj runtime.Object) field.Erro
// WarningsOnCreate returns warnings for the creation of the given object. // WarningsOnCreate returns warnings for the creation of the given object.
func (nodeStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string { func (nodeStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
return dynamicKubeletConfigIsDeprecatedWarning(obj) return fieldIsDeprecatedWarnings(obj)
} }
// Canonicalize normalizes the object after validation. // Canonicalize normalizes the object after validation.
@ -138,7 +138,7 @@ func (nodeStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object)
// WarningsOnUpdate returns warnings for the given update. // WarningsOnUpdate returns warnings for the given update.
func (nodeStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string { func (nodeStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
return dynamicKubeletConfigIsDeprecatedWarning(obj) return fieldIsDeprecatedWarnings(obj)
} }
func (nodeStrategy) AllowUnconditionalUpdate() bool { func (nodeStrategy) AllowUnconditionalUpdate() bool {
@ -267,13 +267,15 @@ func ResourceLocation(getter ResourceGetter, connection client.ConnectionInfoGet
return &url.URL{Scheme: schemeReq, Host: net.JoinHostPort(info.Hostname, portReq)}, proxyTransport, nil return &url.URL{Scheme: schemeReq, Host: net.JoinHostPort(info.Hostname, portReq)}, proxyTransport, nil
} }
func dynamicKubeletConfigIsDeprecatedWarning(obj runtime.Object) []string { func fieldIsDeprecatedWarnings(obj runtime.Object) []string {
newNode := obj.(*api.Node) newNode := obj.(*api.Node)
if newNode.Spec.ConfigSource != nil {
var warnings []string var warnings []string
if newNode.Spec.ConfigSource != nil {
// KEP https://github.com/kubernetes/enhancements/issues/281 // KEP https://github.com/kubernetes/enhancements/issues/281
warnings = append(warnings, "spec.configSource: the feature is removed") warnings = append(warnings, "spec.configSource: the feature is removed")
return warnings
} }
return nil if len(newNode.Spec.DoNotUseExternalID) > 0 {
warnings = append(warnings, "spec.externalID: this field is deprecated, and is unused by Kubernetes")
}
return warnings
} }

View File

@ -298,6 +298,14 @@ func TestWarningOnUpdateAndCreate(t *testing.T) {
"spec.configSource"}, "spec.configSource"},
{api.Node{Spec: api.NodeSpec{ConfigSource: &api.NodeConfigSource{}}}, {api.Node{Spec: api.NodeSpec{ConfigSource: &api.NodeConfigSource{}}},
api.Node{}, ""}, api.Node{}, ""},
{api.Node{},
api.Node{Spec: api.NodeSpec{DoNotUseExternalID: "externalID"}},
"spec.externalID"},
{api.Node{Spec: api.NodeSpec{DoNotUseExternalID: "externalID"}},
api.Node{Spec: api.NodeSpec{DoNotUseExternalID: "externalID"}},
"spec.externalID"},
{api.Node{Spec: api.NodeSpec{DoNotUseExternalID: "externalID"}},
api.Node{}, ""},
} }
for i, test := range tests { for i, test := range tests {
warnings := (nodeStrategy{}).WarningsOnUpdate(context.Background(), &test.node, &test.oldNode) warnings := (nodeStrategy{}).WarningsOnUpdate(context.Background(), &test.node, &test.oldNode)