Skip to content

Commit dbbf5fc

Browse files
committed
fix formatting and type conversion
Signed-off-by: Ankita Thomas <[email protected]>
1 parent a6c02a8 commit dbbf5fc

17 files changed

+302
-173
lines changed

internal/cmd/catalog_remove.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func newCatalogRemoveCmd(cfg *action.Configuration) *cobra.Command {
1212
u := internalaction.NewCatalogRemove(cfg)
1313
cmd := &cobra.Command{
1414
Use: "remove <catalog_name>",
15-
Short: "Remove a operator catalog",
15+
Short: "Remove an operator catalog",
1616
Args: cobra.ExactArgs(1),
1717
Run: func(cmd *cobra.Command, args []string) {
1818
u.CatalogName = args[0]

internal/cmd/internal/olmv1/catalog_delete.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ func NewCatalogDeleteCmd(cfg *action.Configuration) *cobra.Command {
2525
Short: "Delete either a single or all of the existing catalogs",
2626
Run: func(cmd *cobra.Command, args []string) {
2727
if len(args) > 0 {
28+
if d.DeleteAll {
29+
log.Fatalf("failed to delete catalog: cannot specify both --all and a catalog name")
30+
}
2831
d.CatalogName = args[0]
2932
}
3033
catalogs, err := d.Run(cmd.Context())
@@ -33,14 +36,14 @@ func NewCatalogDeleteCmd(cfg *action.Configuration) *cobra.Command {
3336
}
3437

3538
if len(d.DryRun) == 0 {
36-
for _, extn := range catalogs {
37-
log.Printf("extension %s deleted", extn.Name)
39+
for _, catn := range catalogs {
40+
log.Printf("catalog %s deleted", catn.Name)
3841
}
3942
return
4043
}
4144
if len(d.Output) == 0 {
42-
for _, extn := range catalogs {
43-
log.Printf("extension %s deleted (dry run)\n", extn.Name)
45+
for _, catn := range catalogs {
46+
log.Printf("catalog %s deleted (dry run)\n", catn.Name)
4447
}
4548
return
4649
}
@@ -51,7 +54,7 @@ func NewCatalogDeleteCmd(cfg *action.Configuration) *cobra.Command {
5154
}
5255
printFormattedCatalogs(d.Output, catalogs...)
5356
for _, catalog := range catalogs {
54-
log.Printf("catalog %q deleted", catalog)
57+
log.Printf("catalog %q deleted", catalog.Name)
5558
}
5659
},
5760
}
@@ -61,7 +64,7 @@ func NewCatalogDeleteCmd(cfg *action.Configuration) *cobra.Command {
6164
}
6265

6366
func bindCatalogDeleteFlags(fs *pflag.FlagSet, d *v1action.CatalogDelete) {
64-
fs.BoolVar(&d.DeleteAll, "all", false, "delete all catalogs")
67+
fs.BoolVarP(&d.DeleteAll, "all", "a", false, "delete all catalogs")
6568
fs.StringVar(&d.DryRun, "dry-run", "", "display the object that would be sent on a request without applying it. One of: (All)")
6669
fs.StringVarP(&d.Output, "output", "o", "", "output format for dry-run manifests. One of: (json, yaml)")
6770
}

internal/cmd/internal/olmv1/catalog_get.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
77
v1action "github.com/operator-framework/kubectl-operator/internal/pkg/v1/action"
88
"github.com/operator-framework/kubectl-operator/pkg/action"
9-
"k8s.io/apimachinery/pkg/labels"
9+
10+
olmv1 "github.com/operator-framework/operator-controller/api/v1"
11+
"k8s.io/apimachinery/pkg/runtime/schema"
1012
)
1113

1214
// NewCatalogInstalledGetCmd handles get commands in the form of:
@@ -33,16 +35,16 @@ func NewCatalogInstalledGetCmd(cfg *action.Configuration) *cobra.Command {
3335
default:
3436
log.Fatalf("unrecognized output format %s", catalogGetOptions.Output)
3537
}
36-
if len(catalogGetOptions.Selector) > 0 {
37-
i.Selector, err = labels.Parse(catalogGetOptions.Selector)
38-
if err != nil {
39-
log.Fatalf("unable to parse selector %s: %v", catalogGetOptions.Selector, err)
40-
}
41-
}
38+
i.Selector = catalogGetOptions.Selector
4239
installedCatalogs, err := i.Run(cmd.Context())
4340
if err != nil {
4441
log.Fatalf("failed getting installed catalog(s): %v", err)
4542
}
43+
44+
for i := range installedCatalogs {
45+
installedCatalogs[i].GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{Group: olmv1.GroupVersion.Group,
46+
Version: olmv1.GroupVersion.Version, Kind: "ClusterCatalog"})
47+
}
4648
printFormattedCatalogs(catalogGetOptions.Output, installedCatalogs...)
4749
},
4850
}

internal/cmd/internal/olmv1/extension_get.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
v1action "github.com/operator-framework/kubectl-operator/internal/pkg/v1/action"
88
"github.com/operator-framework/kubectl-operator/pkg/action"
99
"k8s.io/apimachinery/pkg/labels"
10+
11+
olmv1 "github.com/operator-framework/operator-controller/api/v1"
12+
"k8s.io/apimachinery/pkg/runtime/schema"
1013
)
1114

1215
// NewExtensionInstalledGetCmd handles get commands in the form of:
@@ -39,6 +42,10 @@ func NewExtensionInstalledGetCmd(cfg *action.Configuration) *cobra.Command {
3942
log.Fatalf("failed getting installed extension(s): %v", err)
4043
}
4144

45+
for i := range installedExtensions {
46+
installedExtensions[i].GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{Group: olmv1.GroupVersion.Group,
47+
Version: olmv1.GroupVersion.Version, Kind: olmv1.ClusterExtensionKind})
48+
}
4249
printFormattedExtensions(extensionGetOptions.Output, installedExtensions...)
4350
},
4451
}

internal/cmd/internal/olmv1/extension_install.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import (
1515
"k8s.io/apimachinery/pkg/runtime/schema"
1616
)
1717

18-
type extentionInstallOptions struct {
18+
type extensionInstallOptions struct {
1919
CatalogSelector string
2020
}
2121

2222
func NewExtensionInstallCmd(cfg *action.Configuration) *cobra.Command {
2323
i := v1action.NewExtensionInstall(cfg)
2424
i.Logf = log.Printf
25-
var extentionInstallOpts extentionInstallOptions
25+
var extentionInstallOpts extensionInstallOptions
2626
var err error
2727

2828
cmd := &cobra.Command{
@@ -53,12 +53,7 @@ func NewExtensionInstallCmd(cfg *action.Configuration) *cobra.Command {
5353
}
5454
extObj, err := i.Run(cmd.Context())
5555
if err != nil {
56-
log.Fatalf("failed to install extension: %v", err)
57-
}
58-
log.Printf("extension %q created", i.ExtensionName)
59-
60-
if err != nil {
61-
log.Fatalf("failed to install extension %q: %v\n", i.ExtensionName, err)
56+
log.Fatalf("failed to install extension %q: %w\n", i.ExtensionName, err)
6257
}
6358
if len(i.DryRun) == 0 {
6459
log.Printf("extension %q created\n", i.ExtensionName)
@@ -80,10 +75,10 @@ func NewExtensionInstallCmd(cfg *action.Configuration) *cobra.Command {
8075
return cmd
8176
}
8277

83-
func bindExtensionInstallFlags(fs *pflag.FlagSet, i *v1action.ExtensionInstall, o *extentionInstallOptions) {
84-
fs.StringVarP(&i.Namespace.Name, "namespace", "n", "", "namespace to install the operator in") //infer?
78+
func bindExtensionInstallFlags(fs *pflag.FlagSet, i *v1action.ExtensionInstall, o *extensionInstallOptions) {
79+
fs.StringVarP(&i.Namespace.Name, "namespace", "n", "olmv1-system", "namespace to install the operator in") //infer?
8580
fs.StringVarP(&i.PackageName, "package-name", "p", "", "package name of the operator to install. Required.")
86-
fs.StringSliceVarP(&i.Channels, "channels", "c", []string{}, "channels which would be to used for getting updates e.g --channels \"stable,dev-preview,preview\"")
81+
fs.StringSliceVarP(&i.Channels, "channels", "c", []string{}, "channels to be used for getting updates e.g --channels \"stable,dev-preview,preview\"")
8782
fs.StringVarP(&i.Version, "version", "v", "", "version (or version range) from which to resolve bundles")
8883
fs.StringVarP(&i.ServiceAccount, "service-account", "s", "default", "service account name to use for the extension installation")
8984
fs.DurationVarP(&i.CleanupTimeout, "cleanup-timeout", "d", time.Minute, "the amount of time to wait before cancelling cleanup after a failed creation attempt")

internal/cmd/olmv1.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
func newOlmV1Cmd(cfg *action.Configuration) *cobra.Command {
1111
cmd := &cobra.Command{
1212
Use: "olmv1",
13-
Short: "Manage extensions via OLMv1 in a cluster from the command line",
14-
Long: "Manage extensions via OLMv1 in a cluster from the command line.",
13+
Short: "Manage OLMv1 extensions and catalogs",
14+
Long: "Manage OLMv1 resources like clusterextensions and clustercatalogs from the command line.",
1515
}
1616

1717
getCmd := &cobra.Command{

internal/pkg/v1/action/catalog_create.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import (
1414
)
1515

1616
type CatalogCreate struct {
17-
config *action.Configuration
18-
CatalogName string
19-
ImageSourceRef string
17+
config *action.Configuration
18+
CatalogName string
2019

20+
ImageSourceRef string
2121
Priority int32
2222
PollIntervalMinutes int
2323
Labels map[string]string
@@ -26,8 +26,7 @@ type CatalogCreate struct {
2626

2727
DryRun string
2828
Output string
29-
30-
Logf func(string, ...interface{})
29+
Logf func(string, ...interface{})
3130
}
3231

3332
func NewCatalogCreate(config *action.Configuration) *CatalogCreate {

internal/pkg/v1/action/catalog_delete.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import (
1414
type CatalogDelete struct {
1515
config *action.Configuration
1616
CatalogName string
17-
DeleteAll bool
1817

19-
Logf func(string, ...interface{})
18+
DeleteAll bool
2019

2120
DryRun string
2221
Output string
22+
Logf func(string, ...interface{})
2323
}
2424

2525
func NewCatalogDelete(cfg *action.Configuration) *CatalogDelete {
@@ -29,21 +29,21 @@ func NewCatalogDelete(cfg *action.Configuration) *CatalogDelete {
2929
}
3030
}
3131

32-
func (cd *CatalogDelete) Run(ctx context.Context) ([]olmv1.ClusterCatalog, error) {
32+
func (i *CatalogDelete) Run(ctx context.Context) ([]olmv1.ClusterCatalog, error) {
3333
// validate
34-
if cd.DeleteAll && cd.CatalogName != "" {
34+
if i.DeleteAll && i.CatalogName != "" {
3535
return nil, ErrNameAndSelector
3636
}
3737

3838
// delete single, specified catalog
39-
if !cd.DeleteAll {
40-
obj, err := cd.deleteCatalog(ctx, cd.CatalogName)
39+
if !i.DeleteAll {
40+
obj, err := i.deleteCatalog(ctx, i.CatalogName)
4141
return []olmv1.ClusterCatalog{obj}, err
4242
}
4343

4444
// delete all existing catalogs
4545
var catatalogList olmv1.ClusterCatalogList
46-
if err := cd.config.Client.List(ctx, &catatalogList); err != nil {
46+
if err := i.config.Client.List(ctx, &catatalogList); err != nil {
4747
return nil, err
4848
}
4949
if len(catatalogList.Items) == 0 {
@@ -53,7 +53,7 @@ func (cd *CatalogDelete) Run(ctx context.Context) ([]olmv1.ClusterCatalog, error
5353
errs := make([]error, 0, len(catatalogList.Items))
5454
result := []olmv1.ClusterCatalog{}
5555
for _, catalog := range catatalogList.Items {
56-
if obj, err := cd.deleteCatalog(ctx, catalog.Name); err != nil {
56+
if obj, err := i.deleteCatalog(ctx, catalog.Name); err != nil {
5757
errs = append(errs, fmt.Errorf("failed deleting catalog %q: %w", catalog.Name, err))
5858
} else {
5959
result = append(result, obj)
@@ -63,17 +63,17 @@ func (cd *CatalogDelete) Run(ctx context.Context) ([]olmv1.ClusterCatalog, error
6363
return result, errors.Join(errs...)
6464
}
6565

66-
func (cd *CatalogDelete) deleteCatalog(ctx context.Context, name string) (olmv1.ClusterCatalog, error) {
66+
func (i *CatalogDelete) deleteCatalog(ctx context.Context, name string) (olmv1.ClusterCatalog, error) {
6767
op := &olmv1.ClusterCatalog{}
6868
op.SetName(name)
6969

70-
if cd.DryRun == DryRunAll {
71-
err := cd.config.Client.Delete(ctx, op, client.DryRunAll)
70+
if i.DryRun == DryRunAll {
71+
err := i.config.Client.Delete(ctx, op, client.DryRunAll)
7272
return *op, err
7373
}
74-
if err := cd.config.Client.Delete(ctx, op); err != nil {
74+
if err := i.config.Client.Delete(ctx, op); err != nil {
7575
return *op, err
7676
}
7777

78-
return *op, waitForDeletion(ctx, cd.config.Client, op)
78+
return *op, waitForDeletion(ctx, i.config.Client, op)
7979
}

internal/pkg/v1/action/catalog_get.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package action
22

33
import (
44
"context"
5-
"fmt"
65

76
"k8s.io/apimachinery/pkg/labels"
87
"k8s.io/apimachinery/pkg/types"
@@ -16,7 +15,6 @@ import (
1615
type CatalogInstalledGet struct {
1716
config *action.Configuration
1817
CatalogName string
19-
Selector labels.Selector
2018

2119
Selector string
2220

@@ -47,8 +45,12 @@ func (i *CatalogInstalledGet) Run(ctx context.Context) ([]olmv1.ClusterCatalog,
4745
// list
4846
var result olmv1.ClusterCatalogList
4947
listOpts := &client.ListOptions{}
50-
if i.Selector != nil {
51-
listOpts.LabelSelector = i.Selector
48+
if len(i.Selector) > 0 {
49+
selector, err := labels.Parse(i.Selector)
50+
if err != nil {
51+
return nil, err
52+
}
53+
listOpts.LabelSelector = selector
5254
}
5355
err := i.config.Client.List(ctx, &result, listOpts)
5456

internal/pkg/v1/action/catalog_search.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package action
22

33
import (
4-
"contz"
4+
"context"
55
"fmt"
66
"time"
77

@@ -16,8 +16,9 @@ import (
1616
)
1717

1818
type CatalogSearch struct {
19-
config *action.Configuration
20-
CatalogName string
19+
config *action.Configuration
20+
CatalogName string
21+
2122
OutputFormat string
2223
Selector string
2324
ListVersions bool

0 commit comments

Comments
 (0)