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

Commit

Permalink
environment variable for events namespace and bug fix (#64)
Browse files Browse the repository at this point in the history
* environment variable for events namespace and bug fix

* environment variable name will be EVENT_NAMESPACE

* revert intentionally done
  • Loading branch information
vgunapati committed Feb 1, 2020
1 parent 1e3763e commit 4b9b744
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 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() + '}'
event_namespace = os.getenv('EVENT_NAMESPACE', 'default')
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=event_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=event_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

0 comments on commit 4b9b744

Please sign in to comment.