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

Commit

Permalink
feat main: Warn if resource set contains no templates
Browse files Browse the repository at this point in the history
If a resource set is specified by the user and does _not_ contain any
templates, a warning will now be printed.

This fixes #79
  • Loading branch information
tazjin committed Aug 22, 2017
1 parent 825506d commit d22b369
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit d22b369

Please sign in to comment.