Skip to content

Commit

Permalink
Try using service account kubernetes client in aws node scripts (#2695)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcibinan committed Aug 19, 2022
1 parent 4eb26db commit a19e73f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
6 changes: 5 additions & 1 deletion scripts/autoscaling/aws/node_reassign.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
RUN_ID_LABEL = 'runid'
AWS_REGION_LABEL = 'aws_region'
CLOUD_REGION_LABEL = 'cloud_region'
KUBE_CONFIG_PATH = '~/.kube/config'


def find_and_tag_instance(ec2, old_id, new_id):
Expand Down Expand Up @@ -98,7 +99,10 @@ def get_aws_region(api, run_id):


def get_kube_api():
api = pykube.HTTPClient(pykube.KubeConfig.from_file("~/.kube/config"))
try:
api = pykube.HTTPClient(pykube.KubeConfig.from_service_account())
except Exception:
api = pykube.HTTPClient(pykube.KubeConfig.from_file(KUBE_CONFIG_PATH))
api.session.verify = False
return api

Expand Down
6 changes: 5 additions & 1 deletion scripts/autoscaling/aws/nodedown.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
RUN_ID_LABEL = 'runid'
AWS_REGION_LABEL = 'aws_region'
CLOUD_REGION_LABEL = 'cloud_region'
KUBE_CONFIG_PATH = '~/.kube/config'
AWS_TERMINATION_ATTEMPTS = 3


Expand Down Expand Up @@ -110,7 +111,10 @@ def get_aws_region(api, run_id):


def get_kube_api():
api = pykube.HTTPClient(pykube.KubeConfig.from_file("~/.kube/config"))
try:
api = pykube.HTTPClient(pykube.KubeConfig.from_service_account())
except Exception:
api = pykube.HTTPClient(pykube.KubeConfig.from_file(KUBE_CONFIG_PATH))
api.session.verify = False
return api

Expand Down
6 changes: 5 additions & 1 deletion scripts/autoscaling/aws/nodeup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
DEFAULT_FS_TYPE = 'btrfs'
SUPPORTED_FS_TYPES = [DEFAULT_FS_TYPE, 'ext4']
POOL_ID_KEY = 'pool_id'
KUBE_CONFIG_PATH = '~/.kube/config'

current_run_id = 0
api_url = None
Expand Down Expand Up @@ -1302,7 +1303,10 @@ def main():
ec2 = boto3.client('ec2', config=Config(retries={'max_attempts': BOTO3_RETRY_COUNT}))

# Setup kubernetes client
api = pykube.HTTPClient(pykube.KubeConfig.from_file("~/.kube/config"))
try:
api = pykube.HTTPClient(pykube.KubeConfig.from_service_account())
except Exception:
api = pykube.HTTPClient(pykube.KubeConfig.from_file(KUBE_CONFIG_PATH))
api.session.verify = False

instance_additional_spec = None
Expand Down
5 changes: 4 additions & 1 deletion scripts/autoscaling/aws/terminate_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ def get_aws_region(api, nodename):


def get_kube_api():
api = pykube.HTTPClient(pykube.KubeConfig.from_file(KUBE_CONFIG_PATH))
try:
api = pykube.HTTPClient(pykube.KubeConfig.from_service_account())
except Exception:
api = pykube.HTTPClient(pykube.KubeConfig.from_file(KUBE_CONFIG_PATH))
api.session.verify = False
return api

Expand Down

0 comments on commit a19e73f

Please sign in to comment.