From 302dba8106c24e5143c7399c2cda1e577a728adb Mon Sep 17 00:00:00 2001 From: Shri Javadekar Date: Sat, 18 Jan 2020 17:00:50 -0800 Subject: [PATCH] Add option for only logging events. (#59) Testing Done: - Unit tests pass. - Verified that setting --events-only only logged events. Didn't change the launch-configs. - Verified that not setting --events-only continued existing behavior. --- cloud_provider/aws/asg_mm.py | 2 +- cloud_provider/aws/aws_minion_manager.py | 16 +++++++++++++--- minion_manager.py | 4 +++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cloud_provider/aws/asg_mm.py b/cloud_provider/aws/asg_mm.py index cf808aa..12b9846 100644 --- a/cloud_provider/aws/asg_mm.py +++ b/cloud_provider/aws/asg_mm.py @@ -110,7 +110,7 @@ def is_instance_running(self, instance): return True def not_terminate_instance(self): - """ Retures is the ASG set not terminate instance """ + """ Returns if the ASG is configure to not terminate instances """ for tag in self.asg_info['Tags']: if tag.get('Key') == NOT_TERMINATE_LABEL: return tag['Value'] diff --git a/cloud_provider/aws/aws_minion_manager.py b/cloud_provider/aws/aws_minion_manager.py index 6c00f39..94a8337 100644 --- a/cloud_provider/aws/aws_minion_manager.py +++ b/cloud_provider/aws/aws_minion_manager.py @@ -49,6 +49,7 @@ def __init__(self, cluster_name, region, refresh_interval_seconds=300, **kwargs) self.incluster = kwargs.get("incluster", True) self._ac_client = boto_session.client('autoscaling') self._ec2_client = boto_session.client('ec2') + self._events_only = kwargs.get("events_only", False) self._refresh_interval_seconds = refresh_interval_seconds self._asg_metas = [] @@ -379,6 +380,10 @@ 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: @@ -542,12 +547,15 @@ def schedule_instance_termination(self, asg_meta): if len(instances) == 0: return - """ - Check is ASG set not to terminate instance - """ + # Check if ASG set not to terminate instance if asg_meta.not_terminate_instance(): return + # Check if the minion-manager is only configured to log events. + if self._events_only: + logger.info("Minion-manager configured for only generating events. No instances will be terminated.") + return + # If the ASG is configured to use "no-spot" or the required tag does not exist, # do not schedule any instance termination. asg_tag = asg_meta.get_mm_tag() @@ -630,6 +638,8 @@ def populate_instances(self, asg_meta): def minion_manager_work(self): """ The main work for dealing with spot-instances happens here. """ logger.info("Running minion-manager...") + if self._events_only: + logger.info("Only logging events\n") while True: try: # Iterate over all asgs and update them if needed. diff --git a/minion_manager.py b/minion_manager.py index f27ef9f..69b9f89 100644 --- a/minion_manager.py +++ b/minion_manager.py @@ -41,6 +41,8 @@ def run(): help="Interval in seconds at which to query AWS") parser.add_argument("--cluster-name", required=True, help="Name of the Kubernetes cluster. Get's used for identifying ASGs") + parser.add_argument("--events-only", action='store_true', required=False, + help="Whether minion-manager should only emit events and *not* actually do spot/on-demand changes to launch-config") usr_args = parser.parse_args() validate_usr_args(usr_args) @@ -52,7 +54,7 @@ def run(): if usr_args.cloud == "aws": minion_manager = Broker.get_impl_object( usr_args.cloud, usr_args.cluster_name, usr_args.region, int(usr_args.refresh_interval_seconds), - aws_profile=usr_args.profile) + aws_profile=usr_args.profile, events_only=usr_args.events_only) minion_manager.run() # A journey of a thousand miles ...