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

Add option for only logging events. #59

Merged
merged 1 commit into from
Jan 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cloud_provider/aws/asg_mm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
16 changes: 13 additions & 3 deletions cloud_provider/aws/aws_minion_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion minion_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 ...
Expand Down