Files
odo/pkg/odo/cli/catalog/search/service.go
Mohammed Ahmed 0b8b712a99 Dropping support for service catalog based services (#4906)
* Removing cli layer and integration tests related to service catalog

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Fixing missing error msg

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Fixing golint errors

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Fixing error for interactive mode

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Moving interactive mode error to top

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Fixing

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Fixing interactive mode error condition

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Removing some more service related code

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Fixing golint

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Removing service catalog backend part 1

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Updating changelogs

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Removing some more of the service catalog related code

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Updating as per comments in review

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Update pkg/odo/cli/service/create.go

Co-authored-by: Parthvi Vala <pvala@redhat.com>

* Fixing gofmt

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Adding kube to cli docs

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Updating changelog as per comments by @dharmit

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Removing some unnessasary stuff

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Updating docs based changes as per review

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Fixing test

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Update pkg/odo/cli/catalog/describe/service.go

Co-authored-by: Philippe Martin <contact@elol.fr>

* Update pkg/odo/cli/service/list.go

Co-authored-by: Philippe Martin <contact@elol.fr>

Co-authored-by: Parthvi Vala <pvala@redhat.com>
Co-authored-by: Philippe Martin <contact@elol.fr>
2021-08-18 11:41:43 +00:00

109 lines
3.3 KiB
Go

package search
import (
"fmt"
"github.com/openshift/odo/pkg/catalog"
"github.com/openshift/odo/pkg/odo/cli/catalog/util"
"github.com/openshift/odo/pkg/odo/genericclioptions"
olm "github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/spf13/cobra"
)
const serviceRecommendedCommandName = "service"
var serviceExample = ` # Search for a service
%[1]s mysql`
// SearchServiceOptions encapsulates the options for the odo catalog describe service command
type SearchServiceOptions struct {
searchTerm string
services catalog.ServiceTypeList
// generic context options common to all commands
csvs *olm.ClusterServiceVersionList
*genericclioptions.Context
}
// NewSearchServiceOptions creates a new SearchServiceOptions instance
func NewSearchServiceOptions() *SearchServiceOptions {
return &SearchServiceOptions{}
}
// Complete completes SearchServiceOptions after they've been created
func (o *SearchServiceOptions) Complete(name string, cmd *cobra.Command, args []string) (err error) {
var noCsvs, noServices bool
o.Context, err = genericclioptions.NewContext(cmd)
if err != nil {
return err
}
o.searchTerm = args[0]
o.csvs, err = o.KClient.SearchClusterServiceVersionList(o.searchTerm)
if err != nil {
// Error only occurs when OperatorHub is not installed/enabled on the
// Kubernetes or OpenShift 4.x cluster. It doesn't occur when there are
// no operators installed.
noCsvs = true
}
// Checks service catalog, but if its not available, we do not error.
o.services, err = catalog.SearchService(o.Client, o.searchTerm)
if err != nil {
// Error occurs if Service Catalog is not enabled on the OpenShift
// 3.x/4.x cluster
noServices = true
// But we don't care about the Service Catalog not being enabled if
// it's 4.x or k8s cluster
if !noCsvs {
err = nil
}
}
if noCsvs && noServices {
// Neither OperatorHub nor Service Catalog is enabled on the cluster
return fmt.Errorf("unable to list services because neither Service Catalog nor Operator Hub is enabled in your cluster: %v", err)
}
o.services = util.FilterHiddenServices(o.services)
return err
}
// Validate validates the SearchServiceOptions based on completed values
func (o *SearchServiceOptions) Validate() (err error) {
if len(o.services.Items) == 0 && len(o.csvs.Items) == 0 {
return fmt.Errorf("no service matched the query: %s", o.searchTerm)
}
return
}
// Run contains the logic for the command associated with SearchServiceOptions
func (o *SearchServiceOptions) Run(cmd *cobra.Command) (err error) {
if len(o.csvs.Items) > 0 {
util.DisplayClusterServiceVersions(o.csvs)
}
if len(o.services.Items) > 0 {
util.DisplayServices(o.services)
}
return
}
// NewCmdCatalogSearchService implements the odo catalog search service command
func NewCmdCatalogSearchService(name, fullName string) *cobra.Command {
o := NewSearchServiceOptions()
return &cobra.Command{
Use: name,
Short: "Search service type in catalog",
Long: `Search service type in catalog.
This searches for a partial match for the given search term in all the available
services from operator hub services.
`,
Example: fmt.Sprintf(serviceExample, fullName),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(o, cmd, args)
},
}
}