Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add aysnc behavior for link creation #84

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions daemon/meshnet/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"github.com/openconfig/gnmi/errlist"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/util/retry"

Expand Down Expand Up @@ -115,6 +116,18 @@ func (m *Meshnet) SetAlive(ctx context.Context, pod *mpb.Pod) (*mpb.BoolResponse
return &mpb.BoolResponse{Response: true}, nil
}

func (m *Meshnet) BatchSkip(ctx context.Context, req *mpb.BatchSkipRequest) (*mpb.BatchSkipResponse, error) {
mnetdLogger.Infof("Processing batch skip request: %+v", req)
var errs errlist.List
brs := []bool{}
for _, skip := range req.Skip {
br, err := m.Skip(ctx, skip)
errs.Add(err)
brs = append(brs, br.Response)
}
return &mpb.BatchSkipResponse{Responses: brs}, errs.Err()
}

// A point to point link between two pods is created only when both the pods are alive.
// While creating a link, when a pod does not find its peer, it marks the peer as skipped for this link UID.
// The pod stores the list of skipped peers and its corresponding link UID in it's skip list.
Expand Down Expand Up @@ -343,6 +356,40 @@ func (m *Meshnet) IsSkipped(ctx context.Context, skip *mpb.SkipQuery) (*mpb.Bool
return &mpb.BoolResponse{Response: false}, nil
}

func (m *Meshnet) ListSkipped(ctx context.Context, req *mpb.ListSkippedRequest) (*mpb.ListSkippedResponse, error) {
mnetdLogger.Infof("Listing skipped links for %s by peer %s", req.Pod, req.Peer)

result, err := m.getPod(ctx, req.Peer, req.KubeNs)
if err != nil {
mnetdLogger.Errorf("listSkipped: Failed to read pod %s from K8s", req.Pod)
return nil, err
}

skipped, found, err := unstructured.NestedSlice(result.Object, "status", "skipped")
if found && err != nil {
mnetdLogger.Errorf("listSkipped: error in retrieving skipped list from peer pod's status, object found: %t, err: %v", found, err)
return nil, err
}

links := []int64{}
for _, peerSkipped := range skipped {
elSkipped, ok := peerSkipped.(map[string]interface{})
if !ok {
mnetdLogger.Errorf("isSkipped: 'Skipped' not recognized")
continue
}
skipped := v1beta1.Skipped{}
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(elSkipped, &skipped); err != nil {
mnetdLogger.Errorf("isSkipped: unable to retrieve Skipped: %v", err)
continue
}
if req.Pod == skipped.PodName {
links = append(links, skipped.LinkId)
}
}
return &mpb.ListSkippedResponse{LinkIds: links}, nil
}

func (m *Meshnet) Update(ctx context.Context, pod *mpb.RemotePod) (*mpb.BoolResponse, error) {
if err := vxlan.CreateOrUpdate(pod); err != nil {
mnetdLogger.Errorf("Failed to Update Vxlan")
Expand Down
Loading
Loading