Skip to content

Commit 019ce08

Browse files
authored
list-operands: include namespace in error message when package is not found (#88)
Signed-off-by: Joe Lanford <[email protected]>
1 parent 07b1999 commit 019ce08

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

pkg/action/operator_list_operands.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ func NewOperatorListOperands(cfg *Configuration) *OperatorListOperands {
2727
}
2828

2929
func (o *OperatorListOperands) Run(ctx context.Context, packageName string) (*unstructured.UnstructuredList, error) {
30-
opKey := types.NamespacedName{
31-
Name: fmt.Sprintf("%s.%s", packageName, o.config.Namespace),
32-
}
33-
34-
result, err := o.listAll(ctx, opKey)
30+
result, err := o.listAll(ctx, packageName)
3531
if err != nil {
3632
return nil, err
3733
}
@@ -40,13 +36,16 @@ func (o *OperatorListOperands) Run(ctx context.Context, packageName string) (*un
4036
}
4137

4238
// FindOperator finds an operator object on-cluster provided a package and namespace.
43-
func (o *OperatorListOperands) findOperator(ctx context.Context, key types.NamespacedName) (*v1.Operator, error) {
44-
operator := v1.Operator{}
39+
func (o *OperatorListOperands) findOperator(ctx context.Context, packageName string) (*v1.Operator, error) {
40+
opKey := types.NamespacedName{
41+
Name: fmt.Sprintf("%s.%s", packageName, o.config.Namespace),
42+
}
4543

46-
err := o.config.Client.Get(ctx, key, &operator)
44+
operator := v1.Operator{}
45+
err := o.config.Client.Get(ctx, opKey, &operator)
4746
if err != nil {
4847
if k8serrors.IsNotFound(err) {
49-
return nil, fmt.Errorf("package %s not found", key.Name)
48+
return nil, fmt.Errorf("package %q not found in namespace %q", packageName, o.config.Namespace)
5049
}
5150
return nil, err
5251
}
@@ -132,8 +131,8 @@ func (o *OperatorListOperands) list(ctx context.Context, crdDesc v1alpha1.CRDDes
132131
}
133132

134133
// ListAll wraps the above functions to provide a convenient command to go from package/namespace to custom resources.
135-
func (o *OperatorListOperands) listAll(ctx context.Context, opKey types.NamespacedName) (*unstructured.UnstructuredList, error) {
136-
operator, err := o.findOperator(ctx, opKey)
134+
func (o *OperatorListOperands) listAll(ctx context.Context, packageName string) (*unstructured.UnstructuredList, error) {
135+
operator, err := o.findOperator(ctx, packageName)
137136
if err != nil {
138137
return nil, err
139138
}

pkg/action/operator_list_operands_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ var _ = Describe("OperatorListOperands", func() {
131131
It("should fail due to missing operator", func() {
132132
lister := action.NewOperatorListOperands(&cfg)
133133
_, err := lister.Run(context.TODO(), "missing")
134-
Expect(err.Error()).To(ContainSubstring("package missing.etcd-namespace not found"))
134+
Expect(err.Error()).To(ContainSubstring(`package "missing" not found in namespace "etcd-namespace"`))
135135
})
136136

137137
It("should fail due to missing operator components", func() {

0 commit comments

Comments
 (0)