Skip to content

Commit

Permalink
Merge pull request #1841 from carlosrodfern/minor-fix
Browse files Browse the repository at this point in the history
refactor(operator): remove config empty check
  • Loading branch information
daemon1024 authored Sep 17, 2024
2 parents dacac4a + 34ea89a commit b6480cd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
16 changes: 10 additions & 6 deletions KubeArmor/core/kubeUpdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2739,13 +2739,17 @@ func (dm *KubeArmorDaemon) WatchConfigMap() cache.InformerSynced {
if _, ok := cm.Data[cfg.ConfigAlertThrottling]; ok {
cfg.GlobalCfg.AlertThrottling = (cm.Data[cfg.ConfigAlertThrottling] == "true")
}
cfg.GlobalCfg.MaxAlertPerSec, err = strconv.Atoi(cm.Data[cfg.ConfigMaxAlertPerSec])
if err != nil {
dm.Logger.Warnf("Error: %s", err)
if _, ok := cm.Data[cfg.ConfigMaxAlertPerSec]; ok {
cfg.GlobalCfg.MaxAlertPerSec, err = strconv.Atoi(cm.Data[cfg.ConfigMaxAlertPerSec])
if err != nil {
dm.Logger.Warnf("Error: %s", err)
}
}
cfg.GlobalCfg.ThrottleSec, err = strconv.Atoi(cm.Data[cfg.ConfigThrottleSec])
if err != nil {
dm.Logger.Warnf("Error: %s", err)
if _, ok := cm.Data[cfg.ConfigMaxAlertPerSec]; ok {
cfg.GlobalCfg.ThrottleSec, err = strconv.Atoi(cm.Data[cfg.ConfigThrottleSec])
if err != nil {
dm.Logger.Warnf("Error: %s", err)
}
}
dm.SystemMonitor.UpdateThrottlingConfig()

Expand Down
5 changes: 5 additions & 0 deletions pkg/KubeArmorOperator/common/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ var (
KubeArmorRelayServerSecretName string = "kubearmor-relay-server-certs"
DefaultTlsCertPath string = "/var/lib/kubearmor/tls"
DefaultMode int32 = 420 // deciaml representation of octal value 644

// throttling
AlertThrottling bool = true
DefaultMaxAlertPerSec string = "10"
DefaultThrottleSec string = "30"
)

var ConfigMapData = map[string]string{
Expand Down
32 changes: 16 additions & 16 deletions pkg/KubeArmorOperator/internal/controller/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,27 +806,27 @@ func UpdateConfigMapData(config *opv1.KubeArmorConfigSpec) bool {
}
}
AlertThrottlingEnabled := strconv.FormatBool(config.AlertThrottling)
if AlertThrottlingEnabled != "" {
if common.ConfigMapData[common.ConfigAlertThrottling] != AlertThrottlingEnabled {
common.ConfigMapData[common.ConfigAlertThrottling] = AlertThrottlingEnabled
updated = true
}
if common.ConfigMapData[common.ConfigAlertThrottling] != AlertThrottlingEnabled {
common.ConfigMapData[common.ConfigAlertThrottling] = AlertThrottlingEnabled
updated = true
}
MaxAlertPerSec := strconv.FormatInt(int64(config.MaxAlertPerSec), 10)
if MaxAlertPerSec != "" {
if common.ConfigMapData[common.ConfigMaxAlertPerSec] != MaxAlertPerSec {
common.ConfigMapData[common.ConfigMaxAlertPerSec] = MaxAlertPerSec
updated = true
}
if config.MaxAlertPerSec == 0 {
MaxAlertPerSec = common.DefaultMaxAlertPerSec
}
ThrottleSec := strconv.FormatInt(int64(config.ThrottleSec), 10)
if MaxAlertPerSec != "" {
if common.ConfigMapData[common.ConfigThrottleSec] != ThrottleSec {
common.ConfigMapData[common.ConfigThrottleSec] = ThrottleSec
updated = true
}
if common.ConfigMapData[common.ConfigMaxAlertPerSec] != MaxAlertPerSec {
common.ConfigMapData[common.ConfigMaxAlertPerSec] = MaxAlertPerSec
updated = true
}

ThrottleSec := strconv.FormatInt(int64(config.ThrottleSec), 10)
if config.ThrottleSec == 0 {
ThrottleSec = common.DefaultThrottleSec
}
if common.ConfigMapData[common.ConfigThrottleSec] != ThrottleSec {
common.ConfigMapData[common.ConfigThrottleSec] = ThrottleSec
updated = true
}
return updated
}

Expand Down

0 comments on commit b6480cd

Please sign in to comment.