Skip to content

Commit

Permalink
Adding logs
Browse files Browse the repository at this point in the history
Signed-off-by: David Wertenteil <[email protected]>
  • Loading branch information
David Wertenteil committed Feb 5, 2024
1 parent 1889117 commit 78a0c4f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
8 changes: 5 additions & 3 deletions continuousscanning/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func eventToUnstructured(e watch.Event) (*unstructured.Unstructured, error) {
}

func triggerScan(ctx context.Context, wp *ants.PoolWithFunc, clusterConfig config.IConfig, command *armoapi.Command) error {
utils.AddCommandToChannel(ctx, clusterConfig, command, wp)
return nil

return utils.AddCommandToChannel(ctx, clusterConfig, command, wp)
}

func unstructuredToScanObject(uObject *unstructured.Unstructured) (*objectsenvelopes.ScanObject, error) {
Expand All @@ -99,7 +99,9 @@ func unstructuredToScanObject(uObject *unstructured.Unstructured) (*objectsenvel
func triggerScanFor(ctx context.Context, uObject *unstructured.Unstructured, isDelete bool, wp *ants.PoolWithFunc, clusterConfig config.IConfig) error {
logger.L().Ctx(ctx).Info(
"triggering scan",
helpers.String("clusterName", clusterConfig.ClusterName()),
helpers.String("kind", uObject.GetKind()),
helpers.String("name", uObject.GetName()),
helpers.String("namespace", uObject.GetNamespace()),
)
sc := makeScanCommand(clusterConfig.ClusterName(), uObject, isDelete)
return triggerScan(ctx, wp, clusterConfig, sc)
Expand Down
19 changes: 3 additions & 16 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"github.com/armosec/armoapi-go/apis"
"github.com/armosec/utils-go/httputils"
"github.com/google/uuid"
"github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/k8s-interface/instanceidhandler"
"github.com/kubescape/k8s-interface/instanceidhandler/v1/containerinstance"
"github.com/kubescape/k8s-interface/instanceidhandler/v1/initcontainerinstance"
Expand Down Expand Up @@ -64,22 +62,11 @@ func ExtractImageID(imageID string) string {
return strings.TrimPrefix(imageID, dockerPullableURN)
}

func AddCommandToChannel(ctx context.Context, config config.IConfig, cmd *apis.Command, workerPool *ants.PoolWithFunc) {
logger.L().Ctx(ctx).Info(
"issuing scan command",
helpers.String("wlid", cmd.Wlid),
helpers.String("command", string(cmd.CommandName)),
)
func AddCommandToChannel(ctx context.Context, config config.IConfig, cmd *apis.Command, workerPool *ants.PoolWithFunc) error {

newSessionObj := NewSessionObj(ctx, config, cmd, "Websocket", "", uuid.NewString(), 1)

if err := workerPool.Invoke(Job{ctx: ctx, sessionObj: *newSessionObj}); err != nil {
logger.L().Ctx(ctx).Error(
"failed to invoke job",
helpers.String("wlid", cmd.Wlid),
helpers.String("command", string(cmd.CommandName)),
helpers.Error(err),
)
}
return workerPool.Invoke(Job{ctx: ctx, sessionObj: *newSessionObj})
}

func ExtractContainersToImageIDsFromPod(pod *core1.Pod) map[string]string {
Expand Down
2 changes: 2 additions & 0 deletions watcher/filteredsbomwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ func (wh *WatchHandler) HandleSBOMFilteredEvents(sfEvents <-chan watch.Event, pr
utils.ArgsContainerData: containerData,
},
}
// send
logger.L().Info("scanning filtered SBOM", helpers.String("wlid", cmd.Wlid), helpers.String("slug", containerData.Slug), helpers.String("containerName", containerData.ContainerName), helpers.String("imageTag", containerData.ImageTag), helpers.String("imageID", containerData.ImageID))
producedCommands <- cmd
}
}
Expand Down
5 changes: 4 additions & 1 deletion watcher/podwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ func (wh *WatchHandler) scanImage(ctx context.Context, pod *core1.Pod, container
}

// send
utils.AddCommandToChannel(ctx, wh.cfg, cmd, workerPool)
logger.L().Info("scanning image", helpers.String("wlid", cmd.Wlid), helpers.String("slug", containerData.Slug), helpers.String("containerName", containerData.ContainerName), helpers.String("imageTag", containerData.ImageTag), helpers.String("imageID", containerData.ImageID))
if err := utils.AddCommandToChannel(ctx, wh.cfg, cmd, workerPool); err != nil {
logger.L().Ctx(ctx).Error("failed to add command to channel", helpers.Error(err), helpers.String("slug", containerData.Slug), helpers.String("imageID", containerData.ImageID))
}
}

func (wh *WatchHandler) listPods(ctx context.Context) error {
Expand Down

0 comments on commit 78a0c4f

Please sign in to comment.