Skip to content

Commit

Permalink
Add images command
Browse files Browse the repository at this point in the history
  • Loading branch information
bertinatto committed Jan 24, 2025
1 parent 7c419f1 commit f1ddad1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ func DefaultExtensionCommands(registry *extension.Registry) []*cobra.Command {
cmdlist.NewListCommand(registry),
cmdinfo.NewInfoCommand(registry),
cmdupdate.NewUpdateCommand(registry),
cmdupdate.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"`
}

0 comments on commit f1ddad1

Please sign in to comment.