Skip to content

Commit

Permalink
Merge pull request #67 from qinqon/udpn-print-errors
Browse files Browse the repository at this point in the history
udpn: Add missing error wrapping
  • Loading branch information
kubevirt-bot authored Sep 12, 2024
2 parents 74c7ef7 + f75faab commit 49ee8d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/udn/primary_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ func FindPrimaryNetwork(ctx context.Context,
namespace string) (*v1.NetworkAttachmentDefinition, error) {
nadList := v1.NetworkAttachmentDefinitionList{}
if err := cli.List(ctx, &nadList, client.InNamespace(namespace)); err != nil {
return nil, fmt.Errorf("failed listing nads for pod namespace %q", namespace)
return nil, fmt.Errorf("failed listing nads for pod namespace %q: %w", namespace, err)
}

for _, nad := range nadList.Items {
netConfig, err := config.NewConfig(nad.Spec.Config)
if err != nil {
return nil, fmt.Errorf("failed to extract the relevant NAD information")
return nil, fmt.Errorf("failed to extract the relevant NAD information: %w", err)
}
if netConfig.Role == config.NetworkRolePrimary {
return ptr.To(nad), nil
Expand Down
5 changes: 3 additions & 2 deletions pkg/vminetworkscontroller/vmi_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ var _ = Describe("VMI IPAM controller", Serial, func() {
vmiReconciler := NewVMIReconciler(mgr)
if config.expectedError != nil {
_, err := vmiReconciler.Reconcile(context.Background(), controllerruntime.Request{NamespacedName: vmiKey})
Expect(err).To(MatchError(config.expectedError))
Expect(err).To(MatchError(config.expectedError.Error()))
} else {
Expect(
vmiReconciler.Reconcile(context.Background(), controllerruntime.Request{NamespacedName: vmiKey}),
Expand Down Expand Up @@ -198,7 +198,8 @@ var _ = Describe("VMI IPAM controller", Serial, func() {
inputNADs: []*nadv1.NetworkAttachmentDefinition{
dummyNADWrongFormat(nadName),
},
expectedError: fmt.Errorf("failed to extract the relevant NAD information"),
expectedError: fmt.Errorf("failed to extract the relevant NAD information: " +
"failed to extract CNI configuration from NAD: invalid character 'h' in literal true (expecting 'r')"),
}),
Entry("the associated VMI exists but points to a NAD that doesn't exist", testConfig{
inputVM: dummyVM(dummyVMISpec(nadName)),
Expand Down

0 comments on commit 49ee8d7

Please sign in to comment.