Skip to content

Commit

Permalink
Add sonobuoy images list command (#1639)
Browse files Browse the repository at this point in the history
* Add sonobuoy images list command

And add --druy-run flag to sonobuoy images command

Signed-off-by: Mathieu Parent <mathieu.parent@insee.fr>

* Return no e2e images instead of outdated info

Signed-off-by: Mathieu Parent <mathieu.parent@insee.fr>
  • Loading branch information
sathieu authored Mar 18, 2022
1 parent b8eb801 commit e8507f2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 58 deletions.
55 changes: 40 additions & 15 deletions cmd/sonobuoy/app/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,42 @@ var (
transformSink = map[string][]func(*manifest.Manifest) error{}
)

func runListImages(flags imagesFlags) {
var client image.Client
if flags.dryRun {
client = image.DryRunClient{}
} else {
client = image.NewDockerClient()
}
version, err := getClusterVersion(flags.k8sVersion, flags.kubeconfig)
if err != nil {
errlog.LogError(err)
os.Exit(1)
}
if err := listImages(flags.plugins, version, client); err != nil {
errlog.LogError(err)
os.Exit(1)
}
}

func NewCmdImages() *cobra.Command {
var flags imagesFlags
// Main command
cmd := &cobra.Command{
Use: "images",
Short: "Manage images used in a plugin to facilitate running them in airgapped (or similar) environments. Supported plugins are: 'e2e'",
Run: func(cmd *cobra.Command, args []string) {
var client image.Client
if flags.dryRun {
client = image.DryRunClient{}
} else {
client = image.NewDockerClient()
}
version, err := getClusterVersion(flags.k8sVersion, flags.kubeconfig)
if err != nil {
errlog.LogError(err)
os.Exit(1)
}
if err := listImages(flags.plugins, version, client); err != nil {
errlog.LogError(err)
os.Exit(1)
}
runListImages(flags)
},
Args: cobra.ExactArgs(0),
}

AddKubeconfigFlag(&flags.kubeconfig, cmd.Flags())
AddPluginListFlag(&flags.plugins, cmd.Flags())
AddDryRunFlag(&flags.dryRun, cmd.Flags())
AddKubernetesVersionFlag(&flags.k8sVersion, &transformSink, cmd.Flags())

cmd.AddCommand(listCmd())
cmd.AddCommand(pullCmd())
cmd.AddCommand(pushCmd())
cmd.AddCommand(downloadCmd())
Expand All @@ -91,6 +97,25 @@ func NewCmdImages() *cobra.Command {
return cmd
}

func listCmd() *cobra.Command {
var flags imagesFlags

listCmd := &cobra.Command{
Use: "list",
Short: "List images",
Run: func(cmd *cobra.Command, args []string) {
runListImages(flags)
},
Args: cobra.ExactArgs(0),
}
AddKubeconfigFlag(&flags.kubeconfig, listCmd.Flags())
AddPluginListFlag(&flags.plugins, listCmd.Flags())
AddDryRunFlag(&flags.dryRun, listCmd.Flags())
AddKubernetesVersionFlag(&flags.k8sVersion, &transformSink, listCmd.Flags())

return listCmd
}

func pullCmd() *cobra.Command {
var flags imagesFlags

Expand Down
46 changes: 3 additions & 43 deletions pkg/image/dryrun_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,17 @@ limitations under the License.
package image

import (
"strings"

"github.com/sirupsen/logrus"
)

// DryRunClient is an implementation of Client that logs the image operations that would
// be performed rather than performing them.
type DryRunClient struct{}

const v1_19_images = `docker.io/library/httpd:2.4.38-alpine
docker.io/library/httpd:2.4.39-alpine
gcr.io/kubernetes-e2e-test-images/nautilus:1.0
docker.io/library/nginx:1.14-alpine
gcr.io/kubernetes-e2e-test-images/volume/gluster:1.0
gcr.io/kubernetes-e2e-test-images/cuda-vector-add:2.0
k8s.gcr.io/build-image/debian-iptables:v12.1.2
docker.io/gluster/glusterdynamic-provisioner:v1.0
docker.io/library/nginx:1.15-alpine
k8s.gcr.io/prometheus-dummy-exporter:v0.1.0
k8s.gcr.io/prometheus-to-sd:v0.5.0
gcr.io/kubernetes-e2e-test-images/resource-consumer:1.5
k8s.gcr.io/sd-dummy-exporter:v0.2.0
gcr.io/k8s-authenticated-test/agnhost:2.6
gcr.io/authenticated-image-pulling/alpine:3.7
gcr.io/kubernetes-e2e-test-images/jessie-dnsutils:1.0
gcr.io/kubernetes-e2e-test-images/volume/nfs:1.0
gcr.io/kubernetes-e2e-test-images/volume/rbd:1.0.1
gcr.io/kubernetes-e2e-test-images/apparmor-loader:1.0
gcr.io/kubernetes-e2e-test-images/cuda-vector-add:1.0
gcr.io/kubernetes-e2e-test-images/nonewprivs:1.0
gcr.io/kubernetes-e2e-test-images/sample-apiserver:1.17
invalid.com/invalid/alpine:3.1
gcr.io/kubernetes-e2e-test-images/ipc-utils:1.0
docker.io/library/perl:5.26
gcr.io/kubernetes-e2e-test-images/regression-issue-74839-amd64:1.0
k8s.gcr.io/e2e-test-images/agnhost:2.20
gcr.io/authenticated-image-pulling/windows-nanoserver:v1
k8s.gcr.io/etcd:3.4.13-0
gcr.io/kubernetes-e2e-test-images/echoserver:2.2
docker.io/library/redis:5.0.5-alpine
gcr.io/kubernetes-e2e-test-images/metadata-concealment:1.2
k8s.gcr.io/pause:3.2
gcr.io/kubernetes-e2e-test-images/nonroot:1.0
gcr.io/kubernetes-e2e-test-images/volume/iscsi:2.0
docker.io/library/busybox:1.29
gcr.io/kubernetes-e2e-test-images/kitten:1.0
k8s.gcr.io/sig-storage/nfs-provisioner:v2.2.2
`

func (i DryRunClient) RunImage(image string, entryPoint string, args ...string) ([]string, error) {
return strings.Split(v1_19_images, "\n"), nil
// Called from collectPluginsImages, retrieve e2e images
// Return empty list instead of outdated info
return []string{}, nil
}

// PullImages logs the images that would be pulled.
Expand Down

0 comments on commit e8507f2

Please sign in to comment.