Change:
What happened: We applied an ingress with annotations that had integers as values but no annotations were applied in Kubernetes and no failure was thrown. What you expected to happen: We would expect an error to be thrown similar to this one: How to reproduce it (as minimally and precisely as possible): Create a file with the following: Apply, Verify, Uncomment Apply, Verify, You will see that it fails to apply any annotations this time but continued to apply the service without errors. To get an error edit manually with and add . Anything else we need to know?: This bug can be replicated on anything that uses annotations as long as it is applied using a file: We have confirmed this exists on -versions of kubectl Environment: Kubernetes version (use ):Cloud provider or hardware configuration: Google GKE OS (e.g. from /etc/os-release): Ubuntu Kubectl Version:Stackdriver logs: Manual Edit Failure: kubectl file apply success (but failed to apply annotations, they are NULL): <!-- DO NOT EDIT BELOW THIS LINE --/kind bug
/sig cli
/kind bug
possible relation to
Issues go stale after 90d of inactivity. Mark the issue as fresh with . Stale issues rot after an additional 30d of inactivity and eventually close. If this issue is safe to close now please do so with . Send feedback to sig-testing, kubernetes/test-infra and/or . /lifecycle stale
Stale issues rot after 30d of inactivity. Mark the issue as fresh with . Rotten issues close after an additional 30d of inactivity. If this issue is safe to close now please do so with . Send feedback to sig-testing, kubernetes/test-infra and/or . /lifecycle rotten
For those hitting this via google -- this is a dup of
Rotten issues close after 30d of inactivity. Reopen the issue with . Mark the issue as fresh with . Send feedback to sig-testing, kubernetes/test-infra and/or . /close
Closing this issue. <detailsIn response to : Rotten issues close after 30d of inactivity. Reopen the issue with . Mark the issue as fresh with . /close Instructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details

Discussion:
"helper.go", "interfaces.go", "mapper.go", <ins> "metadata_decoder.go", </ins> "result.go", "scheme.go", "selector.go",

"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library", <ins> "//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json:go_default_library", </ins> "//staging/src/k8s.io/apimachinery/pkg/types:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",

localFn:      b.isLocal, restMapperFn: b.restMapperFn, clientFn:     b.getClient, <del> decoder:      unstructured.UnstructuredJSONScheme, </del> <ins> decoder:      &metadataValidatingDecoder{unstructured.UnstructuredJSONScheme}, </ins> } return b

} } ` <ins> var aPodBadAnnotations string = ` { "kind": "Pod", "apiVersion": "` + corev1GV.String() + `", "metadata": { "name": "busybox{id}", "labels": { "name": "busybox{id}" }, "annotations": { "name": 0 } }, "spec": { "containers": [ { "name": "busybox", "image": "busybox", "command": [ "sleep", "3600" ], "imagePullPolicy": "IfNotPresent" } ], "restartPolicy": "Always" } } ` </ins> var aRC string = ` {

WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...) } <ins> func newUnstructuredDefaultBuilder() *Builder { return newUnstructuredDefaultBuilderWith(fakeClient()) } func newUnstructuredDefaultBuilderWith(fakeClientFn FakeClientFunc) *Builder { return NewFakeBuilder( fakeClientFn, func() (meta.RESTMapper, error) { return testrestmapper.TestOnlyStaticRESTMapper(scheme.Scheme), nil }, func() (restmapper.CategoryExpander, error) { return FakeCategoryExpander, nil }). Unstructured() } </ins> type errorRestMapper struct { meta.RESTMapper err error

}) } } <ins> func TestUnstructured(t *testing.T) { // create test dirs tmpDir, err := utiltesting.MkTmpdir("unstructured_test") if err != nil { t.Fatalf("error creating temp dir: %v", err) } defer os.RemoveAll(tmpDir) // create test files writeTestFile(t, fmt.Sprintf("%s/pod.json", tmpDir), aPod) writeTestFile(t, fmt.Sprintf("%s/badpod.json", tmpDir), aPodBadAnnotations) tests := []struct { name          string file          string expectedError string }{ { name:          "pod", file:          "pod.json", expectedError: "", }, { name:          "badpod", file:          "badpod.json", expectedError: "v1.ObjectMeta.Annotations", }, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { result := newUnstructuredDefaultBuilder(). ContinueOnError(). FilenameParam(false, &FilenameOptions{Recursive: false, Filenames: []string{fmt.Sprintf("%s/%s", tmpDir, tc.file)}}). Flatten(). Do() err := result.Err() if err == nil { _, err = result.Infos() } if len(tc.expectedError) == 0 { if err != nil { t.Errorf("unexpected error: %v", err) } } else { if err == nil { t.Errorf("expected error, got none") } else if !strings.Contains(err.Error(), tc.expectedError) { t.Errorf("expected error with '%s', got: %v", tc.expectedError, err) } } }) } } </ins>

<ins> /* Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package resource import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer/json" ) // hold a single instance of the case-sensitive decoder var caseSensitiveJsonIterator = json.CaseSensitiveJsonIterator() // metadataValidatingDecoder wraps a decoder and additionally ensures metadata schema fields decode before returning an unstructured object type metadataValidatingDecoder struct { decoder runtime.Decoder } func (m *metadataValidatingDecoder) Decode(data []byte, defaults *schema.GroupVersionKind, into runtime.Object) (runtime.Object, *schema.GroupVersionKind, error) { obj, gvk, err := m.decoder.Decode(data, defaults, into) // if we already errored, return if err != nil { return obj, gvk, err } // if we're not unstructured, return if _, isUnstructured := obj.(runtime.Unstructured); !isUnstructured { return obj, gvk, err } // make sure the data can decode into ObjectMeta before we return, // so we don't silently truncate schema errors in metadata later with accesser get/set calls v := &metadataOnlyObject{} if typedErr := caseSensitiveJsonIterator.Unmarshal(data, v); typedErr != nil { return obj, gvk, typedErr } return obj, gvk, err } type metadataOnlyObject struct { metav1.TypeMeta   `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` } </ins>