Skip to content

Commit

Permalink
Merge pull request #31 from Lyt99/features/no-endpoint
Browse files Browse the repository at this point in the history
fix panic when no service endpoint and exited when non pod/node address as source
  • Loading branch information
BSWANG authored Apr 13, 2023
2 parents af9bdb3 + d8a593f commit 987d51d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 29 deletions.
26 changes: 5 additions & 21 deletions pkg/skoop/model/netnode.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package model

import (
"fmt"

"github.com/samber/lo"
)

Expand All @@ -23,6 +21,11 @@ type NetNode struct {
initiative *Action
}

type NetNodeAction interface {
Send(dst Endpoint, protocol Protocol) ([]Transmission, error)
Receive(upstream *Link) ([]Transmission, error)
}

func NewNetNode(id string, nodeType NetNodeType) *NetNode {
return &NetNode{
ID: id,
Expand Down Expand Up @@ -73,22 +76,3 @@ func (n *NetNode) MaxSuspicionLevel() SuspicionLevel {
levels := lo.Map(n.Suspicions, func(s Suspicion, _ int) SuspicionLevel { return s.Level })
return lo.Max(levels)
}

type NetNodeAction interface {
Send(dst Endpoint, protocol Protocol) ([]Transmission, error)
Receive(upstream *Link) ([]Transmission, error)
}

type GenericNetNode struct {
NetNode *NetNode
}

func (n *GenericNetNode) Send(_ Endpoint, _ Protocol) ([]Transmission, error) {
return nil, fmt.Errorf("non pod/node address as source is not supported")
}

func (n *GenericNetNode) Receive(upstream *Link) ([]Transmission, error) {
upstream.Destination = n.NetNode
n.NetNode.DoAction(ActionServe(upstream))
return nil, nil
}
18 changes: 11 additions & 7 deletions pkg/skoop/model/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,25 @@ func (p *PacketPath) Paths() string {
links := p.Links()
if len(links) == 0 {
for _, n := range p.Nodes() {
buf.WriteString(n.GetID())
buf.WriteString(fmt.Sprintf("\"%v\"", n.GetID()))
}
return buf.String()
}

for _, l := range links {
action := l.Destination.ActionOf(l)
label := p.GetLinkLabel(l, action)

attr := map[string]string{
"label": label,
}
if action.Type == ActionTypeServe {
attr["arrowhead"] = "dot"
attr := map[string]string{}

if action != nil {
label := p.GetLinkLabel(l, action)
attr["label"] = label

if action.Type == ActionTypeServe {
attr["arrowhead"] = "dot"
}
}

attrString := strings.Join(
lo.MapToSlice(attr, func(k, v string) string { return fmt.Sprintf("%s=%q", k, v) }), ",")

Expand Down
2 changes: 1 addition & 1 deletion pkg/skoop/nodemanager/net_node_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (m *defaultNetNodeManager) GetNetNodeFromID(nodeType model.NetNodeType, id
return m.parent.GetNetNodeFromID(nodeType, id)
}

return &model.GenericNetNode{
return &plugin.GenericNetNode{
NetNode: &model.NetNode{
Type: model.NetNodeTypeGeneric,
ID: id,
Expand Down
1 change: 1 addition & 0 deletions pkg/skoop/plugin/calico.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ func (h *calicoHost) ToService(upstream *model.Link, dst model.Endpoint, protoco
Level: model.SuspicionLevelFatal,
Message: fmt.Sprintf("service %s/%s has no valid endpoint", service.Namespace, service.Name),
})
h.netNode.DoAction(model.ActionService(upstream, []*model.Link{}))
return nil, &assertions.CannotBuildTransmissionError{
SrcNode: h.netNode,
Err: fmt.Errorf("service %s/%s has no valid endpoint", service.Namespace, service.Name),
Expand Down
1 change: 1 addition & 0 deletions pkg/skoop/plugin/flannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ func (h *flannelHost) ToService(upstream *model.Link, dst model.Endpoint, protoc
Level: model.SuspicionLevelFatal,
Message: fmt.Sprintf("service %s/%s has no valid endpoint", service.Namespace, service.Name),
})
h.netNode.DoAction(model.ActionService(upstream, []*model.Link{}))
return nil, &assertions.CannotBuildTransmissionError{
SrcNode: h.netNode,
Err: fmt.Errorf("service %s/%s has no valid endpoint", service.Namespace, service.Name),
Expand Down
18 changes: 18 additions & 0 deletions pkg/skoop/plugin/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,21 @@ func (p *simpleVEthPod) Receive(upstream *model.Link) ([]model.Transmission, err
p.netNode.DoAction(model.ActionServe(upstream))
return []model.Transmission{}, nil
}

type GenericNetNode struct {
NetNode *model.NetNode
}

func (n *GenericNetNode) Send(_ model.Endpoint, _ model.Protocol) ([]model.Transmission, error) {
n.NetNode.AddSuspicion(model.SuspicionLevelFatal, "non pod/node address as source is not supported")
return nil, &assertions.CannotBuildTransmissionError{
SrcNode: n.NetNode,
Err: fmt.Errorf("non pod/node address as source is not supported"),
}
}

func (n *GenericNetNode) Receive(upstream *model.Link) ([]model.Transmission, error) {
upstream.Destination = n.NetNode
n.NetNode.DoAction(model.ActionServe(upstream))
return nil, nil
}

0 comments on commit 987d51d

Please sign in to comment.