Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add limit flag #59

Merged
merged 2 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ func init() {
logCmd.Flags().StringVar(&logOptions.PodName, "pod", "", "name of the pod ")
logCmd.Flags().StringVar(&logOptions.Resource, "resource", "", "command used by the user")
logCmd.Flags().StringVar(&logOptions.Source, "source", "", "binary used by the system ")
logCmd.Flags().Uint32Var(&logOptions.Limit, "limit", 0, "number of logs you want to see")
}
19 changes: 15 additions & 4 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Options struct {
PodName string
Source string
Resource string
Limit uint32
}

// StopChan Channel
Expand Down Expand Up @@ -120,7 +121,7 @@ func StartObserver(o Options) error {
}

// create a client
logClient := NewClient(gRPC, o.MsgPath, o.LogPath, o.LogFilter)
logClient := NewClient(gRPC, o.MsgPath, o.LogPath, o.LogFilter, o.Limit)
if logClient == nil {
return errors.New("failed to connect to the gRPC server\nPossible troubleshooting:\n- Check if Kubearmor is running\n- Create a portforward to KubeArmor relay service using\n\t\033[1mkubectl -n kube-system port-forward service/kubearmor --address 0.0.0.0 --address :: 32767:32767\033[0m\n- Configure grpc server information using\n\t\033[1mkarmor log --grpc <info>\033[0m")
}
Expand All @@ -143,6 +144,7 @@ func StartObserver(o Options) error {
return err
}

Limitchan = make(chan bool, 2)
if o.LogPath != "none" {
if o.LogFilter == "all" || o.LogFilter == "policy" {
// watch alerts
Expand All @@ -157,9 +159,18 @@ func StartObserver(o Options) error {
}
}

// listen for interrupt signals
sigChan := GetOSSigChannel()
<-sigChan
if o.Limit != 0 {
if o.LogFilter == "all" {
<-Limitchan
<-Limitchan
} else {
<-Limitchan
}
} else {
// listen for interrupt signals
sigChan := GetOSSigChannel()
<-sigChan
}
close(StopChan)

logClient.Running = false
Expand Down
Loading