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

Skaffold render solely perform the manifests hydration #4193

Merged
merged 21 commits into from
Jun 11, 2020
Merged

Skaffold render solely perform the manifests hydration #4193

merged 21 commits into from
Jun 11, 2020

Conversation

ChrisGe4
Copy link
Contributor

Description
Proposal: go/skaffold-render-hydration-only

Currently skaffold render performs all image builds then outputs hydrated Kubernetes manifests. This PR modifies skaffold render to solely perform the hydration of Kubernetes manifests with the option to build artifacts.

In this PR, a new option --skip-build will be added to the render command. skaffold render --skip-build only hydrated the kubernetes manifests without building the image.

@codecov
Copy link

codecov bot commented May 15, 2020

Codecov Report

Merging #4193 into master will decrease coverage by 0.76%.
The diff coverage is 57.57%.

Impacted Files Coverage Δ
pkg/skaffold/config/options.go 100.00% <ø> (ø)
pkg/skaffold/runner/render.go 0.00% <0.00%> (ø)
pkg/skaffold/runner/runner.go 0.00% <ø> (ø)
pkg/skaffold/deploy/util.go 63.88% <50.00%> (-1.74%) ⬇️
pkg/skaffold/deploy/kubectl.go 67.64% <81.81%> (+1.24%) ⬆️
cmd/skaffold/app/cmd/render.go 47.61% <100.00%> (+5.51%) ⬆️
pkg/skaffold/runner/build_deploy.go 71.91% <100.00%> (+3.09%) ⬆️
pkg/skaffold/deploy/resource/deployment.go 76.84% <0.00%> (-16.15%) ⬇️
pkg/skaffold/deploy/resource/status.go 90.00% <0.00%> (-10.00%) ⬇️
pkg/skaffold/server/server.go 48.88% <0.00%> (-4.77%) ⬇️
... and 19 more

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 my comments - I don't think we should infer the image tags and assume that that's what the user wants.

@balopat balopat self-assigned this May 18, 2020
@balopat balopat added the kokoro:run runs the kokoro jobs on a PR label May 20, 2020
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label May 20, 2020
@ChrisGe4 ChrisGe4 requested a review from tstromberg as a code owner June 2, 2020 02:54
@ChrisGe4 ChrisGe4 requested a review from balopat June 2, 2020 04:01
@@ -39,8 +39,8 @@ func (r *SkaffoldRunner) BuildAndTest(ctx context.Context, out io.Writer, artifa
return nil, err
}

// In dry-run mode, we don't build anything, just return the tag for each artifact.
if r.runCtx.Opts.DryRun {
// In dry-run mode or --digest-source set to 'remote' or 'none', we don't build anything, just return the tag for each artifact.

Choose a reason for hiding this comment

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

Nit: two spaces after --digest-source

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.

I made a few wording suggestions, specifically related to saying that when --digest-source=none, "image tags are used from the skaffold.yaml", which isn't actually true - they're used from the Kubernetes manifests, which is an important distinction.

I also ran into a bug with --digest-source=none:

  1. use the getting-started example in our repo (with skaffold-example as the image in the skaffold.yaml and k8s-pod.yaml
  2. append a :latest to the image in the k8s manifest
  3. set your default-repo to something in skaffold (skaffold config set default-repo gcr.io/my-project)
  4. skaffold render --digest-source=none should give me a manifest with something like
apiVersion: v1
kind: Pod
...
spec:
  containers:
  - image: gcr.io/my-project/skaffold-example:latest
    name: getting-started

but for the image name, I actually get gcr.io/my-project/skaffold-example:v1.10.0-82-gb616768d3-dirty, so it generated me a tag. appending the repository name to the image in the k8s manifest, however, gives me the correct result.

I'm not sure how deep this bug goes, so idk if it should be fixed in this PR or a follow-up. but --digest-source=none will be broken for anyone using the default-repo functionality in skaffold until it's fixed (which I suspect is a sizable number of users).

@@ -39,8 +39,8 @@ func (r *SkaffoldRunner) BuildAndTest(ctx context.Context, out io.Writer, artifa
return nil, err
}

// In dry-run mode, we don't build anything, just return the tag for each artifact.
if r.runCtx.Opts.DryRun {
// In dry-run mode or --digest-source set to 'remote' or 'none', we don't build anything, just return the tag for each artifact.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// In dry-run mode or --digest-source set to 'remote' or 'none', we don't build anything, just return the tag for each artifact.
// In dry-run mode or with --digest-source set to 'remote' or 'none', we don't build anything, just return the tag for each artifact.

@@ -38,10 +38,12 @@ var (
func NewCmdRender() *cobra.Command {
return NewCmd("render").
WithDescription("[alpha] Perform all image builds, and output rendered Kubernetes manifests").
WithExample("Hydrate Kubernetes manifests without building the images ", "render --digest-source=remote").
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
WithExample("Hydrate Kubernetes manifests without building the images ", "render --digest-source=remote").
WithExample("Hydrate Kubernetes manifests without building the images, using digest resolved from tag in remote registry", "render --digest-source=remote").

WithCommonFlags().
WithFlags(func(f *pflag.FlagSet) {
f.BoolVar(&showBuild, "loud", false, "Show the build logs and output")
f.StringVar(&renderOutputPath, "output", "", "file to write rendered manifests to")
f.StringVar(&opts.DigestSource, "digest-source", "local", "Set to 'local' to build and tag images, and output templated Kubernetes manifests; Set to 'remote' to resolve the digest of the image by tag from the container registry and output templated Kubernetes manifests; Set to 'none' to output templated Kubernetes manifests with images listed in skaffold.yaml")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
f.StringVar(&opts.DigestSource, "digest-source", "local", "Set to 'local' to build and tag images, and output templated Kubernetes manifests; Set to 'remote' to resolve the digest of the image by tag from the container registry and output templated Kubernetes manifests; Set to 'none' to output templated Kubernetes manifests with images listed in skaffold.yaml")
f.StringVar(&opts.DigestSource, "digest-source", "local", "Set to 'local' to build images locally and use digests from built images; Set to 'remote' to resolve the digest of images by tag from the remote registry; Set to 'none' to use tags directly from the Kubernetes manifests")

}
}
if r.runCtx.Opts.DigestSource == noneDigestSource {
color.Default.Fprintln(out, "--digest-source set to 'none', tags listed in skaffold.yaml will be used for render")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
color.Default.Fprintln(out, "--digest-source set to 'none', tags listed in skaffold.yaml will be used for render")
color.Default.Fprintln(out, "--digest-source set to 'none', tags listed in Kubernetes manifests will be used for render")

@ChrisGe4
Copy link
Contributor Author

ChrisGe4 commented Jun 9, 2020

I made a few wording suggestions, specifically related to saying that when --digest-source=none, "image tags are used from the skaffold.yaml", which isn't actually true - they're used from the Kubernetes manifests, which is an important distinction.

I also ran into a bug with --digest-source=none:

  1. use the getting-started example in our repo (with skaffold-example as the image in the skaffold.yaml and k8s-pod.yaml
  2. append a :latest to the image in the k8s manifest
  3. set your default-repo to something in skaffold (skaffold config set default-repo gcr.io/my-project)
  4. skaffold render --digest-source=none should give me a manifest with something like
apiVersion: v1
kind: Pod
...
spec:
  containers:
  - image: gcr.io/my-project/skaffold-example:latest
    name: getting-started

but for the image name, I actually get gcr.io/my-project/skaffold-example:v1.10.0-82-gb616768d3-dirty, so it generated me a tag. appending the repository name to the image in the k8s manifest, however, gives me the correct result.

I'm not sure how deep this bug goes, so idk if it should be fixed in this PR or a follow-up. but --digest-source=none will be broken for anyone using the default-repo functionality in skaffold until it's fixed (which I suspect is a sizable number of users).

Thank you for reviewing this PR. I misunderstood the use case before and I have got the issue fixed. However, there is one question regarding the example you put in the comment. The image used in k8s-pod.yaml is skaffold-example, should I leave it as it be or add latest tag as it in your example? I think we should just use skaffold-example, right?

@nkubala
Copy link
Contributor

nkubala commented Jun 9, 2020

ok just tried it out with --digest-source=none and it's just leaving the image alone now which is what I'd expect. one thing I noticed though is that it doesn't actually respect the default-repo value now - so even if I have gcr.io/my-project set as a default repo, the image in the rendered manifest is still skaffold-example when using --digest-source=none. for remote and local digests it's working as intended.

I think we do still want to respect the default repo in this case: this flag is indicating that the tag will not be touched by skaffold, but the default repo functionality should still be applied here.

should I leave it as it be or add latest tag as it in your example?

I actually wouldn't mind adding latest to the "rendered" image name in the manifest - in container image land, the absence of a tag usually implies latest anyway, so I think it's ok to just add it on there since it's probably what the user was trying to do. it's not a huge deal either way though, since functionally they should be equivalent.

@pull-request-size pull-request-size bot added size/L and removed size/M labels Jun 10, 2020
@nkubala nkubala merged commit 256e79a into GoogleContainerTools:master Jun 11, 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.

7 participants