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
This commit is contained in:
parent
825506d2e9
commit
d22b3694fe
1 changed files with 13 additions and 3 deletions
16
main.go
16
main.go
|
@ -83,6 +83,11 @@ func templateCommand() {
|
||||||
_, resourceSets := loadContextAndResources(templateFile)
|
_, resourceSets := loadContextAndResources(templateFile)
|
||||||
|
|
||||||
for _, rs := 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)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
for _, r := range rs.Resources {
|
for _, r := range rs.Resources {
|
||||||
fmt.Fprintf(os.Stderr, "Rendered file %s/%s:\n", rs.Name, r.Filename)
|
fmt.Fprintf(os.Stderr, "Rendered file %s/%s:\n", rs.Name, r.Filename)
|
||||||
fmt.Println(r.Rendered)
|
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 {
|
func runKubectlWithResources(c *context.Context, kubectlArgs *[]string, resourceSets *[]templater.RenderedResourceSet) error {
|
||||||
args := append(*kubectlArgs, fmt.Sprintf("--context=%s", c.Name))
|
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...)
|
kubectl := exec.Command("kubectl", args...)
|
||||||
|
|
||||||
stdin, err := kubectl.StdinPipe()
|
stdin, err := kubectl.StdinPipe()
|
||||||
|
@ -165,8 +175,8 @@ func runKubectlWithResources(c *context.Context, kubectlArgs *[]string, resource
|
||||||
return meep.New(&KubeCtlError{}, meep.Cause(err))
|
return meep.New(&KubeCtlError{}, meep.Cause(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, r := range resourceSet.Resources {
|
for _, r := range rs.Resources {
|
||||||
fmt.Printf("Passing file %s/%s to kubectl\n", resourceSet.Name, r.Filename)
|
fmt.Printf("Passing file %s/%s to kubectl\n", rs.Name, r.Filename)
|
||||||
fmt.Fprintln(stdin, r.Rendered)
|
fmt.Fprintln(stdin, r.Rendered)
|
||||||
}
|
}
|
||||||
stdin.Close()
|
stdin.Close()
|
||||||
|
|
Loading…
Add table
Reference in a new issue