Skip to content

Commit

Permalink
koordlet: fix struct type lost of node slo extension (koordinator-sh#…
Browse files Browse the repository at this point in the history
…1847)

Signed-off-by: 佑祎 <zzw261520@alibaba-inc.com>
  • Loading branch information
zwzhang0107 authored and ls-2018 committed Mar 25, 2024
1 parent 3954021 commit 008719c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apis/configuration/slo_controller_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (in *ExtensionCfg) DeepCopy() *ExtensionCfg {
// +k8s:deepcopy-gen=false
type NodeExtensionStrategy struct {
NodeCfgProfile `json:",inline"`
NodeStrategy interface{} // for third-party extension
NodeStrategy interface{} `json:",inline"` // for third-party extension
}

func (in *NodeExtensionStrategy) DeepCopyInto(out *NodeExtensionStrategy) {
Expand Down
15 changes: 11 additions & 4 deletions pkg/koordlet/statesinformer/impl/states_nodeslo.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,18 @@ func mergeSLOSpecExtensions(defaultSpec,
if newSpec != nil {
spec = newSpec
}
// ignore err for serializing/deserializing the same struct type
data, _ := json.Marshal(spec)
// NOTE: use deepcopy to avoid a overwrite to the global default

out := defaultSpec.DeepCopy()
_ = json.Unmarshal(data, &out)
for key := range out.Object {
// merge extension one by one so that all extension types can be protected during unmarshal
if newObj, exist := spec.Object[key]; exist {
// ignore err for serializing/deserializing the same struct type
data, _ := json.Marshal(newObj)
// NOTE: use deepcopy to avoid a overwrite to the global default
_ = json.Unmarshal(data, out.Object[key])
}
}

return out
}

Expand Down
1 change: 0 additions & 1 deletion pkg/koordlet/statesinformer/impl/states_nodeslo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func Test_mergeNodeSLOSpec(t *testing.T) {
SystemStrategy: &slov1alpha1.SystemStrategy{
WatermarkScaleFactor: pointer.Int64(200),
},
Extensions: &slov1alpha1.ExtensionsMap{},
}
testingMergedNodeSLOSpec := sloconfig.DefaultNodeSLOSpecConfig()
mergedInterface, err := util.MergeCfg(&testingMergedNodeSLOSpec, &testingCustomNodeSLOSpec)
Expand Down

0 comments on commit 008719c

Please sign in to comment.