Skip to content
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

empty lists cause error about missing metadata #246

Closed
docwhat opened this issue Jul 30, 2020 · 5 comments · Fixed by #283
Closed

empty lists cause error about missing metadata #246

docwhat opened this issue Jul 30, 2020 · 5 comments · Fixed by #283

Comments

@docwhat
Copy link

docwhat commented Jul 30, 2020

When a kind: List is empty (items contains no objects) then kubeval incorrectly complains about a missing metadata key.

❯ cat empty-list.yaml
---
apiVersion: v1
kind: List
items: []
❯ cat empty-list.yaml | kubeval
ERR  - stdin: Missing 'metadata' key
❯ kubeval --version
Version: 0.15.0
Commit: df50ea7fd4fd202458002a40a6a39ffbb3125bad
Date: 2020-04-14T09:32:50Z
@docwhat
Copy link
Author

docwhat commented Jul 30, 2020

Here's a quick patch to add a test:

diff --git a/fixtures/list_empty_valid.yaml b/fixtures/list_empty_valid.yaml
new file mode 100644
index 0000000..2276fbb
--- /dev/null
+++ b/fixtures/list_empty_valid.yaml
@@ -0,0 +1,4 @@
+---
+apiVersion: v1
+kind: List
+items: []
\ No newline at end of file
diff --git a/kubeval/kubeval_test.go b/kubeval/kubeval_test.go
index d8132d7..b9c9be1 100644
--- a/kubeval/kubeval_test.go
+++ b/kubeval/kubeval_test.go
@@ -34,6 +34,7 @@ func TestValidateValidInputs(t *testing.T) {
 		"extra_property.yaml",
 		"full_domain_group.yaml",
 		"unconventional_keys.yaml",
+		"list_empty_valid.yaml",
 		"list_valid.yaml",
 		"same-object-different-namespace.yaml",
 		"same-object-different-namespace-default.yaml",

@yannh
Copy link

yannh commented Nov 2, 2020

@docwhat This page seems to say that the metadata field is mandatory? https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/#required-fields

@docwhat
Copy link
Author

docwhat commented Nov 6, 2020

Unfortunately, this isn't clearly documented. My thinking is thus:

Based on kubernetes/kubectl#837, kind: List is just union of all the kind: *List types. In 1.19 all the kind: *List docs have metadata as type ObjectMeta. The docs for ObjectMeta says:

ObjectMeta is metadata that all persisted resources must have, which includes all objects users must create.

All the Lists are not persisted; there is no List object stored in the cluster.

@pgold30
Copy link

pgold30 commented Jan 14, 2021

@docwhat hitting this issue now , you know if your fix is going to be merged ?

@docwhat
Copy link
Author

docwhat commented Jan 15, 2021

You'd have to ask the Authors. I'm just a external user like yourself. 😜

carlossg added a commit that referenced this issue Mar 30, 2021
carlossg added a commit that referenced this issue Mar 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants