Skip to content

Commit 9906f8a

Browse files
committed
fix
Signed-off-by: Mikhail Scherba <mikhail.scherba@flant.com>
1 parent e76a82a commit 9906f8a

File tree

3 files changed

+14
-71
lines changed

3 files changed

+14
-71
lines changed

pkg/kube_config_manager/backend/configmap/configmap.go

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,9 @@ func (b Backend) SaveConfigValues(ctx context.Context, key string, values utils.
7474
}
7575

7676
func (b Backend) saveGlobalConfigValues(ctx context.Context, values utils.Values) ( /*checksum*/ string, error) {
77-
globalKubeConfig, err := config.ParseGlobalKubeConfigFromValues(values)
78-
if err != nil {
79-
return "", err
80-
}
81-
if globalKubeConfig == nil {
82-
return "", nil
77+
globalKubeConfig := &config.GlobalKubeConfig{
78+
Values: values,
79+
Checksum: values.Checksum(),
8380
}
8481

8582
if b.isDebugEnabled(ctx) {
@@ -90,7 +87,7 @@ func (b Backend) saveGlobalConfigValues(ctx context.Context, values utils.Values
9087
b.logger.Info("Save global values to ConfigMap", slog.String("name", b.name))
9188
}
9289

93-
err = b.mergeValues(ctx, globalKubeConfig.GetValuesWithGlobalName())
90+
err := b.mergeValues(ctx, "global", globalKubeConfig.GetValues())
9491

9592
return globalKubeConfig.Checksum, err
9693
}
@@ -107,10 +104,9 @@ func (b Backend) isDebugEnabled(ctx context.Context) bool {
107104
// saveModuleConfigValues updates module section in ConfigMap.
108105
// It uses knownChecksums to prevent KubeConfigChanged event on self-update.
109106
func (b Backend) saveModuleConfigValues(ctx context.Context, moduleName string, values utils.Values) ( /*checksum*/ string, error) {
110-
moduleKubeConfig := config.ParseModuleKubeConfigFromValues(moduleName, values)
111-
112-
if moduleKubeConfig == nil {
113-
return "", nil
107+
moduleKubeConfig := &config.ModuleKubeConfig{
108+
ModuleConfig: *utils.NewModuleConfig(moduleName, values),
109+
Checksum: values.Checksum(),
114110
}
115111

116112
if b.isDebugEnabled(ctx) {
@@ -124,7 +120,7 @@ func (b Backend) saveModuleConfigValues(ctx context.Context, moduleName string,
124120
slog.String("configMapName", b.name))
125121
}
126122

127-
err := b.mergeValues(ctx, moduleKubeConfig.GetValuesWithModuleName()) //nolint: staticcheck,nolintlint
123+
err := b.mergeValues(ctx, utils.ModuleNameToValuesKey(moduleName), moduleKubeConfig.GetValues()) //nolint: staticcheck,nolintlint
128124

129125
return moduleKubeConfig.Checksum, err
130126
}
@@ -282,15 +278,14 @@ func fromConfigMapData(moduleName string, configData map[string]string) (*utils.
282278
return mc.LoadFromValues(configValues)
283279
}
284280

285-
func (b Backend) mergeValues(ctx context.Context, values utils.Values) error {
286-
cmData, err := values.AsConfigMapData()
287-
if err != nil {
288-
return err
289-
}
281+
func (b Backend) mergeValues(ctx context.Context, moduleName string, values utils.Values) error {
290282
return b.updateConfigMap(ctx, func(obj *v1.ConfigMap) error {
291-
for k, v := range cmData {
292-
obj.Data[k] = v
283+
data, err := yaml.Marshal(values)
284+
if err != nil {
285+
return err
293286
}
287+
288+
obj.Data[moduleName] = string(data)
294289
return nil
295290
})
296291
}

pkg/kube_config_manager/config/config.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ type GlobalKubeConfig struct {
1414
Checksum string
1515
}
1616

17-
// GetValuesWithGlobalName
18-
// Deprecated: use GetValues instead
19-
func (gkc GlobalKubeConfig) GetValuesWithGlobalName() utils.Values {
20-
return gkc.Values
21-
}
22-
2317
// GetValues returns global values, enrich them with top level key 'global'
2418
func (gkc GlobalKubeConfig) GetValues() utils.Values {
2519
if len(gkc.Values) == 0 {
@@ -64,35 +58,3 @@ const (
6458
KubeConfigChanged KubeConfigType = "Changed"
6559
KubeConfigInvalid KubeConfigType = "Invalid"
6660
)
67-
68-
func ParseGlobalKubeConfigFromValues(values utils.Values) (*GlobalKubeConfig, error) {
69-
if !values.HasGlobal() {
70-
return nil, nil
71-
}
72-
73-
globalValues := values.Global()
74-
75-
checksum := globalValues.Checksum()
76-
77-
return &GlobalKubeConfig{
78-
Values: globalValues,
79-
Checksum: checksum,
80-
}, nil
81-
}
82-
83-
func ParseModuleKubeConfigFromValues(moduleName string, values utils.Values) *ModuleKubeConfig {
84-
valuesKey := utils.ModuleNameToValuesKey(moduleName)
85-
if !values.HasKey(valuesKey) {
86-
return nil
87-
}
88-
89-
//nolint: staticcheck,nolintlint
90-
moduleValues := values.SectionByKey(valuesKey)
91-
92-
checksum := moduleValues.Checksum()
93-
94-
return &ModuleKubeConfig{
95-
ModuleConfig: *utils.NewModuleConfig(moduleName, moduleValues),
96-
Checksum: checksum,
97-
}
98-
}

pkg/utils/values.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,20 +168,6 @@ func (v Values) AsString(format string) string {
168168
return string(b)
169169
}
170170

171-
// AsConfigMapData returns values as map that can be used as a 'data' field in the ConfigMap.
172-
func (v Values) AsConfigMapData() (map[string]string, error) {
173-
res := make(map[string]string)
174-
175-
for k, value := range v {
176-
dump, err := yaml.Marshal(value)
177-
if err != nil {
178-
return nil, err
179-
}
180-
res[k] = string(dump)
181-
}
182-
return res, nil
183-
}
184-
185171
func (v Values) JsonString() string {
186172
return v.AsString("json")
187173
}

0 commit comments

Comments
 (0)