Skip to content

Commit e8cfd1e

Browse files
committed
list-available: show channel and latest version, optional package name arg; other minor fixes
1 parent 0d82ca4 commit e8cfd1e

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

internal/cmd/operator_list_available.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ func newOperatorListAvailableCmd(cfg *action.Configuration) *cobra.Command {
4646
})
4747

4848
tw := tabwriter.NewWriter(os.Stdout, 3, 4, 2, ' ', 0)
49-
_, _ = fmt.Fprintf(tw, "NAME\tCATALOG\tAGE\n")
49+
_, _ = fmt.Fprintf(tw, "NAME\tCATALOG\tCHANNEL\tLATEST CSV\tAGE\n")
5050
for _, op := range operators {
5151
age := time.Now().Sub(op.CreationTimestamp.Time)
52-
_, _ = fmt.Fprintf(tw, "%s\t%s\t%s\n", op.Name, op.Status.CatalogSourceDisplayName, duration.HumanDuration(age))
52+
for _, ch := range op.Status.Channels {
53+
_, _ = fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%s\n", op.Name, op.Status.CatalogSourceDisplayName, ch.Name, ch.CurrentCSV, duration.HumanDuration(age))
54+
}
5355
}
5456
_ = tw.Flush()
5557
},

internal/pkg/action/operator_install.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (i *OperatorInstall) Run(ctx context.Context) (*v1alpha1.ClusterServiceVers
7878
}
7979
log.Printf("operatorgroup %q created", og.Name)
8080
} else {
81-
return nil, fmt.Errorf("namespace %q has no existing operator group", i.config.Namespace)
81+
return nil, fmt.Errorf("namespace %q has no existing operator group; use --create-operator-group to create one automatically", i.config.Namespace)
8282
}
8383
} else if err := i.validateOperatorGroup(*og, supported); err != nil {
8484
return nil, err
@@ -302,9 +302,3 @@ func (i *OperatorInstall) getCSV(ctx context.Context, ip *v1alpha1.InstallPlan)
302302
}
303303
return csv, nil
304304
}
305-
306-
func (i *OperatorInstall) cleanup(ctx context.Context, sub *v1alpha1.Subscription) {
307-
if err := i.config.Client.Delete(ctx, sub); err != nil {
308-
log.Printf("delete subscription %q: %v", sub.Name, err)
309-
}
310-
}

internal/pkg/action/operator_list_available.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,27 @@ func NewOperatorListAvailable(cfg *Configuration) *OperatorListAvailable {
2626

2727
func (l *OperatorListAvailable) Run(ctx context.Context) ([]v1.PackageManifest, error) {
2828
if l.Package != "" {
29-
return nil, fmt.Errorf("listing all versions of a package is not currently supported")
29+
pm, err := l.getPackageManifestByName(ctx, l.Package)
30+
if err != nil {
31+
return nil, err
32+
}
33+
return []v1.PackageManifest{*pm}, nil
3034
}
3135
return l.getAllPackageManifests(ctx)
3236
}
3337

38+
func (l *OperatorListAvailable) getPackageManifestByName(ctx context.Context, packageName string) (*v1.PackageManifest, error) {
39+
pm := v1.PackageManifest{}
40+
pmKey := types.NamespacedName{
41+
Namespace: l.config.Namespace,
42+
Name: packageName,
43+
}
44+
if err := l.config.Client.Get(ctx, pmKey, &pm); err != nil {
45+
return nil, err
46+
}
47+
return &pm, nil
48+
}
49+
3450
func (l *OperatorListAvailable) getAllPackageManifests(ctx context.Context) ([]v1.PackageManifest, error) {
3551
labelSelector := client.MatchingLabels{}
3652
if l.Catalog.Name != "" {

internal/pkg/action/operator_uninstall.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ func (u *OperatorUninstall) Run(ctx context.Context) error {
5656
}
5757
log.Printf("subscription %q deleted", sub.Name)
5858

59-
if sub.Status.CurrentCSV != sub.Status.InstalledCSV {
59+
if sub.Status.CurrentCSV != "" && sub.Status.CurrentCSV != sub.Status.InstalledCSV {
6060
if err := u.deleteCSVandCRDs(ctx, sub.Status.CurrentCSV, true); err != nil {
6161
return err
6262
}
6363
}
64-
if err := u.deleteCSVandCRDs(ctx, sub.Status.InstalledCSV, false); err != nil {
65-
return err
64+
if sub.Status.InstalledCSV != "" {
65+
if err := u.deleteCSVandCRDs(ctx, sub.Status.InstalledCSV, false); err != nil {
66+
return err
67+
}
6668
}
6769

6870
if u.DeleteOperatorGroup {

internal/pkg/action/operator_upgrade.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"k8s.io/apimachinery/pkg/types"
1111
"k8s.io/apimachinery/pkg/util/wait"
1212
"sigs.k8s.io/controller-runtime/pkg/client"
13-
14-
"github.com/joelanford/kubectl-operator/internal/pkg/log"
1513
)
1614

1715
type OperatorUpgrade struct {
@@ -127,9 +125,3 @@ func (u *OperatorUpgrade) getCSV(ctx context.Context, ip *v1alpha1.InstallPlan)
127125
}
128126
return csv, nil
129127
}
130-
131-
func (u *OperatorUpgrade) cleanup(ctx context.Context, sub *v1alpha1.Subscription) {
132-
if err := u.config.Client.Delete(ctx, sub); err != nil {
133-
log.Printf("delete subscription %q: %v", sub.Name, err)
134-
}
135-
}

0 commit comments

Comments
 (0)