Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
Event Only Update (#60)
Browse files Browse the repository at this point in the history
* bug fix: spot recommendation

* bug fix: sport price

* price as string in event
  • Loading branch information
vgunapati committed Jan 31, 2020
1 parent 302dba8 commit eda8a86
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions cloud_provider/aws/aws_minion_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def _describe_launch_configuration():
launch_config.LaunchConfigurationName, bid_info)

def log_k8s_event(self, asg_name, price="", useSpot=False):
msg_str = '{"apiVersion":"v1alpha1","spotPrice":' + price + ', "useSpot": ' + str(useSpot) + '}'
msg_str = '{"apiVersion":"v1alpha1","spotPrice":"' + price + '", "useSpot": ' + str(useSpot).lower() + '}'
if not self.incluster:
logger.info(msg_str)
return
Expand Down Expand Up @@ -202,32 +202,44 @@ def log_k8s_event(self, asg_name, price="", useSpot=False):
except Exception as e:
logger.info("Failed to log event: " + str(e))

def get_new_bid_info(self, asg_meta):
""" get new bid price. """
new_bid_info = self.bid_advisor.get_new_bid(
zones=asg_meta.asg_info.AvailabilityZones,
instance_type=asg_meta.lc_info.InstanceType)
return new_bid_info

def update_needed(self, asg_meta):
""" Checks if an ASG needs to be updated. """
try:
current_price = ""
asg_tag = asg_meta.get_mm_tag()
bid_info = asg_meta.get_bid_info()
if not bid_info.get("price"):
if self.get_new_bid_info(asg_meta).get("price"):
current_price = self.get_new_bid_info(asg_meta).get("price")

if asg_tag == "no-spot":
if bid_info["type"] == "spot":
logger.info("ASG %s configured with on-demand but currently using spot. Update needed", asg_meta.get_name())
# '{"apiVersion":"v1alpha1","spotPrice":bid_info["price"], "useSpot": true}'
self.log_k8s_event(asg_meta.get_name(), bid_info.get("price", ""), True)
# '{"apiVersion":"v1alpha1","spotPrice":bid_info["price"], "useSpot": False}'
self.log_k8s_event(asg_meta.get_name(), current_price, False)
return True
elif bid_info["type"] == "on-demand":
logger.info("ASG %s configured with on-demand and currently using on-demand. No update needed", asg_meta.get_name())
# '{"apiVersion":"v1alpha1","spotPrice":"", "useSpot": false}'
# '{"apiVersion":"v1alpha1","spotPrice":"", "useSpot": False}'
self.log_k8s_event(asg_meta.get_name(), "", False)
return False

# The asg_tag is "spot".
if bid_info["type"] == "on-demand":
logger.info("ASG %s configured with spot but currently using on-demand. Update needed", asg_meta.get_name())
# '{"apiVersion":"v1alpha1","spotPrice":"", "useSpot": false}'
self.log_k8s_event(asg_meta.get_name(), "", True)
# '{"apiVersion":"v1alpha1","spotPrice":"", "useSpot": true}'
self.log_k8s_event(asg_meta.get_name(), current_price, True)
return True
else:
# Continue to use spot
self.log_k8s_event(asg_meta.get_name(), bid_info.get("price", ""), True)
self.log_k8s_event(asg_meta.get_name(), current_price, True)
assert bid_info["type"] == "spot"
if self.check_scaling_group_instances(asg_meta):
# Desired # of instances running. No updates needed.
Expand Down Expand Up @@ -664,9 +676,7 @@ def minion_manager_work(self):
self.update_scaling_group(asg_meta, new_bid_info)
continue

new_bid_info = self.bid_advisor.get_new_bid(
zones=asg_meta.asg_info.AvailabilityZones,
instance_type=asg_meta.lc_info.InstanceType)
new_bid_info = self.get_new_bid_info(asg_meta)

# Change ASG to on-demand if insufficient capacity
if self.check_insufficient_capacity(asg_meta):
Expand Down

0 comments on commit eda8a86

Please sign in to comment.