Skip to content

Commit

Permalink
bug fixes:
Browse files Browse the repository at this point in the history
- only handle pods on the same node
- fix a crash where accessing a static var before it is initialized
  • Loading branch information
orishavit committed Sep 19, 2024
1 parent 3b19f6c commit 3461594
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/node-agent/pkg/ebpf/openssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions src/node-agent/pkg/reconcilers/ebpfreconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/node-agent/pkg/service/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
var (
podName string
podNamespace string
nodeName string
printHttpRequests = false
)

Expand All @@ -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"
}

Expand All @@ -35,6 +42,10 @@ func PodNamespace() string {
return podNamespace
}

func NodeName() string {
return nodeName
}

func PrintHttpRequests() bool {
return printHttpRequests
}

0 comments on commit 3461594

Please sign in to comment.