Don't output empty sections in the manifests

In our kube-dns manifest for 1.6 we often had an empty section,
normalization converted this to `{}` which causes `kubectl apply` to
fail.

We can simply skip empty objects when outputing.
This commit is contained in:
Justin SB 2020-01-11 18:18:15 -05:00
parent adc4083caa
commit f348b47332
No known key found for this signature in database
GPG Key ID: 8DEC5C8217494E37
2 changed files with 10 additions and 0 deletions

View File

@ -111,6 +111,11 @@ func (a *AssetBuilder) RemapManifest(data []byte) ([]byte, error) {
return nil, fmt.Errorf("error remapping images: %v", err)
}
// Don't serialize empty objects - they confuse yaml parsers
if manifest.IsEmptyObject() {
continue
}
y, err := manifest.ToYAML()
if err != nil {
return nil, fmt.Errorf("error re-marshaling manifest: %v", err)

View File

@ -65,3 +65,8 @@ func (m *Manifest) accept(visitor Visitor) error {
})
return err
}
// IsEmptyObject checks if the object has no keys set (i.e. `== {}`)
func (m *Manifest) IsEmptyObject() bool {
return len(m.data) == 0
}