Skip to content

Conversation

@ankitathomas
Copy link
Contributor

Adds a new command to list contents of available, healthy ClusterCatalogs.

Addresses operator-framework/operator-controller#1768

$ kubectl operator olmv1 search catalog  --help
Search catalogs for installable operators matching parameters

Usage:
  operator olmv1 search catalog [flags]

Aliases:
  catalog, catalogs

Flags:
      --catalog string              Catalog to search on. If not provided, all available catalogs are searched.
      --catalogd-namespace string   Namespace for the catalogd controller (default "olmv1-system")
  -h, --help                        help for catalog
      --list-versions               List all versions available for each package
  -o, --output string               output format. One of: (yaml|json)
      --package string              Search for package by name. If empty, all available packages will be listed
  -l, --selector string             Selector (label query) to filter catalogs on, supports '=', '==', and '!='
      --timeout string              Timeout for fetching catalog contents (default "5m")

Global Flags:
  -n, --namespace string   If present, namespace scope for this CLI request
ankithom@ankithom-thinkpadt14sgen2i:~/go/src/github.com/operator-framework/ku

By default, the command lists all available packages and channels from all catalogs present on cluster. --timeout can be modified to support listing large catalogs.

$ kubectl operator olmv1 search catalog 
PACKAGE                                   CATALOG        PROVIDER  CHANNELS
accuknox-operator                         operatorhubio            stable
aerospike-kubernetes-operator             operatorhubio            alpha,stable
...

The command also supports listing available bundle versions with `--list-versions`
```bash
$ kubectl operator olmv1 search catalog --list-versions
PACKAGE                                   CATALOG        PROVIDER                            VERSION
accuknox-operator                         operatorhubio  Accuknox Inc.                       0.7.1
ack-acm-controller                        operatorhubio  Amazon, Inc.                        1.1.1
ack-acm-controller                        operatorhubio  Amazon, Inc.                        1.1.0

The queried catalogs can be restricted via a label selector, specified by --selector, and the output can be restricted to a specific package with --package.

Currently supports yaml and json outputs for the catalog FBC, in addition to the table output.

@openshift-ci openshift-ci bot requested review from benluddy and jmrodri November 3, 2025 15:03
Signed-off-by: Ankita Thomas <ankithom@redhat.com>
"github.com/spf13/pflag"
)

// NewCatalogInstalledGetCmd handles get commands in the form of:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// NewCatalogInstalledGetCmd handles get commands in the form of:
// NewCatalogSearchCmd handles get commands in the form of:

Short: "Search for packages",
Long: "Search one or all available catalogs for packages or versions",
}
searchCmd.AddCommand(olmv1.NewCatalogSearchCmd(cfg))
Copy link
Member

Choose a reason for hiding this comment

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

As this command is for searching through one or more catalogs and also users might type catalogs plural, we could considering add an alias:

searchCmd.Aliases = []string{"catalogs"}

}

if len(i.Timeout) > 0 {
if catalogListTimeout, err := time.ParseDuration(i.Timeout); err == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Errors from time.ParseDuration(i.Timeout) are silently ignored here. We should add an error check here to indicate an invalid timeout.

Others: []declcfg.Meta{},
}
for _, p := range dcfg.Packages {
if p.Name == packageName {
Copy link
Member

Choose a reason for hiding this comment

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

We should also add an error here when a package isn't found as we risk giving back empty results.

}
}
for _, e := range dcfg.Channels {
if e.Package == packageName {
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above for returning error when a package with the name specified isn't found.

readyAddresses = append(readyAddresses, subset.Addresses...)
}

randAddress := rand.Int31n(int32(len(readyAddresses)))
Copy link
Member

Choose a reason for hiding this comment

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

This will panic if readyAddresses is empty. So we should add a check before this to ensure readyAddresses is non-empty

}
baseURL, err := url.Parse(cc.Status.URLs.Base)
if err != nil {
return nil, err
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return nil, err
return nil, fmt.Errorf("failed to parse ClusterCatalog URL %q: %w", cc.Status.URLs.Base, err)

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.

2 participants