Skip to content

Commit

Permalink
WIP: cache fine-tuning support
Browse files Browse the repository at this point in the history
TBD
tests missing

Signed-off-by: Francesco Romani <[email protected]>
  • Loading branch information
ffromani committed Nov 28, 2023
1 parent d46345b commit 213c9f0
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
48 changes: 47 additions & 1 deletion pkg/manifests/schedparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,22 @@ const (
SchedulerPluginName = "NodeResourceTopologyMatch"
)

const (
ForeignPodsDetectNone = "None"
ForeignPodsDetectAll = "All"
ForeignPodsDetectOnlyExclusiveResources = "OnlyExclusiveResources"
)

const (
CacheResyncAutodetect = "Autodetect"
CacheResyncAll = "All"
CacheResyncOnlyExclusiveResources = "OnlyExclusiveResources"
)

type ConfigCacheParams struct {
ResyncPeriodSeconds *int64
ResyncPeriodSeconds *int64
ResyncMethod *string
ForeignPodsDetectMode *string
}

type ConfigParams struct {
Expand Down Expand Up @@ -132,5 +146,37 @@ func extractParams(profileName string, args map[string]interface{}) (ConfigParam

val := int64(resyncPeriod)
params.Cache.ResyncPeriodSeconds = &val

cacheArgs, ok, err := unstructured.NestedMap(args, "cache")
if !ok {
// nothing to do
return params, nil
}
if err != nil {
return params, fmt.Errorf("cannot process field cache: %w", err)
}

resyncMethod, ok, err := unstructured.NestedString(cacheArgs, "resyncMethod")
if !ok {
// nothing to do
return params, nil
}
if err != nil {
return params, fmt.Errorf("cannot process field cache.resyncMethod: %w", err)
}

params.Cache.ResyncMethod = &resyncMethod

foreignPodsDetect, ok, err := unstructured.NestedString(cacheArgs, "foreignPodsDetect")
if !ok {
// nothing to do
return params, nil
}
if err != nil {
return params, fmt.Errorf("cannot process field cache.foreignPodsDetect: %w", err)
}

params.Cache.ForeignPodsDetectMode = &foreignPodsDetect

return params, nil
}
46 changes: 46 additions & 0 deletions pkg/objectupdate/sched/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,55 @@ func updateArgs(args map[string]interface{}, params *manifests.ConfigParams) (bo
updated++
}
}

cacheArgs, ok, err := unstructured.NestedMap(args, "cache")
if !ok {
cacheArgs = make(map[string]interface{})
}
if err != nil {
return updated > 0, err
}

cacheArgsUpdated, err := updateCacheArgs(cacheArgs, params)
if err != nil {
return updated > 0, err
}
updated += cacheArgsUpdated

if cacheArgsUpdated > 0 {
if err := unstructured.SetNestedMap(args, cacheArgs, "cache"); err != nil {
return updated > 0, err
}
}
return updated > 0, ensureBackwardCompatibility(args)
}

func updateCacheArgs(args map[string]interface{}, params *manifests.ConfigParams) (int, error) {
var updated int
var err error

if params.Cache != nil {
if params.Cache.ResyncMethod != nil {
resyncMethod := *params.Cache.ResyncMethod // shortcut
err = unstructured.SetNestedField(args, resyncMethod, "resyncMethod")
if err != nil {
return updated, err
}
updated++
}
if params.Cache.ForeignPodsDetectMode != nil {
foreignPodsMode := *params.Cache.ForeignPodsDetectMode // shortcut
err = unstructured.SetNestedField(args, foreignPodsMode, "foreignPodsDetect")
if err != nil {
return updated, err
}
updated++
}
}

return updated, nil
}

func ensureBackwardCompatibility(args map[string]interface{}) error {
resyncPeriod, ok, err := unstructured.NestedInt64(args, "cacheResyncPeriodSeconds")
if !ok {
Expand Down

0 comments on commit 213c9f0

Please sign in to comment.