Skip to content

Commit b892e74

Browse files
committed
Add new API to danmep package for UID based search
1 parent 6454a2c commit b892e74

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

pkg/danmep/danmep.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func CidsByHost(client danmclientset.Interface, host string)(map[string]danmtype
110110
}
111111

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

133+
// FindByPodUid returns a map of DanmEps which belong to the same Pod instance in a given namespace
134+
// If no Pod name is provided, function returns no DanmEps
135+
func FindByPodUid(client danmclientset.Interface, podUid, ns string) ([]danmtypes.DanmEp, error) {
136+
result, err := client.DanmV1().DanmEps(ns).List(context.TODO(), meta_v1.ListOptions{})
137+
if err != nil {
138+
return nil, errors.New("cannot list DanmEps because:" + err.Error())
139+
}
140+
ret := make([]danmtypes.DanmEp, 0)
141+
if result == nil {
142+
return ret, nil
143+
}
144+
eplist := result.Items
145+
for _, ep := range eplist {
146+
if podUid != "" && string(ep.Spec.PodUID) != podUid {
147+
continue
148+
}
149+
ret = append(ret, ep)
150+
}
151+
return ret, nil
152+
}
153+
133154

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

0 commit comments

Comments
 (0)