diff --git a/src/node-agent/pkg/ebpf/openssl.go b/src/node-agent/pkg/ebpf/openssl.go index d7d877f7..acb14490 100644 --- a/src/node-agent/pkg/ebpf/openssl.go +++ b/src/node-agent/pkg/ebpf/openssl.go @@ -9,11 +9,13 @@ import ( "github.com/sirupsen/logrus" ) -var progs = []BpfProgram{ - {BpfEventTypeUProbe, "SSL_write", otrzebpf.Objs.OtterizeSSL_write, otrzebpf.Specs.OtterizeSSL_write, 0}, - {BpfEventTypeURetProbe, "SSL_write", otrzebpf.Objs.OtterizeSSL_writeRet, otrzebpf.Specs.OtterizeSSL_writeRet, 0}, - {BpfEventTypeUProbe, "SSL_write_ex", otrzebpf.Objs.OtterizeSSL_write, otrzebpf.Specs.OtterizeSSL_write, 0}, - {BpfEventTypeURetProbe, "SSL_write_ex", otrzebpf.Objs.OtterizeSSL_writeRet, otrzebpf.Specs.OtterizeSSL_writeRet, 0}, +func opensslPrograms() []BpfProgram { + return []BpfProgram{ + {BpfEventTypeUProbe, "SSL_write", otrzebpf.Objs.OtterizeSSL_write, otrzebpf.Specs.OtterizeSSL_write, 0}, + {BpfEventTypeURetProbe, "SSL_write", otrzebpf.Objs.OtterizeSSL_writeRet, otrzebpf.Specs.OtterizeSSL_writeRet, 0}, + {BpfEventTypeUProbe, "SSL_write_ex", otrzebpf.Objs.OtterizeSSL_write, otrzebpf.Specs.OtterizeSSL_write, 0}, + {BpfEventTypeURetProbe, "SSL_write_ex", otrzebpf.Objs.OtterizeSSL_writeRet, otrzebpf.Specs.OtterizeSSL_writeRet, 0}, + } } func (t *Tracer) AttachToOpenSSL(cInfo container.ContainerInfo) error { @@ -34,7 +36,7 @@ func (t *Tracer) AttachToOpenSSL(cInfo container.ContainerInfo) error { return errors.Wrap(err) } - for _, prog := range progs { + for _, prog := range opensslPrograms() { logrus.WithField("pid", cInfo.Pid).WithField("symbol", prog.Symbol).WithField("file", libsslPath).Debug("Attaching openssl probe") err = t.attachBpfProgram(ex, inode, prog) diff --git a/src/node-agent/pkg/reconcilers/ebpfreconciler.go b/src/node-agent/pkg/reconcilers/ebpfreconciler.go index b265baf2..6b4c981b 100644 --- a/src/node-agent/pkg/reconcilers/ebpfreconciler.go +++ b/src/node-agent/pkg/reconcilers/ebpfreconciler.go @@ -8,6 +8,7 @@ import ( "github.com/otterize/network-mapper/src/node-agent/pkg/container" "github.com/otterize/network-mapper/src/node-agent/pkg/ebpf" "github.com/otterize/network-mapper/src/node-agent/pkg/labels" + "github.com/otterize/network-mapper/src/node-agent/pkg/service" "github.com/otterize/network-mapper/src/shared/kubeutils" "github.com/sirupsen/logrus" corev1 "k8s.io/api/core/v1" @@ -68,6 +69,11 @@ func (r *EBPFReconciler) Reconcile(ctx context.Context, req reconcile.Request) ( return reconcile.Result{}, errors.Wrap(err) } + if pod.Spec.NodeName != service.NodeName() { + logger.Debug("Pod is not scheduled on this node, skipping") + return reconcile.Result{}, nil + } + if pod.Status.Phase != corev1.PodRunning { logger.Debug("Pod is not running, skipping") return reconcile.Result{}, nil diff --git a/src/node-agent/pkg/service/env.go b/src/node-agent/pkg/service/env.go index 270fd435..69745e07 100644 --- a/src/node-agent/pkg/service/env.go +++ b/src/node-agent/pkg/service/env.go @@ -8,6 +8,7 @@ import ( var ( podName string podNamespace string + nodeName string printHttpRequests = false ) @@ -24,6 +25,12 @@ func init() { logrus.Panic("POD_NAMESPACE environment variable must be set") } + nodeName = os.Getenv("NODE_NAME") + + if nodeName == "" { + logrus.Panic("NODE_NAME environment variable must be set") + } + printHttpRequests = os.Getenv("OTTERIZE_PRINT_HTTP_REQUESTS") == "true" } @@ -35,6 +42,10 @@ func PodNamespace() string { return podNamespace } +func NodeName() string { + return nodeName +} + func PrintHttpRequests() bool { return printHttpRequests }