about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2017-06-11T19·34+0200
committerVincent Ambo <tazjin@gmail.com>2017-06-11T20·09+0200
commit162b962fad4e9d4f99b865aa4d22e7c3581756e8 (patch)
tree03e27506ad396af6cdf78b7325e77a61419def01
parentf3264329b92c93177e771e3786a91e0b9c68dec5 (diff)
refactor main: Call kubectl individually per resource set
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
-rw-r--r--main.go41
1 files changed, 24 insertions, 17 deletions
diff --git a/main.go b/main.go
index 033f2b5ca893..57dd62068b0b 100644
--- a/main.go
+++ b/main.go
@@ -130,13 +130,13 @@ 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)
 	}
@@ -144,29 +144,36 @@ func loadContextAndResources(file *string) (*context.Context, *[]string) {
 	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) {