Skip to content
This repository has been archived by the owner on Dec 21, 2019. It is now read-only.

Commit

Permalink
refactor main: Call kubectl individually per resource set
Browse files Browse the repository at this point in the history
Instead of passing the rendered output of all resource sets to kubectl
simultaneously, build upon the previous commit and pass resource sets
individually to new instances of kubectl.

This resolves #51
  • Loading branch information
tazjin committed Jun 11, 2017
1 parent f326432 commit 162b962
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,43 +130,50 @@ func createCommand() {
}
}

func loadContextAndResources(file *string) (*context.Context, *[]string) {
func loadContextAndResources(file *string) (*context.Context, *[]templater.RenderedResourceSet) {
ctx, err := context.LoadContextFromFile(*file)
if err != nil {
app.Fatalf("Error loading context: %v\n", err)
}

resources, err := templater.LoadAndPrepareTemplates(includes, excludes, ctx)
resources, err := templater.LoadAndApplyTemplates(includes, excludes, ctx)
if err != nil {
app.Fatalf("Error templating resource sets: %v\n", err)
}

return ctx, &resources
}

func runKubectlWithResources(c *context.Context, kubectlArgs *[]string, resources *[]string) error {
func runKubectlWithResources(c *context.Context, kubectlArgs *[]string, resourceSets *[]templater.RenderedResourceSet) error {
args := append(*kubectlArgs, fmt.Sprintf("--context=%s", c.Name))

kubectl := exec.Command("kubectl", args...)
for _, resourceSet := range *resourceSets {
kubectl := exec.Command("kubectl", args...)

stdin, err := kubectl.StdinPipe()
if err != nil {
return meep.New(&KubeCtlError{}, meep.Cause(err))
}
stdin, err := kubectl.StdinPipe()
if err != nil {
return meep.New(&KubeCtlError{}, meep.Cause(err))
}

kubectl.Stdout = os.Stdout
kubectl.Stderr = os.Stderr
kubectl.Stdout = os.Stdout
kubectl.Stderr = os.Stderr

if err = kubectl.Start(); err != nil {
return meep.New(&KubeCtlError{}, meep.Cause(err))
}
if err = kubectl.Start(); err != nil {
return meep.New(&KubeCtlError{}, meep.Cause(err))
}

for _, r := range *resources {
fmt.Fprintln(stdin, r)
for _, r := range resourceSet.Resources {
fmt.Printf("Passing file %s/%s to kubectl", resourceSet.Name, r.Filename)
fmt.Fprintln(stdin, r.Rendered)
}
stdin.Close()

if err = kubectl.Wait(); err != nil {
return err
}
}
stdin.Close()

return kubectl.Wait()
return nil
}

func failWithKubectlError(err error) {
Expand Down

0 comments on commit 162b962

Please sign in to comment.