diff --git a/pkg/skaffold/deploy/kubectl.go b/pkg/skaffold/deploy/kubectl.go index 461365f1149..83452a1f2f5 100644 --- a/pkg/skaffold/deploy/kubectl.go +++ b/pkg/skaffold/deploy/kubectl.go @@ -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) } diff --git a/pkg/skaffold/deploy/kubectl/version.go b/pkg/skaffold/deploy/kubectl/version.go index 3a2f73814b4..ef85a2b5efe 100644 --- a/pkg/skaffold/deploy/kubectl/version.go +++ b/pkg/skaffold/deploy/kubectl/version.go @@ -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") } @@ -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{ @@ -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 { diff --git a/pkg/skaffold/deploy/kubectl_test.go b/pkg/skaffold/deploy/kubectl_test.go index e5995eaf4e7..2fb6c2bfb66 100644 --- a/pkg/skaffold/deploy/kubectl_test.go +++ b/pkg/skaffold/deploy/kubectl_test.go @@ -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 @@ -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{ { @@ -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{ { @@ -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{ { @@ -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: diff --git a/pkg/skaffold/deploy/kustomize.go b/pkg/skaffold/deploy/kustomize.go index 19f1765b24d..47d89e29deb 100644 --- a/pkg/skaffold/deploy/kustomize.go +++ b/pkg/skaffold/deploy/kustomize.go @@ -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 { @@ -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 @@ -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) } @@ -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 } diff --git a/pkg/skaffold/deploy/kustomize_test.go b/pkg/skaffold/deploy/kustomize_test.go index ef5708f79c2..021d87945c8 100644 --- a/pkg/skaffold/deploy/kustomize_test.go +++ b/pkg/skaffold/deploy/kustomize_test.go @@ -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]`,