Skip to content

Commit 5d905c1

Browse files
committed
fixing tests
Signed-off-by: Ankita Thomas <[email protected]>
1 parent 1900b43 commit 5d905c1

23 files changed

+196
-248
lines changed

internal/cmd/internal/olmv1/catalog_create.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import (
55

66
"github.com/spf13/cobra"
77
"github.com/spf13/pflag"
8+
"k8s.io/apimachinery/pkg/runtime/schema"
9+
"k8s.io/apimachinery/pkg/util/errors"
10+
11+
olmv1 "github.com/operator-framework/operator-controller/api/v1"
812

913
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
1014
v1action "github.com/operator-framework/kubectl-operator/internal/pkg/v1/action"
1115
"github.com/operator-framework/kubectl-operator/pkg/action"
12-
13-
olmv1 "github.com/operator-framework/operator-controller/api/v1"
14-
"k8s.io/apimachinery/pkg/runtime/schema"
15-
"k8s.io/apimachinery/pkg/util/errors"
1616
)
1717

1818
type catalogCreateOptions struct {
@@ -40,6 +40,10 @@ func NewCatalogCreateCmd(cfg *action.Configuration) *cobra.Command {
4040
}
4141
i.DryRun = opts.DryRun
4242
i.Output = opts.Output
43+
i.AvailabilityMode = opts.AvailabilityMode
44+
i.Priority = opts.Priority
45+
i.Labels = opts.Labels
46+
i.PollIntervalMinutes = opts.PollIntervalMinutes
4347
catalogObj, err := i.Run(cmd.Context())
4448
if err != nil {
4549
log.Fatalf("failed to create catalog %q: %v\n", i.CatalogName, err)

internal/cmd/internal/olmv1/catalog_delete.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package olmv1
33
import (
44
"github.com/spf13/cobra"
55
"github.com/spf13/pflag"
6+
"k8s.io/apimachinery/pkg/runtime/schema"
7+
8+
olmv1 "github.com/operator-framework/operator-controller/api/v1"
69

710
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
811
v1action "github.com/operator-framework/kubectl-operator/internal/pkg/v1/action"
912
"github.com/operator-framework/kubectl-operator/pkg/action"
10-
11-
olmv1 "github.com/operator-framework/operator-controller/api/v1"
12-
"k8s.io/apimachinery/pkg/runtime/schema"
1313
)
1414

1515
type catalogDeleteOptions struct {

internal/cmd/internal/olmv1/catalog_get.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package olmv1
22

33
import (
44
"github.com/spf13/cobra"
5+
"k8s.io/apimachinery/pkg/runtime/schema"
6+
7+
olmv1 "github.com/operator-framework/operator-controller/api/v1"
58

69
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
710
v1action "github.com/operator-framework/kubectl-operator/internal/pkg/v1/action"
811
"github.com/operator-framework/kubectl-operator/pkg/action"
9-
10-
olmv1 "github.com/operator-framework/operator-controller/api/v1"
11-
"k8s.io/apimachinery/pkg/runtime/schema"
1212
)
1313

1414
// NewCatalogInstalledGetCmd handles get commands in the form of:
@@ -18,7 +18,7 @@ import (
1818
func NewCatalogInstalledGetCmd(cfg *action.Configuration) *cobra.Command {
1919
i := v1action.NewCatalogInstalledGet(cfg)
2020
i.Logf = log.Printf
21-
catalogGetOptions := getOptions{}
21+
opts := getOptions{}
2222

2323
cmd := &cobra.Command{
2424
Use: "catalog [catalog_name]",
@@ -30,12 +30,12 @@ func NewCatalogInstalledGetCmd(cfg *action.Configuration) *cobra.Command {
3030
i.CatalogName = args[0]
3131
}
3232
var err error
33-
switch catalogGetOptions.Output {
33+
switch opts.Output {
3434
case "yaml", "json", "":
3535
default:
36-
log.Fatalf("unrecognized output format %s", catalogGetOptions.Output)
36+
log.Fatalf("unrecognized output format %s", opts.Output)
3737
}
38-
i.Selector = catalogGetOptions.Selector
38+
i.Selector = opts.Selector
3939
installedCatalogs, err := i.Run(cmd.Context())
4040
if err != nil {
4141
log.Fatalf("failed getting installed catalog(s): %v", err)
@@ -45,10 +45,10 @@ func NewCatalogInstalledGetCmd(cfg *action.Configuration) *cobra.Command {
4545
installedCatalogs[i].GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{Group: olmv1.GroupVersion.Group,
4646
Version: olmv1.GroupVersion.Version, Kind: "ClusterCatalog"})
4747
}
48-
printFormattedCatalogs(catalogGetOptions.Output, installedCatalogs...)
48+
printFormattedCatalogs(opts.Output, installedCatalogs...)
4949
},
5050
}
51-
bindGetFlags(cmd.Flags(), &catalogGetOptions)
51+
bindGetFlags(cmd.Flags(), &opts)
5252

5353
return cmd
5454
}

internal/cmd/internal/olmv1/catalog_update.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ package olmv1
22

33
import (
44
"github.com/spf13/cobra"
5-
"github.com/spf13/pflag"
5+
"k8s.io/apimachinery/pkg/runtime/schema"
6+
"k8s.io/apimachinery/pkg/util/errors"
7+
8+
olmv1 "github.com/operator-framework/operator-controller/api/v1"
69

710
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
811
v1action "github.com/operator-framework/kubectl-operator/internal/pkg/v1/action"
912
"github.com/operator-framework/kubectl-operator/pkg/action"
10-
11-
olmv1 "github.com/operator-framework/operator-controller/api/v1"
12-
"k8s.io/apimachinery/pkg/runtime/schema"
13-
"k8s.io/apimachinery/pkg/util/errors"
1413
)
1514

1615
type catalogUpdateOptions struct {
1716
mutableCatalogOptions
17+
updateDefaultFieldOptions
1818
dryRunOptions
1919
}
2020

@@ -42,7 +42,9 @@ func NewCatalogUpdateCmd(cfg *action.Configuration) *cobra.Command {
4242
if cmd.Flags().Changed("labels") {
4343
i.Labels = opts.Labels
4444
}
45+
i.ImageRef = opts.Image
4546
i.AvailabilityMode = opts.AvailabilityMode
47+
i.IgnoreUnset = opts.IgnoreUnset
4648
i.DryRun = opts.DryRun
4749
i.Output = opts.Output
4850
catalogObj, err := i.Run(cmd.Context())
@@ -64,18 +66,13 @@ func NewCatalogUpdateCmd(cfg *action.Configuration) *cobra.Command {
6466
printFormattedCatalogs(i.Output, *catalogObj)
6567
},
6668
}
67-
bindCatalogUpdateFlags(cmd.Flags(), i)
6869
bindMutableCatalogFlags(cmd.Flags(), &opts.mutableCatalogOptions)
70+
bindUpdateFieldOptions(cmd.Flags(), &opts.updateDefaultFieldOptions, "clustercatalog")
6971
bindDryRunFlags(cmd.Flags(), &opts.dryRunOptions)
7072

7173
return cmd
7274
}
7375

74-
func bindCatalogUpdateFlags(fs *pflag.FlagSet, i *v1action.CatalogUpdate) {
75-
fs.StringVar(&i.ImageRef, "image", "", "image reference for the catalog source. Leave unset to retain the current image.")
76-
fs.BoolVar(&i.IgnoreUnset, "ignore-unset", true, "set to false to revert all values not specifically set with flags in the command to their default as defined by the clustercatalog customresoucedefinition.")
77-
}
78-
7976
func (o *catalogUpdateOptions) validate() error {
8077
var errs []error
8178
if err := o.dryRunOptions.validate(); err != nil {

internal/cmd/internal/olmv1/extension_delete.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package olmv1
33
import (
44
"github.com/spf13/cobra"
55
"github.com/spf13/pflag"
6+
"k8s.io/apimachinery/pkg/runtime/schema"
7+
8+
olmv1 "github.com/operator-framework/operator-controller/api/v1"
69

710
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
811
v1action "github.com/operator-framework/kubectl-operator/internal/pkg/v1/action"
912
"github.com/operator-framework/kubectl-operator/pkg/action"
10-
11-
olmv1 "github.com/operator-framework/operator-controller/api/v1"
12-
"k8s.io/apimachinery/pkg/runtime/schema"
1313
)
1414

1515
type extensionDeleteOptions struct {

internal/cmd/internal/olmv1/extension_get.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package olmv1
22

33
import (
44
"github.com/spf13/cobra"
5+
"k8s.io/apimachinery/pkg/labels"
6+
"k8s.io/apimachinery/pkg/runtime/schema"
7+
8+
olmv1 "github.com/operator-framework/operator-controller/api/v1"
59

610
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
711
v1action "github.com/operator-framework/kubectl-operator/internal/pkg/v1/action"
812
"github.com/operator-framework/kubectl-operator/pkg/action"
9-
"k8s.io/apimachinery/pkg/labels"
10-
11-
olmv1 "github.com/operator-framework/operator-controller/api/v1"
12-
"k8s.io/apimachinery/pkg/runtime/schema"
1313
)
1414

1515
// NewExtensionInstalledGetCmd handles get commands in the form of:
@@ -19,7 +19,7 @@ import (
1919
func NewExtensionInstalledGetCmd(cfg *action.Configuration) *cobra.Command {
2020
i := v1action.NewExtensionInstalledGet(cfg)
2121
i.Logf = log.Printf
22-
extensionGetOptions := getOptions{}
22+
opts := getOptions{}
2323

2424
cmd := &cobra.Command{
2525
Use: "extension [extension_name]",
@@ -31,10 +31,10 @@ func NewExtensionInstalledGetCmd(cfg *action.Configuration) *cobra.Command {
3131
i.ExtensionName = args[0]
3232
}
3333
var err error
34-
if len(extensionGetOptions.Selector) > 0 {
35-
i.Selector, err = labels.Parse(extensionGetOptions.Selector)
34+
if len(opts.Selector) > 0 {
35+
i.Selector, err = labels.Parse(opts.Selector)
3636
if err != nil {
37-
log.Fatalf("unable to parse selector %s: %v", extensionGetOptions.Selector, err)
37+
log.Fatalf("unable to parse selector %s: %v", opts.Selector, err)
3838
}
3939
}
4040
installedExtensions, err := i.Run(cmd.Context())
@@ -46,10 +46,10 @@ func NewExtensionInstalledGetCmd(cfg *action.Configuration) *cobra.Command {
4646
installedExtensions[i].GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{Group: olmv1.GroupVersion.Group,
4747
Version: olmv1.GroupVersion.Version, Kind: olmv1.ClusterExtensionKind})
4848
}
49-
printFormattedExtensions(extensionGetOptions.Output, installedExtensions...)
49+
printFormattedExtensions(opts.Output, installedExtensions...)
5050
},
5151
}
52-
bindGetFlags(cmd.Flags(), &extensionGetOptions)
52+
bindGetFlags(cmd.Flags(), &opts)
5353

5454
return cmd
5555
}

internal/cmd/internal/olmv1/extension_install.go

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

66
"github.com/spf13/cobra"
77
"github.com/spf13/pflag"
8+
"k8s.io/apimachinery/pkg/runtime/schema"
9+
"k8s.io/apimachinery/pkg/util/errors"
10+
11+
olmv1 "github.com/operator-framework/operator-controller/api/v1"
812

913
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
1014
v1action "github.com/operator-framework/kubectl-operator/internal/pkg/v1/action"
1115
"github.com/operator-framework/kubectl-operator/pkg/action"
12-
13-
olmv1 "github.com/operator-framework/operator-controller/api/v1"
14-
"k8s.io/apimachinery/pkg/runtime/schema"
15-
"k8s.io/apimachinery/pkg/util/errors"
1616
)
1717

1818
type extensionInstallOptions struct {
@@ -58,7 +58,6 @@ func NewExtensionInstallCmd(cfg *action.Configuration) *cobra.Command {
5858
extObj.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{Group: olmv1.GroupVersion.Group,
5959
Version: olmv1.GroupVersion.Version, Kind: olmv1.ClusterExtensionKind})
6060
printFormattedExtensions(i.Output, *extObj)
61-
6261
},
6362
}
6463
bindExtensionInstallFlags(cmd.Flags(), i)

internal/cmd/internal/olmv1/extension_update.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ package olmv1
22

33
import (
44
"github.com/spf13/cobra"
5-
"github.com/spf13/pflag"
5+
"k8s.io/apimachinery/pkg/runtime/schema"
6+
"k8s.io/apimachinery/pkg/util/errors"
7+
8+
olmv1 "github.com/operator-framework/operator-controller/api/v1"
69

710
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
811
v1action "github.com/operator-framework/kubectl-operator/internal/pkg/v1/action"
912
"github.com/operator-framework/kubectl-operator/pkg/action"
10-
11-
olmv1 "github.com/operator-framework/operator-controller/api/v1"
12-
"k8s.io/apimachinery/pkg/runtime/schema"
13-
"k8s.io/apimachinery/pkg/util/errors"
1413
)
1514

1615
type extensionUpdateOptions struct {
1716
dryRunOptions
1817
mutableExtensionOptions
18+
updateDefaultFieldOptions
1919
}
2020

2121
// NewExtensionUpdateCmd allows updating a selected operator
@@ -39,6 +39,7 @@ func NewExtensionUpdateCmd(cfg *action.Configuration) *cobra.Command {
3939
i.UpgradeConstraintPolicy = opts.UpgradeConstraintPolicy
4040
i.CRDUpgradeSafetyEnforcement = opts.CRDUpgradeSafetyEnforcement
4141
i.CatalogSelector = opts.ParsedSelector
42+
i.IgnoreUnset = opts.IgnoreUnset
4243
i.DryRun = opts.DryRun
4344
i.Output = opts.Output
4445
extObj, err := i.Run(cmd.Context())
@@ -59,17 +60,13 @@ func NewExtensionUpdateCmd(cfg *action.Configuration) *cobra.Command {
5960
printFormattedExtensions(i.Output, *extObj)
6061
},
6162
}
62-
bindExtensionUpdateFlags(cmd.Flags(), i)
6363
bindMutableExtensionFlags(cmd.Flags(), &opts.mutableExtensionOptions)
64+
bindUpdateFieldOptions(cmd.Flags(), &opts.updateDefaultFieldOptions, "clusterextension")
6465
bindDryRunFlags(cmd.Flags(), &opts.dryRunOptions)
6566

6667
return cmd
6768
}
6869

69-
func bindExtensionUpdateFlags(fs *pflag.FlagSet, i *v1action.ExtensionUpdate) {
70-
fs.BoolVar(&i.IgnoreUnset, "ignore-unset", true, "set to false to revert all values not specifically set with flags in the command to their default as defined by the clusterextension customresoucedefinition.")
71-
}
72-
7370
func (o *extensionUpdateOptions) validate() error {
7471
var errs []error
7572
if err := o.dryRunOptions.validate(); err != nil {

internal/cmd/internal/olmv1/flags.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ func bindGetFlags(fs *pflag.FlagSet, o *getOptions) {
2424
fs.StringVarP(&o.Selector, "selector", "l", "", "selector (label query) to filter on, "+
2525
"supports '=', '==', '!=', 'in', 'notin'.(e.g. -l key1=value1,key2=value2,key3 "+
2626
"in (value3)). Matching objects must satisfy all of the specified label constraints.")
27-
2827
}
2928

3029
type dryRunOptions struct {
@@ -50,6 +49,14 @@ func (o *dryRunOptions) validate() error {
5049
return errors.NewAggregate(errs)
5150
}
5251

52+
type updateDefaultFieldOptions struct {
53+
IgnoreUnset bool
54+
}
55+
56+
func bindUpdateFieldOptions(fs *pflag.FlagSet, o *updateDefaultFieldOptions, resourceType string) {
57+
fs.BoolVar(&o.IgnoreUnset, "ignore-unset", true, fmt.Sprintf("set to false to revert all values not specifically set with flags in the command to their default as defined by the %s customresoucedefinition.", resourceType))
58+
}
59+
5360
type mutableExtensionOptions struct {
5461
Channels []string
5562
Version string
@@ -76,7 +83,7 @@ func bindMutableExtensionFlags(fs *pflag.FlagSet, o *mutableExtensionOptions) {
7683
"in (value3)). Matching objects must satisfy all of the specified label constraints.")
7784
}
7885

79-
func (o mutableExtensionOptions) validate() error {
86+
func (o *mutableExtensionOptions) validate() error {
8087
var errs []error
8188
if len(o.Version) > 0 {
8289
if _, err := semver.ParseRange(o.Version); err != nil {
@@ -121,9 +128,10 @@ func bindMutableCatalogFlags(fs *pflag.FlagSet, o *mutableCatalogOptions) {
121128
fs.IntVar(&o.PollIntervalMinutes, "source-poll-interval-minutes", 0, "the interval in minutes to poll the catalog's source image for new content."+
122129
" Only valid for tag based source image references. Set to 0 or -1 to disable polling.")
123130
fs.StringToStringVar(&o.Labels, "labels", map[string]string{}, "labels to add to the catalog. Set a label's value as empty to remove it.")
131+
fs.StringVar(&o.Image, "image", "", "image reference for the catalog source. Leave unset to retain the current image.")
124132
}
125133

126-
func (o mutableCatalogOptions) validate() error {
134+
func (o *mutableCatalogOptions) validate() error {
127135
var errs []error
128136
switch o.AvailabilityMode {
129137
case "":

0 commit comments

Comments
 (0)