From 62cbeac9b8072b4ac0b3e50f4379859ba1e58c8e Mon Sep 17 00:00:00 2001 From: daddz Date: Thu, 12 Sep 2019 19:41:05 +0200 Subject: [PATCH 1/5] add buildArgs to config --- docs/content/en/schemas/v1beta14.json | 12 +++++++++++- integration/examples/kustomize/README.adoc | 14 ++++++++++++++ .../kustomize/skaffold-kustomize-args.yaml | 6 ++++++ pkg/skaffold/deploy/kustomize.go | 1 + pkg/skaffold/schema/latest/config.go | 3 +++ 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 integration/examples/kustomize/skaffold-kustomize-args.yaml diff --git a/docs/content/en/schemas/v1beta14.json b/docs/content/en/schemas/v1beta14.json index b67cc7d7943..9f88d573570 100755 --- a/docs/content/en/schemas/v1beta14.json +++ b/docs/content/en/schemas/v1beta14.json @@ -1417,6 +1417,15 @@ }, "KustomizeDeploy": { "properties": { + "buildArgs": { + "items": { + "type": "string" + }, + "type": "array", + "description": "additional args passed to `kustomize build`.", + "x-intellij-html-description": "additional args passed to kustomize build.", + "default": "[]" + }, "flags": { "$ref": "#/definitions/KubectlFlags", "description": "additional flags passed to `kubectl`.", @@ -1431,7 +1440,8 @@ }, "preferredOrder": [ "path", - "flags" + "flags", + "buildArgs" ], "additionalProperties": false, "description": "*beta* uses the `kustomize` CLI to \"patch\" a deployment for a target environment.", diff --git a/integration/examples/kustomize/README.adoc b/integration/examples/kustomize/README.adoc index 8db1e0fb390..34d7ee8a3f5 100644 --- a/integration/examples/kustomize/README.adoc +++ b/integration/examples/kustomize/README.adoc @@ -28,3 +28,17 @@ include::deployment.yaml[] ---- endif::[] + +=== Example: passing arguments to kustomize +:icons: font + +This is an example demonstrating how additional arguments can be passed to kustomize + +ifndef::env-github[] + +[source,yaml, indent=3, title=skaffold-kustomize-args.yaml] +---- +include::skaffold-kustomize-args.yaml[] +---- + +endif::[] diff --git a/integration/examples/kustomize/skaffold-kustomize-args.yaml b/integration/examples/kustomize/skaffold-kustomize-args.yaml new file mode 100644 index 00000000000..dad5497a0eb --- /dev/null +++ b/integration/examples/kustomize/skaffold-kustomize-args.yaml @@ -0,0 +1,6 @@ +apiVersion: skaffold/v1beta14 +kind: Config +deploy: + kustomize: + buildArgs: + - "--load_restrictor none" diff --git a/pkg/skaffold/deploy/kustomize.go b/pkg/skaffold/deploy/kustomize.go index 494b520cff4..fb974b8b3bc 100644 --- a/pkg/skaffold/deploy/kustomize.go +++ b/pkg/skaffold/deploy/kustomize.go @@ -85,6 +85,7 @@ func NewKustomizeDeployer(runCtx *runcontext.RunContext) *KustomizeDeployer { }, defaultRepo: runCtx.DefaultRepo, insecureRegistries: runCtx.InsecureRegistries, + BuildArgs: runCtx.Cfg.Deploy.KustomizeDeploy.BuildArgs, } } diff --git a/pkg/skaffold/schema/latest/config.go b/pkg/skaffold/schema/latest/config.go index b127c4943b2..79a0a6f3741 100644 --- a/pkg/skaffold/schema/latest/config.go +++ b/pkg/skaffold/schema/latest/config.go @@ -427,6 +427,9 @@ type KustomizeDeploy struct { // Flags are additional flags passed to `kubectl`. Flags KubectlFlags `yaml:"flags,omitempty"` + + // BuildArgs are additional args passed to `kustomize build`. + BuildArgs []string `yaml:"buildArgs,omitempty"` } // HelmRelease describes a helm release to be deployed. From b2641e9676afdfa57e9a0a106ae2d3a29851e010 Mon Sep 17 00:00:00 2001 From: Dominic Werner Date: Thu, 12 Sep 2019 19:44:42 +0200 Subject: [PATCH 2/5] Update README.adoc --- integration/examples/kustomize/README.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/examples/kustomize/README.adoc b/integration/examples/kustomize/README.adoc index 34d7ee8a3f5..8da32c884af 100644 --- a/integration/examples/kustomize/README.adoc +++ b/integration/examples/kustomize/README.adoc @@ -32,7 +32,7 @@ endif::[] === Example: passing arguments to kustomize :icons: font -This is an example demonstrating how additional arguments can be passed to kustomize +This is an example demonstrating how additional arguments can be passed to the `kustomize build` command. ifndef::env-github[] From 0515170d1d8a7e71539350bd5558241c06a54968 Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Mon, 16 Sep 2019 13:23:54 -0700 Subject: [PATCH 3/5] regenerate schema --- docs/content/en/schemas/v1beta14.json | 12 +----------- docs/content/en/schemas/v1beta15.json | 12 +++++++++++- pkg/skaffold/schema/v1beta14/upgrade.go | 1 + 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/content/en/schemas/v1beta14.json b/docs/content/en/schemas/v1beta14.json index 9f88d573570..b67cc7d7943 100755 --- a/docs/content/en/schemas/v1beta14.json +++ b/docs/content/en/schemas/v1beta14.json @@ -1417,15 +1417,6 @@ }, "KustomizeDeploy": { "properties": { - "buildArgs": { - "items": { - "type": "string" - }, - "type": "array", - "description": "additional args passed to `kustomize build`.", - "x-intellij-html-description": "additional args passed to kustomize build.", - "default": "[]" - }, "flags": { "$ref": "#/definitions/KubectlFlags", "description": "additional flags passed to `kubectl`.", @@ -1440,8 +1431,7 @@ }, "preferredOrder": [ "path", - "flags", - "buildArgs" + "flags" ], "additionalProperties": false, "description": "*beta* uses the `kustomize` CLI to \"patch\" a deployment for a target environment.", diff --git a/docs/content/en/schemas/v1beta15.json b/docs/content/en/schemas/v1beta15.json index b67cc7d7943..9f88d573570 100755 --- a/docs/content/en/schemas/v1beta15.json +++ b/docs/content/en/schemas/v1beta15.json @@ -1417,6 +1417,15 @@ }, "KustomizeDeploy": { "properties": { + "buildArgs": { + "items": { + "type": "string" + }, + "type": "array", + "description": "additional args passed to `kustomize build`.", + "x-intellij-html-description": "additional args passed to kustomize build.", + "default": "[]" + }, "flags": { "$ref": "#/definitions/KubectlFlags", "description": "additional flags passed to `kubectl`.", @@ -1431,7 +1440,8 @@ }, "preferredOrder": [ "path", - "flags" + "flags", + "buildArgs" ], "additionalProperties": false, "description": "*beta* uses the `kustomize` CLI to \"patch\" a deployment for a target environment.", diff --git a/pkg/skaffold/schema/v1beta14/upgrade.go b/pkg/skaffold/schema/v1beta14/upgrade.go index 2f8e24d1741..67aa8867627 100755 --- a/pkg/skaffold/schema/v1beta14/upgrade.go +++ b/pkg/skaffold/schema/v1beta14/upgrade.go @@ -25,6 +25,7 @@ import ( // Upgrade upgrades a configuration to the next version. // Config changes from v1beta14 to v1beta15 // 1. Additions: +// buildArgs for Kustomize deployer // 2. Removals: // 3. No updates func (config *SkaffoldConfig) Upgrade() (util.VersionedConfig, error) { From d6569338df293a0694fa3739fcf45de72fbfeb66 Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Mon, 16 Sep 2019 13:47:04 -0700 Subject: [PATCH 4/5] Small refactors 1. Refactor signature 2. Move `Deployment.WithStatus` to `withStatus` since it was used for testing. --- pkg/skaffold/deploy/resource/deployment.go | 6 -- pkg/skaffold/deploy/status_check.go | 4 +- pkg/skaffold/deploy/status_check_test.go | 72 ++++++++++++++++------ 3 files changed, 54 insertions(+), 28 deletions(-) diff --git a/pkg/skaffold/deploy/resource/deployment.go b/pkg/skaffold/deploy/resource/deployment.go index a393ad73687..b6b854d064a 100644 --- a/pkg/skaffold/deploy/resource/deployment.go +++ b/pkg/skaffold/deploy/resource/deployment.go @@ -82,9 +82,3 @@ func NewDeployment(name string, ns string, deadline time.Duration) *Deployment { status: newStatus("", nil), } } - -// For testing -func (d *Deployment) WithStatus(details string, err error) *Deployment { - d.UpdateStatus(details, err) - return d -} diff --git a/pkg/skaffold/deploy/status_check.go b/pkg/skaffold/deploy/status_check.go index b1cd4664807..fb16cd826d9 100644 --- a/pkg/skaffold/deploy/status_check.go +++ b/pkg/skaffold/deploy/status_check.go @@ -81,7 +81,7 @@ func StatusCheck(ctx context.Context, defaultLabeller *DefaultLabeller, runCtx * defer wg.Done() pollDeploymentRolloutStatus(ctx, kubectl.NewFromRunContext(runCtx), d) pending := c.markProcessed() - printStatusCheckSummary(d, pending, c.total, out) + printStatusCheckSummary(out, d, pending, c.total) }(d) } @@ -166,7 +166,7 @@ func getDeadline(d int) time.Duration { return defaultStatusCheckDeadline } -func printStatusCheckSummary(d *resource.Deployment, pending int, total int, out io.Writer) { +func printStatusCheckSummary(out io.Writer, d *resource.Deployment, pending int, total int) { status := fmt.Sprintf("%s %s", tabHeader, d) if err := d.Status().Error(); err != nil { status = fmt.Sprintf("%s failed.%s Error: %s.", diff --git a/pkg/skaffold/deploy/status_check_test.go b/pkg/skaffold/deploy/status_check_test.go index b69db95b8a8..04592269fd9 100644 --- a/pkg/skaffold/deploy/status_check_test.go +++ b/pkg/skaffold/deploy/status_check_test.go @@ -258,10 +258,16 @@ func TestGetDeployStatus(t *testing.T) { { description: "one error", deps: []*resource.Deployment{ - resource.NewDeployment("dep1", "test", time.Second). - WithStatus("success", nil), - resource.NewDeployment("dep2", "test", time.Second). - WithStatus("error", errors.New("could not return within default timeout")), + withStatus( + resource.NewDeployment("dep1", "test", time.Second), + "success", + nil, + ), + withStatus( + resource.NewDeployment("dep2", "test", time.Second), + "error", + errors.New("could not return within default timeout"), + ), }, expectedErrMsg: []string{"dep2 failed due to could not return within default timeout"}, shouldErr: true, @@ -269,21 +275,35 @@ func TestGetDeployStatus(t *testing.T) { { description: "no error", deps: []*resource.Deployment{ - resource.NewDeployment("dep1", "test", time.Second). - WithStatus("success", nil), - resource.NewDeployment("dep2", "test", time.Second). - WithStatus("running", nil), + withStatus( + resource.NewDeployment("dep1", "test", time.Second), + "success", + nil, + ), + withStatus(resource.NewDeployment("dep2", "test", time.Second), + "running", + nil, + ), }, }, { description: "multiple errors", deps: []*resource.Deployment{ - resource.NewDeployment("dep1", "test", time.Second). - WithStatus("success", nil), - resource.NewDeployment("dep2", "test", time.Second). - WithStatus("error", errors.New("could not return within default timeout")), - resource.NewDeployment("dep3", "test", time.Second). - WithStatus("error", errors.New("ERROR")), + withStatus( + resource.NewDeployment("dep1", "test", time.Second), + "success", + nil, + ), + withStatus( + resource.NewDeployment("dep2", "test", time.Second), + "error", + errors.New("could not return within default timeout"), + ), + withStatus( + resource.NewDeployment("dep3", "test", time.Second), + "error", + errors.New("ERROR"), + ), }, expectedErrMsg: []string{"dep2 failed due to could not return within default timeout", "dep3 failed due to ERROR"}, @@ -385,10 +405,11 @@ func TestPrintSummaryStatus(t *testing.T) { testutil.Run(t, test.description, func(t *testutil.T) { out := new(bytes.Buffer) printStatusCheckSummary( - resource.NewDeployment("dep", "test", 0).WithStatus("", test.err), + out, + withStatus(resource.NewDeployment("dep", "test", 0), "", test.err), int(test.pending), 10, - out) + ) t.CheckDeepEqual(test.expected, out.String()) }) } @@ -431,8 +452,11 @@ func TestPrintStatus(t *testing.T) { "succes", nil, ), - resource.NewDeployment("r2", "test", 1). - WithStatus("pending", nil), + withStatus( + resource.NewDeployment("r2", "test", 1), + "pending", + nil, + ), }, expectedOut: " - test:deployment/r2 pending\n", }, @@ -444,8 +468,11 @@ func TestPrintStatus(t *testing.T) { "succes", nil, ), - resource.NewDeployment("r2", "test", 1). - WithStatus("", fmt.Errorf("context deadline expired")), + withStatus( + resource.NewDeployment("r2", "test", 1), + "", + fmt.Errorf("context deadline expired"), + ), }, expectedOut: " - test:deployment/r2 context deadline expired\n", }, @@ -466,3 +493,8 @@ func withDone(d *resource.Deployment, details string, err error) *resource.Deplo d.MarkDone() return d } + +func withStatus(d *resource.Deployment, details string, err error) *resource.Deployment { + d.UpdateStatus(details, err) + return d +} From 2d7e0408ec1ea399115016d7168bb7f57dcb53f7 Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Mon, 16 Sep 2019 15:14:47 -0700 Subject: [PATCH 5/5] test commit --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 2731f933f01..662131db82b 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + GOOS ?= $(shell go env GOOS) GOARCH = amd64 BUILD_DIR ?= ./out