Skip to content

Commit

Permalink
tetragon-oci-hook: container name from annotations
Browse files Browse the repository at this point in the history
We cannot use arg.Watcher.FindContainer() because it uses k8s API where
the container is still not available.

Instead, we extract the name of the container from arg.Req.ContainerName

Fixes: #1879

Signed-off-by: Oleh Neichev <[email protected]>
  • Loading branch information
BonySmoke committed Mar 25, 2024
1 parent b597146 commit 405531f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/policyfilter/rthooks/rthooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package rthooks

import (
"context"
"fmt"
"path/filepath"
"time"

Expand Down Expand Up @@ -92,15 +93,14 @@ func createContainerHook(_ context.Context, arg *rthooks.CreateContainerArg) err
return err
}

var containerFound bool
var container *corev1.ContainerStatus
namespace := pod.ObjectMeta.Namespace
pod, container, containerFound = arg.Watcher.FindContainer(containerID)
if !containerFound {
log.WithError(err).Warnf("failed to find container information %s, aborting hook.", containerID)
}

containerName := container.Name
containerName := arg.Req.ContainerName
if containerName == "" {
err := fmt.Errorf("failed to find container information %s, aborting hook", containerID)
log.Warn(err)
return err
}

log.WithFields(logrus.Fields{
"pod-id": podID,
Expand Down

0 comments on commit 405531f

Please sign in to comment.