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 images command #20

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"github.com/spf13/cobra"

"github.com/openshift-eng/openshift-tests-extension/pkg/cmd/cmdimages"
"github.com/openshift-eng/openshift-tests-extension/pkg/cmd/cmdinfo"
"github.com/openshift-eng/openshift-tests-extension/pkg/cmd/cmdlist"
"github.com/openshift-eng/openshift-tests-extension/pkg/cmd/cmdrun"
Expand All @@ -17,5 +18,6 @@ func DefaultExtensionCommands(registry *extension.Registry) []*cobra.Command {
cmdlist.NewListCommand(registry),
cmdinfo.NewInfoCommand(registry),
cmdupdate.NewUpdateCommand(registry),
cmdimages.NewImagesCommand(registry),
}
}
36 changes: 36 additions & 0 deletions pkg/cmd/cmdimages/cmdimages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cmdimages

import (
"encoding/json"
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/openshift-eng/openshift-tests-extension/pkg/extension"
"github.com/openshift-eng/openshift-tests-extension/pkg/flags"
)

func NewImagesCommand(registry *extension.Registry) *cobra.Command {
componentFlags := flags.NewComponentFlags()

cmd := &cobra.Command{
Use: "images",
Short: "List test images",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
extension := registry.Get(componentFlags.Component)
if extension == nil {
return fmt.Errorf("couldn't find the component %q", componentFlags.Component)
}
images, err := json.Marshal(extension.Images)
if err != nil {
return err
}
fmt.Fprintf(os.Stdout, "%s\n", images)
return nil
},
}
componentFlags.BindFlags(cmd.Flags())
return cmd
}
5 changes: 5 additions & 0 deletions pkg/extension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ func (e *Extension) AddSuite(suite Suite) *Extension {
return e
}

func (e *Extension) RegisterImage(image Image) *Extension {
e.Images = append(e.Images, image)
return e
}

func (e *Extension) FindSpecsByName(names ...string) (et.ExtensionTestSpecs, error) {
var specs et.ExtensionTestSpecs
var notFound []string
Expand Down
9 changes: 9 additions & 0 deletions pkg/extension/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type Extension struct {
// Suites that the extension wants to advertise/participate in.
Suites []Suite `json:"suites"`

Images []Image `json:"images"`

// Private data
specs extensiontests.ExtensionTestSpecs
obsoleteTests sets.Set[string]
Expand Down Expand Up @@ -53,3 +55,10 @@ type Suite struct {
// Qualifiers are CEL expressions that are OR'd together for test selection that are members of the suite.
Qualifiers []string `json:"qualifiers,omitempty"`
}

type Image struct {
Index int `json:"index"`
Registry string `json:"registry"`
Name string `json:"name"`
Version string `json:"version"`
}