Skip to content

Commit

Permalink
fix: Don't write yamls to disk in buildKustomize
Browse files Browse the repository at this point in the history
And also avoid loading this yaml back into memory. We can simply use the
in-memory result of the kustomize run.
  • Loading branch information
codablock committed May 30, 2022
1 parent aa47679 commit 7270131
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 35 deletions.
9 changes: 2 additions & 7 deletions pkg/deployment/deployment_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,9 @@ func (c *DeploymentCollection) buildKustomizeObjects() error {

wg.Add(1)
go func() {
err := d.loadObjects()
err := d.postprocessCRDs()
if err != nil {
handleError(fmt.Errorf("loading objects failed: %w", err))
} else {
err = d.postprocessCRDs()
if err != nil {
handleError(fmt.Errorf("postprocessing CRDs failed: %w", err))
}
handleError(fmt.Errorf("postprocessing CRDs failed: %w", err))
}
wg.Done()
}()
Expand Down
31 changes: 3 additions & 28 deletions pkg/deployment/deployment_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,41 +416,16 @@ func (di *DeploymentItem) buildKustomize() error {
return err
}

var yamls []interface{}
di.Objects = nil
for _, r := range rm.Resources() {
y, err := r.Map()
if err != nil {
return err
}
yamls = append(yamls, y)
o := uo.FromMap(y)
di.Objects = append(di.Objects, o)
}

err = yaml.WriteYamlAllFile(di.renderedYamlPath, yamls)
if err != nil {
return err
}

return nil
}

func (di *DeploymentItem) loadObjects() error {
if di.dir == nil {
return nil
}

objects, err := yaml.ReadYamlAllFile(di.renderedYamlPath)
if err != nil {
return err
}

di.Objects = []*uo.UnstructuredObject{}
for _, o := range objects {
m, ok := o.(map[string]interface{})
if !ok {
return fmt.Errorf("object is not a map")
}
di.Objects = append(di.Objects, uo.FromMap(m))
}
return nil
}

Expand Down

0 comments on commit 7270131

Please sign in to comment.