From f9457e152b543422de379fcfd48e11972a06d21c Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Thu, 5 May 2022 19:48:29 +0700 Subject: [PATCH 1/3] add check for mechanism Signed-off-by: Nikita Skrynnik --- pkg/kernel/tools/heal/liveness_check.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/kernel/tools/heal/liveness_check.go b/pkg/kernel/tools/heal/liveness_check.go index 58efa5e5..ed2eaeec 100644 --- a/pkg/kernel/tools/heal/liveness_check.go +++ b/pkg/kernel/tools/heal/liveness_check.go @@ -24,6 +24,7 @@ import ( "time" "github.com/networkservicemesh/api/pkg/api/networkservice" + "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel" "github.com/networkservicemesh/sdk/pkg/tools/log" "github.com/tatsushid/go-fastping" ) @@ -35,6 +36,10 @@ const ( // NewKernelLivenessCheck is an implementation of heal.LivenessCheck. It sends ICMP // ping and checks reply. Returns false if didn't get reply. func NewKernelLivenessCheck(deadlineCtx context.Context, conn *networkservice.Connection) bool { + if mechanism := kernel.ToMechanism(conn.GetMechanism()); mechanism == nil { + log.FromContext(deadlineCtx).Errorf("Ping failed: wrong mechanism type") + } + p := fastping.NewPinger() deadline, ok := deadlineCtx.Deadline() if !ok { From c821537aecb7e10f99babd464bc5f2cf76ae1c12 Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Thu, 5 May 2022 20:06:02 +0700 Subject: [PATCH 2/3] apply comments Signed-off-by: Nikita Skrynnik --- pkg/kernel/tools/heal/liveness_check.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/kernel/tools/heal/liveness_check.go b/pkg/kernel/tools/heal/liveness_check.go index ed2eaeec..6d6eb0c7 100644 --- a/pkg/kernel/tools/heal/liveness_check.go +++ b/pkg/kernel/tools/heal/liveness_check.go @@ -36,8 +36,9 @@ const ( // NewKernelLivenessCheck is an implementation of heal.LivenessCheck. It sends ICMP // ping and checks reply. Returns false if didn't get reply. func NewKernelLivenessCheck(deadlineCtx context.Context, conn *networkservice.Connection) bool { - if mechanism := kernel.ToMechanism(conn.GetMechanism()); mechanism == nil { - log.FromContext(deadlineCtx).Errorf("Ping failed: wrong mechanism type") + if mechanism := conn.GetMechanism().GetType(); mechanism != kernel.MECHANISM { + log.FromContext(deadlineCtx).Warnf("ping is not supported for mechanism %v", mechanism) + return true } p := fastping.NewPinger() From 46f009a03e03d55e33ea50500caf2126a10857e4 Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Thu, 5 May 2022 20:14:55 +0700 Subject: [PATCH 3/3] fix name Signed-off-by: Nikita Skrynnik --- pkg/kernel/tools/heal/liveness_check.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/kernel/tools/heal/liveness_check.go b/pkg/kernel/tools/heal/liveness_check.go index 6d6eb0c7..72d4a00f 100644 --- a/pkg/kernel/tools/heal/liveness_check.go +++ b/pkg/kernel/tools/heal/liveness_check.go @@ -33,9 +33,9 @@ const ( defaultTimeout = 200 * time.Millisecond ) -// NewKernelLivenessCheck is an implementation of heal.LivenessCheck. It sends ICMP +// KernelLivenessCheck is an implementation of heal.LivenessCheck. It sends ICMP // ping and checks reply. Returns false if didn't get reply. -func NewKernelLivenessCheck(deadlineCtx context.Context, conn *networkservice.Connection) bool { +func KernelLivenessCheck(deadlineCtx context.Context, conn *networkservice.Connection) bool { if mechanism := conn.GetMechanism().GetType(); mechanism != kernel.MECHANISM { log.FromContext(deadlineCtx).Warnf("ping is not supported for mechanism %v", mechanism) return true