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
This commit is contained in:
parent
f3264329b9
commit
162b962fad
1 changed files with 27 additions and 20 deletions
19
main.go
19
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)
|
ctx, err := context.LoadContextFromFile(*file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Fatalf("Error loading context: %v\n", err)
|
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 {
|
if err != nil {
|
||||||
app.Fatalf("Error templating resource sets: %v\n", err)
|
app.Fatalf("Error templating resource sets: %v\n", err)
|
||||||
}
|
}
|
||||||
|
@ -144,9 +144,10 @@ func loadContextAndResources(file *string) (*context.Context, *[]string) {
|
||||||
return ctx, &resources
|
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))
|
args := append(*kubectlArgs, fmt.Sprintf("--context=%s", c.Name))
|
||||||
|
|
||||||
|
for _, resourceSet := range *resourceSets {
|
||||||
kubectl := exec.Command("kubectl", args...)
|
kubectl := exec.Command("kubectl", args...)
|
||||||
|
|
||||||
stdin, err := kubectl.StdinPipe()
|
stdin, err := kubectl.StdinPipe()
|
||||||
|
@ -161,12 +162,18 @@ 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 *resources {
|
for _, r := range resourceSet.Resources {
|
||||||
fmt.Fprintln(stdin, r)
|
fmt.Printf("Passing file %s/%s to kubectl", resourceSet.Name, r.Filename)
|
||||||
|
fmt.Fprintln(stdin, r.Rendered)
|
||||||
}
|
}
|
||||||
stdin.Close()
|
stdin.Close()
|
||||||
|
|
||||||
return kubectl.Wait()
|
if err = kubectl.Wait(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func failWithKubectlError(err error) {
|
func failWithKubectlError(err error) {
|
||||||
|
|
Loading…
Reference in a new issue