Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.23.4

require (
github.com/blang/semver/v4 v4.0.0
github.com/briandowns/spinner v1.23.2
github.com/containerd/containerd v1.7.26
github.com/containerd/platforms v0.2.1
github.com/onsi/ginkgo v1.16.5
Expand All @@ -19,6 +20,7 @@ require (
k8s.io/api v0.32.2
k8s.io/apiextensions-apiserver v0.32.2
k8s.io/apimachinery v0.32.2
k8s.io/cli-runtime v0.32.2
k8s.io/client-go v0.32.2
sigs.k8s.io/controller-runtime v0.20.2
sigs.k8s.io/yaml v1.4.0
Expand All @@ -27,6 +29,7 @@ require (
require (
cel.dev/expr v0.18.0 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Microsoft/hcsshim v0.12.9 // indirect
Expand Down Expand Up @@ -54,6 +57,7 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
Expand Down Expand Up @@ -83,14 +87,18 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/moby/spdystream v0.5.0 // indirect
github.com/moby/sys/capability v0.3.0 // indirect
github.com/moby/sys/mountinfo v0.7.2 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.3.0 // indirect
github.com/moby/sys/userns v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
Expand Down
22 changes: 22 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ cel.dev/expr v0.18.0/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
Expand All @@ -20,6 +22,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/briandowns/spinner v1.23.2 h1:Zc6ecUnI+YzLmJniCfDNaMbW0Wid1d5+qcTq4L2FW8w=
github.com/briandowns/spinner v1.23.2/go.mod h1:LaZeM4wm2Ywy6vO571mvhQNRcWfRUnXOs0RcKV0wYKM=
github.com/bshuster-repo/logrus-logstash-hook v1.0.0 h1:e+C0SB5R1pu//O4MQ3f9cFuPGoOVeF2fE4Og9otCc70=
github.com/bshuster-repo/logrus-logstash-hook v1.0.0/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
Expand Down Expand Up @@ -62,6 +66,8 @@ github.com/containers/storage v1.56.1/go.mod h1:c6WKowcAlED/DkWGNuL9bvGYqIWCVy7i
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand Down Expand Up @@ -97,6 +103,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/evanphx/json-patch/v5 v5.9.11 h1:/8HVnzMq13/3x9TPvjG08wUGqBTmZBsCWzjTM0wiaDU=
github.com/evanphx/json-patch/v5 v5.9.11/go.mod h1:3j+LviiESTElxA4p3EMKAB9HXj3/XEtnUf6OZxqIQTM=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down Expand Up @@ -212,8 +220,15 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0=
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg=
Expand All @@ -230,6 +245,8 @@ github.com/moby/sys/user v0.3.0 h1:9ni5DlcW5an3SvRSx4MouotOygvzaXbaSrc/wGDFWPo=
github.com/moby/sys/user v0.3.0/go.mod h1:bG+tYYYJgaMtRKgEmuueC0hJEAZWwtIbZTB+85uoHjs=
github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g=
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down Expand Up @@ -424,7 +441,10 @@ golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
Expand Down Expand Up @@ -512,6 +532,8 @@ k8s.io/apimachinery v0.32.2 h1:yoQBR9ZGkA6Rgmhbp/yuT9/g+4lxtsGYwW6dR6BDPLQ=
k8s.io/apimachinery v0.32.2/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE=
k8s.io/apiserver v0.32.2 h1:WzyxAu4mvLkQxwD9hGa4ZfExo3yZZaYzoYvvVDlM6vw=
k8s.io/apiserver v0.32.2/go.mod h1:PEwREHiHNU2oFdte7BjzA1ZyjWjuckORLIK/wLV5goM=
k8s.io/cli-runtime v0.32.2 h1:aKQR4foh9qeyckKRkNXUccP9moxzffyndZAvr+IXMks=
k8s.io/cli-runtime v0.32.2/go.mod h1:a/JpeMztz3xDa7GCyyShcwe55p8pbcCVQxvqZnIwXN8=
k8s.io/client-go v0.32.2 h1:4dYCD4Nz+9RApM2b/3BtVvBHw54QjMFUl1OLcJG5yOA=
k8s.io/client-go v0.32.2/go.mod h1:fpZ4oJXclZ3r2nDOv+Ux3XcJutfrwjKTCHz2H3sww94=
k8s.io/component-base v0.32.2 h1:1aUL5Vdmu7qNo4ZsE+569PV5zFatM9hl+lb3dEea2zU=
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/catalog_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func newCatalogRemoveCmd(cfg *action.Configuration) *cobra.Command {
u := internalaction.NewCatalogRemove(cfg)
cmd := &cobra.Command{
Use: "remove <catalog_name>",
Short: "Remove a operator catalog",
Short: "Remove an operator catalog",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
u.CatalogName = args[0]
Expand Down
61 changes: 51 additions & 10 deletions internal/cmd/internal/olmv1/catalog_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,27 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/errors"

olmv1 "github.com/operator-framework/operator-controller/api/v1"

"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
v1action "github.com/operator-framework/kubectl-operator/internal/pkg/v1/action"
"github.com/operator-framework/kubectl-operator/pkg/action"
)

// NewCatalogCreateCmd allows creating a new catalog
type catalogCreateOptions struct {
dryRunOptions
mutableCatalogOptions
}

// NewCatalogCreateCmd creates a new catalog, requiring a minimum
// of a name for the new catalog and a source image reference
func NewCatalogCreateCmd(cfg *action.Configuration) *cobra.Command {
i := v1action.NewCatalogCreate(cfg)
i.Logf = log.Printf
var opts catalogCreateOptions

cmd := &cobra.Command{
Use: "catalog <catalog_name> <image_source_ref>",
Expand All @@ -24,22 +35,52 @@ func NewCatalogCreateCmd(cfg *action.Configuration) *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
i.CatalogName = args[0]
i.ImageSourceRef = args[1]

if err := i.Run(cmd.Context()); err != nil {
log.Fatalf("failed to create catalog %q: %v", i.CatalogName, err)
opts.Image = i.ImageSourceRef
if err := opts.validate(); err != nil {
log.Fatalf("failed to parse flags: %w", err)
}
i.DryRun = opts.DryRun
i.Output = opts.Output
i.AvailabilityMode = opts.AvailabilityMode
i.Priority = opts.Priority
i.Labels = opts.Labels
i.PollIntervalMinutes = opts.PollIntervalMinutes
catalogObj, err := i.Run(cmd.Context())
if err != nil {
log.Fatalf("failed to create catalog %q: %w", i.CatalogName, err)
}
if len(i.DryRun) == 0 {
log.Printf("catalog %q created", i.CatalogName)
return
}
log.Printf("catalog %q created", i.CatalogName)
if len(i.Output) == 0 {
log.Printf("catalog %q created (dry run)", i.CatalogName)
return
}

catalogObj.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{Group: olmv1.GroupVersion.Group,
Version: olmv1.GroupVersion.Version, Kind: "ClusterCatalog"})
printFormattedCatalogs(i.Output, *catalogObj)
},
}
bindMutableCatalogFlags(cmd.Flags(), &opts.mutableCatalogOptions)
bindCatalogCreateFlags(cmd.Flags(), i)
bindDryRunFlags(cmd.Flags(), &opts.dryRunOptions)

return cmd
}

func bindCatalogCreateFlags(fs *pflag.FlagSet, i *v1action.CatalogCreate) {
fs.Int32Var(&i.Priority, "priority", 0, "priority determines the likelihood of a catalog being selected in conflict scenarios")
fs.BoolVar(&i.Available, "available", true, "true means that the catalog should be active and serving data")
fs.IntVar(&i.PollIntervalMinutes, "source-poll-interval-minutes", 10, "catalog source polling interval [in minutes]")
fs.StringToStringVar(&i.Labels, "labels", map[string]string{}, "labels that will be added to the catalog")
fs.DurationVar(&i.CleanupTimeout, "cleanup-timeout", time.Minute, "the amount of time to wait before cancelling cleanup after a failed creation attempt")
fs.DurationVar(&i.CleanupTimeout, "cleanup-timeout", time.Minute, "the amount of time to wait before cancelling cleanup after a failed creation attempt.")
}

func (o *catalogCreateOptions) validate() error {
var errs []error
if err := o.dryRunOptions.validate(); err != nil {
errs = append(errs, err)
}
if err := o.mutableCatalogOptions.validate(); err != nil {
errs = append(errs, err)
}
return errors.NewAggregate(errs)
}
59 changes: 42 additions & 17 deletions internal/cmd/internal/olmv1/catalog_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,73 @@ package olmv1
import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/runtime/schema"

olmv1 "github.com/operator-framework/operator-controller/api/v1"

"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
v1action "github.com/operator-framework/kubectl-operator/internal/pkg/v1/action"
"github.com/operator-framework/kubectl-operator/pkg/action"
)

// NewCatalogDeleteCmd allows deleting either a single or all
// existing catalogs
type catalogDeleteOptions struct {
dryRunOptions
}

// NewCatalogDeleteCmd deletes either a specific catalog by name
// or all catalogs on cluster.
func NewCatalogDeleteCmd(cfg *action.Configuration) *cobra.Command {
d := v1action.NewCatalogDelete(cfg)
d.Logf = log.Printf
i := v1action.NewCatalogDelete(cfg)
i.Logf = log.Printf
var opts catalogDeleteOptions

cmd := &cobra.Command{
Use: "catalog [catalog_name]",
Aliases: []string{"catalogs [catalog_name]"},
Args: cobra.RangeArgs(0, 1),
Short: "Delete either a single or all of the existing catalogs",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
catalogs, err := d.Run(cmd.Context())
if err != nil {
log.Fatalf("failed deleting catalogs: %v", err)
if len(args) > 0 {
if i.DeleteAll {
log.Fatalf("failed to delete catalog: cannot specify both --all and a catalog name")
}
i.CatalogName = args[0]
}
if err := opts.validate(); err != nil {
log.Fatalf("failed to parse flags: %w", err)
}
i.DryRun = opts.DryRun
i.Output = opts.Output
catalogs, err := i.Run(cmd.Context())
if err != nil {
log.Fatalf("failed to delete catalog(s): %v", err)
}
if len(i.DryRun) == 0 {
for _, c := range catalogs {
log.Printf("catalog %q deleted", c.Name)
}
for _, catalog := range catalogs {
log.Printf("catalog %q deleted", catalog)
return
}
if len(i.Output) == 0 {
for _, c := range catalogs {
log.Printf("catalog %q deleted (dry run)", c.Name)
}

return
}

d.CatalogName = args[0]
if _, err := d.Run(cmd.Context()); err != nil {
log.Fatalf("failed to delete catalog %q: %v", d.CatalogName, err)
for _, c := range catalogs {
c.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{Group: olmv1.GroupVersion.Group,
Version: olmv1.GroupVersion.Version, Kind: "ClusterCatalog"})
}
log.Printf("catalog %q deleted", d.CatalogName)
printFormattedCatalogs(i.Output, catalogs...)
},
}
bindCatalogDeleteFlags(cmd.Flags(), d)
bindCatalogDeleteFlags(cmd.Flags(), i)
bindDryRunFlags(cmd.Flags(), &opts.dryRunOptions)

return cmd
}

func bindCatalogDeleteFlags(fs *pflag.FlagSet, d *v1action.CatalogDelete) {
fs.BoolVar(&d.DeleteAll, "all", false, "delete all catalogs")
fs.BoolVarP(&d.DeleteAll, "all", "a", false, "delete all catalogs")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,50 @@ package olmv1

import (
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/runtime/schema"

olmv1 "github.com/operator-framework/operator-controller/api/v1"

"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
v1action "github.com/operator-framework/kubectl-operator/internal/pkg/v1/action"
"github.com/operator-framework/kubectl-operator/pkg/action"
)

// NewCatalogInstalledGetCmd handles get commands in the form of:
// catalog(s) [catalog_name] - this will either list all the installed operators
// catalog(s) [catalog_name] - this will either list all the installed catalogs
// if no catalog_name has been provided or display the details of the specific
// one otherwise
func NewCatalogInstalledGetCmd(cfg *action.Configuration) *cobra.Command {
i := v1action.NewCatalogInstalledGet(cfg)
i.Logf = log.Printf
var opts getOptions

cmd := &cobra.Command{
Use: "catalog [catalog_name]",
Aliases: []string{"catalogs"},
Aliases: []string{"catalogs [catalog_name]"},
Args: cobra.RangeArgs(0, 1),
Short: "Display one or many installed catalogs",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 1 {
i.CatalogName = args[0]
}
if err := opts.validate(); err != nil {
log.Fatalf("failed to parse flags: %w", err)
}
i.Selector = opts.ParsedSelector
installedCatalogs, err := i.Run(cmd.Context())
if err != nil {
log.Fatalf("failed getting installed catalog(s): %v", err)
log.Fatalf("failed getting installed catalog(s): %w", err)
}

printFormattedCatalogs(installedCatalogs...)
for i := range installedCatalogs {
installedCatalogs[i].GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{Group: olmv1.GroupVersion.Group,
Version: olmv1.GroupVersion.Version, Kind: "ClusterCatalog"})
}
printFormattedCatalogs(opts.Output, installedCatalogs...)
},
}
bindGetFlags(cmd.Flags(), &opts)

return cmd
}
Loading