Skip to content

Commit

Permalink
koord-manager: fix node slo extension got overwriten (#1552)
Browse files Browse the repository at this point in the history
Signed-off-by: 佑祎 <[email protected]>
  • Loading branch information
zwzhang0107 authored Aug 16, 2023
1 parent 4d28dbc commit b791330
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/slo-controller/nodeslo/extender_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

func getDefaultExtensionStrategy() *slov1alpha1.ExtensionsMap {
defaultCfg := getDefaultExtensionCfg()
defaultStrategy := slov1alpha1.ExtensionsMap{}
defaultStrategy := slov1alpha1.ExtensionsMap{Object: map[string]interface{}{}}
if defaultCfg == nil || defaultCfg.Object == nil {
return &defaultStrategy
}
Expand Down
19 changes: 10 additions & 9 deletions pkg/slo-controller/nodeslo/extender_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ func calculateExtensionsCfgMerged(oldCfgMap configuration.ExtensionCfgMap, confi
return mergedCfgMap
}

func getExtensionsConfigSpec(node *corev1.Node, cfgMap *configuration.ExtensionCfgMap) *slov1alpha1.ExtensionsMap {
extMap := slov1alpha1.ExtensionsMap{}
func getExtensionsConfigSpec(node *corev1.Node, oldSpec *slov1alpha1.NodeSLOSpec, cfgMap *configuration.ExtensionCfgMap) *slov1alpha1.ExtensionsMap {
extMap := &slov1alpha1.ExtensionsMap{Object: map[string]interface{}{}}
if oldSpec != nil && oldSpec.Extensions != nil && oldSpec.Extensions.Object != nil {
extMap = oldSpec.Extensions.DeepCopy()
}
if cfgMap == nil || cfgMap.Object == nil {
return &extMap
return extMap
}
for name, extender := range globalNodeSLOMergedExtender {
extKey, extStrategy, err := extender.GetNodeSLOExtension(node, cfgMap)
Expand All @@ -75,16 +78,14 @@ func getExtensionsConfigSpec(node *corev1.Node, cfgMap *configuration.ExtensionC
continue
}
if extStrategy == nil {
continue
}
if extMap.Object == nil {
extMap.Object = make(map[string]interface{})
delete(extMap.Object, extKey)
} else {
extMap.Object[extKey] = extStrategy
}
extMap.Object[extKey] = extStrategy
metrics.RecordNodeSLOSpecParseCount(true, "getNodeSLOExtension")
klog.V(5).Infof("run get nodeSLO extender %v success, extMap %v", name, extMap)
}
return &extMap
return extMap
}

func UnregisterNodeSLOMergedExtender(name string) {
Expand Down
16 changes: 15 additions & 1 deletion pkg/slo-controller/nodeslo/extender_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/client-go/tools/record"

"github.com/koordinator-sh/koordinator/apis/configuration"
slov1alpha1 "github.com/koordinator-sh/koordinator/apis/slo/v1alpha1"
)

const (
Expand Down Expand Up @@ -62,18 +63,31 @@ func Test_NodeMergedExtender(t *testing.T) {
testExtKey: testExtIF,
},
}
oldOtherExtKey := "old-other-ext-key"
oldOtherExtVal := "old-other-ext-val"
oldSpec := &slov1alpha1.NodeSLOSpec{
Extensions: &slov1alpha1.ExtensionsMap{
Object: map[string]interface{}{
oldOtherExtKey: oldOtherExtVal,
},
},
}
node := &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{},
},
}
cfgMap := configuration.ExtensionCfgMap{}
newCfg := calculateExtensionsCfgMerged(cfgMap, configMap, &record.FakeRecorder{})
extMap := getExtensionsConfigSpec(node, &newCfg)
extMap := getExtensionsConfigSpec(node, oldSpec, &newCfg)
gotIf := extMap.Object[testExtKey].(string)
if gotIf != testExtIF {
t.Errorf("run NodeMergedExtender got ext key %s, want %s", gotIf, testExtIF)
}
gotOtherIf := extMap.Object[oldOtherExtKey].(string)
if gotOtherIf != oldOtherExtVal {
t.Errorf("run NodeMergedExtender got other ext key %s, want %s", gotOtherIf, oldOtherExtVal)
}
UnregisterNodeSLOMergedExtender(pluginName)
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/slo-controller/nodeslo/nodeslo_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (r *NodeSLOReconciler) getNodeSLOSpec(node *corev1.Node, oldSpec *slov1alph
metrics.RecordNodeSLOSpecParseCount(true, "getSystemConfigSpec")
}

nodeSLOSpec.Extensions = getExtensionsConfigSpec(node, &sloCfg.ExtensionCfgMerged)
nodeSLOSpec.Extensions = getExtensionsConfigSpec(node, oldSpec, &sloCfg.ExtensionCfgMerged)

return nodeSLOSpec, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/slo-controller/nodeslo/nodeslo_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import (
// plugins in koordlet/resmanager will get the interface and
// change it to strategy individually
func getExtensionsIfMap(in slov1alpha1.ExtensionsMap) (*slov1alpha1.ExtensionsMap, error) {
extensionsMap := &slov1alpha1.ExtensionsMap{}
extensionsMap := &slov1alpha1.ExtensionsMap{Object: map[string]interface{}{}}
for extkey, extIf := range in.Object {
//marshal unmarshal to
extStr, err := json.Marshal(extIf)
Expand Down

0 comments on commit b791330

Please sign in to comment.