diff --git a/cloud_provider/aws/aws_minion_manager.py b/cloud_provider/aws/aws_minion_manager.py index bfcf84f..8c41a12 100644 --- a/cloud_provider/aws/aws_minion_manager.py +++ b/cloud_provider/aws/aws_minion_manager.py @@ -3,6 +3,7 @@ import logging import re import sys +import os import time import base64 from datetime import datetime @@ -169,6 +170,7 @@ def _describe_launch_configuration(): def log_k8s_event(self, asg_name, price="", useSpot=False): msg_str = '{"apiVersion":"v1alpha1","spotPrice":"' + price + '", "useSpot": ' + str(useSpot).lower() + '}' + event_namespace = os.getenv('EVENT_NAMESPACE', 'default') if not self.incluster: logger.info(msg_str) return @@ -184,6 +186,7 @@ def log_k8s_event(self, asg_name, price="", useSpot=False): involved_object=client.V1ObjectReference( kind="SpotPriceInfo", name=asg_name, + namespace=event_namespace, ), last_timestamp=event_timestamp, metadata=client.V1ObjectMeta( @@ -197,7 +200,7 @@ def log_k8s_event(self, asg_name, price="", useSpot=False): type="Normal", ) - v1.create_namespaced_event(namespace="default", body=new_event) + v1.create_namespaced_event(namespace=event_namespace, body=new_event) logger.info("Spot price info event logged") except Exception as e: logger.info("Failed to log event: " + str(e)) @@ -212,12 +215,12 @@ def get_new_bid_info(self, asg_meta): 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") + current_price = self.get_new_bid_info(asg_meta).get("price") or "" + else: + current_price = bid_info.get("price") if asg_tag == "no-spot": if bid_info["type"] == "spot": @@ -371,6 +374,10 @@ def update_scaling_group(self, asg_meta, new_bid_info): Updates the AWS AutoScalingGroup. Makes the next_bid_info as the new bid_info. """ + if self._events_only: + logger.info("Minion-manager configured for only generating events. No changes to launch config will be made.") + return + logger.info("Updating ASG: %s, Bid: %s", asg_meta.get_name(), new_bid_info) launch_config = asg_meta.get_lc_info() @@ -392,10 +399,6 @@ def update_scaling_group(self, asg_meta, new_bid_info): logger.info("ASG(%s): New launch-config name: %s", asg_meta.get_name(), new_lc_name) - if self._events_only: - logger.info("Minion-manager configured for only generating events. No changes to launch config will be made.") - return - if spot_price is None: self.create_lc_on_demand(new_lc_name, launch_config) else: