Skip to content

Commit

Permalink
Add support for pulling and pushing all images
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
zubron committed Dec 20, 2019
1 parent 78b256d commit 02fbd27
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 160 deletions.
16 changes: 15 additions & 1 deletion cmd/sonobuoy/app/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
pluginFlag = "plugin"
timeoutFlag = "timeout"
waitOutputFlag = "wait-output"
customRegistryFlag = "custom-registry"
)

// AddNamespaceFlag initialises a namespace flag.
Expand Down Expand Up @@ -132,7 +133,15 @@ func AddPluginFlag(cfg *string, flags *pflag.FlagSet) {
func AddE2ERegistryConfigFlag(cfg *string, flags *pflag.FlagSet) {
flags.StringVar(
cfg, e2eRegistryConfigFlag, "",
"Specify a yaml file acting as KUBE_TEST_REPO_LIST, overriding registries for test images.",
"Specify a yaml file acting as KUBE_TEST_REPO_LIST, overriding registries for test images. Required when pushing images for the e2e plugin.",
)
}

// AddCustomRepoFlag adds a custom registry flag to the provided command.
func AddCustomRegistryFlag(cfg *string, flags *pflag.FlagSet) {
flags.StringVar(
cfg, customRegistryFlag, "",
"Specify a registry to override the Sonobuoy and Plugin image registries.",
)
}

Expand Down Expand Up @@ -348,6 +357,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').")
}

// AddShortFlag adds a boolean flag to just print the Sonobuoy version and
// nothing else. Useful in scripts.
func AddShortFlag(flag *bool, flags *pflag.FlagSet) {
Expand Down
13 changes: 7 additions & 6 deletions cmd/sonobuoy/app/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ func (g *genFlags) Config() (*client.GenConfig, error) {
return nil, err
}

image = fmt.Sprintf("%v:%v",
resolveConformanceImage(imageVersion),
imageVersion)
image = resolveConformanceImage(imageVersion)
}

return &client.GenConfig{
Expand Down Expand Up @@ -175,14 +173,17 @@ func resolveConformanceImage(imageVersion string) string {
// required as we phase in the use of the upstream k8s kube-conformance
// image instead of our own heptio/kube-conformance one. They started
// publishing it for v1.14.1. (https://github.com/kubernetes/kubernetes/pull/76101)
var imageURL string
switch {
case imageVersion == imagepkg.ConformanceImageVersionLatest:
return config.UpstreamKubeConformanceImageURL
imageURL = config.UpstreamKubeConformanceImageURL
case imageVersion < "v1.14.1":
return config.DefaultKubeConformanceImageURL
imageURL = config.DefaultKubeConformanceImageURL
default:
return config.UpstreamKubeConformanceImageURL
imageURL = config.UpstreamKubeConformanceImageURL
}
return fmt.Sprintf("%v:%v", imageURL, imageVersion)

}

func NewCmdGen() *cobra.Command {
Expand Down
16 changes: 8 additions & 8 deletions cmd/sonobuoy/app/gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,35 @@ func TestResolveConformanceImage(t *testing.T) {
{
name: "Comparison is lexical",
requestedVersion: "foo",
expected: "gcr.io/heptio-images/kube-conformance",
expected: "gcr.io/heptio-images/kube-conformance:foo",
}, {
name: "Prior to v1.14.0 uses heptio and major.minor",
requestedVersion: "v1.13.99",
expected: "gcr.io/heptio-images/kube-conformance",
expected: "gcr.io/heptio-images/kube-conformance:v1.13.99",
}, {
name: "v1.14.0 uses heptio and major.minor",
requestedVersion: "v1.14.0",
expected: "gcr.io/heptio-images/kube-conformance",
expected: "gcr.io/heptio-images/kube-conformance:v1.14.0",
}, {
name: "v1.14.1 and after uses upstream and major.minor.patch",
requestedVersion: "v1.14.1",
expected: "gcr.io/google-containers/conformance",
expected: "gcr.io/google-containers/conformance:v1.14.1",
}, {
name: "v1.14.0 and after uses upstream and major.minor.patch",
requestedVersion: "v1.15.1",
expected: "gcr.io/google-containers/conformance",
expected: "gcr.io/google-containers/conformance:v1.15.1",
}, {
name: "latest should use upstream image",
requestedVersion: "latest",
expected: "gcr.io/google-containers/conformance",
expected: "gcr.io/google-containers/conformance:latest",
}, {
name: "explicit version before v1.14.0 should use heptio image and given version",
requestedVersion: "v1.12+.0.alpha+",
expected: "gcr.io/heptio-images/kube-conformance",
expected: "gcr.io/heptio-images/kube-conformance:v1.12+.0.alpha+",
}, {
name: "explicit version after v1.14.0 should use upstream and use given version",
requestedVersion: "v1.14.1",
expected: "gcr.io/google-containers/conformance",
expected: "gcr.io/google-containers/conformance:v1.14.1",
},
}

Expand Down
Loading

0 comments on commit 02fbd27

Please sign in to comment.