Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list-operands: include namespace in error message when package is not found #88

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 10 additions & 11 deletions pkg/action/operator_list_operands.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ func NewOperatorListOperands(cfg *Configuration) *OperatorListOperands {
}

func (o *OperatorListOperands) Run(ctx context.Context, packageName string) (*unstructured.UnstructuredList, error) {
opKey := types.NamespacedName{
Name: fmt.Sprintf("%s.%s", packageName, o.config.Namespace),
}

result, err := o.listAll(ctx, opKey)
result, err := o.listAll(ctx, packageName)
if err != nil {
return nil, err
}
Expand All @@ -40,13 +36,16 @@ func (o *OperatorListOperands) Run(ctx context.Context, packageName string) (*un
}

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

err := o.config.Client.Get(ctx, key, &operator)
operator := v1.Operator{}
err := o.config.Client.Get(ctx, opKey, &operator)
if err != nil {
if k8serrors.IsNotFound(err) {
return nil, fmt.Errorf("package %s not found", key.Name)
return nil, fmt.Errorf("package %q not found in namespace %q", packageName, o.config.Namespace)
}
return nil, err
}
Expand Down Expand Up @@ -132,8 +131,8 @@ func (o *OperatorListOperands) list(ctx context.Context, crdDesc v1alpha1.CRDDes
}

// ListAll wraps the above functions to provide a convenient command to go from package/namespace to custom resources.
func (o *OperatorListOperands) listAll(ctx context.Context, opKey types.NamespacedName) (*unstructured.UnstructuredList, error) {
operator, err := o.findOperator(ctx, opKey)
func (o *OperatorListOperands) listAll(ctx context.Context, packageName string) (*unstructured.UnstructuredList, error) {
operator, err := o.findOperator(ctx, packageName)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/action/operator_list_operands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ var _ = Describe("OperatorListOperands", func() {
It("should fail due to missing operator", func() {
lister := action.NewOperatorListOperands(&cfg)
_, err := lister.Run(context.TODO(), "missing")
Expect(err.Error()).To(ContainSubstring("package missing.etcd-namespace not found"))
Expect(err.Error()).To(ContainSubstring(`package "missing" not found in namespace "etcd-namespace"`))
})

It("should fail due to missing operator components", func() {
Expand Down
Loading