Skip to content

Commit

Permalink
Merge pull request #1488 from dgageot/fix-1035
Browse files Browse the repository at this point in the history
 Support secretGenerators with kustomize
  • Loading branch information
nkubala authored Jan 19, 2019
2 parents 7ec7dc3 + 37b455e commit 4ec6b23
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pkg/skaffold/deploy/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func (k *KubectlDeployer) Labels() map[string]string {
// Deploy templates the provided manifests with a simple `find and replace` and
// runs `kubectl apply` on those manifests
func (k *KubectlDeployer) Deploy(ctx context.Context, out io.Writer, builds []build.Artifact, labellers []Labeller) error {
color.Default.Fprintln(out, "kubectl client version:", k.kubectl.Version())
if err := k.kubectl.CheckVersion(); err != nil {
color.Default.Fprintln(out, "kubectl client version:", k.kubectl.Version(ctx))
if err := k.kubectl.CheckVersion(ctx); err != nil {
color.Default.Fprintln(out, err)
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/skaffold/deploy/kubectl/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func (v ClientVersion) String() string {
}

// CheckVersion warns the user if their kubectl version is < 1.12.0
func (c *CLI) CheckVersion() error {
m, err := strconv.Atoi(c.Version().Minor)
func (c *CLI) CheckVersion(ctx context.Context) error {
m, err := strconv.Atoi(c.Version(ctx).Minor)
if err != nil {
return errors.Wrap(err, "couldn't get kubectl minor version")
}
Expand All @@ -61,7 +61,7 @@ func (c *CLI) CheckVersion() error {
}

// Version returns the client version of kubectl.
func (c *CLI) Version() ClientVersion {
func (c *CLI) Version(ctx context.Context) ClientVersion {
c.versionOnce.Do(func() {
version := Version{
Client: ClientVersion{
Expand All @@ -70,7 +70,7 @@ func (c *CLI) Version() ClientVersion {
},
}

buf, err := c.getVersion(context.Background())
buf, err := c.getVersion(ctx)
if err != nil {
logrus.Warnln("unable to get kubectl client version", err)
} else if err := json.Unmarshal(buf, &version); err != nil {
Expand Down
13 changes: 8 additions & 5 deletions pkg/skaffold/deploy/kubectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import (
"github.com/pkg/errors"
)

const testKubeContext = "kubecontext"
const (
testKubeContext = "kubecontext"
kubectlVersion = `{"clientVersion":{"major":"1","minor":"12"}}`
)

const deploymentWebYAML = `apiVersion: v1
kind: Pod
Expand Down Expand Up @@ -89,7 +92,7 @@ func TestKubectlDeploy(t *testing.T) {
Manifests: []string{"deployment.yaml"},
},
command: testutil.NewFakeCmd(t).
WithRunOut("kubectl version --client -ojson", "1.12").
WithRunOut("kubectl version --client -ojson", kubectlVersion).
WithRun("kubectl --context kubecontext --namespace testNamespace apply --force -f -"),
builds: []build.Artifact{
{
Expand All @@ -105,7 +108,7 @@ func TestKubectlDeploy(t *testing.T) {
Manifests: []string{"deployment.yaml"},
},
command: testutil.NewFakeCmd(t).
WithRunOut("kubectl version --client -ojson", "1.12").
WithRunOut("kubectl version --client -ojson", kubectlVersion).
WithRunErr("kubectl --context kubecontext --namespace testNamespace apply --force -f -", fmt.Errorf("")),
builds: []build.Artifact{
{
Expand All @@ -126,7 +129,7 @@ func TestKubectlDeploy(t *testing.T) {
},
},
command: testutil.NewFakeCmd(t).
WithRunOut("kubectl version --client -ojson", "1.12").
WithRunOut("kubectl version --client -ojson", kubectlVersion).
WithRunErr("kubectl --context kubecontext --namespace testNamespace -v=0 apply --overwrite=true --force -f -", fmt.Errorf("")),
builds: []build.Artifact{
{
Expand Down Expand Up @@ -216,7 +219,7 @@ func TestKubectlCleanup(t *testing.T) {
func TestKubectlRedeploy(t *testing.T) {
defer func(c util.Command) { util.DefaultExecCommand = c }(util.DefaultExecCommand)
util.DefaultExecCommand = testutil.NewFakeCmd(t).
WithRunOut("kubectl version --client -ojson", "1.12").
WithRunOut("kubectl version --client -ojson", kubectlVersion).
WithRunInput("kubectl --context kubecontext --namespace testNamespace apply --force -f -", `apiVersion: v1
kind: Pod
metadata:
Expand Down
12 changes: 10 additions & 2 deletions pkg/skaffold/deploy/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type kustomization struct {
CRDs []string `yaml:"crds"`
PatchesJSON6902 []patchJSON6902 `yaml:"patchesJson6902"`
ConfigMapGenerator []configMapGenerator `yaml:"configMapGenerator"`
SecretGenerator []secretGenerator `yaml:"secretGenerator"`
}

type patchJSON6902 struct {
Expand All @@ -52,6 +53,10 @@ type configMapGenerator struct {
Files []string `yaml:"files"`
}

type secretGenerator struct {
Files []string `yaml:"files"`
}

// KustomizeDeployer deploys workflows using kustomize CLI.
type KustomizeDeployer struct {
*latest.KustomizeDeploy
Expand Down Expand Up @@ -81,8 +86,8 @@ func (k *KustomizeDeployer) Labels() map[string]string {

// Deploy runs `kubectl apply` on the manifest generated by kustomize.
func (k *KustomizeDeployer) Deploy(ctx context.Context, out io.Writer, builds []build.Artifact, labellers []Labeller) error {
color.Default.Fprintln(out, "kubectl client version:", k.kubectl.Version())
if err := k.kubectl.CheckVersion(); err != nil {
color.Default.Fprintln(out, "kubectl client version:", k.kubectl.Version(ctx))
if err := k.kubectl.CheckVersion(ctx); err != nil {
color.Default.Fprintln(out, err)
}

Expand Down Expand Up @@ -159,6 +164,9 @@ func dependenciesForKustomization(dir string) ([]string, error) {
for _, generator := range content.ConfigMapGenerator {
deps = append(deps, joinPaths(dir, generator.Files)...)
}
for _, generator := range content.SecretGenerator {
deps = append(deps, joinPaths(dir, generator.Files)...)
}

return deps, nil
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/skaffold/deploy/kustomize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ func TestDependenciesForKustomization(t *testing.T) {
- files: [app2.properties, app3.properties]`,
expected: []string{"kustomization.yaml", "app1.properties", "app2.properties", "app3.properties"},
},
{
description: "secretGenerator",
yaml: `secretGenerator:
- files: [secret1.file]
- files: [secret2.file, secret3.file]`,
expected: []string{"kustomization.yaml", "secret1.file", "secret2.file", "secret3.file"},
},
{
description: "unknown base",
yaml: `bases: [other]`,
Expand Down

0 comments on commit 4ec6b23

Please sign in to comment.