Skip to content

Commit

Permalink
Merge pull request #590 from ffromani/resync-exclusive-resources
Browse files Browse the repository at this point in the history
nodetopologymatch: allow to track only pods with exclusive resources
  • Loading branch information
k8s-ci-robot committed Jun 1, 2023
2 parents 5af1783 + f5d7100 commit cbf2979
Show file tree
Hide file tree
Showing 28 changed files with 1,249 additions and 93 deletions.
38 changes: 38 additions & 0 deletions apis/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,42 @@ type ScoringStrategy struct {
Resources []schedconfig.ResourceSpec
}

// ForeignPodsDetectMode is a "string" type.
type ForeignPodsDetectMode string

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

// CacheResyncMethod is a "string" type.
type CacheResyncMethod string

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

// NodeResourceTopologyCache define configuration details for the NodeResourceTopology cache.
type NodeResourceTopologyCache struct {
// ForeignPodsDetect sets how foreign pods should be handled.
// Foreign pods are pods detected running on nodes managed by a NodeResourceTopologyMatch-enabled
// scheduler, but not scheduled by this scheduler instance, likely because this is running as
// secondary scheduler. To make sure the cache is consistent, foreign pods need to be handled.
// Has no effect if caching is disabled (CacheResyncPeriod is zero) or
// if DiscardReservedNodes is enabled. If unspecified, default is "All".
ForeignPodsDetect *ForeignPodsDetectMode
// ResyncMethod sets how the resync behaves to compute the expected node state.
// "All" consider all pods to compute the node state. "OnlyExclusiveResources" consider
// only pods regardless of their QoS which have exclusive resources assigned to their
// containers (CPUs, devices...).
// Has no effect if caching is disabled (CacheResyncPeriod is zero) or if DiscardReservedNodes
// is enabled. "Autodetect" is the default, reads hint from NRT objects. Fallback is "All".
ResyncMethod *CacheResyncMethod
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// NodeResourceTopologyMatchArgs holds arguments used to configure the NodeResourceTopologyMatch plugin
Expand All @@ -156,6 +192,8 @@ type NodeResourceTopologyMatchArgs struct {
// this option takes precedence over CacheResyncPeriodSeconds
// if DiscardReservedNodes is enabled, CacheResyncPeriodSeconds option is noop
DiscardReservedNodes bool
// Cache enables to fine tune the caching behavior
Cache *NodeResourceTopologyCache
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
15 changes: 15 additions & 0 deletions apis/config/v1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ var (
{Name: string(v1.ResourceMemory), Weight: 1},
}

defaultForeignPodsDetect = ForeignPodsDetectAll

defaultResyncMethod = CacheResyncAutodetect

// Defaults for NetworkOverhead
// DefaultWeightsName contains the default costs to be used by networkAware plugins
DefaultWeightsName = "UserDefined"
Expand Down Expand Up @@ -151,6 +155,17 @@ func SetDefaults_NodeResourceTopologyMatchArgs(obj *NodeResourceTopologyMatchArg
obj.ScoringStrategy.Resources[i].Weight = 1
}
}

if obj.Cache == nil {
obj.Cache = &NodeResourceTopologyCache{}
}
if obj.Cache.ForeignPodsDetect == nil {
obj.Cache.ForeignPodsDetect = &defaultForeignPodsDetect

}
if obj.Cache.ResyncMethod == nil {
obj.Cache.ResyncMethod = &defaultResyncMethod
}
}

// SetDefaults_PreemptionTolerationArgs reuses SetDefaults_DefaultPreemptionArgs
Expand Down
4 changes: 4 additions & 0 deletions apis/config/v1/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ func TestSchedulingDefaults(t *testing.T) {
Type: LeastAllocated,
Resources: defaultResourceSpec,
},
Cache: &NodeResourceTopologyCache{
ForeignPodsDetect: &defaultForeignPodsDetect,
ResyncMethod: &defaultResyncMethod,
},
},
},
{
Expand Down
38 changes: 38 additions & 0 deletions apis/config/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,42 @@ type ScoringStrategy struct {
Resources []schedulerconfigv1.ResourceSpec `json:"resources,omitempty"`
}

// ForeignPodsDetectMode is a "string" type.
type ForeignPodsDetectMode string

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

// CacheResyncMethod is a "string" type.
type CacheResyncMethod string

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

// NodeResourceTopologyCache define configuration details for the NodeResourceTopology cache.
type NodeResourceTopologyCache struct {
// ForeignPodsDetect sets how foreign pods should be handled.
// Foreign pods are pods detected running on nodes managed by a NodeResourceTopologyMatch-enabled
// scheduler, but not scheduled by this scheduler instance, likely because this is running as
// secondary scheduler. To make sure the cache is consistent, foreign pods need to be handled.
// Has no effect if caching is disabled (CacheResyncPeriod is zero) or if DiscardReservedNodes
// is enabled. If unspecified, default is "All". Use "None" to disable.
ForeignPodsDetect *ForeignPodsDetectMode `json:"foreignPodsDetect,omitempty"`
// ResyncMethod sets how the resync behaves to compute the expected node state.
// "All" consider all pods to compute the node state. "OnlyExclusiveResources" consider
// only pods regardless of their QoS which have exclusive resources assigned to their
// containers (CPUs, devices...).
// Has no effect if caching is disabled (CacheResyncPeriod is zero) or if DiscardReservedNodes
// is enabled. "Autodetect" is the default, reads hint from NRT objects. Fallback is "All".
ResyncMethod *CacheResyncMethod `json:"resyncMethod,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// NodeResourceTopologyMatchArgs holds arguments used to configure the NodeResourceTopologyMatch plugin
Expand All @@ -153,6 +189,8 @@ type NodeResourceTopologyMatchArgs struct {
// this option takes precedence over CacheResyncPeriodSeconds
// if DiscardReservedNodes is enabled, CacheResyncPeriodSeconds option is noop
DiscardReservedNodes bool `json:"discardReservedNodes,omitempty"`
// Cache enables to fine tune the caching behavior
Cache *NodeResourceTopologyCache `json:"cache,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
34 changes: 34 additions & 0 deletions apis/config/v1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions apis/config/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions apis/config/v1beta2/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ var (
{Name: string(v1.ResourceCPU), Weight: 1},
{Name: string(v1.ResourceMemory), Weight: 1},
}

defaultForeignPodsDetect = ForeignPodsDetectAll

defaultResyncMethod = CacheResyncAutodetect
)

// SetDefaults_CoschedulingArgs sets the default parameters for Coscheduling plugin.
Expand Down Expand Up @@ -149,6 +153,16 @@ func SetDefaults_NodeResourceTopologyMatchArgs(obj *NodeResourceTopologyMatchArg
obj.ScoringStrategy.Resources[i].Weight = 1
}
}

if obj.Cache == nil {
obj.Cache = &NodeResourceTopologyCache{}
}
if obj.Cache.ForeignPodsDetect == nil {
obj.Cache.ForeignPodsDetect = &defaultForeignPodsDetect
}
if obj.Cache.ResyncMethod == nil {
obj.Cache.ResyncMethod = &defaultResyncMethod
}
}

// SetDefaults_PreemptionTolerationArgs reuses SetDefaults_DefaultPreemptionArgs
Expand Down
4 changes: 4 additions & 0 deletions apis/config/v1beta2/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ func TestSchedulingDefaults(t *testing.T) {
Type: LeastAllocated,
Resources: defaultResourceSpec,
},
Cache: &NodeResourceTopologyCache{
ForeignPodsDetect: &defaultForeignPodsDetect,
ResyncMethod: &defaultResyncMethod,
},
},
},
{
Expand Down
38 changes: 38 additions & 0 deletions apis/config/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,42 @@ type ScoringStrategy struct {
Resources []schedulerconfigv1beta2.ResourceSpec `json:"resources,omitempty"`
}

// ForeignPodsDetectMode is a "string" type.
type ForeignPodsDetectMode string

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

// CacheResyncMethod is a "string" type.
type CacheResyncMethod string

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

// NodeResourceTopologyCache define configuration details for the NodeResourceTopology cache.
type NodeResourceTopologyCache struct {
// ForeignPodsDetect sets how foreign pods should be handled.
// Foreign pods are pods detected running on nodes managed by a NodeResourceTopologyMatch-enabled
// scheduler, but not scheduled by this scheduler instance, likely because this is running as
// secondary scheduler. To make sure the cache is consistent, foreign pods need to be handled.
// Has no effect if caching is disabled (CacheResyncPeriod is zero) or if DiscardReservedNodes
// is enabled. If unspecified, default is "All". Use "None" to disable.
ForeignPodsDetect *ForeignPodsDetectMode `json:"foreignPodsDetect,omitempty"`
// ResyncMethod sets how the resync behaves to compute the expected node state.
// "All" consider all pods to compute the node state. "OnlyExclusiveResources" consider
// only pods regardless of their QoS which have exclusive resources assigned to their
// containers (CPUs, devices...).
// Has no effect if caching is disabled (CacheResyncPeriod is zero) or if DiscardReservedNodes
// is enabled. "Autodetect" is the default, reads hint from NRT objects. Fallback is "All".
ResyncMethod *CacheResyncMethod `json:"resyncMethod,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// NodeResourceTopologyMatchArgs holds arguments used to configure the NodeResourceTopologyMatch plugin
Expand All @@ -152,6 +188,8 @@ type NodeResourceTopologyMatchArgs struct {
// this option takes precedence over CacheResyncPeriodSeconds
// if DiscardReservedNodes is enabled, CacheResyncPeriodSeconds option is noop
DiscardReservedNodes bool `json:"discardReservedNodes,omitempty"`
// Cache enables to fine tune the caching behavior
Cache *NodeResourceTopologyCache `json:"cache,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
Loading

0 comments on commit cbf2979

Please sign in to comment.