Skip to content

Commit

Permalink
Add new API to danmep package for UID based search
Browse files Browse the repository at this point in the history
  • Loading branch information
Levovar committed Aug 29, 2020
1 parent 6454a2c commit b892e74
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion pkg/danmep/danmep.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func CidsByHost(client danmclientset.Interface, host string)(map[string]danmtype
}

// FindByPodName returns a map of DanmEps which belong to the same Pod in a given namespace
// If no Pod name is provided, function returns all DanmEps
// If no Pod name is provided, function returns no DanmEps
func FindByPodName(client danmclientset.Interface, podName, ns string) ([]danmtypes.DanmEp, error) {
result, err := client.DanmV1().DanmEps(ns).List(context.TODO(), meta_v1.ListOptions{})
if err != nil {
Expand All @@ -130,6 +130,27 @@ func FindByPodName(client danmclientset.Interface, podName, ns string) ([]danmty
return ret, nil
}

// FindByPodUid returns a map of DanmEps which belong to the same Pod instance in a given namespace
// If no Pod name is provided, function returns no DanmEps
func FindByPodUid(client danmclientset.Interface, podUid, ns string) ([]danmtypes.DanmEp, error) {
result, err := client.DanmV1().DanmEps(ns).List(context.TODO(), meta_v1.ListOptions{})
if err != nil {
return nil, errors.New("cannot list DanmEps because:" + err.Error())
}
ret := make([]danmtypes.DanmEp, 0)
if result == nil {
return ret, nil
}
eplist := result.Items
for _, ep := range eplist {
if podUid != "" && string(ep.Spec.PodUID) != podUid {
continue
}
ret = append(ret, ep)
}
return ret, nil
}


func AddIpvlanInterface(dnet *danmtypes.DanmNet, ep *danmtypes.DanmEp) error {
if ep.Spec.NetworkType != "ipvlan" {
Expand Down

0 comments on commit b892e74

Please sign in to comment.