Skip to content

Commit 2c72aab

Browse files
committed
fix: rename MaintenanceState to Maintenance
Signed-off-by: Evsyukov Denis <[email protected]>
1 parent 0abfaa1 commit 2c72aab

File tree

7 files changed

+53
-53
lines changed

7 files changed

+53
-53
lines changed

pkg/addon-operator/operator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ func (op *AddonOperator) StartModuleManagerEventHandler() {
12011201
}
12021202

12031203
for module, state := range event.ModuleMaintenanceChanged {
1204-
op.ModuleManager.SetModuleMaintenanceState(module, state)
1204+
op.ModuleManager.SetModuleMaintenance(module, state)
12051205
}
12061206

12071207
// if global hooks haven't been run yet, script enabled extender fails due to missing global values,

pkg/kube_config_manager/backend/configmap/configmap.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ func getModulesNamesFromConfigData(configData map[string]string) (map[string]boo
195195
continue
196196
}
197197

198-
// Treat Enabled and MaintenanceState flags as module section.
198+
// Treat Enabled and Maintenance flags as module section.
199199
key = strings.TrimSuffix(key, utils.EnabledSuffix)
200-
key = strings.TrimSuffix(key, utils.MaintenanceStateSuffix)
200+
key = strings.TrimSuffix(key, utils.MaintenanceSuffix)
201201

202202
modName := utils.ModuleNameFromValuesKey(key)
203203

@@ -272,20 +272,20 @@ func fromConfigMapData(moduleName string, configData map[string]string) (*utils.
272272
configValues[mc.ModuleEnabledKey()] = enabled
273273
}
274274

275-
maintenanceStateString, hasKey := configData[mc.ModuleMaintenanceStateKey()]
275+
maintenanceString, hasKey := configData[mc.ModuleMaintenanceKey()]
276276
if hasKey {
277277
var state utils.Maintenance
278278

279-
switch maintenanceStateString {
279+
switch maintenanceString {
280280
case "NoResourceReconciliation", "noresourcereconciliation":
281281
state = utils.NoResourceReconciliation
282282
case "":
283283
state = utils.Managed
284284
default:
285-
return nil, fmt.Errorf("module maintenanceState key '%s' can only take 'NoResourceReconciliation', 'noresourcereconciliation' or '' values, got '%v'", mc.ModuleMaintenanceStateKey(), maintenanceStateString)
285+
return nil, fmt.Errorf("module maintenance key '%s' can only take 'NoResourceReconciliation', 'noresourcereconciliation' or '' values, got '%v'", mc.ModuleMaintenanceKey(), maintenanceString)
286286
}
287287

288-
configValues[mc.ModuleMaintenanceStateKey()] = state
288+
configValues[mc.ModuleMaintenanceKey()] = state
289289
}
290290

291291
if len(configValues) == 0 {

pkg/kube_config_manager/kube_config_manager.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func (kcm *KubeConfigManager) handleConfigEvent(obj config.Event) {
258258
modulesStateChanged = append(modulesStateChanged, moduleName)
259259
}
260260

261-
if kcm.currentConfig.Modules[moduleName].GetMaintenanceState() == utils.NoResourceReconciliation {
261+
if kcm.currentConfig.Modules[moduleName].GetMaintenance() == utils.NoResourceReconciliation {
262262
moduleMaintenanceChanged[moduleName] = utils.Managed
263263
}
264264

@@ -287,27 +287,27 @@ func (kcm *KubeConfigManager) handleConfigEvent(obj config.Event) {
287287
modulesStateChanged = append(modulesStateChanged, moduleName)
288288
}
289289

290-
if kcm.currentConfig.Modules[moduleName].GetMaintenanceState() != moduleCfg.GetMaintenanceState() {
291-
moduleMaintenanceChanged[moduleName] = moduleCfg.GetMaintenanceState()
290+
if kcm.currentConfig.Modules[moduleName].GetMaintenance() != moduleCfg.GetMaintenance() {
291+
moduleMaintenanceChanged[moduleName] = moduleCfg.GetMaintenance()
292292
}
293293
kcm.logger.Info("Module section changed. Enabled flag transition.",
294294
slog.String("moduleName", moduleName),
295295
slog.String("previous", kcm.currentConfig.Modules[moduleName].GetEnabled()),
296296
slog.String("current", moduleCfg.GetEnabled()),
297-
slog.String("maintenanceFlag", moduleCfg.GetMaintenanceState().String()))
297+
slog.String("maintenanceFlag", moduleCfg.GetMaintenance().String()))
298298
} else {
299299
modulesChanged = append(modulesChanged, moduleName)
300300
if moduleCfg.GetEnabled() != "" && moduleCfg.GetEnabled() != "n/d" {
301301
modulesStateChanged = append(modulesStateChanged, moduleName)
302302
}
303303

304-
if moduleCfg.GetMaintenanceState() == utils.NoResourceReconciliation {
304+
if moduleCfg.GetMaintenance() == utils.NoResourceReconciliation {
305305
moduleMaintenanceChanged[moduleName] = utils.NoResourceReconciliation
306306
}
307307
kcm.logger.Info("Module section added",
308308
slog.String("moduleName", moduleName),
309309
slog.String("enabledFlag", moduleCfg.GetEnabled()),
310-
slog.String("maintenanceFlag", moduleCfg.GetMaintenanceState().String()))
310+
slog.String("maintenanceFlag", moduleCfg.GetMaintenance().String()))
311311
}
312312
}
313313

@@ -375,29 +375,29 @@ func (kcm *KubeConfigManager) handleBatchConfigEvent(obj config.Event) {
375375
modulesStateChanged = append(modulesStateChanged, moduleName)
376376
}
377377

378-
if kcm.currentConfig.Modules[moduleName].GetMaintenanceState() != moduleCfg.GetMaintenanceState() {
379-
moduleMaintenanceChanged[moduleName] = moduleCfg.GetMaintenanceState()
378+
if kcm.currentConfig.Modules[moduleName].GetMaintenance() != moduleCfg.GetMaintenance() {
379+
moduleMaintenanceChanged[moduleName] = moduleCfg.GetMaintenance()
380380
}
381381

382382
kcm.logger.Info("Module section changed. Enabled flag transition",
383383
slog.String("moduleName", moduleName),
384384
slog.String("previous", kcm.currentConfig.Modules[moduleName].GetEnabled()),
385385
slog.String("current", moduleCfg.GetEnabled()),
386-
slog.String("maintenanceFlag", moduleCfg.GetMaintenanceState().String()))
386+
slog.String("maintenanceFlag", moduleCfg.GetMaintenance().String()))
387387
} else {
388388
modulesChanged = append(modulesChanged, moduleName)
389389
if moduleCfg.GetEnabled() != "" && moduleCfg.GetEnabled() != "n/d" {
390390
modulesStateChanged = append(modulesStateChanged, moduleName)
391391
}
392392

393-
if moduleCfg.GetMaintenanceState() == utils.NoResourceReconciliation {
393+
if moduleCfg.GetMaintenance() == utils.NoResourceReconciliation {
394394
moduleMaintenanceChanged[moduleName] = utils.NoResourceReconciliation
395395
}
396396

397397
kcm.logger.Info("Module section added",
398398
slog.String("moduleName", moduleName),
399399
slog.String("enabledFlag", moduleCfg.GetEnabled()),
400-
slog.String("maintenanceFlag", moduleCfg.GetMaintenanceState().String()))
400+
slog.String("maintenanceFlag", moduleCfg.GetMaintenance().String()))
401401
}
402402
}
403403
}

pkg/module_manager/models/modules/basic.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,17 @@ func (bm *BasicModule) SetHooksControllersReady() {
188188
// ResetState drops the module state
189189
func (bm *BasicModule) ResetState() {
190190
bm.l.Lock()
191-
var maintenanceState MaintenanceState
191+
var maintenance Maintenance
192192

193-
if bm.state.maintenanceState == UnmanagedEnforced {
194-
maintenanceState = UnmanagedEnabled
193+
if bm.state.maintenance == UnmanagedEnforced {
194+
maintenance = UnmanagedEnabled
195195
}
196196

197197
bm.state = &moduleState{
198198
Phase: Startup,
199199
hookErrors: make(map[string]error),
200200
synchronizationState: NewSynchronizationState(),
201-
maintenanceState: maintenanceState,
201+
maintenance: maintenance,
202202
}
203203
bm.l.Unlock()
204204
}
@@ -544,34 +544,34 @@ func (bm *BasicModule) SaveHookError(hookName string, err error) {
544544
bm.l.Unlock()
545545
}
546546

547-
func (bm *BasicModule) SetMaintenanceState(state utils.Maintenance) {
547+
func (bm *BasicModule) SetMaintenance(state utils.Maintenance) {
548548
bm.l.Lock()
549549
switch state {
550550
case utils.NoResourceReconciliation:
551-
if bm.state.maintenanceState == Managed {
552-
bm.state.maintenanceState = UnmanagedEnabled
551+
if bm.state.maintenance == Managed {
552+
bm.state.maintenance = UnmanagedEnabled
553553
}
554554
case utils.Managed:
555-
if bm.state.maintenanceState != Managed {
556-
bm.state.maintenanceState = Managed
555+
if bm.state.maintenance != Managed {
556+
bm.state.maintenance = Managed
557557
}
558558
}
559559
bm.l.Unlock()
560560
}
561561

562562
func (bm *BasicModule) SetUnmanagedEnforced() {
563563
bm.l.Lock()
564-
if bm.state.maintenanceState == UnmanagedEnabled {
565-
bm.state.maintenanceState = UnmanagedEnforced
564+
if bm.state.maintenance == UnmanagedEnabled {
565+
bm.state.maintenance = UnmanagedEnforced
566566
}
567567
bm.l.Unlock()
568568
}
569569

570-
func (bm *BasicModule) GetMaintenanceState() MaintenanceState {
570+
func (bm *BasicModule) GetMaintenance() Maintenance {
571571
bm.l.RLock()
572572
defer bm.l.RUnlock()
573573

574-
return bm.state.maintenanceState
574+
return bm.state.maintenance
575575
}
576576

577577
// RunHooksByBinding gets all hooks for binding, for each hook it creates a BindingContext,
@@ -1278,11 +1278,11 @@ const (
12781278
HooksDisabled ModuleRunPhase = "HooksDisabled"
12791279
)
12801280

1281-
type MaintenanceState int
1281+
type Maintenance int
12821282

12831283
const (
12841284
// Module runs in a normal mode
1285-
Managed MaintenanceState = iota
1285+
Managed Maintenance = iota
12861286
// Next helm run will enforce NoResourceReconciliation mode (removes heritage labels and stops resource informer)
12871287
UnmanagedEnabled
12881288
// All consequent helm runs are inhibited
@@ -1291,7 +1291,7 @@ const (
12911291

12921292
type moduleState struct {
12931293
Enabled bool
1294-
maintenanceState MaintenanceState
1294+
maintenance Maintenance
12951295
Phase ModuleRunPhase
12961296
lastModuleErr error
12971297
hookErrors map[string]error

pkg/module_manager/models/modules/helm.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ func NewHelmModule(bm *BasicModule, namespace string, tmpDir string, deps *HelmM
7676
}
7777

7878
additionalLabels := make(map[string]string)
79-
if bm.GetMaintenanceState() != Managed {
80-
additionalLabels["maintenanceState"] = utils.NoResourceReconciliation.String()
79+
if bm.GetMaintenance() != Managed {
80+
additionalLabels["maintenance"] = utils.NoResourceReconciliation.String()
8181
}
8282

8383
hm := &HelmModule{

pkg/module_manager/module_manager.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ func (mm *ModuleManager) validateNewKubeConfig(kubeConfig *config.KubeConfig, al
284284
continue
285285
}
286286

287-
if moduleConfig.GetMaintenanceState() == utils.NoResourceReconciliation {
287+
if moduleConfig.GetMaintenance() == utils.NoResourceReconciliation {
288288
mm.dependencies.MetricStorage.Grouped().GaugeSet(moduleMaintenanceMetricGroup, moduleMaintenanceMetricName, 1, map[string]string{"moduleName": moduleName, "state": utils.NoResourceReconciliation.String()})
289-
mod.SetMaintenanceState(moduleConfig.GetMaintenanceState())
289+
mod.SetMaintenance(moduleConfig.GetMaintenance())
290290
}
291291

292292
validateConfig := false
@@ -498,9 +498,9 @@ func (mm *ModuleManager) UpdateModulesMetrics() {
498498
}
499499
}
500500

501-
func (mm *ModuleManager) SetModuleMaintenanceState(moduleName string, state utils.Maintenance) {
501+
func (mm *ModuleManager) SetModuleMaintenance(moduleName string, state utils.Maintenance) {
502502
if bm := mm.GetModule(moduleName); bm != nil {
503-
bm.SetMaintenanceState(state)
503+
bm.SetMaintenance(state)
504504
mm.logger.Info("set module management state",
505505
slog.String("module", moduleName),
506506
slog.String("state", state.String()))
@@ -742,12 +742,12 @@ func (mm *ModuleManager) RunModule(moduleName string, logLabels map[string]strin
742742
}
743743

744744
if err == nil {
745-
moduleMaintenanceState := bm.GetMaintenanceState()
746-
if moduleMaintenanceState != modules.UnmanagedEnforced {
745+
moduleMaintenance := bm.GetMaintenance()
746+
if moduleMaintenance != modules.UnmanagedEnforced {
747747
err = helmModule.RunHelmInstall(logLabels)
748748
}
749749

750-
if moduleMaintenanceState == modules.UnmanagedEnabled {
750+
if moduleMaintenance == modules.UnmanagedEnabled {
751751
bm.SetUnmanagedEnforced()
752752
mm.dependencies.HelmResourcesManager.StopMonitor(moduleName)
753753
}

pkg/utils/module_config.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ var (
1414
ModuleEnabled = true
1515
ModuleDisabled = false
1616

17-
EnabledSuffix = "Enabled"
18-
MaintenanceStateSuffix = "Maintenance"
17+
EnabledSuffix = "Enabled"
18+
MaintenanceSuffix = "Maintenance"
1919
)
2020

2121
type Maintenance string
@@ -39,7 +39,7 @@ type ModuleConfig struct {
3939

4040
// String returns description of ModuleConfig values.
4141
func (mc *ModuleConfig) String() string {
42-
return fmt.Sprintf("Module(Name=%s IsEnabled=%v MaintenanceState=%v Values:\n%s)", mc.ModuleName, mc.IsEnabled, mc.Maintenance, mc.values.DebugString())
42+
return fmt.Sprintf("Module(Name=%s IsEnabled=%v Maintenance=%v Values:\n%s)", mc.ModuleName, mc.IsEnabled, mc.Maintenance, mc.values.DebugString())
4343
}
4444

4545
// ModuleConfigKey transforms module kebab-case name to the config camelCase name
@@ -52,9 +52,9 @@ func (mc *ModuleConfig) ModuleEnabledKey() string {
5252
return ModuleNameToValuesKey(mc.ModuleName) + EnabledSuffix
5353
}
5454

55-
// ModuleMaintenanceStateKey transforms module kebab-case name to the config camelCase name with 'MaintenanceState' suffix
56-
func (mc *ModuleConfig) ModuleMaintenanceStateKey() string {
57-
return ModuleNameToValuesKey(mc.ModuleName) + MaintenanceStateSuffix
55+
// ModuleMaintenanceKey transforms module kebab-case name to the config camelCase name with 'Maintenance' suffix
56+
func (mc *ModuleConfig) ModuleMaintenanceKey() string {
57+
return ModuleNameToValuesKey(mc.ModuleName) + MaintenanceSuffix
5858
}
5959

6060
// GetEnabled returns string description of enabled status.
@@ -72,7 +72,7 @@ func (mc *ModuleConfig) GetEnabled() string {
7272
}
7373
}
7474

75-
func (mc *ModuleConfig) GetMaintenanceState() Maintenance {
75+
func (mc *ModuleConfig) GetMaintenance() Maintenance {
7676
if mc == nil {
7777
return Managed
7878
}
@@ -158,12 +158,12 @@ func (mc *ModuleConfig) LoadFromValues(values Values) (*ModuleConfig, error) {
158158
}
159159
}
160160

161-
if maintenanceState, hasMaintenanceState := values[mc.ModuleMaintenanceStateKey()]; hasMaintenanceState {
162-
switch v := maintenanceState.(type) {
161+
if maintenance, hasMaintenance := values[mc.ModuleMaintenanceKey()]; hasMaintenance {
162+
switch v := maintenance.(type) {
163163
case Maintenance:
164164
mc.Maintenance = v
165165
default:
166-
return nil, fmt.Errorf("load '%s' MaintenanceState config: MaintenanceState value should be string. Got: %#v", mc.ModuleName, maintenanceState)
166+
return nil, fmt.Errorf("load '%s' Maintenance config: Maintenance value should be string. Got: %#v", mc.ModuleName, maintenance)
167167
}
168168
}
169169

0 commit comments

Comments
 (0)