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

Add option to render manifest from previous build result #3567

Merged
merged 7 commits into from Jun 17, 2020

Conversation

AndiDog
Copy link
Contributor

@AndiDog AndiDog commented Jan 23, 2020

Relates to #1187, #922, #1937

Should merge before : n/a

Should merge after : n/a

Description

Add option to render manifest from previous build result.

This is helpful e.g. in scenarios where build should be run just once, but manifest generation multiple times (for instance, once for dev/staging/prod).

User facing changes

Backwards-compatible: skaffold render first builds, unless the new parameter --build-artifacts is given – then it reads the images from the existing build output file.

Next PRs

Only slightly related: potentially, an option --no-build would make sense to render the manifest as specified in deploy: section, but without building and replacing image tags. That could be used in CI to fail early if the manifest / Helm chart isn't valid – before running the build which could take several minutes and incur network/compute resources.

Hints for reviewer

Didn't see a good place to add tests, since my implementation is at cmd level. Please advise and I'll happily add a test.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes unit tests
  • Mentions any output changes.
  • Adds documentation as needed: user docs, YAML reference, CLI reference.
  • Adds integration tests if needed.

Reviewer Notes

  • The code flow looks good.
  • Unit test added.
  • User facing changes look good.

Release Notes

`skaffold render` now supports a parameter `--build-artifacts` to take image tags from a previous file (as created by `skaffold build --file-output=...`). Without this parameter, the default behavior is to build the images first.

@AndiDog
Copy link
Contributor Author

AndiDog commented Jan 23, 2020

Changed parameter name to -a/--build-artifacts for consistency with skaffold deploy.

@pull-request-size pull-request-size bot added size/S and removed size/M labels Jan 23, 2020
@balopat
Copy link
Contributor

balopat commented Jan 27, 2020

Thanks @AndiDog, can you please run ./hack/generate-man.sh and commit the results?

Copy link
Contributor

@balopat balopat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a nit. I think this looks good but can you think about adding a test somehow to this? If you're stuck with it, I'm happy to help out there.

cmd/skaffold/app/cmd/render.go Outdated Show resolved Hide resolved
@balopat balopat added pr/changes-requested kokoro:run runs the kokoro jobs on a PR labels Jan 27, 2020
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Jan 27, 2020
@AndiDog
Copy link
Contributor Author

AndiDog commented Jan 27, 2020

@balopat do you have a hint where a test could be placed? My implementation is at cmd level, so integration/render_test.go doesn't really fit since the builds: []build.Artifact{ ... } is already filled there, instead of taken from a file. Ideally, there would be a test that runs the skaffold executable directly instead of running a Go test function. I could add a test for flags.BuildOutputFileFlag :: func BuildArtifacts which is what the command implementation uses?!

@balopat
Copy link
Contributor

balopat commented Jan 27, 2020

@balopat do you have a hint where a test could be placed? My implementation is at cmd level, so integration/render_test.go doesn't really fit since the builds: []build.Artifact{ ... } is already filled there, instead of taken from a file. Ideally, there would be a test that runs the skaffold executable directly instead of running a Go test function. I could add a test for flags.BuildOutputFileFlag :: func BuildArtifacts which is what the command implementation uses?!

I think adding an integration test is a good incremental step. You can create a new function TestKubectlRenderFromBuildOutput in integration/render_test.go that is similar to TestKubectlRender, just takes a build output file as well as an input.

@balopat balopat assigned tejal29 and balopat and unassigned tejal29 Jan 27, 2020
@AndiDog
Copy link
Contributor Author

AndiDog commented Jan 28, 2020

I modified the command code to make it testable – please have a look. This also makes testing other deployers much easier because the test works almost exactly like running skaffold render directly.

Plus new commit "Ignore local executables for integration test (architecture/OS might mismatch)". Makes the kind-based integration test work on macOS for me.

Please have a look if this way of testing looks good.

@balopat balopat added the kokoro:run runs the kokoro jobs on a PR label Jan 29, 2020
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Jan 29, 2020
Makefile Outdated Show resolved Hide resolved
@balopat
Copy link
Contributor

balopat commented Jan 29, 2020

I modified the command code to make it testable – please have a look. This also makes testing other deployers much easier because the test works almost exactly like running skaffold render directly.

Thanks for doing this work! The test logic itself looks good.
However - I don't see the benefit yet in the refactoring part: integration tests are supposed to call the built skaffold binary with flags. The three things you pass in here and the buildoutput flag should all be available as flags to the skaffold command.

@balopat
Copy link
Contributor

balopat commented Jan 29, 2020

Plus new commit "Ignore local executables for integration test (architecture/OS might mismatch)". Makes the kind-based integration test work on macOS for me.

Thanks - this is cool. I don't know when I ran kind integration tests on my mac the last time :) probably that's why you ran into this!

@balopat
Copy link
Contributor

balopat commented Jan 29, 2020

We have another motivation to remove the BUILDKIT env var, our kokoro test is failing due to this here:

++ gcloud auth configure-docker -q
Docker configuration file updated.
++ '[' -e /tmpfs/src/gfile/bazel-cache-gcs ']'
+ pushd /tmpfs/src/github/skaffold
+ GCP_ONLY=true
+ make integration-in-docker
DOCKER_BUILDKIT=1 time docker build \
		-f deploy/skaffold/Dockerfile \
		-t gcr.io/k8s-skaffold/skaffold-builder \
		.
buildkit not supported by daemon
Command exited with non-zero status 1

@AndiDog
Copy link
Contributor Author

AndiDog commented Feb 11, 2020

Working on the changes.

I noted that skaffold render connects to the Kubernetes cluster in the renderManifests function. That shouldn't be the case, or it's totally unusable for CI use cases. skaffold render should only render, i.e. do text replacement in an existing manifest, nothing else. That should be offline. Have to fix that as well before I can push the changes for your review.

@AndiDog AndiDog force-pushed the render-from-build-output branch 2 times, most recently from 233d370 to fec732b Compare May 23, 2020 21:36
Copy link
Contributor

@nkubala nkubala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndiDog a few small nits but this is basically ready in my eyes. there are definitely a few more things to review than we'd like in this PR but in interest of not blocking you I think it's ok to let them in together.

cmd/skaffold/app/cmd/render.go Outdated Show resolved Hide resolved
cmd/skaffold/app/cmd/render.go Outdated Show resolved Hide resolved
cmd/skaffold/app/cmd/render.go Outdated Show resolved Hide resolved
@nkubala
Copy link
Contributor

nkubala commented Jun 16, 2020

@AndiDog rename those two vars and rebase to get CI green and I'll merge this!

@AndiDog
Copy link
Contributor Author

AndiDog commented Jun 16, 2020

@nkubala ready!

@tejal29 tejal29 added kokoro:run runs the kokoro jobs on a PR and removed pr/changes-requested labels Jun 17, 2020
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Jun 17, 2020
@tejal29 tejal29 dismissed stale reviews from nkubala, balopat, and tstromberg June 17, 2020 22:24

addressed comments.

@tejal29 tejal29 merged commit fddc954 into GoogleContainerTools:master Jun 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants