Skip to content
This repository has been archived by the owner on Jun 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #16 from caos/restructuring
Browse files Browse the repository at this point in the history
fix(kustomize): fixed kustomize step only apply when bool true
  • Loading branch information
stebenz authored Jan 16, 2020
2 parents a3783db + 3807d57 commit 851a98b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
4 changes: 2 additions & 2 deletions cmd/boom/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func main() {
}

if !localMode {
cmd, err := kustomize.New("/crd")
cmd, err := kustomize.New("/crd", true)
if err != nil {
setupLog.Error(err, "unable to locate crd")
os.Exit(1)
Expand Down Expand Up @@ -190,7 +190,7 @@ func main() {

setupLog.Info("starting manager")
} else {
cmd, err := kustomize.New("../../config/crd")
cmd, err := kustomize.New("../../config/crd", true)
if err != nil {
setupLog.Error(err, "unable to locate crd")
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion internal/bundle/application/applications/grafana/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func getKustomizeOutput(folders []string) ([]string, error) {
ret := make([]string, len(folders))
for n, folder := range folders {

cmd, err := kustomize.New(folder)
cmd, err := kustomize.New(folder, false)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func getKustomizeOutput(folders []string) ([]string, error) {
ret := make([]string, len(folders))
for n, folder := range folders {

cmd, err := kustomize.New(folder)
cmd, err := kustomize.New(folder, false)
if err != nil {
return nil, err
}
Expand Down
34 changes: 18 additions & 16 deletions internal/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"github.com/caos/boom/internal/bundle/application"
"github.com/caos/boom/internal/bundle/bundles"
"github.com/caos/boom/internal/bundle/config"
"github.com/caos/boom/internal/helper"
"github.com/caos/boom/internal/kubectl"
"github.com/caos/boom/internal/name"
"github.com/caos/boom/internal/templator"
helperTemp "github.com/caos/boom/internal/templator/helper"
Expand Down Expand Up @@ -126,22 +128,22 @@ func (b *Bundle) ReconcileApplication(appName name.Application, spec *v1beta1.To

b.logger.WithFields(logFields).Info("Reconciling")

// deploy := app.Deploy(spec)
// var command string
// if deploy {
// command = "apply"
// } else if !deploy && app.Changed(spec) && !app.Initial() {
// command = "delete"
// }

// resultFunc := func(resultFilePath, namespace string) error {
// kubectlCmd := kubectl.New(command).AddParameter("-f", resultFilePath).AddParameter("-n", namespace)
// return errors.Wrapf(helper.Run(b.logger, kubectlCmd.Build()), "Failed to apply with file %s", resultFilePath)
// }

// if command == "" {
resultFunc := func(resultFilePath, namespace string) error { return nil }
// }
deploy := app.Deploy(spec)
var command string
if deploy {
command = "apply"
} else if !deploy && app.Changed(spec) && !app.Initial() {
command = "delete"
}

resultFunc := func(resultFilePath, namespace string) error {
kubectlCmd := kubectl.New(command).AddParameter("-f", resultFilePath).AddParameter("-n", namespace)
return errors.Wrapf(helper.Run(b.logger, kubectlCmd.Build()), "Failed to apply with file %s", resultFilePath)
}

if command == "" {
resultFunc = func(resultFilePath, namespace string) error { return nil }
}

b.status = b.Templator.Template(app, spec, resultFunc).GetStatus()
if b.status != nil {
Expand Down
13 changes: 9 additions & 4 deletions internal/kustomize/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,27 @@ import (
)

type Kustomize struct {
path string
path string
apply bool
}

func New(path string) (*Kustomize, error) {
func New(path string, apply bool) (*Kustomize, error) {
abspath, err := filepath.Abs(path)
if err != nil {
return nil, err
}

return &Kustomize{
path: abspath,
path: abspath,
apply: apply,
}, nil
}

func (k *Kustomize) Build() exec.Cmd {
all := strings.Join([]string{"kustomize", "build", k.path, "| kubectl apply -f -"}, " ")
all := strings.Join([]string{"kustomize", "build", k.path}, " ")
if k.apply {
all = strings.Join([]string{all, "| kubectl apply -f -"}, " ")
}
cmd := exec.Command("/bin/sh", "-c", all)
return *cmd
}

0 comments on commit 851a98b

Please sign in to comment.