diff --git a/cli/dpservice-cli/cmd/capture_start.go b/cli/dpservice-cli/cmd/capture_start.go index 26dbc204..07ede8c2 100644 --- a/cli/dpservice-cli/cmd/capture_start.go +++ b/cli/dpservice-cli/cmd/capture_start.go @@ -148,7 +148,7 @@ func RunCaptureStart(ctx context.Context, dpdkClientFactory DPDKClientFactory, r }, }) - if err != nil && capture.Status.Code == 0 { + if err != nil { return fmt.Errorf("error initializing packet capturing: %w", err) } diff --git a/cli/dpservice-cli/cmd/capture_status.go b/cli/dpservice-cli/cmd/capture_status.go index c7a6686a..74a72ec9 100644 --- a/cli/dpservice-cli/cmd/capture_status.go +++ b/cli/dpservice-cli/cmd/capture_status.go @@ -46,7 +46,7 @@ func RunCaptureStatus( }() capture, err := client.CaptureStatus(ctx) - if err != nil && capture.Status.Code == 0 { + if err != nil { return fmt.Errorf("error checking initialization status: %w", err) } diff --git a/cli/dpservice-cli/cmd/capture_stop.go b/cli/dpservice-cli/cmd/capture_stop.go index 3b32bd10..d1f6191c 100644 --- a/cli/dpservice-cli/cmd/capture_stop.go +++ b/cli/dpservice-cli/cmd/capture_stop.go @@ -41,7 +41,7 @@ func RunCaptureStop(ctx context.Context, dpdkClientFactory DPDKClientFactory, re captureStop, err := dpdkClient.CaptureStop(ctx) - if err != nil && captureStop.Status.Code == 0 { + if err != nil { return fmt.Errorf("error stopping capturing: %w", err) } diff --git a/cli/dpservice-cli/cmd/common.go b/cli/dpservice-cli/cmd/common.go index 554e359c..292228e7 100644 --- a/cli/dpservice-cli/cmd/common.go +++ b/cli/dpservice-cli/cmd/common.go @@ -158,12 +158,6 @@ func (o *RendererOptions) RenderObject(operation string, w io.Writer, obj api.Ob } func (o *RendererOptions) RenderList(operation string, w io.Writer, list api.List) error { - if list.GetStatus().Code != 0 { - operation = fmt.Sprintf("server error: %d, %s", list.GetStatus().Code, list.GetStatus().Message) - if o.Output == "table" { - o.Output = "name" - } - } renderer, err := o.NewRenderer(operation, w) if err != nil { return fmt.Errorf("error creating renderer: %w", err) @@ -171,9 +165,6 @@ func (o *RendererOptions) RenderList(operation string, w io.Writer, list api.Lis if err := renderer.Render(list); err != nil { return fmt.Errorf("error rendering %s: %w", list.GetItems()[0].GetKind(), err) } - if list.GetStatus().Code != 0 { - return fmt.Errorf(strconv.Itoa(apierrors.SERVER_ERROR)) - } return nil } diff --git a/cli/dpservice-cli/cmd/create_firewall_rule.go b/cli/dpservice-cli/cmd/create_firewall_rule.go index ab217799..0ded6370 100644 --- a/cli/dpservice-cli/cmd/create_firewall_rule.go +++ b/cli/dpservice-cli/cmd/create_firewall_rule.go @@ -199,7 +199,7 @@ func RunCreateFirewallRule(ctx context.Context, dpdkClientFactory DPDKClientFact Filter: protocolFilter.Filter}, }, }) - if err != nil && fwrule.Status.Code == 0 { + if err != nil { return fmt.Errorf("error creating firewall rule: %w", err) } diff --git a/cli/dpservice-cli/cmd/create_interface.go b/cli/dpservice-cli/cmd/create_interface.go index 302acbd1..e000da80 100644 --- a/cli/dpservice-cli/cmd/create_interface.go +++ b/cli/dpservice-cli/cmd/create_interface.go @@ -97,7 +97,7 @@ func RunCreateInterface(ctx context.Context, dpdkClientFactory DPDKClientFactory Metering: &api.MeteringParams{TotalRate: opts.TotalMeterRate, PublicRate: opts.PublicMeterRate}, }, }) - if err != nil && iface.Status.Code == 0 { + if err != nil { return fmt.Errorf("error creating interface: %w", err) } diff --git a/cli/dpservice-cli/cmd/create_loadbalancer.go b/cli/dpservice-cli/cmd/create_loadbalancer.go index 3f91d963..4ae9697e 100644 --- a/cli/dpservice-cli/cmd/create_loadbalancer.go +++ b/cli/dpservice-cli/cmd/create_loadbalancer.go @@ -93,7 +93,7 @@ func RunCreateLoadBalancer(ctx context.Context, dpdkClientFactory DPDKClientFact Lbports: ports, }, }) - if err != nil && lb.Status.Code == 0 { + if err != nil { return fmt.Errorf("error creating loadbalancer: %w", err) } diff --git a/cli/dpservice-cli/cmd/create_loadbalancer_prefix.go b/cli/dpservice-cli/cmd/create_loadbalancer_prefix.go index 674f87e3..800ef8b6 100644 --- a/cli/dpservice-cli/cmd/create_loadbalancer_prefix.go +++ b/cli/dpservice-cli/cmd/create_loadbalancer_prefix.go @@ -87,7 +87,7 @@ func RunCreateLoadBalancerPrefix( Prefix: opts.Prefix, }, }) - if err != nil && lbprefix.Status.Code == 0 { + if err != nil { return fmt.Errorf("error creating loadbalancer prefix: %w", err) } diff --git a/cli/dpservice-cli/cmd/create_loadbalancer_target.go b/cli/dpservice-cli/cmd/create_loadbalancer_target.go index 10c49f0c..2b11bb4a 100644 --- a/cli/dpservice-cli/cmd/create_loadbalancer_target.go +++ b/cli/dpservice-cli/cmd/create_loadbalancer_target.go @@ -84,7 +84,7 @@ func RunCreateLoadBalancerTarget( LoadBalancerTargetMeta: api.LoadBalancerTargetMeta{LoadbalancerID: opts.LoadBalancerID}, Spec: api.LoadBalancerTargetSpec{TargetIP: &opts.TargetIP}, }) - if err != nil && lbtarget.Status.Code == 0 { + if err != nil { return fmt.Errorf("error creating loadbalancer target: %w", err) } diff --git a/cli/dpservice-cli/cmd/create_nat.go b/cli/dpservice-cli/cmd/create_nat.go index 5bda9c62..0122a082 100644 --- a/cli/dpservice-cli/cmd/create_nat.go +++ b/cli/dpservice-cli/cmd/create_nat.go @@ -85,7 +85,7 @@ func RunCreateNat(ctx context.Context, dpdkClientFactory DPDKClientFactory, rend MaxPort: opts.MaxPort, }, }) - if err != nil && nat.Status.Code == 0 { + if err != nil { return fmt.Errorf("error creating nat: %w", err) } diff --git a/cli/dpservice-cli/cmd/create_neighbor_nat.go b/cli/dpservice-cli/cmd/create_neighbor_nat.go index 03b5b31f..42f4d251 100644 --- a/cli/dpservice-cli/cmd/create_neighbor_nat.go +++ b/cli/dpservice-cli/cmd/create_neighbor_nat.go @@ -89,7 +89,7 @@ func RunCreateNeighborNat(ctx context.Context, dpdkClientFactory DPDKClientFacto } nnat, err := client.CreateNeighborNat(ctx, neigbhorNat) - if err != nil && nnat.Status.Code == 0 { + if err != nil { return fmt.Errorf("error creating neighbor nat: %w", err) } diff --git a/cli/dpservice-cli/cmd/create_prefix.go b/cli/dpservice-cli/cmd/create_prefix.go index 4ced9387..197e053d 100644 --- a/cli/dpservice-cli/cmd/create_prefix.go +++ b/cli/dpservice-cli/cmd/create_prefix.go @@ -87,7 +87,7 @@ func RunCreatePrefix( Prefix: opts.Prefix, }, }) - if err != nil && prefix.Status.Code == 0 { + if err != nil { return fmt.Errorf("error creating prefix: %w", err) } diff --git a/cli/dpservice-cli/cmd/create_route.go b/cli/dpservice-cli/cmd/create_route.go index 1cb987c2..22f6ea34 100644 --- a/cli/dpservice-cli/cmd/create_route.go +++ b/cli/dpservice-cli/cmd/create_route.go @@ -90,7 +90,7 @@ func RunCreateRoute( IP: &opts.NextHopIP, }}, }) - if err != nil && route.Status.Code == 0 { + if err != nil { return fmt.Errorf("error creating route: %w", err) } diff --git a/cli/dpservice-cli/cmd/create_virtualip.go b/cli/dpservice-cli/cmd/create_virtualip.go index 2fdbbe4e..b7983213 100644 --- a/cli/dpservice-cli/cmd/create_virtualip.go +++ b/cli/dpservice-cli/cmd/create_virtualip.go @@ -84,7 +84,7 @@ func RunCreateVirtualIP( IP: &opts.Vip, }, }) - if err != nil && virtualIP.Status.Code == 0 { + if err != nil { return fmt.Errorf("error creating virtual ip: %w", err) } diff --git a/cli/dpservice-cli/cmd/delete_firewall_rule.go b/cli/dpservice-cli/cmd/delete_firewall_rule.go index 1f723055..d3123025 100644 --- a/cli/dpservice-cli/cmd/delete_firewall_rule.go +++ b/cli/dpservice-cli/cmd/delete_firewall_rule.go @@ -69,7 +69,7 @@ func RunDeleteFirewallRule(ctx context.Context, dpdkClientFactory DPDKClientFact defer DpdkClose(cleanup) fwrule, err := client.DeleteFirewallRule(ctx, opts.InterfaceID, opts.RuleID) - if err != nil && fwrule.Status.Code == 0 { + if err != nil { return fmt.Errorf("error deleting firewall rule: %w", err) } diff --git a/cli/dpservice-cli/cmd/delete_interface.go b/cli/dpservice-cli/cmd/delete_interface.go index e1894d09..b5543aac 100644 --- a/cli/dpservice-cli/cmd/delete_interface.go +++ b/cli/dpservice-cli/cmd/delete_interface.go @@ -67,7 +67,7 @@ func RunDeleteInterface(ctx context.Context, dpdkClientFactory DPDKClientFactory defer DpdkClose(cleanup) iface, err := client.DeleteInterface(ctx, opts.ID) - if err != nil && iface.Status.Code == 0 { + if err != nil { return fmt.Errorf("error deleting interface: %w", err) } diff --git a/cli/dpservice-cli/cmd/delete_loadbalancer.go b/cli/dpservice-cli/cmd/delete_loadbalancer.go index c05422ce..db9b3b83 100644 --- a/cli/dpservice-cli/cmd/delete_loadbalancer.go +++ b/cli/dpservice-cli/cmd/delete_loadbalancer.go @@ -67,7 +67,7 @@ func RunDeleteLoadBalancer(ctx context.Context, dpdkClientFactory DPDKClientFact defer DpdkClose(cleanup) lb, err := client.DeleteLoadBalancer(ctx, opts.ID) - if err != nil && lb.Status.Code == 0 { + if err != nil { return fmt.Errorf("error deleting loadbalancer: %w", err) } diff --git a/cli/dpservice-cli/cmd/delete_loadbalancer_prefix.go b/cli/dpservice-cli/cmd/delete_loadbalancer_prefix.go index 08523b7d..6ec33692 100644 --- a/cli/dpservice-cli/cmd/delete_loadbalancer_prefix.go +++ b/cli/dpservice-cli/cmd/delete_loadbalancer_prefix.go @@ -71,7 +71,7 @@ func RunDeleteLoadBalancerPrefix(ctx context.Context, dpdkClientFactory DPDKClie defer DpdkClose(cleanup) lbprefix, err := client.DeleteLoadBalancerPrefix(ctx, opts.InterfaceID, &opts.Prefix) - if err != nil && lbprefix.Status.Code == 0 { + if err != nil { return fmt.Errorf("error deleting loadbalancer prefix: %w", err) } diff --git a/cli/dpservice-cli/cmd/delete_loadbalancer_target.go b/cli/dpservice-cli/cmd/delete_loadbalancer_target.go index cf803e3e..7bee3d6f 100644 --- a/cli/dpservice-cli/cmd/delete_loadbalancer_target.go +++ b/cli/dpservice-cli/cmd/delete_loadbalancer_target.go @@ -71,7 +71,7 @@ func RunDeleteLoadBalancerTarget(ctx context.Context, dpdkClientFactory DPDKClie defer DpdkClose(cleanup) lbtarget, err := client.DeleteLoadBalancerTarget(ctx, opts.LoadBalancerID, &opts.TargetIP) - if err != nil && lbtarget.Status.Code == 0 { + if err != nil { return fmt.Errorf("error deleting neighbor nat: %w", err) } diff --git a/cli/dpservice-cli/cmd/delete_nat.go b/cli/dpservice-cli/cmd/delete_nat.go index a0f7ed6d..efd7393e 100644 --- a/cli/dpservice-cli/cmd/delete_nat.go +++ b/cli/dpservice-cli/cmd/delete_nat.go @@ -67,7 +67,7 @@ func RunDeleteNat(ctx context.Context, dpdkClientFactory DPDKClientFactory, rend defer DpdkClose(cleanup) nat, err := client.DeleteNat(ctx, opts.InterfaceID) - if err != nil && nat.Status.Code == 0 { + if err != nil { return fmt.Errorf("error deleting nat: %w", err) } diff --git a/cli/dpservice-cli/cmd/delete_neighbor_nat.go b/cli/dpservice-cli/cmd/delete_neighbor_nat.go index ccf6a2f7..fcf8f11c 100644 --- a/cli/dpservice-cli/cmd/delete_neighbor_nat.go +++ b/cli/dpservice-cli/cmd/delete_neighbor_nat.go @@ -85,7 +85,7 @@ func RunDeleteNeighborNat(ctx context.Context, dpdkClientFactory DPDKClientFacto }, } nnat, err := client.DeleteNeighborNat(ctx, &neigbhorNat) - if err != nil && nnat.Status.Code == 0 { + if err != nil { return fmt.Errorf("error deleting neighbor nat: %w", err) } diff --git a/cli/dpservice-cli/cmd/delete_prefix.go b/cli/dpservice-cli/cmd/delete_prefix.go index df22b7cb..e48cac9f 100644 --- a/cli/dpservice-cli/cmd/delete_prefix.go +++ b/cli/dpservice-cli/cmd/delete_prefix.go @@ -71,7 +71,7 @@ func RunDeletePrefix(ctx context.Context, dpdkClientFactory DPDKClientFactory, r defer DpdkClose(cleanup) prefix, err := client.DeletePrefix(ctx, opts.InterfaceID, &opts.Prefix) - if err != nil && prefix.Status.Code == 0 { + if err != nil { return fmt.Errorf("error deleting prefix: %w", err) } diff --git a/cli/dpservice-cli/cmd/delete_route.go b/cli/dpservice-cli/cmd/delete_route.go index f43a8ec9..d40ee88e 100644 --- a/cli/dpservice-cli/cmd/delete_route.go +++ b/cli/dpservice-cli/cmd/delete_route.go @@ -71,7 +71,7 @@ func RunDeleteRoute(ctx context.Context, dpdkClientFactory DPDKClientFactory, re defer DpdkClose(cleanup) route, err := client.DeleteRoute(ctx, opts.VNI, &opts.Prefix) - if err != nil && route.Status.Code == 0 { + if err != nil { return fmt.Errorf("error deleting route: %w", err) } diff --git a/cli/dpservice-cli/cmd/delete_virtualip.go b/cli/dpservice-cli/cmd/delete_virtualip.go index b877f3eb..71f484b8 100644 --- a/cli/dpservice-cli/cmd/delete_virtualip.go +++ b/cli/dpservice-cli/cmd/delete_virtualip.go @@ -67,7 +67,7 @@ func RunDeleteVirtualIP(ctx context.Context, dpdkClientFactory DPDKClientFactory defer DpdkClose(cleanup) virtualIP, err := client.DeleteVirtualIP(ctx, opts.InterfaceID) - if err != nil && virtualIP.Status.Code == 0 { + if err != nil { return fmt.Errorf("error deleting virtual ip: %w", err) } diff --git a/cli/dpservice-cli/cmd/get_firewall_rule.go b/cli/dpservice-cli/cmd/get_firewall_rule.go index 97ae79c0..1bce66da 100644 --- a/cli/dpservice-cli/cmd/get_firewall_rule.go +++ b/cli/dpservice-cli/cmd/get_firewall_rule.go @@ -86,7 +86,7 @@ func RunGetFirewallRule( ) } else { fwrule, err := client.GetFirewallRule(ctx, opts.InterfaceID, opts.RuleID) - if err != nil && fwrule.Status.Code == 0 { + if err != nil { return fmt.Errorf("error getting firewall rule: %w", err) } diff --git a/cli/dpservice-cli/cmd/get_init.go b/cli/dpservice-cli/cmd/get_init.go index bd3cc4f0..1862f2cc 100644 --- a/cli/dpservice-cli/cmd/get_init.go +++ b/cli/dpservice-cli/cmd/get_init.go @@ -46,7 +46,7 @@ func RunGetInit( }() init, err := client.CheckInitialized(ctx) - if err != nil && init.Status.Code == 0 { + if err != nil { return fmt.Errorf("error checking initialization status: %w", err) } diff --git a/cli/dpservice-cli/cmd/get_interface.go b/cli/dpservice-cli/cmd/get_interface.go index eaf355dd..6d6caf54 100644 --- a/cli/dpservice-cli/cmd/get_interface.go +++ b/cli/dpservice-cli/cmd/get_interface.go @@ -74,7 +74,7 @@ func RunGetInterface( ) } else { iface, err := client.GetInterface(ctx, opts.ID) - if err != nil && iface.Status.Code == 0 { + if err != nil { return fmt.Errorf("error getting interface: %w", err) } diff --git a/cli/dpservice-cli/cmd/get_loadbalancer.go b/cli/dpservice-cli/cmd/get_loadbalancer.go index 53798df7..e512f0c2 100644 --- a/cli/dpservice-cli/cmd/get_loadbalancer.go +++ b/cli/dpservice-cli/cmd/get_loadbalancer.go @@ -75,7 +75,7 @@ func RunGetLoadBalancer( ) } else { lb, err := client.GetLoadBalancer(ctx, opts.ID) - if err != nil && lb.Status.Code == 0 { + if err != nil { return fmt.Errorf("error getting loadbalancer: %w", err) } diff --git a/cli/dpservice-cli/cmd/get_nat.go b/cli/dpservice-cli/cmd/get_nat.go index 910d67c8..963aef6f 100644 --- a/cli/dpservice-cli/cmd/get_nat.go +++ b/cli/dpservice-cli/cmd/get_nat.go @@ -69,7 +69,7 @@ func RunGetNat( if opts.InterfaceID == "" { ifaces, err := client.ListInterfaces(ctx) - if err != nil && ifaces.Status.Code == 0 { + if err != nil { return fmt.Errorf("error listing interfaces: %w", err) } natList := api.NatList{ @@ -77,7 +77,7 @@ func RunGetNat( } for _, iface := range ifaces.Items { nat, err := client.GetNat(ctx, iface.ID) - if err != nil && nat.Status.Code == 0 { + if err != nil { return fmt.Errorf("error getting nat: %w", err) } natList.Items = append(natList.Items, *nat) @@ -87,7 +87,7 @@ func RunGetNat( } nat, err := client.GetNat(ctx, opts.InterfaceID) - if err != nil && nat.Status.Code == 0 { + if err != nil { return fmt.Errorf("error getting nat: %w", err) } diff --git a/cli/dpservice-cli/cmd/get_version.go b/cli/dpservice-cli/cmd/get_version.go index e5aaac6f..7efe1660 100644 --- a/cli/dpservice-cli/cmd/get_version.go +++ b/cli/dpservice-cli/cmd/get_version.go @@ -72,7 +72,7 @@ func RunGetVersion( ClientVersion: util.BuildVersion, }, }) - if err != nil && svcVersion.Status.Code == 0 { + if err != nil { return fmt.Errorf("error getting version: %w", err) } return rendererFactory.RenderObject("", os.Stdout, svcVersion) diff --git a/cli/dpservice-cli/cmd/get_virtualip.go b/cli/dpservice-cli/cmd/get_virtualip.go index ef92bdb4..598faf20 100644 --- a/cli/dpservice-cli/cmd/get_virtualip.go +++ b/cli/dpservice-cli/cmd/get_virtualip.go @@ -70,31 +70,23 @@ func RunGetVirtualIP( if opts.InterfaceID == "" { ifaces, err := client.ListInterfaces(ctx) - if err != nil && ifaces.Status.Code == 0 { + if err != nil { return fmt.Errorf("error listing interfaces: %w", err) } + if len(ifaces.Items) == 0 { + return fmt.Errorf("error getting virtual ip: [error code %d] NO_VM", errors.NO_VM) + } + virtualIPs := make([]*api.VirtualIP, 0, len(ifaces.Items)) for _, iface := range ifaces.Items { vip, err := client.GetVirtualIP(ctx, iface.ID, errors.Ignore(errors.SNAT_NO_DATA)) - if err != nil && vip.Status.Code == 0 { + if err != nil { return fmt.Errorf("error getting virtual ip: %w", err) } if vip.Status.Code == 0 { virtualIPs = append(virtualIPs, vip) } } - if len(virtualIPs) == 0 { - noVipFound := api.VirtualIP{ - TypeMeta: api.TypeMeta{ - Kind: api.VirtualIPKind, - }, - Status: api.Status{ - Code: errors.SNAT_NO_DATA, - Message: "SNAT_NO_DATA", - }, - } - return rendererFactory.RenderObject("no interface has virtual ip configured", os.Stdout, &noVipFound) - } for _, vip := range virtualIPs { err = rendererFactory.RenderObject("", os.Stdout, vip) if err != nil { @@ -105,7 +97,7 @@ func RunGetVirtualIP( } virtualIP, err := client.GetVirtualIP(ctx, opts.InterfaceID) - if err != nil && virtualIP.Status.Code == 0 { + if err != nil { return fmt.Errorf("error getting virtual ip: %w", err) } diff --git a/cli/dpservice-cli/cmd/get_vni.go b/cli/dpservice-cli/cmd/get_vni.go index 09b68953..495bd978 100644 --- a/cli/dpservice-cli/cmd/get_vni.go +++ b/cli/dpservice-cli/cmd/get_vni.go @@ -74,7 +74,7 @@ func RunGetVni( defer DpdkClose(cleanup) vni, err := client.GetVni(ctx, opts.VNI, opts.VniType) - if err != nil && vni.Status.Code == 0 { + if err != nil { return fmt.Errorf("error getting vni: %w", err) } diff --git a/cli/dpservice-cli/cmd/init.go b/cli/dpservice-cli/cmd/init.go index ccf25adc..00ccbd26 100644 --- a/cli/dpservice-cli/cmd/init.go +++ b/cli/dpservice-cli/cmd/init.go @@ -78,7 +78,7 @@ func RunInit( } // else initialize and show uuid init, err := client.Initialize(ctx) - if err != nil && res.Status.Code == 0 { + if err != nil { return fmt.Errorf("error initializing: %w", err) } diff --git a/cli/dpservice-cli/cmd/list_firewall_rules.go b/cli/dpservice-cli/cmd/list_firewall_rules.go index 58672269..80434e1d 100644 --- a/cli/dpservice-cli/cmd/list_firewall_rules.go +++ b/cli/dpservice-cli/cmd/list_firewall_rules.go @@ -75,13 +75,13 @@ func RunListFirewallRules( } if opts.InterfaceID == "" { ifaces, err := client.ListInterfaces(ctx) - if err != nil && ifaces.Status.Code == 0 { + if err != nil { return fmt.Errorf("error listing interfaces: %w", err) } for _, iface := range ifaces.Items { fwrule, err := client.ListFirewallRules(ctx, iface.ID) - if err != nil && fwrule.Status.Code == 0 { + if err != nil { return fmt.Errorf("error getting firewall rules: %w", err) } fwruleList.Items = append(fwruleList.Items, fwrule.Items...) diff --git a/cli/dpservice-cli/cmd/list_loadbalancer_prefixes.go b/cli/dpservice-cli/cmd/list_loadbalancer_prefixes.go index 8160f5d6..277b4198 100644 --- a/cli/dpservice-cli/cmd/list_loadbalancer_prefixes.go +++ b/cli/dpservice-cli/cmd/list_loadbalancer_prefixes.go @@ -76,13 +76,13 @@ func RunListLoadBalancerPrefixes( } if opts.InterfaceID == "" { ifaces, err := client.ListInterfaces(ctx) - if err != nil && ifaces.Status.Code == 0 { + if err != nil { return fmt.Errorf("error listing interfaces: %w", err) } for _, iface := range ifaces.Items { prefixes, err := client.ListLoadBalancerPrefixes(ctx, iface.ID) - if err != nil && prefixes.Status.Code == 0 { + if err != nil { return fmt.Errorf("error getting loadbalancer prefixes: %w", err) } for id := range prefixes.Items { diff --git a/cli/dpservice-cli/cmd/list_loadbalancer_targets.go b/cli/dpservice-cli/cmd/list_loadbalancer_targets.go index 9dfb5e22..addea2f5 100644 --- a/cli/dpservice-cli/cmd/list_loadbalancer_targets.go +++ b/cli/dpservice-cli/cmd/list_loadbalancer_targets.go @@ -75,7 +75,7 @@ func RunListLoadBalancerTargets( defer DpdkClose(cleanup) lbtargets, err := client.ListLoadBalancerTargets(ctx, opts.LoadBalancerID) - if err != nil && lbtargets.Status.Code == 0 { + if err != nil { return fmt.Errorf("error listing loadbalancer targets: %w", err) } diff --git a/cli/dpservice-cli/cmd/list_nats.go b/cli/dpservice-cli/cmd/list_nats.go index a02b10f9..7ea70be2 100644 --- a/cli/dpservice-cli/cmd/list_nats.go +++ b/cli/dpservice-cli/cmd/list_nats.go @@ -25,7 +25,7 @@ func ListNats(dpdkClientFactory DPDKClientFactory, rendererFactory RendererFacto cmd := &cobra.Command{ Use: "nats <--nat-ip> <--nat-type>", Short: "List local/neighbor/both nats with selected IP", - Example: "dpservice-cli list nats --nat-ip=10.20.30.40 --info-type=local", + Example: "dpservice-cli list nats --nat-ip=10.20.30.40 --nat-type=local", Aliases: NatAliases, Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cli/dpservice-cli/cmd/list_prefixes.go b/cli/dpservice-cli/cmd/list_prefixes.go index ea804e48..afb521aa 100644 --- a/cli/dpservice-cli/cmd/list_prefixes.go +++ b/cli/dpservice-cli/cmd/list_prefixes.go @@ -75,13 +75,13 @@ func RunListPrefixes( } if opts.InterfaceID == "" { ifaces, err := client.ListInterfaces(ctx) - if err != nil && ifaces.Status.Code == 0 { + if err != nil { return fmt.Errorf("error listing interfaces: %w", err) } for _, iface := range ifaces.Items { prefixes, err := client.ListPrefixes(ctx, iface.ID) - if err != nil && prefixes.Status.Code == 0 { + if err != nil { return fmt.Errorf("error getting prefixes: %w", err) } for id := range prefixes.Items { diff --git a/cli/dpservice-cli/main.go b/cli/dpservice-cli/main.go index 50394287..eb708150 100644 --- a/cli/dpservice-cli/main.go +++ b/cli/dpservice-cli/main.go @@ -25,10 +25,11 @@ func main() { } // check if it is Server side error if err.Error() == strconv.Itoa(errors.SERVER_ERROR) || strings.Contains(err.Error(), "error code") { + fmt.Fprintf(os.Stderr, "Server error: %v\n", err) os.Exit(errors.SERVER_ERROR) } // else it is Client side error - fmt.Fprintf(os.Stderr, "Error running command: %v\n", err) + fmt.Fprintf(os.Stderr, "Client error: %v\n", err) os.Exit(errors.CLIENT_ERROR) } } diff --git a/go/dpservice-go/client/client.go b/go/dpservice-go/client/client.go index 62fb5b43..3b0468f1 100644 --- a/go/dpservice-go/client/client.go +++ b/go/dpservice-go/client/client.go @@ -100,14 +100,19 @@ func (c *client) GetLoadBalancer(ctx context.Context, id string, ignoredErrors . func (c *client) ListLoadBalancers(ctx context.Context, ignoredErrors ...[]uint32) (*api.LoadBalancerList, error) { res, err := c.DPDKironcoreClient.ListLoadBalancers(ctx, &dpdkproto.ListLoadBalancersRequest{}) if err != nil { - return nil, err + return &api.LoadBalancerList{}, err + } + if res.GetStatus().GetCode() != 0 { + return &api.LoadBalancerList{ + TypeMeta: api.TypeMeta{Kind: api.LoadBalancerListKind}, + Status: api.ProtoStatusToStatus(res.Status)}, errors.GetError(res.Status, ignoredErrors) } lbs := make([]api.LoadBalancer, len(res.GetLoadbalancers())) for i, dpdkLb := range res.GetLoadbalancers() { lb, err := api.ProtoLoadBalancerToLoadBalancer(dpdkLb) if err != nil { - return nil, err + return &api.LoadBalancerList{}, err } lbs[i] = *lb @@ -177,14 +182,19 @@ func (c *client) ListLoadBalancerPrefixes(ctx context.Context, interfaceID strin InterfaceId: []byte(interfaceID), }) if err != nil { - return nil, err + return &api.PrefixList{}, err + } + if res.GetStatus().GetCode() != 0 { + return &api.PrefixList{ + TypeMeta: api.TypeMeta{Kind: api.PrefixListKind}, + Status: api.ProtoStatusToStatus(res.Status)}, errors.GetError(res.Status, ignoredErrors) } prefixes := make([]api.Prefix, len(res.GetPrefixes())) for i, dpdkPrefix := range res.GetPrefixes() { prefix, err := api.ProtoPrefixToPrefix(interfaceID, dpdkPrefix) if err != nil { - return nil, err + return &api.PrefixList{}, err } prefix.Kind = api.LoadBalancerPrefixKind @@ -273,7 +283,7 @@ func (c *client) ListLoadBalancerTargets(ctx context.Context, loadBalancerID str lbtarget.TypeMeta.Kind = api.LoadBalancerTargetKind lbtarget.Spec.TargetIP, err = api.ProtoIpAddressToNetIPAddr(dpdkLBtarget) if err != nil { - return nil, err + return &api.LoadBalancerTargetList{}, err } lbtarget.LoadBalancerTargetMeta.LoadbalancerID = loadBalancerID @@ -346,14 +356,19 @@ func (c *client) GetInterface(ctx context.Context, id string, ignoredErrors ...[ func (c *client) ListInterfaces(ctx context.Context, ignoredErrors ...[]uint32) (*api.InterfaceList, error) { res, err := c.DPDKironcoreClient.ListInterfaces(ctx, &dpdkproto.ListInterfacesRequest{}) if err != nil { - return nil, err + return &api.InterfaceList{}, err + } + if res.GetStatus().GetCode() != 0 { + return &api.InterfaceList{ + TypeMeta: api.TypeMeta{Kind: api.InterfaceListKind}, + Status: api.ProtoStatusToStatus(res.Status)}, errors.GetError(res.Status, ignoredErrors) } ifaces := make([]api.Interface, len(res.GetInterfaces())) for i, dpdkIface := range res.GetInterfaces() { iface, err := api.ProtoInterfaceToInterface(dpdkIface) if err != nil { - return nil, err + return &api.InterfaceList{}, err } ifaces[i] = *iface @@ -492,14 +507,19 @@ func (c *client) ListPrefixes(ctx context.Context, interfaceID string, ignoredEr InterfaceId: []byte(interfaceID), }) if err != nil { - return nil, err + return &api.PrefixList{}, err + } + if res.GetStatus().GetCode() != 0 { + return &api.PrefixList{ + TypeMeta: api.TypeMeta{Kind: api.PrefixListKind}, + Status: api.ProtoStatusToStatus(res.Status)}, errors.GetError(res.Status, ignoredErrors) } prefixes := make([]api.Prefix, len(res.GetPrefixes())) for i, dpdkPrefix := range res.GetPrefixes() { prefix, err := api.ProtoPrefixToPrefix(interfaceID, dpdkPrefix) if err != nil { - return nil, err + return &api.PrefixList{}, err } prefixes[i] = *prefix @@ -569,12 +589,12 @@ func (c *client) DeletePrefix(ctx context.Context, interfaceID string, prefix *n func (c *client) CreateRoute(ctx context.Context, route *api.Route, ignoredErrors ...[]uint32) (*api.Route, error) { if route.Spec.Prefix == nil { - return nil, fmt.Errorf("prefix needs to be specified") + return &api.Route{}, fmt.Errorf("prefix needs to be specified") } routePrefixAddr := route.Spec.Prefix.Addr() if route.Spec.NextHop == nil { - return nil, fmt.Errorf("nextHop needs to be specified") + return &api.Route{}, fmt.Errorf("nextHop needs to be specified") } res, err := c.DPDKironcoreClient.CreateRoute(ctx, &dpdkproto.CreateRouteRequest{ Vni: route.VNI, @@ -641,14 +661,19 @@ func (c *client) ListRoutes(ctx context.Context, vni uint32, ignoredErrors ...[] Vni: vni, }) if err != nil { - return nil, err + return &api.RouteList{}, err + } + if res.GetStatus().GetCode() != 0 { + return &api.RouteList{ + TypeMeta: api.TypeMeta{Kind: api.RouteListKind}, + Status: api.ProtoStatusToStatus(res.Status)}, errors.GetError(res.Status, ignoredErrors) } routes := make([]api.Route, len(res.GetRoutes())) for i, dpdkRoute := range res.GetRoutes() { route, err := api.ProtoRouteToRoute(vni, dpdkRoute) if err != nil { - return nil, err + return &api.RouteList{}, err } routes[i] = *route @@ -729,7 +754,7 @@ func (c *client) ListLocalNats(ctx context.Context, natIP *netip.Addr, ignoredEr func (c *client) CreateNeighborNat(ctx context.Context, nNat *api.NeighborNat, ignoredErrors ...[]uint32) (*api.NeighborNat, error) { if nNat.Spec.UnderlayRoute == nil { - return nil, fmt.Errorf("underlayRoute needs to be specified") + return &api.NeighborNat{}, fmt.Errorf("underlayRoute needs to be specified") } res, err := c.DPDKironcoreClient.CreateNeighborNat(ctx, &dpdkproto.CreateNeighborNatRequest{ NatIp: api.NetIPAddrToProtoIpAddress(nNat.NatIP), @@ -763,7 +788,7 @@ func (c *client) ListNats(ctx context.Context, natIP *netip.Addr, natType string case "any", "0", "": nType = 0 default: - return nil, fmt.Errorf("nat type can be only: Any = 0/Local = 1/Neigh(bor) = 2") + return &api.NatList{}, fmt.Errorf("nat type can be only: Any = 0/Local = 1/Neigh(bor) = 2") } req := api.NetIPAddrToProtoIpAddress(natIP) @@ -775,25 +800,35 @@ func (c *client) ListNats(ctx context.Context, natIP *netip.Addr, natType string case 0: res1, err1 := c.DPDKironcoreClient.ListLocalNats(ctx, &dpdkproto.ListLocalNatsRequest{NatIp: req}) if err1 != nil { - return nil, err1 + return &api.NatList{}, err1 } res2, err2 := c.DPDKironcoreClient.ListNeighborNats(ctx, &dpdkproto.ListNeighborNatsRequest{NatIp: req}) if err2 != nil { - return nil, err2 + return &api.NatList{}, err2 } natEntries = append(natEntries, res1.NatEntries...) natEntries = append(natEntries, res2.NatEntries...) case 1: res, err := c.DPDKironcoreClient.ListLocalNats(ctx, &dpdkproto.ListLocalNatsRequest{NatIp: req}) if err != nil { - return nil, err + return &api.NatList{}, err + } + if res.GetStatus().GetCode() != 0 { + return &api.NatList{ + TypeMeta: api.TypeMeta{Kind: api.NatListKind}, + Status: api.ProtoStatusToStatus(res.Status)}, errors.GetError(res.Status, ignoredErrors) } natEntries = res.GetNatEntries() status = res.Status case 2: res, err := c.DPDKironcoreClient.ListNeighborNats(ctx, &dpdkproto.ListNeighborNatsRequest{NatIp: req}) if err != nil { - return nil, err + return &api.NatList{}, err + } + if res.GetStatus().GetCode() != 0 { + return &api.NatList{ + TypeMeta: api.TypeMeta{Kind: api.NatListKind}, + Status: api.ProtoStatusToStatus(res.Status)}, errors.GetError(res.Status, ignoredErrors) } natEntries = res.GetNatEntries() status = res.Status @@ -807,7 +842,7 @@ func (c *client) ListNats(ctx context.Context, natIP *netip.Addr, natType string if natEntry.GetUnderlayRoute() != nil { underlayRoute, err = netip.ParseAddr(string(natEntry.GetUnderlayRoute())) if err != nil { - return nil, fmt.Errorf("error parsing underlay route: %w", err) + return &api.NatList{}, fmt.Errorf("error parsing underlay route: %w", err) } nat.Spec.UnderlayRoute = &underlayRoute nat.Spec.NatIP = nil @@ -815,7 +850,7 @@ func (c *client) ListNats(ctx context.Context, natIP *netip.Addr, natType string } else if natEntry.GetNatIp() != nil { vipIP, err = netip.ParseAddr(string(natEntry.GetNatIp().GetAddress())) if err != nil { - return nil, fmt.Errorf("error parsing nat ip: %w", err) + return &api.NatList{}, fmt.Errorf("error parsing nat ip: %w", err) } nat.Spec.NatIP = &vipIP nat.Kind = api.NatKind @@ -865,6 +900,11 @@ func (c *client) ListFirewallRules(ctx context.Context, interfaceID string, igno if err != nil { return &api.FirewallRuleList{}, err } + if res.GetStatus().GetCode() != 0 { + return &api.FirewallRuleList{ + TypeMeta: api.TypeMeta{Kind: api.FirewallRuleListKind}, + Status: api.ProtoStatusToStatus(res.Status)}, errors.GetError(res.Status, ignoredErrors) + } fwRules := make([]api.FirewallRule, len(res.GetRules())) for i, dpdkFwRule := range res.GetRules() { @@ -909,11 +949,11 @@ func (c *client) CreateFirewallRule(ctx context.Context, fwRule *api.FirewallRul } if fwRule.Spec.SourcePrefix == nil { - return nil, fmt.Errorf("source prefix needs to be specified") + return &api.FirewallRule{}, fmt.Errorf("source prefix needs to be specified") } fwRuleSrcPrefixAddr := fwRule.Spec.SourcePrefix.Addr() if fwRule.Spec.DestinationPrefix == nil { - return nil, fmt.Errorf("destination prefix needs to be specified") + return &api.FirewallRule{}, fmt.Errorf("destination prefix needs to be specified") } fwRuleDstPrefixAddr := fwRule.Spec.DestinationPrefix.Addr() req := dpdkproto.CreateFirewallRuleRequest{