Skip to content

Commit 66ff960

Browse files
committed
limit number of audit entries
1 parent 757b877 commit 66ff960

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

cmd/minikube/cmd/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ var settings = []Setting{
168168
name: config.Rootless,
169169
set: SetBool,
170170
},
171+
{
172+
name: config.MaxAuditEntries,
173+
set: SetInt,
174+
},
171175
}
172176

173177
// ConfigCmd represents the config command

cmd/minikube/cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ func setupViper() {
325325
viper.SetDefault(config.ReminderWaitPeriodInHours, 24)
326326
viper.SetDefault(config.WantNoneDriverWarning, true)
327327
viper.SetDefault(config.WantVirtualBoxDriverWarning, true)
328+
viper.SetDefault(config.MaxAuditEntries, 1000)
328329
}
329330

330331
func addToPath(dir string) {

pkg/minikube/audit/audit.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ func LogCommandEnd(id string) error {
9898
return err
9999
}
100100
var entriesNeedsToUpdate int
101+
102+
startIndex := getStartIndex(len(rowSlice))
103+
rowSlice = rowSlice[startIndex:]
101104
for _, v := range rowSlice {
102105
if v.id == id {
103106
v.endTime = time.Now().Format(constants.TimeFormat)
@@ -118,6 +121,15 @@ func LogCommandEnd(id string) error {
118121
return nil
119122
}
120123

124+
func getStartIndex(entryCount int) int {
125+
maxEntries := viper.GetInt(config.MaxAuditEntries)
126+
startIndex := entryCount - maxEntries
127+
if maxEntries <= 0 || startIndex <= 0 {
128+
return 0
129+
}
130+
return startIndex
131+
}
132+
121133
// shouldLog returns if the command should be logged.
122134
func shouldLog() bool {
123135
// in rare chance we get here without a command, don't log

pkg/minikube/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ const (
5454
AddonListFlag = "addons"
5555
// EmbedCerts represents the config for embedding certificates in kubeconfig
5656
EmbedCerts = "EmbedCerts"
57+
// MaxAuditEntries is the maximum number of audit entries to retain
58+
MaxAuditEntries = "MaxAuditEntries"
5759
)
5860

5961
var (

0 commit comments

Comments
 (0)