Skip to content

Commit d81e2e5

Browse files
y-youngSpace
authored and
Space
committed
feat: pod node selector
1 parent 98f71e6 commit d81e2e5

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

resources/src/objects/pod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use indenter::indented;
77
use serde::{Deserialize, Serialize};
88
use strum::{Display, EnumIter, IntoEnumIterator};
99

10-
use super::{function::Function, metrics, Metadata, Object};
10+
use super::{function::Function, metrics, Labels, Metadata, Object};
1111

1212
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
1313
pub struct Pod {
@@ -167,6 +167,11 @@ pub struct PodSpec {
167167
/// Default to false.
168168
#[serde(default)]
169169
pub host_network: bool,
170+
/// NodeSelector is a selector which must be true for the pod to fit on a node.
171+
/// Selector which must match a node's labels
172+
/// for the pod to be scheduledon that node.
173+
#[serde(default)]
174+
pub node_selector: Labels,
170175
/// NodeName is a request to schedule this pod onto a specific node.
171176
/// If it is non-empty, the scheduler simply schedules this pod onto that node,
172177
/// assuming that it fits resource requirements.

scheduler/src/algorithm/simple.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ use resources::objects::{object_reference::ObjectReference, pod::Pod};
22

33
use crate::cache::{Cache, NodeState};
44

5-
pub fn simple(_pod: &Pod, cache: &Cache) -> Option<ObjectReference> {
5+
pub fn simple(pod: &Pod, cache: &Cache) -> Option<ObjectReference> {
66
let mut candidate = None;
77
cache
88
.node_states
99
.iter()
1010
.filter(|(_, state)| state.is_ready)
11+
.filter(|(_, state)| state.labels.matches(&pod.spec.node_selector))
1112
.for_each(|(_, state)| {
1213
if is_better_than(Some(state), candidate) {
1314
candidate = Some(state);

scheduler/src/cache.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ use std::collections::HashMap;
22

33
use resources::{
44
informer::Store,
5-
objects::{node::Node, pod::Pod},
5+
objects::{node::Node, pod::Pod, Labels},
66
};
77

88
#[derive(Debug, Default)]
99
pub struct NodeState {
1010
pub name: String,
11+
pub labels: Labels,
1112
pub is_ready: bool,
1213
pub pod_count: u32,
1314
}
@@ -78,6 +79,7 @@ impl Cache {
7879
node.metadata.name.to_owned(),
7980
NodeState {
8081
name: node.metadata.name,
82+
labels: node.metadata.labels,
8183
is_ready,
8284
..Default::default()
8385
},
@@ -96,6 +98,7 @@ impl Cache {
9698
pub async fn calculate_node_state(&self, node: &Node) -> NodeState {
9799
let mut node_state = NodeState {
98100
name: node.metadata.name.to_owned(),
101+
labels: node.metadata.labels.to_owned(),
99102
is_ready: node.is_ready(),
100103
..Default::default()
101104
};

0 commit comments

Comments
 (0)