From 7047000f9aa7a47fe618bca86e7129977d290703 Mon Sep 17 00:00:00 2001 From: Shawn Hurley Date: Wed, 14 Jul 2021 15:31:14 -0400 Subject: [PATCH] fixes #15 : Handle missing transform files by creating the resource file int the output dir during apply (#18) --- cmd/apply/apply.go | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/cmd/apply/apply.go b/cmd/apply/apply.go index 0358ccb..f269d86 100644 --- a/cmd/apply/apply.go +++ b/cmd/apply/apply.go @@ -108,24 +108,32 @@ func (o *Options) run() error { continue } + // Set doc to the object, only update the file if the transfrom file exists + doc, err := f.Unstructured.MarshalJSON() + if err != nil { + return err + } + tfPath := opts.GetTransformPath(f.Path) // Check if transform file exists // If the transform does not exist, assume that the resource file is // not needed and ignore for now. _, tfStatErr := os.Stat(tfPath) - if errors.Is(tfStatErr, os.ErrNotExist) { - o.logger.Infof("resource file: %v is skipped due to no transform file: %v", f.Info.Name(), tfPath) - continue - } - - transformfile, err := os.ReadFile(tfPath) - if err != nil { + if err != nil && !errors.Is(tfStatErr, os.ErrNotExist) { + // Some other error here err out return err } - doc, err := a.Apply(f.Unstructured, transformfile) - if err != nil { - return err + if !errors.Is(tfStatErr, os.ErrNotExist) { + transformfile, err := os.ReadFile(tfPath) + if err != nil { + return err + } + + doc, err = a.Apply(f.Unstructured, transformfile) + if err != nil { + return err + } } y, err := yaml.JSONToYAML(doc)