Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

koordlet: fix struct type lost of node slo extension #1847

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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