sharding

package
v1.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2026 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConfigMapDataKey is the key inside the ConfigMap that holds the YAML configuration.
	ConfigMapDataKey = "sharding.yaml"
	// DefaultConfigMapName is the default name of the sharding ConfigMap.
	DefaultConfigMapName = "volcano-sharding-configmap"
	// DefaultConfigMapNamespace is the default namespace of the sharding ConfigMap.
	DefaultConfigMapNamespace = "volcano-system"
	// DefaultPolicyName is the policy used when none is specified (backward compatibility).
	DefaultPolicyName = "allocation-rate"
)

Variables

This section is empty.

Functions

func CleanupController

func CleanupController(testCtrl *TestShardingController)

CleanupController cleans up controller resources

func CreateTestNode

func CreateTestNode(name string, cpu string, isWarmup bool, labels map[string]string) *corev1.Node

CreateTestNode creates a test node with specified configuration

func CreateTestNodeWithPods

func CreateTestNodeWithPods(t *testing.T, controller *ShardingController, nodeName string, cpu string, isWarmup bool, pods []*corev1.Pod)

CreateTestNodeWithPods creates a test node with multiple pods

func CreateTestPod

func CreateTestPod(namespace, name, nodeName, cpu, memory string) *corev1.Pod

CreateTestPod creates a test pod with specified resource requests

func ForceSyncShards

func ForceSyncShards(t *testing.T, controller *ShardingController, timeout time.Duration)

ForceSyncShards forces a shard synchronization and waits for completion

func SetupPodsOnNode

func SetupPodsOnNode(t *testing.T, controller *ShardingController, nodeName string, pods []*corev1.Pod)

SetupPodsOnNode creates multiple pods on a specific node

func VerifyAssignment

func VerifyAssignment(t *testing.T, controller *ShardingController, schedulerName string, expectedNodes []string)

VerifyAssignment verifies assignment for a scheduler

func VerifyAssignmentUpdate

func VerifyAssignmentUpdate(t *testing.T, controller *ShardingController, schedulerName string, expectedNodesToAdd []string, expectedNodesToRemove []string)

func WaitForNodeMetricsUpdate

func WaitForNodeMetricsUpdate(t *testing.T, controller *ShardingController, nodeName string, timeout time.Duration)

WaitForNodeMetricsUpdate waits for node metrics to be updated

func WaitForQueueProcessing

func WaitForQueueProcessing(controller *ShardingController, timeout time.Duration) error

WaitForQueueProcessing waits for queue to be processed

Types

type AssignmentCache

type AssignmentCache struct {
	Version     string
	Timestamp   time.Time
	Assignments map[string]*ShardAssignment // scheduler name -> assignment
}

AssignmentCache stores the result of shard assignments with version control

type AssignmentChangeEvent

type AssignmentChangeEvent struct {
	SchedulerName string
	OldNodes      []string
	NewNodes      []string
	NodesToAdd    []string
	NodesToRemove []string
	Version       string
	Timestamp     time.Time
}

AssignmentChangeEvent represents a change in assignment

type AssignmentContext

type AssignmentContext struct {
	AllNodes         []*corev1.Node
	CurrentShards    map[string]*shardv1alpha1.NodeShard
	SchedulerConfigs []SchedulerConfig
	AssignedNodes    map[string]string // node name -> scheduler name
	Timestamp        time.Time
}

AssignmentContext contains context information for shard assignment

type NodeEvent

type NodeEvent struct {
	EventType string // "pod-added", "pod-updated", "pod-deleted", "node-updated"
	NodeName  string
	Source    string // "pod-controller", "node-controller"
	Timestamp time.Time
}

NodeEvent represents a node-related event

type NodeMetrics

type NodeMetrics struct {
	NodeName        string
	ResourceVersion string
	LastUpdated     time.Time

	// Resource capacity and allocatable
	CPUCapacity       resource.Quantity
	CPUAllocatable    resource.Quantity
	MemoryCapacity    resource.Quantity
	MemoryAllocatable resource.Quantity

	// Resource utilization
	CPUUtilization    float64 // 0.0 to 1.0
	MemoryUtilization float64 // 0.0 to 1.0

	// Node characteristics
	IsWarmupNode bool
	PodCount     int
	Labels       map[string]string
	Annotations  map[string]string
}

NodeMetrics contains comprehensive metrics for a node

type NodeMetricsProvider

type NodeMetricsProvider interface {
	GetNodeMetrics(nodeName string) *NodeMetrics
	GetAllNodeMetrics() map[string]*NodeMetrics
	UpdateNodeMetrics(nodeName string, metrics *NodeMetrics)
}

NodeMetricsProvider provides access to node metrics

type NodeResourceInfo

type NodeResourceInfo struct {
	NodeName          string
	CPUAllocatable    resource.Quantity
	CPUCapacity       resource.Quantity
	MemoryAllocatable resource.Quantity
	MemoryCapacity    resource.Quantity
	CPUUtilization    float64 // 0.0 to 1.0
	MemoryUtilization float64 // 0.0 to 1.0
	IsWarmupNode      bool
	PodCount          int
	Labels            map[string]string
	Annotations       map[string]string
}

NodeResourceInfo contains resource utilization information for a node

type PolicyRef added in v1.15.0

type PolicyRef struct {
	Name      string                 // registered policy name (e.g. "allocation-rate")
	Weight    int                    // applied to Score output; default 1; only meaningful for Scorers
	Arguments map[string]interface{} // policy-specific arguments
}

PolicyRef is one entry in a scheduler's policy chain. Multiple PolicyRefs drive the multi-policy pipeline: each Filterer contributes to the filter phase (OR-union) and each Scorer to the score phase (weighted sum).

type PolicySpec added in v1.15.0

type PolicySpec struct {
	// Name is the registered policy name (e.g. "allocation-rate", "warmup").
	Name string `json:"name"`
	// Weight scales the policy's Score contribution; default 1. Only
	// meaningful for policies that implement the Scorer interface.
	Weight int `json:"weight,omitempty"`
	// Arguments holds policy-specific arguments. minNodes/maxNodes are only
	// valid on the node-limit policy.
	Arguments map[string]interface{} `json:"arguments,omitempty"`
}

PolicySpec is one policy entry in a scheduler's policy chain. Mirrors the user-facing YAML shape; converted to the internal PolicyRef at controller setup.

type SchedulerConfig

type SchedulerConfig struct {
	Name string
	Type string // "volcano" or "agent"

	// Policies is the per-scheduler policy chain. Filterers contribute to
	// filter (OR-union); Scorers to score (weighted sum). Empty means no
	// policy participation in those phases.
	Policies []PolicyRef

	// MinNodes and MaxNodes are common (non-policy-specific) bounds on the
	// number of nodes assigned to this scheduler. The sharding controller
	// clamps the policy output to this range; policies do not see them.
	MinNodes int
	MaxNodes int
}

SchedulerConfig defines the configuration for a scheduler.

type SchedulerConfigSpec

type SchedulerConfigSpec struct {
	// Name is the scheduler name (must match the schedulerName field in NodeShard).
	Name string `json:"name"`
	// Type describes the workload class (e.g. "volcano", "agent").
	Type string `json:"type"`

	// Policies is the per-scheduler policy chain. When empty,
	// applyPolicyDefaults synthesizes a default chain from legacy fields.
	Policies []PolicySpec `json:"policies,omitempty"`
	// Arguments holds legacy single-policy arguments. Deprecated: use Policies.
	Arguments map[string]interface{} `json:"arguments,omitempty"`
	// CPUUtilizationMin is the lower bound (inclusive) of the CPU utilisation range
	// [0.0, 1.0] that makes a node eligible for this scheduler's shard.
	//
	// Deprecated: use Policies instead.
	CPUUtilizationMin float64 `json:"cpuUtilizationMin"`
	// CPUUtilizationMax is the upper bound (inclusive) of the CPU utilisation range.
	//
	// Deprecated: use Policies instead.
	CPUUtilizationMax float64 `json:"cpuUtilizationMax"`
	// PreferWarmupNodes indicates whether warmup nodes should be sorted before
	// regular nodes when selecting shard members.
	//
	// Deprecated: use Policies (add a "warmup" entry) instead.
	PreferWarmupNodes bool `json:"preferWarmupNodes"`

	// MinNodes is informational only: the framework cannot synthesize nodes
	// that don't exist. If the policy chain returns fewer than MinNodes, the
	// shortfall is logged but the result is not padded. Scheduler-level
	// scalar; not a per-policy setting.
	//
	// Deprecated: use Policies (add a "node-limit" entry) instead.
	MinNodes int `json:"minNodes"`
	// MaxNodes is a hard cap. The policy-selected node list is truncated to
	// at most MaxNodes by the framework. Scheduler-level scalar; not a
	// per-policy setting. MaxNodes <= 0 means "no upper bound".
	//
	// Deprecated: use Policies (add a "node-limit" entry) instead.
	MaxNodes int `json:"maxNodes"`
}

SchedulerConfigSpec defines the per-scheduler sharding parameters. It is used both as the internal representation and as the YAML-serialisable form stored in the sharding ConfigMap.

type ShardAssignment

type ShardAssignment struct {
	SchedulerName string
	NodesDesired  []string
	Version       string
}

ShardAssignment represents assignment for a single scheduler.

type ShardingConfig added in v1.15.0

type ShardingConfig struct {
	// SchedulerConfigs holds the per-scheduler shard specifications.
	SchedulerConfigs []SchedulerConfigSpec `json:"schedulerConfigs"`
	// ShardSyncPeriod overrides the periodic sync interval when set.
	// Accepts Go duration strings such as "60s", "2m".
	ShardSyncPeriod string `json:"shardSyncPeriod,omitempty"`
	// EnableNodeEventTrigger controls event-driven shard updates.
	EnableNodeEventTrigger *bool `json:"enableNodeEventTrigger,omitempty"`
}

ShardingConfig is the top-level structure that is serialised as YAML into the sharding ConfigMap (key: sharding.yaml). See example/sharding/sharding-config-configmap.yaml for the full format.

func ParseShardingConfig added in v1.15.0

func ParseShardingConfig(data []byte) (*ShardingConfig, error)

ParseShardingConfig deserialises YAML bytes into a ShardingConfig. Returns an error when the input is not valid YAML or violates basic constraints (e.g. empty scheduler list).

type ShardingController

type ShardingController struct {
	// contains filtered or unexported fields
}

ShardingController implements the framework.Controller interface

func (*ShardingController) AddFlags added in v1.15.0

func (sc *ShardingController) AddFlags(fs *pflag.FlagSet)

AddFlags implements framework.FlagProvider, registering controller-specific flags before the binary's flag set is parsed.

func (*ShardingController) GetAllNodeMetrics

func (sc *ShardingController) GetAllNodeMetrics() map[string]*NodeMetrics

func (*ShardingController) GetNodeMetrics

func (sc *ShardingController) GetNodeMetrics(nodeName string) *NodeMetrics

Implement NodeMetricsProvider interface

func (*ShardingController) Initialize

func (sc *ShardingController) Initialize(opt *framework.ControllerOption) error

Initialize initializes the controller

func (*ShardingController) Name

func (sc *ShardingController) Name() string

Return the name of the controller

func (*ShardingController) Run

func (sc *ShardingController) Run(stopCh <-chan struct{})

Run starts the controller

func (*ShardingController) UpdateNodeMetrics

func (sc *ShardingController) UpdateNodeMetrics(nodeName string, metrics *NodeMetrics)

type ShardingControllerOptions

type ShardingControllerOptions struct {
	// SchedulerConfigsRaw holds the legacy colon-separated scheduler config
	// strings, provided via --scheduler-configs flag.
	SchedulerConfigsRaw []string
	// SchedulerConfigs is the parsed representation of SchedulerConfigsRaw.
	SchedulerConfigs []SchedulerConfigSpec
	// ShardSyncPeriod is the period between full shard reconciliations.
	ShardSyncPeriod time.Duration
	// EnableNodeEventTrigger controls whether node/pod events trigger immediate
	// shard reconciliation.
	EnableNodeEventTrigger bool
	// ConfigMapName is the name of the ConfigMap that holds the sharding
	// configuration.  When non-empty, the controller prefers ConfigMap-based
	// configuration over flag-based configuration and watches the ConfigMap
	// for live updates.
	ConfigMapName string
	// ConfigMapNamespace is the namespace of the sharding ConfigMap.
	ConfigMapNamespace string
}

ShardingControllerOptions holds all runtime-configurable options for the ShardingController.

func NewShardingControllerOptions

func NewShardingControllerOptions() ShardingControllerOptions

NewShardingControllerOptions returns a ShardingControllerOptions with sensible defaults.

func (*ShardingControllerOptions) AddFlags

func (opts *ShardingControllerOptions) AddFlags(fs *pflag.FlagSet)

AddFlags adds flags to the flag set using pflag pattern.

func (*ShardingControllerOptions) ParseConfig

func (opts *ShardingControllerOptions) ParseConfig() error

ParseConfig parses the raw colon-separated config strings into SchedulerConfigs. This is used only when ConfigMap-based configuration is not available. Warning: configuring sharding via command line is deprecated and will be removed in a future release; use the sharding ConfigMap instead.

type ShardingManager

type ShardingManager struct {
	// contains filtered or unexported fields
}

ShardingManager calculates shard assignments

func NewShardingManager

func NewShardingManager(schedulerConfigs []SchedulerConfig, nodeMetricsProvider NodeMetricsProvider) *ShardingManager

NewShardingManager creates a new sharding manager

func (*ShardingManager) CalculateShardAssignments

func (sm *ShardingManager) CalculateShardAssignments(
	nodes []*corev1.Node,
	currentShards []*shardv1alpha1.NodeShard,
) (map[string]*ShardAssignment, error)

CalculateShardAssignments calculates shard assignments for all schedulers

type TestControllerOption

type TestControllerOption struct {
	InitialObjects   []runtime.Object
	SchedulerConfigs []SchedulerConfigSpec
	ShardSyncPeriod  time.Duration
	StopCh           chan struct{}
	// SkipConfigMap, when true, omits the sharding ConfigMap from the fake
	// client so the controller exercises the flag-based fallback path.
	SkipConfigMap bool
}

TestControllerOption contains options for test controller

type TestShardingController

type TestShardingController struct {
	Controller *ShardingController
	StopCh     chan struct{}
}

TestShardingController is a test wrapper for ShardingController

Directories

Path Synopsis
builtin
Package builtin registers all built-in shard policies with the policy registry.
Package builtin registers all built-in shard policies with the policy registry.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL