Skip to content

Commit

Permalink
fixes #15 : Handle missing transform files by creating the resource f…
Browse files Browse the repository at this point in the history
…ile int the output dir during apply (#18)
  • Loading branch information
shawn-hurley authored Jul 14, 2021
1 parent 47a22ee commit 7047000
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions cmd/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7047000

Please sign in to comment.