From 00226b7a0d9717d5318def9cb403d15b99fa0ba3 Mon Sep 17 00:00:00 2001 From: gunjan5 Date: Mon, 8 May 2017 18:16:35 -0700 Subject: [PATCH] list WEP and Policy should return empty KVP lists --- lib/backend/k8s/k8s.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/backend/k8s/k8s.go b/lib/backend/k8s/k8s.go index 8b5ad265d..8382b066f 100644 --- a/lib/backend/k8s/k8s.go +++ b/lib/backend/k8s/k8s.go @@ -500,13 +500,15 @@ func (c *KubeClient) listWorkloadEndpoints(l model.WorkloadEndpointListOptions) WorkloadID: l.WorkloadID, }) if err != nil { - // Error getting the endpoint. - return nil, err - } - if kvp == nil { - // The workload endpoint doesn't exist. - return nil, nil + switch err.(type) { + // Return empty slice of KVPair if the object doesn't exist, return the error otherwise. + case errors.ErrorResourceDoesNotExist: + return []*model.KVPair{}, nil + default: + return nil, err + } } + return []*model.KVPair{kvp}, nil } @@ -558,8 +560,15 @@ func (c *KubeClient) listPolicies(l model.PolicyListOptions) ([]*model.KVPair, e // Exact lookup on a NetworkPolicy. kvp, err := c.getPolicy(model.PolicyKey{Name: l.Name}) if err != nil { - return []*model.KVPair{}, nil + switch err.(type) { + // Return empty slice of KVPair if the object doesn't exist, return the error otherwise. + case errors.ErrorResourceDoesNotExist: + return []*model.KVPair{}, nil + default: + return nil, err + } } + return []*model.KVPair{kvp}, nil }