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

environment variable for events namespace and bug fix #64

Merged
merged 3 commits into from
Feb 1, 2020
Merged
Changes from 1 commit
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
21 changes: 12 additions & 9 deletions cloud_provider/aws/aws_minion_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import re
import sys
import os
import time
import base64
from datetime import datetime
Expand Down Expand Up @@ -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() + '}'
mm_namespace = os.getenv('MINION_MANAGER_NAMESPACE', 'default')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

if not self.incluster:
logger.info(msg_str)
return
Expand All @@ -184,6 +186,7 @@ def log_k8s_event(self, asg_name, price="", useSpot=False):
involved_object=client.V1ObjectReference(
kind="SpotPriceInfo",
name=asg_name,
namespace=mm_namespace,
),
last_timestamp=event_timestamp,
metadata=client.V1ObjectMeta(
Expand All @@ -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=mm_namespace, body=new_event)
logger.info("Spot price info event logged")
except Exception as e:
logger.info("Failed to log event: " + str(e))
Expand All @@ -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":
Expand Down Expand Up @@ -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()
Expand All @@ -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:
Expand Down Expand Up @@ -685,7 +688,7 @@ def minion_manager_work(self):
self.update_scaling_group(asg_meta, new_bid_info)
continue

# Update ASGs iff new bid is different from current bid.
# Update ASGs if new bid is different from current bid.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The iff here was intentional. iff was for "if and only if"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, I reverted the change

if self.are_bids_equal(asg_meta.bid_info, new_bid_info):
logger.info("No change in bid info for %s",
asg_meta.get_name())
Expand Down