Skip to content

Commit

Permalink
test to update boto3 with token
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Jul 7, 2023
1 parent b21cd3b commit 8a5e18b
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions kubescaler/scaler/aws/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def __init__(
self.configuration = None
self._kubectl = None

# Client connections
self.refresh_clients()
# Client connections - use default botocore session
self.new_clients()

# Will be set later!
self.workers_stack = None
Expand All @@ -105,7 +105,7 @@ def set_stack_failure(self, on_stack_failure):
f"{on_stack_failure} is not a valid option, choices are: {options}"
)

def refresh_clients(self):
def new_clients(self):
"""
Given we hit some error, refresh all clients
"""
Expand All @@ -115,6 +115,29 @@ def refresh_clients(self):
self.iam = self.session.client("iam")
self.eks = self.session.client("eks")

def refresh_clients(self):
"""
Refresh clients with a custom auth_token.
This is currently an experiment.
"""
# Generate a new token
token = get_bearer_token(self.cluster_name, self.token_expires)

def new_boto_client(service_name):
# this call in boto3 passes forward to botocore, and we are providing a resfreshed auth token
# https://github.com/boto/boto3/blob/3c988a24f22795d3cb9cf26a74c085d2e6a58504/boto3/session.py#L217
return self.session._session.create_client(
service_name,
region_name=self.region,
aws_session_token=token["status"]["token"],
)

self.ec2 = new_boto_client("ec2")
self.cf = new_boto_client("cloudformation")
self.iam = new_boto_client("iam")
self.eks = new_boto_client("eks")

@timed
def create_cluster(self):
"""
Expand Down

0 comments on commit 8a5e18b

Please sign in to comment.