Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic support for watching Kustomize dependencies #1015

Merged
merged 1 commit into from
Sep 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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