From 6b478a1136eb90a41343aa167dad2c4538e9eaa2 Mon Sep 17 00:00:00 2001 From: Michael Puncel Date: Thu, 28 Jun 2018 12:27:28 -0400 Subject: [PATCH] Add FromBytesNoValidation() function to manifest package This is useful for use cases where you don't want to error on an invalid manifest, for instance if you're parsing previously deployed manifests that might be invalid according to newly introduced validations --- pkg/manifest/manifest.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/manifest/manifest.go b/pkg/manifest/manifest.go index 8e86f1f8d..6f8c90234 100644 --- a/pkg/manifest/manifest.go +++ b/pkg/manifest/manifest.go @@ -345,6 +345,18 @@ func FromReader(reader io.Reader) (Manifest, error) { // manifest can be a raw YAML document or a PGP clearsigned YAML document. If signed, the // signature components will be stored inside the Manifest instance. func FromBytes(bytes []byte) (Manifest, error) { + manifest, err := FromBytesNoValidation(bytes) + if err != nil { + return nil, err + } + + if err := ValidManifest(manifest); err != nil { + return nil, util.Errorf("invalid manifest: %s", err) + } + return manifest, nil +} + +func FromBytesNoValidation(bytes []byte) (Manifest, error) { manifest := &manifest{} // Preserve the raw manifest so that manifest.Bytes() returns bytes in @@ -371,9 +383,6 @@ func FromBytes(bytes []byte) (Manifest, error) { if err := yaml.Unmarshal(bytes, manifest); err != nil { return nil, util.Errorf("Could not read pod manifest: %s", err) } - if err := ValidManifest(manifest); err != nil { - return nil, util.Errorf("invalid manifest: %s", err) - } return manifest, nil }