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 support for pulling and pushing all images #1061

Merged
merged 1 commit into from
Jan 7, 2020

Conversation

zubron
Copy link
Contributor

@zubron zubron commented Dec 20, 2019

What this PR does / why we need it:
This changes adds support for pulling the Sonobuoy worker image, the
systemd-logs image and the Kubernetes conformance image in addition to
the images required for the e2e plugin.

The individual images to pull cannot be configured. Only the default
version for the cluster will be pulled. The images can only be pushed to
one registry which is specified with the new flags --custom-registry.

This currently only works for the default built in plugins. A follow up
change will be made to apply the same approach to any image in a plugin
definition.

Signed-off-by: Bridget McErlean bmcerlean@vmware.com

Which issue(s) this PR fixes

Special notes for your reviewer:
I've tested the new commands for this manually. I ran the following locally:

sonobuoy images pull -p systemd-logs
sonobuoy images push -p systemd-logs --custom-registry zubron

And you can see that the images were pushed to my public registry: https://hub.docker.com/u/zubron

Release note:

Sonobuoy can now pull all images for Sonobuoy and the built-in plugins and push them to a custom registry. The E2E test images are still configured as before, however all other images will be pushed to a custom registry specified using the flag `--custom-registry`. The image operations can also be previewed by using the `--dry-run` flag.

@zubron zubron force-pushed the include-all-images-1028 branch 2 times, most recently from 5301e9a to 02fbd27 Compare December 20, 2019 17:24
func downloadImages(plugins []string, kubeconfig Kubeconfig, e2eRegistryConfig string) error {
for _, plugin := range plugins {
switch plugin {
case e2ePlugin:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't updated this function as I don't know if we should maintain it: #1058

@codecov-io
Copy link

codecov-io commented Dec 20, 2019

Codecov Report

Merging #1061 into master will increase coverage by 0.79%.
The diff coverage is 33.59%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1061      +/-   ##
=========================================
+ Coverage   49.91%   50.7%   +0.79%     
=========================================
  Files          78      79       +1     
  Lines        5634    5745     +111     
=========================================
+ Hits         2812    2913     +101     
- Misses       2654    2659       +5     
- Partials      168     173       +5
Impacted Files Coverage Δ
pkg/image/dryrun_client.go 0% <0%> (ø)
cmd/sonobuoy/app/args.go 91.05% <100%> (+0.49%) ⬆️
pkg/image/manifest.go 70.43% <54.28%> (+1.54%) ⬆️
cmd/sonobuoy/app/gen.go 75.88% <83.33%> (+1.41%) ⬆️
cmd/sonobuoy/app/images.go 26.12% <9.93%> (-5.91%) ⬇️
pkg/image/docker_client.go 92.1% <92.1%> (ø)
pkg/plugin/aggregation/aggregator.go 75.77% <0%> (+3.1%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bb0c5a3...e928173. Read the comment docs.

return imageClient.DeleteImages(images, numDockerRetries)
func substituteRegistry(image string, customRegistry string) string {
trimmedRegistry := strings.TrimRight(customRegistry, "/")
components := strings.SplitAfter(image, "/")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought I left a comment on this but it's gotten lost 😕

This is a best attempt at replacing the registry in a full image name. It's possible for the "name" component of an image name to also contain a / and we see that in some of the E2E test images. In cases like these, this function would substitute everything up to the last / which could include the registry and part of the image name. I don't think there's a way to identify what is the registry URL component of a FQIN. The images will still tag and push correctly, but it might be confusing for users when replacing images in their plugin definitions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Its a short function but I think this is a good function to have in a function so that we can visually ensure it handles certain cases.

@@ -348,6 +351,11 @@ func AddPluginEnvFlag(p *PluginEnvVars, flags *pflag.FlagSet) {
flags.Var(p, "plugin-env", "Set env vars on plugins. Values can be given multiple times and are in the form plugin.env=value")
}

// AddPluginListFlag adds the flag to keep track of which built-in plugins to use.
func AddPluginListFlag(p *[]string, flags *pflag.FlagSet) {
flags.StringSliceVarP(p, "plugin", "p", []string{"e2e"}, "Describe which plugin's images to interact (Valid plugins are 'e2e', 'systemd-logs').")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this default to both plugins now? Seems like that would be simpler UX here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it looks like this is just used for the images command. If we are going to, by default, try to run both of those plugins and the images commands can support both of them, I agree it should.

@zubron zubron marked this pull request as ready for review December 20, 2019 18:03
if err != nil {
return errors.Wrap(err, "failed to get cluster version")
}
func listImages(plugins []string, kubeconfig Kubeconfig) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is another good candidate for a test function; we can add it when we expand to other plugins though. I know the systemd-logs test wouldnt be very significant and the e2e one is a bit awkward to test.

Copy link
Contributor

@johnSchnake johnSchnake left a comment

Choose a reason for hiding this comment

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

I'll have to try this out a bit more before I want to merge it; no rush. Enjoy the time off.

@johnSchnake
Copy link
Contributor

My only other idea for this is if it would be useful to have a dry-run option when pushing so that you can confirm the repos/tags are as expected.

When trying to manually confirm this all works, I can't actually check much manually without actually pushing some images.

Otherwise, my only comments were (already commented but adding for clarity):

  • ideally add another test to ensure we are splitting registries/tags appropriately
  • default to doing both systemd-logs and e2e

@zubron
Copy link
Contributor Author

zubron commented Jan 7, 2020

Thanks for the feedback! I've addressed your two comments. I also added a dry-run option which just performs the logging operations that the existing docker image client does. I've left it as a separate commit for now. Let me know what you think!

Copy link
Contributor

@johnSchnake johnSchnake left a comment

Choose a reason for hiding this comment

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

I ❤️ the dry run client you added; it surpasses what I was hoping for. Good to squash/merge

This changes adds support for pulling the Sonobuoy worker image, the
systemd-logs image and the Kubernetes conformance image in addition to
the images required for the e2e plugin.

The individual images to pull cannot be configured. Only the default
version for the cluster will be pulled. The images can only be pushed to
one registry which is specified with the new flags `--custom-registry`.

This currently only works for the default built in plugins. A follow up
change will be made to apply the same approach to any image in a plugin
definition.

Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
@zubron zubron merged commit 23d1d5c into vmware-tanzu:master Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make e2eRegistryConfig flag not required Include all necessary images in images pull/push commands
3 participants