def get_pods_to_schedule(self, pods): """ given a list of KubePod objects, return a map of (selectors hash -> pods) to be scheduled """ pending_unassigned_pods = [ p for p in pods if p.status == KubePodStatus.PENDING and (not p.node_name) ] # we only consider a pod to be schedulable if it's pending and # unassigned and feasible pods_to_schedule = {} now = datetime.datetime.now(pytz.utc) for pod in pending_unassigned_pods: age = (now - pod.creation_time).total_seconds() self.stats.histogram('autoscaler.scaling_loop.pending_pod_age', age) if capacity.is_possible(pod): pods_to_schedule.setdefault( utils.selectors_to_hash(pod.selectors), []).append(pod) else: recommended_capacity = capacity.max_capacity_for_selectors( pod.selectors, pod.resources) logger.warn( "Pending pod %s cannot fit %s. " "Please check that requested resource amount is " "consistent with node selectors (recommended max: %s). " "Scheduling skipped." % (pod.name, pod.selectors, recommended_capacity)) self.notifier.notify_invalid_pod_capacity( pod, recommended_capacity) return pods_to_schedule
def get_pods_to_schedule(self, pods): """ given a list of KubePod objects, return a map of (selectors hash -> pods) to be scheduled """ pending_unassigned_pods = [ p for p in pods if p.is_pending_unassigned_and_scaleworthy(self.scale_label) ] # we only consider a pod to be schedulable if it's pending and # unassigned and feasible pods_to_schedule = {} for pod in pending_unassigned_pods: if capacity.is_possible(pod): pods_to_schedule.setdefault( utils.selectors_to_hash(pod.selectors), []).append(pod) else: recommended_capacity = capacity.max_capacity_for_selectors( pod.selectors) logger.warn( "Pending pod %s cannot fit %s. " "Please check that requested resource amount is " "consistent with node selectors (recommended max: %s). " "Scheduling skipped." % (pod.name, pod.selectors, recommended_capacity)) self.notifier.notify_invalid_pod_capacity( pod, recommended_capacity) return pods_to_schedule
def test_impossible(self): self.dummy_pod['spec']['nodeSelector'] = {'aws/type': 't2.micro'} print repr(self.dummy_pod['metadata']['creationTimestamp']) from dateutil.parser import parse as dateutil_parse print dateutil_parse(self.dummy_pod['metadata']['creationTimestamp']) pod = KubePod(pykube.Pod(self.api, self.dummy_pod)) assert not capacity.is_possible(pod)
def get_pods_to_schedule(self, pods): """ given a list of KubePod objects, return a map of (selectors hash -> pods) to be scheduled """ pending_unassigned_pods = [ p for p in pods if p.status == KubePodStatus.PENDING and (not p.node_name) ] # we only consider a pod to be schedulable if it's pending and unassigned and feasible pods_to_schedule = {} for pod in pending_unassigned_pods: if capacity.is_possible(pod): pods_to_schedule.setdefault(utils.selectors_to_hash(pod.selectors), []).append(pod) else: logger.warn( "Pending pod %s cannot fit %s. Ignored" % (pod.name, pod.selectors)) return pods_to_schedule
def get_pods_to_schedule(self, pods): """ given a list of KubePod objects, return a map of (selectors hash -> pods) to be scheduled """ pending_unassigned_pods = [ p for p in pods if p.status == KubePodStatus.PENDING and (not p.node_name) ] # we only consider a pod to be schedulable if it's pending and unassigned and feasible pods_to_schedule = {} for pod in pending_unassigned_pods: if capacity.is_possible(pod): pods_to_schedule.setdefault(utils.selectors_to_hash(pod.selectors), []).append(pod) else: logger.warn( "Pending pod %s cannot fit %s. " "Please check that requested resource amount is " "consistent with node selectors. Scheduling skipped." % (pod.name, pod.selectors)) return pods_to_schedule
def get_pods_to_schedule(self, pods, agent_pools): """ given a list of KubePod objects, return a map of (selectors hash -> pods) to be scheduled """ pending_unassigned_pods = [ p for p in pods if p.status == KubePodStatus.PENDING and (not p.node_name) ] # we only consider a pod to be schedulable if it's pending and # unassigned and feasible pods_to_schedule = [] for pod in pending_unassigned_pods: if capacity.is_possible(pod, agent_pools): pods_to_schedule.append(pod) else: logger.warn("Pending pod %s cannot fit. " "Please check that requested resource amount is " "consistent with node size." "Scheduling skipped." % (pod.name)) return pods_to_schedule
def test_possible(self): pod = KubePod(pykube.Pod(self.api, self.dummy_pod)) assert capacity.is_possible(pod)
def test_impossible(self): self.dummy_pod['spec']['nodeSelector'] = {'aws/type': 't2.micro'} pod = KubePod(pykube.Pod(self.api, self.dummy_pod)) assert not capacity.is_possible(pod)