Skip to content

Commit b6480cd

Browse files
authored
Merge pull request #1841 from carlosrodfern/minor-fix
refactor(operator): remove config empty check
2 parents dacac4a + 34ea89a commit b6480cd

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

KubeArmor/core/kubeUpdate.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2739,13 +2739,17 @@ func (dm *KubeArmorDaemon) WatchConfigMap() cache.InformerSynced {
27392739
if _, ok := cm.Data[cfg.ConfigAlertThrottling]; ok {
27402740
cfg.GlobalCfg.AlertThrottling = (cm.Data[cfg.ConfigAlertThrottling] == "true")
27412741
}
2742-
cfg.GlobalCfg.MaxAlertPerSec, err = strconv.Atoi(cm.Data[cfg.ConfigMaxAlertPerSec])
2743-
if err != nil {
2744-
dm.Logger.Warnf("Error: %s", err)
2742+
if _, ok := cm.Data[cfg.ConfigMaxAlertPerSec]; ok {
2743+
cfg.GlobalCfg.MaxAlertPerSec, err = strconv.Atoi(cm.Data[cfg.ConfigMaxAlertPerSec])
2744+
if err != nil {
2745+
dm.Logger.Warnf("Error: %s", err)
2746+
}
27452747
}
2746-
cfg.GlobalCfg.ThrottleSec, err = strconv.Atoi(cm.Data[cfg.ConfigThrottleSec])
2747-
if err != nil {
2748-
dm.Logger.Warnf("Error: %s", err)
2748+
if _, ok := cm.Data[cfg.ConfigMaxAlertPerSec]; ok {
2749+
cfg.GlobalCfg.ThrottleSec, err = strconv.Atoi(cm.Data[cfg.ConfigThrottleSec])
2750+
if err != nil {
2751+
dm.Logger.Warnf("Error: %s", err)
2752+
}
27492753
}
27502754
dm.SystemMonitor.UpdateThrottlingConfig()
27512755

pkg/KubeArmorOperator/common/defaults.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ var (
119119
KubeArmorRelayServerSecretName string = "kubearmor-relay-server-certs"
120120
DefaultTlsCertPath string = "/var/lib/kubearmor/tls"
121121
DefaultMode int32 = 420 // deciaml representation of octal value 644
122+
123+
// throttling
124+
AlertThrottling bool = true
125+
DefaultMaxAlertPerSec string = "10"
126+
DefaultThrottleSec string = "30"
122127
)
123128

124129
var ConfigMapData = map[string]string{

pkg/KubeArmorOperator/internal/controller/cluster.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -806,27 +806,27 @@ func UpdateConfigMapData(config *opv1.KubeArmorConfigSpec) bool {
806806
}
807807
}
808808
AlertThrottlingEnabled := strconv.FormatBool(config.AlertThrottling)
809-
if AlertThrottlingEnabled != "" {
810-
if common.ConfigMapData[common.ConfigAlertThrottling] != AlertThrottlingEnabled {
811-
common.ConfigMapData[common.ConfigAlertThrottling] = AlertThrottlingEnabled
812-
updated = true
813-
}
809+
if common.ConfigMapData[common.ConfigAlertThrottling] != AlertThrottlingEnabled {
810+
common.ConfigMapData[common.ConfigAlertThrottling] = AlertThrottlingEnabled
811+
updated = true
814812
}
815813
MaxAlertPerSec := strconv.FormatInt(int64(config.MaxAlertPerSec), 10)
816-
if MaxAlertPerSec != "" {
817-
if common.ConfigMapData[common.ConfigMaxAlertPerSec] != MaxAlertPerSec {
818-
common.ConfigMapData[common.ConfigMaxAlertPerSec] = MaxAlertPerSec
819-
updated = true
820-
}
814+
if config.MaxAlertPerSec == 0 {
815+
MaxAlertPerSec = common.DefaultMaxAlertPerSec
821816
}
822-
ThrottleSec := strconv.FormatInt(int64(config.ThrottleSec), 10)
823-
if MaxAlertPerSec != "" {
824-
if common.ConfigMapData[common.ConfigThrottleSec] != ThrottleSec {
825-
common.ConfigMapData[common.ConfigThrottleSec] = ThrottleSec
826-
updated = true
827-
}
817+
if common.ConfigMapData[common.ConfigMaxAlertPerSec] != MaxAlertPerSec {
818+
common.ConfigMapData[common.ConfigMaxAlertPerSec] = MaxAlertPerSec
819+
updated = true
828820
}
829821

822+
ThrottleSec := strconv.FormatInt(int64(config.ThrottleSec), 10)
823+
if config.ThrottleSec == 0 {
824+
ThrottleSec = common.DefaultThrottleSec
825+
}
826+
if common.ConfigMapData[common.ConfigThrottleSec] != ThrottleSec {
827+
common.ConfigMapData[common.ConfigThrottleSec] = ThrottleSec
828+
updated = true
829+
}
830830
return updated
831831
}
832832

0 commit comments

Comments
 (0)