From 694999b9ef483aff8d34c32e1ccdd05e5e722821 Mon Sep 17 00:00:00 2001 From: Dmitriy Ivolgin Date: Wed, 22 May 2024 10:39:34 -0700 Subject: [PATCH] Allow ignoring errors when loading kotskinds (#4634) --- pkg/kotsutil/kots.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/kotsutil/kots.go b/pkg/kotsutil/kots.go index c7413f60d1..50ebe68cef 100644 --- a/pkg/kotsutil/kots.go +++ b/pkg/kotsutil/kots.go @@ -666,6 +666,16 @@ func GetKotsKindsPath(archive string) string { // it loads the rendered kots kinds if they exist (should always be the case for app version archives created by newer kots versions). // otherwise it loads the non-rendered kots kinds (app version archives created by older kots versions). func LoadKotsKinds(archive string) (*KotsKinds, error) { + return LoadKotsKindsWithOpts(archive, LoadKotsKindsOptions{Strict: true}) +} + +// When strict is true, it returns an error if it fails to load any kotskinds file. +// When strict is false, kotskinds with errors will be ignored if they cannot be parsed. +type LoadKotsKindsOptions struct { + Strict bool +} + +func LoadKotsKindsWithOpts(archive string, opts LoadKotsKindsOptions) (*KotsKinds, error) { kotsKinds := EmptyKotsKinds() fromDir := GetKotsKindsPath(archive) @@ -703,7 +713,9 @@ func LoadKotsKinds(archive string) (*KotsKinds, error) { } if err := kotsKinds.addKotsKinds(contents); err != nil { - return errors.Wrapf(err, "failed to add kots kinds from %s", path) + if opts.Strict { + return errors.Wrapf(err, "failed to add kots kinds from %s", path) + } } return nil