about summary refs log tree commit diff
path: root/main.go
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2017-08-22T17·04+0200
committerVincent Ambo <tazjin@gmail.com>2017-08-22T17·08+0200
commitd22b3694fe5e0fb0ec9d45f6724a7e5dcdbaaad1 (patch)
tree3724da5ea3bc412407df92e4c59ccad3bb512eb9 /main.go
parent825506d2e9e88773c91942b8a39058c7efd61bd1 (diff)
feat main: Warn if resource set contains no templates
If a resource set is specified by the user and does _not_ contain any
templates, a warning will now be printed.

This fixes #79
Diffstat (limited to 'main.go')
-rw-r--r--main.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/main.go b/main.go
index 0d809071ab5e..fe2311599818 100644
--- a/main.go
+++ b/main.go
@@ -83,6 +83,11 @@ func templateCommand() {
 	_, resourceSets := loadContextAndResources(templateFile)
 
 	for _, rs := range *resourceSets {
+		if len(rs.Resources) == 0 {
+			fmt.Fprintf(os.Stderr, "Warning: Resource set '%s' contains no valid templates\n", rs.Name)
+			break
+		}
+
 		for _, r := range rs.Resources {
 			fmt.Fprintf(os.Stderr, "Rendered file %s/%s:\n", rs.Name, r.Filename)
 			fmt.Println(r.Rendered)
@@ -150,7 +155,12 @@ func loadContextAndResources(file *string) (*context.Context, *[]templater.Rende
 func runKubectlWithResources(c *context.Context, kubectlArgs *[]string, resourceSets *[]templater.RenderedResourceSet) error {
 	args := append(*kubectlArgs, fmt.Sprintf("--context=%s", c.Name))
 
-	for _, resourceSet := range *resourceSets {
+	for _, rs := range *resourceSets {
+		if len(rs.Resources) == 0 {
+			fmt.Fprintf(os.Stderr, "Warning: Resource set '%s' contains no valid templates\n", rs.Name)
+			continue
+		}
+
 		kubectl := exec.Command("kubectl", args...)
 
 		stdin, err := kubectl.StdinPipe()
@@ -165,8 +175,8 @@ func runKubectlWithResources(c *context.Context, kubectlArgs *[]string, resource
 			return meep.New(&KubeCtlError{}, meep.Cause(err))
 		}
 
-		for _, r := range resourceSet.Resources {
-			fmt.Printf("Passing file %s/%s to kubectl\n", resourceSet.Name, r.Filename)
+		for _, r := range rs.Resources {
+			fmt.Printf("Passing file %s/%s to kubectl\n", rs.Name, r.Filename)
 			fmt.Fprintln(stdin, r.Rendered)
 		}
 		stdin.Close()