Skip to content

Commit

Permalink
Merge pull request #1015 from tesserai/kustomize-deploy-deps
Browse files Browse the repository at this point in the history
Basic support for watching Kustomize dependencies
  • Loading branch information
dgageot authored Sep 23, 2018
2 parents f9cab4d + fd31ddc commit 1ba8da2
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions pkg/skaffold/deploy/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ package deploy
import (
"context"
"io"
"os"
"os/exec"
"path/filepath"

yaml "gopkg.in/yaml.v2"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
Expand Down Expand Up @@ -88,9 +92,47 @@ func (k *KustomizeDeployer) Cleanup(ctx context.Context, out io.Writer) error {
return nil
}

func dependenciesForKustomization(dir string) ([]string, error) {
path := filepath.Join(dir, "kustomization.yaml")
deps := []string{path}

file, err := os.Open(path)
if err != nil {
return deps, err
}
defer file.Close()

contents := struct {
Bases []string `yaml:"bases"`
Resources []string `yaml:"resources"`
Patches []string `yaml:"patches"`
}{}
decoder := yaml.NewDecoder(file)
err = decoder.Decode(&contents)
if err != nil {
return deps, err
}

for _, base := range contents.Bases {
baseDeps, err := dependenciesForKustomization(filepath.Join(dir, base))
deps = append(deps, baseDeps...)
if err != nil {
return deps, err
}
}

for _, resource := range contents.Resources {
deps = append(deps, filepath.Join(dir, resource))
}

for _, patch := range contents.Patches {
deps = append(deps, filepath.Join(dir, patch))
}

return deps, nil
}
func (k *KustomizeDeployer) Dependencies() ([]string, error) {
// TODO(r2d4): parse kustomization yaml and add base and patches as dependencies
return []string{k.KustomizePath}, nil
return dependenciesForKustomization(k.KustomizePath)
}

func (k *KustomizeDeployer) readManifests(ctx context.Context) (kubectl.ManifestList, error) {
Expand Down

0 comments on commit 1ba8da2

Please sign in to comment.