├── .github └── workflows │ └── prbuilder.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── Makefile ├── Pipfile ├── Pipfile.lock ├── README.md ├── binaries └── kubectl-v1.12.3-linux-amd64 ├── build.sh ├── cloud_broker ├── __init__.py ├── broker.py └── broker_test.py ├── cloud_provider ├── __init__.py ├── aws │ ├── __init__.py │ ├── asg_mm.py │ ├── aws_bid_advisor.py │ ├── aws_bid_advisor_test.py │ ├── aws_minion_manager.py │ ├── aws_minion_manager_test.py │ └── price_info_reporter.py └── base.py ├── constants.py ├── deploy └── mm.yaml └── minion_manager.py /.github/workflows/prbuilder.yml: -------------------------------------------------------------------------------- 1 | name: PR Builder 2 | 3 | on: 4 | pull_request: 5 | branches: master 6 | 7 | jobs: 8 | build: 9 | 10 | runs-on: ubuntu-latest 11 | strategy: 12 | max-parallel: 4 13 | matrix: 14 | python-version: [2.7] 15 | 16 | steps: 17 | - uses: actions/checkout@v1 18 | - name: Set up Python ${{ matrix.python-version }} 19 | uses: actions/setup-python@v1 20 | with: 21 | python-version: ${{ matrix.python-version }} 22 | - name: Install dependencies 23 | run: | 24 | python -m pip install --upgrade pip 25 | - name: Test with pytest 26 | run: | 27 | pip install pytest pipenv 28 | pipenv install --system --deploy --dev 29 | make test 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.swp 3 | .vscode 4 | .pytest_cache 5 | .idea 6 | .DS_Store 7 | .coverage 8 | coverage.xml 9 | htmlcov 10 | pylint.log 11 | pyflakes.log 12 | pytest-results.xml 13 | /flake8-report/ 14 | .cache 15 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:2.7.15-alpine3.8 AS Base 2 | 3 | RUN pip install pipenv==2018.10.13 4 | WORKDIR /src 5 | COPY Pipfile /src/ 6 | COPY Pipfile.lock /src/ 7 | RUN wget -O /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/v1.18.16/bin/linux/amd64/kubectl 8 | RUN chmod +x /usr/local/bin/kubectl 9 | 10 | # This will be used as Main Image 11 | FROM Base AS Main 12 | 13 | RUN pipenv install --system --deploy 14 | COPY . /src 15 | ENV PYTHONPATH=/src 16 | RUN chmod u+x minion_manager.py 17 | 18 | 19 | FROM Base AS Dev 20 | 21 | RUN apk add --no-cache build-base openssl-dev libffi-dev 22 | RUN pipenv install --system --deploy --dev -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2019 The Orka Authors 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TEST_PATH=./ 2 | BUILD=docker build --target 3 | RUN=docker run --rm -it 4 | VERSION=v0.14-dev 5 | GIT_TAG=$(shell git rev-parse --short HEAD) 6 | 7 | ifeq (${DOCKER_PUSH},true) 8 | ifndef IMAGE_NAMESPACE 9 | $(error IMAGE_NAMESPACE must be set to push images (e.g. IMAGE_NAMESPACE=docker.mycompany.com)) 10 | endif 11 | endif 12 | 13 | ifdef IMAGE_NAMESPACE 14 | IMAGE_PREFIX=${IMAGE_NAMESPACE}/ 15 | endif 16 | 17 | ifndef IMAGE_TAG 18 | IMAGE_TAG=${GIT_TAG} 19 | endif 20 | 21 | all: clean test 22 | 23 | clean: clean-pyc clean-pytest 24 | 25 | clean-pyc: 26 | find . -name '*.pyc' -exec rm {} \; 27 | find . -name __pycache__ | xargs -n1 rm -rf 28 | 29 | clean-pytest: 30 | rm -rf __pycache__ coverage.xml .coverage htmlcov .pytest_cache pylint.log pytest-results.xml 31 | 32 | test: clean 33 | pytest --junitxml=${TEST_PATH}/pytest-results.xml -s --color=yes $(TEST_PATH) 34 | 35 | docker-test: clean 36 | $(BUILD) dev -t $(IMAGE_PREFIX)minion-manager-test:$(IMAGE_TAG) . 37 | $(RUN) -v ${PWD}:/src -v ~/.aws:/root/.aws $(IMAGE_PREFIX)minion-manager-test:$(IMAGE_TAG) make test 38 | 39 | docker: clean 40 | $(BUILD) main -t $(IMAGE_PREFIX)minion-manager:$(IMAGE_TAG) . 41 | docker tag $(IMAGE_PREFIX)minion-manager:$(IMAGE_TAG) $(IMAGE_PREFIX)minion-manager:${VERSION} 42 | @if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)minion-manager:$(IMAGE_TAG) ; fi 43 | 44 | .PHONY: clean-pyc clean-pytest all test 45 | -------------------------------------------------------------------------------- /Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | url = "https://pypi.org/simple" 3 | verify_ssl = true 4 | name = "pypi" 5 | 6 | [packages] 7 | boto3 = "==1.9.140" 8 | retrying = "==1.3.3" 9 | bunch = "==1.0.1" 10 | pytz = "==2016.10" 11 | kubernetes = "==2.0.0" 12 | Jinja2 = ">=2.10.1" 13 | pyyaml = ">=4.2b1" 14 | requests = ">=2.20.0" 15 | flask = ">=0.12.3" 16 | 17 | [dev-packages] 18 | pytest = "==3.9.3" 19 | mock = "==2.0.0" 20 | moto = "==1.3.8" 21 | 22 | [requires] 23 | python_version = "2.7.15" -------------------------------------------------------------------------------- /Pipfile.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_meta": { 3 | "hash": { 4 | "sha256": "35b3622b0a03026e526b675c56478847abdd82598aae6f3568da16d0fe9e3ece" 5 | }, 6 | "pipfile-spec": 6, 7 | "requires": { 8 | "python_version": "2.7.15" 9 | }, 10 | "sources": [ 11 | { 12 | "name": "pypi", 13 | "url": "https://pypi.org/simple", 14 | "verify_ssl": true 15 | } 16 | ] 17 | }, 18 | "default": { 19 | "boto3": { 20 | "hashes": [ 21 | "sha256:7485ae2b6d9a380af74285890229659d6f114168ab5133aed924b5c41a28860a", 22 | "sha256:b8107b5b4296c2c8a68cd67b44988317dd1e11dd2b295e41d502c17b1e227bfc" 23 | ], 24 | "index": "pypi", 25 | "version": "==1.9.140" 26 | }, 27 | "botocore": { 28 | "hashes": [ 29 | "sha256:3baf129118575602ada9926f5166d82d02273c250d0feb313fc270944b27c48b", 30 | "sha256:dc080aed4f9b220a9e916ca29ca97a9d37e8e1d296fe89cbaeef929bf0c8066b" 31 | ], 32 | "version": "==1.12.253" 33 | }, 34 | "bunch": { 35 | "hashes": [ 36 | "sha256:3c554816ba260634b55c1edf8de6467d8122dbd18ec20f323e181869bc48ac93", 37 | "sha256:50c77a0fc0cb372dfe48b5e11937d5f70e743adbf42683f3a6d2857645a76aaa" 38 | ], 39 | "index": "pypi", 40 | "version": "==1.0.1" 41 | }, 42 | "certifi": { 43 | "hashes": [ 44 | "sha256:1a4995114262bffbc2413b159f2a1a480c969de6e6eb13ee966d470af86af59c", 45 | "sha256:719a74fb9e33b9bd44cc7f3a8d94bc35e4049deebe19ba7d8e108280cfd59830" 46 | ], 47 | "version": "==2020.12.5" 48 | }, 49 | "chardet": { 50 | "hashes": [ 51 | "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", 52 | "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691" 53 | ], 54 | "version": "==3.0.4" 55 | }, 56 | "click": { 57 | "hashes": [ 58 | "sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a", 59 | "sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc" 60 | ], 61 | "version": "==7.1.2" 62 | }, 63 | "docutils": { 64 | "hashes": [ 65 | "sha256:6c4f696463b79f1fb8ba0c594b63840ebd41f059e92b31957c46b74a4599b6d0", 66 | "sha256:9e4d7ecfc600058e07ba661411a2b7de2fd0fafa17d1a7f7361cd47b1175c827", 67 | "sha256:a2aeea129088da402665e92e0b25b04b073c04b2dce4ab65caaa38b7ce2e1a99" 68 | ], 69 | "version": "==0.15.2" 70 | }, 71 | "flask": { 72 | "hashes": [ 73 | "sha256:13f9f196f330c7c2c5d7a5cf91af894110ca0215ac051b5844701f2bfd934d52", 74 | "sha256:45eb5a6fd193d6cf7e0cf5d8a5b31f83d5faae0293695626f539a823e93b13f6" 75 | ], 76 | "index": "pypi", 77 | "version": "==1.1.1" 78 | }, 79 | "futures": { 80 | "hashes": [ 81 | "sha256:49b3f5b064b6e3afc3316421a3f25f66c137ae88f068abbf72830170033c5e16", 82 | "sha256:7e033af76a5e35f58e56da7a91e687706faf4e7bdfb2cbc3f2cca6b9bcda9794" 83 | ], 84 | "markers": "python_version == '2.6' or python_version == '2.7'", 85 | "version": "==3.3.0" 86 | }, 87 | "httplib2": { 88 | "hashes": [ 89 | "sha256:749c32603f9bf16c1277f59531d502e8f1c2ca19901ae653b49c4ed698f0820e", 90 | "sha256:e0d428dad43c72dbce7d163b7753ffc7a39c097e6788ef10f4198db69b92f08e" 91 | ], 92 | "index": "pypi", 93 | "version": "==0.19.0" 94 | }, 95 | "idna": { 96 | "hashes": [ 97 | "sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407", 98 | "sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c" 99 | ], 100 | "version": "==2.8" 101 | }, 102 | "ipaddress": { 103 | "hashes": [ 104 | "sha256:6e0f4a39e66cb5bb9a137b00276a2eff74f93b71dcbdad6f10ff7df9d3557fcc", 105 | "sha256:b7f8e0369580bb4a24d5ba1d7cc29660a4a6987763faf1d8a8046830e020e7e2" 106 | ], 107 | "version": "==1.0.23" 108 | }, 109 | "itsdangerous": { 110 | "hashes": [ 111 | "sha256:321b033d07f2a4136d3ec762eac9f16a10ccd60f53c0c91af90217ace7ba1f19", 112 | "sha256:b12271b2047cb23eeb98c8b5622e2e5c5e9abd9784a153e9d8ef9cb4dd09d749" 113 | ], 114 | "version": "==1.1.0" 115 | }, 116 | "jinja2": { 117 | "hashes": [ 118 | "sha256:065c4f02ebe7f7cf559e49ee5a95fb800a9e4528727aec6f24402a5374c65013", 119 | "sha256:14dd6caf1527abb21f08f86c784eac40853ba93edb79552aa1e4b8aef1b61c7b" 120 | ], 121 | "index": "pypi", 122 | "version": "==2.10.1" 123 | }, 124 | "jmespath": { 125 | "hashes": [ 126 | "sha256:b85d0567b8666149a93172712e68920734333c0ce7e89b78b3e987f71e5ed4f9", 127 | "sha256:cdf6525904cc597730141d61b36f2e4b8ecc257c420fa2f4549bac2c2d0cb72f" 128 | ], 129 | "version": "==0.10.0" 130 | }, 131 | "kubernetes": { 132 | "hashes": [ 133 | "sha256:3fa1a50330f0da9d9ba1cd8cc425df481e0326136899875db9448913246f2753", 134 | "sha256:e02057b674bebe763c6916a356b2f39f6919e3cf60396f7a932c1996663d91b7" 135 | ], 136 | "index": "pypi", 137 | "version": "==2.0.0" 138 | }, 139 | "markupsafe": { 140 | "hashes": [ 141 | "sha256:00bc623926325b26bb9605ae9eae8a215691f33cae5df11ca5424f06f2d1f473", 142 | "sha256:09027a7803a62ca78792ad89403b1b7a73a01c8cb65909cd876f7fcebd79b161", 143 | "sha256:09c4b7f37d6c648cb13f9230d847adf22f8171b1ccc4d5682398e77f40309235", 144 | "sha256:1027c282dad077d0bae18be6794e6b6b8c91d58ed8a8d89a89d59693b9131db5", 145 | "sha256:13d3144e1e340870b25e7b10b98d779608c02016d5184cfb9927a9f10c689f42", 146 | "sha256:195d7d2c4fbb0ee8139a6cf67194f3973a6b3042d742ebe0a9ed36d8b6f0c07f", 147 | "sha256:22c178a091fc6630d0d045bdb5992d2dfe14e3259760e713c490da5323866c39", 148 | "sha256:24982cc2533820871eba85ba648cd53d8623687ff11cbb805be4ff7b4c971aff", 149 | "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b", 150 | "sha256:2beec1e0de6924ea551859edb9e7679da6e4870d32cb766240ce17e0a0ba2014", 151 | "sha256:3b8a6499709d29c2e2399569d96719a1b21dcd94410a586a18526b143ec8470f", 152 | "sha256:43a55c2930bbc139570ac2452adf3d70cdbb3cfe5912c71cdce1c2c6bbd9c5d1", 153 | "sha256:46c99d2de99945ec5cb54f23c8cd5689f6d7177305ebff350a58ce5f8de1669e", 154 | "sha256:500d4957e52ddc3351cabf489e79c91c17f6e0899158447047588650b5e69183", 155 | "sha256:535f6fc4d397c1563d08b88e485c3496cf5784e927af890fb3c3aac7f933ec66", 156 | "sha256:596510de112c685489095da617b5bcbbac7dd6384aeebeda4df6025d0256a81b", 157 | "sha256:62fe6c95e3ec8a7fad637b7f3d372c15ec1caa01ab47926cfdf7a75b40e0eac1", 158 | "sha256:6788b695d50a51edb699cb55e35487e430fa21f1ed838122d722e0ff0ac5ba15", 159 | "sha256:6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1", 160 | "sha256:6f1e273a344928347c1290119b493a1f0303c52f5a5eae5f16d74f48c15d4a85", 161 | "sha256:6fffc775d90dcc9aed1b89219549b329a9250d918fd0b8fa8d93d154918422e1", 162 | "sha256:717ba8fe3ae9cc0006d7c451f0bb265ee07739daf76355d06366154ee68d221e", 163 | "sha256:79855e1c5b8da654cf486b830bd42c06e8780cea587384cf6545b7d9ac013a0b", 164 | "sha256:7c1699dfe0cf8ff607dbdcc1e9b9af1755371f92a68f706051cc8c37d447c905", 165 | "sha256:7fed13866cf14bba33e7176717346713881f56d9d2bcebab207f7a036f41b850", 166 | "sha256:84dee80c15f1b560d55bcfe6d47b27d070b4681c699c572af2e3c7cc90a3b8e0", 167 | "sha256:88e5fcfb52ee7b911e8bb6d6aa2fd21fbecc674eadd44118a9cc3863f938e735", 168 | "sha256:8defac2f2ccd6805ebf65f5eeb132adcf2ab57aa11fdf4c0dd5169a004710e7d", 169 | "sha256:98bae9582248d6cf62321dcb52aaf5d9adf0bad3b40582925ef7c7f0ed85fceb", 170 | "sha256:98c7086708b163d425c67c7a91bad6e466bb99d797aa64f965e9d25c12111a5e", 171 | "sha256:9add70b36c5666a2ed02b43b335fe19002ee5235efd4b8a89bfcf9005bebac0d", 172 | "sha256:9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c", 173 | "sha256:a6a744282b7718a2a62d2ed9d993cad6f5f585605ad352c11de459f4108df0a1", 174 | "sha256:acf08ac40292838b3cbbb06cfe9b2cb9ec78fce8baca31ddb87aaac2e2dc3bc2", 175 | "sha256:ade5e387d2ad0d7ebf59146cc00c8044acbd863725f887353a10df825fc8ae21", 176 | "sha256:b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2", 177 | "sha256:b1282f8c00509d99fef04d8ba936b156d419be841854fe901d8ae224c59f0be5", 178 | "sha256:b1dba4527182c95a0db8b6060cc98ac49b9e2f5e64320e2b56e47cb2831978c7", 179 | "sha256:b2051432115498d3562c084a49bba65d97cf251f5a331c64a12ee7e04dacc51b", 180 | "sha256:b7d644ddb4dbd407d31ffb699f1d140bc35478da613b441c582aeb7c43838dd8", 181 | "sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6", 182 | "sha256:bf5aa3cbcfdf57fa2ee9cd1822c862ef23037f5c832ad09cfea57fa846dec193", 183 | "sha256:c8716a48d94b06bb3b2524c2b77e055fb313aeb4ea620c8dd03a105574ba704f", 184 | "sha256:caabedc8323f1e93231b52fc32bdcde6db817623d33e100708d9a68e1f53b26b", 185 | "sha256:cd5df75523866410809ca100dc9681e301e3c27567cf498077e8551b6d20e42f", 186 | "sha256:cdb132fc825c38e1aeec2c8aa9338310d29d337bebbd7baa06889d09a60a1fa2", 187 | "sha256:d53bc011414228441014aa71dbec320c66468c1030aae3a6e29778a3382d96e5", 188 | "sha256:d73a845f227b0bfe8a7455ee623525ee656a9e2e749e4742706d80a6065d5e2c", 189 | "sha256:d9be0ba6c527163cbed5e0857c451fcd092ce83947944d6c14bc95441203f032", 190 | "sha256:e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7", 191 | "sha256:e8313f01ba26fbbe36c7be1966a7b7424942f670f38e666995b88d012765b9be", 192 | "sha256:feb7b34d6325451ef96bc0e36e1a6c0c1c64bc1fbec4b854f4529e51887b1621" 193 | ], 194 | "version": "==1.1.1" 195 | }, 196 | "oauth2client": { 197 | "hashes": [ 198 | "sha256:b8a81cc5d60e2d364f0b1b98f958dbd472887acaf1a5b05e21c28c31a2d6d3ac", 199 | "sha256:d486741e451287f69568a4d26d70d9acd73a2bbfa275746c535b4209891cccc6" 200 | ], 201 | "version": "==4.1.3" 202 | }, 203 | "pyasn1": { 204 | "hashes": [ 205 | "sha256:39c7e2ec30515947ff4e87fb6f456dfc6e84857d34be479c9d4a4ba4bf46aa5d", 206 | "sha256:aef77c9fb94a3ac588e87841208bdec464471d9871bd5050a287cc9a475cd0ba" 207 | ], 208 | "version": "==0.4.8" 209 | }, 210 | "pyasn1-modules": { 211 | "hashes": [ 212 | "sha256:905f84c712230b2c592c19470d3ca8d552de726050d1d1716282a1f6146be65e", 213 | "sha256:a50b808ffeb97cb3601dd25981f6b016cbb3d31fbf57a8b8a87428e6158d0c74" 214 | ], 215 | "version": "==0.2.8" 216 | }, 217 | "pyparsing": { 218 | "hashes": [ 219 | "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1", 220 | "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b" 221 | ], 222 | "version": "==2.4.7" 223 | }, 224 | "python-dateutil": { 225 | "hashes": [ 226 | "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c", 227 | "sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a" 228 | ], 229 | "markers": "python_version >= '2.7'", 230 | "version": "==2.8.1" 231 | }, 232 | "pytz": { 233 | "hashes": [ 234 | "sha256:7016b2c4fa075c564b81c37a252a5fccf60d8964aa31b7f5eae59aeb594ae02b", 235 | "sha256:9a43e20aa537cfad8fe7a1715165c91cb4a6935d40947f2d070e4c80f2dcd22b", 236 | "sha256:a1ea35e87a63c7825846d5b5c81d23d668e8a102d3b1b465ce95afe1b3a2e065", 237 | "sha256:aafbf066975fe217ed49d7d197b26903d3b43e9ca2aa6ba0a211081f13c41917" 238 | ], 239 | "index": "pypi", 240 | "version": "==2016.10" 241 | }, 242 | "pyyaml": { 243 | "hashes": [ 244 | "sha256:57acc1d8533cbe51f6662a55434f0dbecfa2b9eaf115bede8f6fd00115a0c0d3", 245 | "sha256:588c94b3d16b76cfed8e0be54932e5729cc185caffaa5a451e7ad2f7ed8b4043", 246 | "sha256:68c8dd247f29f9a0d09375c9c6b8fdc64b60810ebf07ba4cdd64ceee3a58c7b7", 247 | "sha256:70d9818f1c9cd5c48bb87804f2efc8692f1023dac7f1a1a5c61d454043c1d265", 248 | "sha256:86a93cccd50f8c125286e637328ff4eef108400dd7089b46a7be3445eecfa391", 249 | "sha256:a0f329125a926876f647c9fa0ef32801587a12328b4a3c741270464e3e4fa778", 250 | "sha256:a3c252ab0fa1bb0d5a3f6449a4826732f3eb6c0270925548cac342bc9b22c225", 251 | "sha256:b4bb4d3f5e232425e25dda21c070ce05168a786ac9eda43768ab7f3ac2770955", 252 | "sha256:cd0618c5ba5bda5f4039b9398bb7fb6a317bb8298218c3de25c47c4740e4b95e", 253 | "sha256:ceacb9e5f8474dcf45b940578591c7f3d960e82f926c707788a570b51ba59190", 254 | "sha256:fe6a88094b64132c4bb3b631412e90032e8cfe9745a58370462240b8cb7553cd" 255 | ], 256 | "index": "pypi", 257 | "version": "==5.1.1" 258 | }, 259 | "requests": { 260 | "hashes": [ 261 | "sha256:11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4", 262 | "sha256:9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9a590f48c010551dc6c4b31" 263 | ], 264 | "index": "pypi", 265 | "version": "==2.22.0" 266 | }, 267 | "retrying": { 268 | "hashes": [ 269 | "sha256:08c039560a6da2fe4f2c426d0766e284d3b736e355f8dd24b37367b0bb41973b" 270 | ], 271 | "index": "pypi", 272 | "version": "==1.3.3" 273 | }, 274 | "rsa": { 275 | "hashes": [ 276 | "sha256:35c5b5f6675ac02120036d97cf96f1fde4d49670543db2822ba5015e21a18032", 277 | "sha256:4d409f5a7d78530a4a2062574c7bd80311bc3af29b364e293aa9b03eea77714f" 278 | ], 279 | "version": "==4.5" 280 | }, 281 | "s3transfer": { 282 | "hashes": [ 283 | "sha256:6efc926738a3cd576c2a79725fed9afde92378aa5c6a957e3af010cb019fac9d", 284 | "sha256:b780f2411b824cb541dbcd2c713d0cb61c7d1bcadae204cdddda2b35cef493ba" 285 | ], 286 | "version": "==0.2.1" 287 | }, 288 | "six": { 289 | "hashes": [ 290 | "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259", 291 | "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced" 292 | ], 293 | "version": "==1.15.0" 294 | }, 295 | "urllib3": { 296 | "hashes": [ 297 | "sha256:8d7eaa5a82a1cac232164990f04874c594c9453ec55eef02eab885aa02fc17a2", 298 | "sha256:f5321fbe4bf3fefa0efd0bfe7fb14e90909eb62a48ccda331726b4319897dd5e" 299 | ], 300 | "markers": "python_version == '2.7'", 301 | "version": "==1.25.11" 302 | }, 303 | "websocket-client": { 304 | "hashes": [ 305 | "sha256:0fc45c961324d79c781bab301359d5a1b00b13ad1b10415a4780229ef71a5549", 306 | "sha256:d735b91d6d1692a6a181f2a8c9e0238e5f6373356f561bb9dc4c7af36f452010" 307 | ], 308 | "version": "==0.57.0" 309 | }, 310 | "werkzeug": { 311 | "hashes": [ 312 | "sha256:2de2a5db0baeae7b2d2664949077c2ac63fbd16d98da0ff71837f7d1dea3fd43", 313 | "sha256:6c80b1e5ad3665290ea39320b91e1be1e0d5f60652b964a3070216de83d2e47c" 314 | ], 315 | "version": "==1.0.1" 316 | } 317 | }, 318 | "develop": { 319 | "atomicwrites": { 320 | "hashes": [ 321 | "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197", 322 | "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a" 323 | ], 324 | "version": "==1.4.0" 325 | }, 326 | "attrs": { 327 | "hashes": [ 328 | "sha256:31b2eced602aa8423c2aea9c76a724617ed67cf9513173fd3a4f03e3a929c7e6", 329 | "sha256:832aa3cde19744e49938b91fea06d69ecb9e649c93ba974535d08ad92164f700" 330 | ], 331 | "version": "==20.3.0" 332 | }, 333 | "aws-sam-translator": { 334 | "hashes": [ 335 | "sha256:1cfc8ba13c43e8c425fdcd6c246fdd90899a3ed89310d84a72ccdf082e4146d7", 336 | "sha256:857c62a03e3bb4a3f7074e867f52ced636dc06192c8216e00732122f21a206c2", 337 | "sha256:a22d505ddc0c48e3cf0ff0127096bdc1231d20c852509201ffba47dc8e683a1a" 338 | ], 339 | "version": "==1.34.0" 340 | }, 341 | "aws-xray-sdk": { 342 | "hashes": [ 343 | "sha256:076f7c610cd3564bbba3507d43e328fb6ff4a2e841d3590f39b2c3ce99d41e1d", 344 | "sha256:abf5b90f740e1f402e23414c9670e59cb9772e235e271fef2bce62b9100cbc77" 345 | ], 346 | "version": "==2.6.0" 347 | }, 348 | "backports.ssl-match-hostname": { 349 | "hashes": [ 350 | "sha256:bb82e60f9fbf4c080eabd957c39f0641f0fc247d9a16e31e26d594d8f42b9fd2" 351 | ], 352 | "markers": "python_version < '3.5'", 353 | "version": "==3.7.0.1" 354 | }, 355 | "backports.tempfile": { 356 | "hashes": [ 357 | "sha256:05aa50940946f05759696156a8c39be118169a0e0f94a49d0bb106503891ff54", 358 | "sha256:1c648c452e8770d759bdc5a5e2431209be70d25484e1be24876cf2168722c762" 359 | ], 360 | "markers": "python_version < '3.3'", 361 | "version": "==1.0" 362 | }, 363 | "backports.weakref": { 364 | "hashes": [ 365 | "sha256:81bc9b51c0abc58edc76aefbbc68c62a787918ffe943a37947e162c3f8e19e82", 366 | "sha256:bc4170a29915f8b22c9e7c4939701859650f2eb84184aee80da329ac0b9825c2" 367 | ], 368 | "version": "==1.0.post1" 369 | }, 370 | "boto": { 371 | "hashes": [ 372 | "sha256:147758d41ae7240dc989f0039f27da8ca0d53734be0eb869ef16e3adcfa462e8", 373 | "sha256:ea0d3b40a2d852767be77ca343b58a9e3a4b00d9db440efb8da74b4e58025e5a" 374 | ], 375 | "version": "==2.49.0" 376 | }, 377 | "boto3": { 378 | "hashes": [ 379 | "sha256:7485ae2b6d9a380af74285890229659d6f114168ab5133aed924b5c41a28860a", 380 | "sha256:b8107b5b4296c2c8a68cd67b44988317dd1e11dd2b295e41d502c17b1e227bfc" 381 | ], 382 | "index": "pypi", 383 | "version": "==1.9.140" 384 | }, 385 | "botocore": { 386 | "hashes": [ 387 | "sha256:3baf129118575602ada9926f5166d82d02273c250d0feb313fc270944b27c48b", 388 | "sha256:dc080aed4f9b220a9e916ca29ca97a9d37e8e1d296fe89cbaeef929bf0c8066b" 389 | ], 390 | "version": "==1.12.253" 391 | }, 392 | "certifi": { 393 | "hashes": [ 394 | "sha256:1a4995114262bffbc2413b159f2a1a480c969de6e6eb13ee966d470af86af59c", 395 | "sha256:719a74fb9e33b9bd44cc7f3a8d94bc35e4049deebe19ba7d8e108280cfd59830" 396 | ], 397 | "version": "==2020.12.5" 398 | }, 399 | "cffi": { 400 | "hashes": [ 401 | "sha256:00a1ba5e2e95684448de9b89888ccd02c98d512064b4cb987d48f4b40aa0421e", 402 | "sha256:00e28066507bfc3fe865a31f325c8391a1ac2916219340f87dfad602c3e48e5d", 403 | "sha256:045d792900a75e8b1e1b0ab6787dd733a8190ffcf80e8c8ceb2fb10a29ff238a", 404 | "sha256:0638c3ae1a0edfb77c6765d487fee624d2b1ee1bdfeffc1f0b58c64d149e7eec", 405 | "sha256:105abaf8a6075dc96c1fe5ae7aae073f4696f2905fde6aeada4c9d2926752362", 406 | "sha256:155136b51fd733fa94e1c2ea5211dcd4c8879869008fc811648f16541bf99668", 407 | "sha256:1a465cbe98a7fd391d47dce4b8f7e5b921e6cd805ef421d04f5f66ba8f06086c", 408 | "sha256:1d2c4994f515e5b485fd6d3a73d05526aa0fcf248eb135996b088d25dfa1865b", 409 | "sha256:2c24d61263f511551f740d1a065eb0212db1dbbbbd241db758f5244281590c06", 410 | "sha256:51a8b381b16ddd370178a65360ebe15fbc1c71cf6f584613a7ea08bfad946698", 411 | "sha256:594234691ac0e9b770aee9fcdb8fa02c22e43e5c619456efd0d6c2bf276f3eb2", 412 | "sha256:5cf4be6c304ad0b6602f5c4e90e2f59b47653ac1ed9c662ed379fe48a8f26b0c", 413 | "sha256:64081b3f8f6f3c3de6191ec89d7dc6c86a8a43911f7ecb422c60e90c70be41c7", 414 | "sha256:6bc25fc545a6b3d57b5f8618e59fc13d3a3a68431e8ca5fd4c13241cd70d0009", 415 | "sha256:798caa2a2384b1cbe8a2a139d80734c9db54f9cc155c99d7cc92441a23871c03", 416 | "sha256:7c6b1dece89874d9541fc974917b631406233ea0440d0bdfbb8e03bf39a49b3b", 417 | "sha256:7ef7d4ced6b325e92eb4d3502946c78c5367bc416398d387b39591532536734e", 418 | "sha256:840793c68105fe031f34d6a086eaea153a0cd5c491cde82a74b420edd0a2b909", 419 | "sha256:8d6603078baf4e11edc4168a514c5ce5b3ba6e3e9c374298cb88437957960a53", 420 | "sha256:9cc46bc107224ff5b6d04369e7c595acb700c3613ad7bcf2e2012f62ece80c35", 421 | "sha256:9f7a31251289b2ab6d4012f6e83e58bc3b96bd151f5b5262467f4bb6b34a7c26", 422 | "sha256:9ffb888f19d54a4d4dfd4b3f29bc2c16aa4972f1c2ab9c4ab09b8ab8685b9c2b", 423 | "sha256:a5ed8c05548b54b998b9498753fb9cadbfd92ee88e884641377d8a8b291bcc01", 424 | "sha256:a7711edca4dcef1a75257b50a2fbfe92a65187c47dab5a0f1b9b332c5919a3fb", 425 | "sha256:af5c59122a011049aad5dd87424b8e65a80e4a6477419c0c1015f73fb5ea0293", 426 | "sha256:b18e0a9ef57d2b41f5c68beefa32317d286c3d6ac0484efd10d6e07491bb95dd", 427 | "sha256:b4e248d1087abf9f4c10f3c398896c87ce82a9856494a7155823eb45a892395d", 428 | "sha256:ba4e9e0ae13fc41c6b23299545e5ef73055213e466bd107953e4a013a5ddd7e3", 429 | "sha256:c6332685306b6417a91b1ff9fae889b3ba65c2292d64bd9245c093b1b284809d", 430 | "sha256:d5ff0621c88ce83a28a10d2ce719b2ee85635e85c515f12bac99a95306da4b2e", 431 | "sha256:d9efd8b7a3ef378dd61a1e77367f1924375befc2eba06168b6ebfa903a5e59ca", 432 | "sha256:df5169c4396adc04f9b0a05f13c074df878b6052430e03f50e68adf3a57aa28d", 433 | "sha256:ebb253464a5d0482b191274f1c8bf00e33f7e0b9c66405fbffc61ed2c839c775", 434 | "sha256:ec80dc47f54e6e9a78181ce05feb71a0353854cc26999db963695f950b5fb375", 435 | "sha256:f032b34669220030f905152045dfa27741ce1a6db3324a5bc0b96b6c7420c87b", 436 | "sha256:f60567825f791c6f8a592f3c6e3bd93dd2934e3f9dac189308426bd76b00ef3b", 437 | "sha256:f803eaa94c2fcda012c047e62bc7a51b0bdabda1cad7a92a522694ea2d76e49f" 438 | ], 439 | "version": "==1.14.4" 440 | }, 441 | "cfn-lint": { 442 | "hashes": [ 443 | "sha256:52ce84ab8266138d6997544aa91206399a9b59a456715a16f2d63f7dbef8e2a2", 444 | "sha256:dec1fd133c419e8e9ba56ac2906dd385ddd5fc6b76e1c28db276c078096fd75c" 445 | ], 446 | "version": "==0.44.6" 447 | }, 448 | "chardet": { 449 | "hashes": [ 450 | "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", 451 | "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691" 452 | ], 453 | "version": "==3.0.4" 454 | }, 455 | "configparser": { 456 | "hashes": [ 457 | "sha256:254c1d9c79f60c45dfde850850883d5aaa7f19a23f13561243a050d5a7c3fe4c", 458 | "sha256:c7d282687a5308319bf3d2e7706e575c635b0a470342641c93bea0ea3b5331df" 459 | ], 460 | "markers": "python_version < '3'", 461 | "version": "==4.0.2" 462 | }, 463 | "contextlib2": { 464 | "hashes": [ 465 | "sha256:01f490098c18b19d2bd5bb5dc445b2054d2fa97f09a4280ba2c5f3c394c8162e", 466 | "sha256:3355078a159fbb44ee60ea80abd0d87b80b78c248643b49aa6d94673b413609b" 467 | ], 468 | "markers": "python_version < '3'", 469 | "version": "==0.6.0.post1" 470 | }, 471 | "cookies": { 472 | "hashes": [ 473 | "sha256:15bee753002dff684987b8df8c235288eb8d45f8191ae056254812dfd42c81d3", 474 | "sha256:d6b698788cae4cfa4e62ef8643a9ca332b79bd96cb314294b864ae8d7eb3ee8e" 475 | ], 476 | "markers": "python_version < '3.4'", 477 | "version": "==2.2.1" 478 | }, 479 | "cryptography": { 480 | "hashes": [ 481 | "sha256:0d7b69674b738068fa6ffade5c962ecd14969690585aaca0a1b1fc9058938a72", 482 | "sha256:1bd0ccb0a1ed775cd7e2144fe46df9dc03eefd722bbcf587b3e0616ea4a81eff", 483 | "sha256:3c284fc1e504e88e51c428db9c9274f2da9f73fdf5d7e13a36b8ecb039af6e6c", 484 | "sha256:49570438e60f19243e7e0d504527dd5fe9b4b967b5a1ff21cc12b57602dd85d3", 485 | "sha256:541dd758ad49b45920dda3b5b48c968f8b2533d8981bcdb43002798d8f7a89ed", 486 | "sha256:5a60d3780149e13b7a6ff7ad6526b38846354d11a15e21068e57073e29e19bed", 487 | "sha256:7951a966613c4211b6612b0352f5bf29989955ee592c4a885d8c7d0f830d0433", 488 | "sha256:922f9602d67c15ade470c11d616f2b2364950602e370c76f0c94c94ae672742e", 489 | "sha256:a0f0b96c572fc9f25c3f4ddbf4688b9b38c69836713fb255f4a2715d93cbaf44", 490 | "sha256:a777c096a49d80f9d2979695b835b0f9c9edab73b59e4ceb51f19724dda887ed", 491 | "sha256:a9a4ac9648d39ce71c2f63fe7dc6db144b9fa567ddfc48b9fde1b54483d26042", 492 | "sha256:aa4969f24d536ae2268c902b2c3d62ab464b5a66bcb247630d208a79a8098e9b", 493 | "sha256:c7390f9b2119b2b43160abb34f63277a638504ef8df99f11cb52c1fda66a2e6f", 494 | "sha256:e18e6ab84dfb0ab997faf8cca25a86ff15dfea4027b986322026cc99e0a892da" 495 | ], 496 | "version": "==3.3.2" 497 | }, 498 | "decorator": { 499 | "hashes": [ 500 | "sha256:41fa54c2a0cc4ba648be4fd43cff00aedf5b9465c9bf18d64325bc225f08f760", 501 | "sha256:e3a62f0520172440ca0dcc823749319382e377f37f140a0b99ef45fecb84bfe7" 502 | ], 503 | "version": "==4.4.2" 504 | }, 505 | "docker": { 506 | "hashes": [ 507 | "sha256:0604a74719d5d2de438753934b755bfcda6f62f49b8e4b30969a4b0a2a8a1220", 508 | "sha256:e455fa49aabd4f22da9f4e1c1f9d16308286adc60abaf64bf3e1feafaed81d06" 509 | ], 510 | "version": "==4.4.1" 511 | }, 512 | "ecdsa": { 513 | "hashes": [ 514 | "sha256:64c613005f13efec6541bb0a33290d0d03c27abab5f15fbab20fb0ee162bdd8e", 515 | "sha256:e108a5fe92c67639abae3260e43561af914e7fd0d27bae6d2ec1312ae7934dfe" 516 | ], 517 | "version": "==0.14.1" 518 | }, 519 | "enum34": { 520 | "hashes": [ 521 | "sha256:a98a201d6de3f2ab3db284e70a33b0f896fbf35f8086594e8c9e74b909058d53", 522 | "sha256:c3858660960c984d6ab0ebad691265180da2b43f07e061c0f8dca9ef3cffd328", 523 | "sha256:cce6a7477ed816bd2542d03d53db9f0db935dd013b70f336a95c73979289f248" 524 | ], 525 | "markers": "python_version < '3.4'", 526 | "version": "==1.1.10" 527 | }, 528 | "funcsigs": { 529 | "hashes": [ 530 | "sha256:330cc27ccbf7f1e992e69fef78261dc7c6569012cf397db8d3de0234e6c937ca", 531 | "sha256:a7bb0f2cf3a3fd1ab2732cb49eba4252c2af4240442415b4abce3b87022a8f50" 532 | ], 533 | "markers": "python_version < '3.3'", 534 | "version": "==1.0.2" 535 | }, 536 | "functools32": { 537 | "hashes": [ 538 | "sha256:89d824aa6c358c421a234d7f9ee0bd75933a67c29588ce50aaa3acdf4d403fa0", 539 | "sha256:f6253dfbe0538ad2e387bd8fdfd9293c925d63553f5813c4e587745416501e6d" 540 | ], 541 | "markers": "python_version < '3'", 542 | "version": "==3.2.3.post2" 543 | }, 544 | "future": { 545 | "hashes": [ 546 | "sha256:b1bead90b70cf6ec3f0710ae53a525360fa360d306a86583adc6bf83a4db537d" 547 | ], 548 | "version": "==0.18.2" 549 | }, 550 | "futures": { 551 | "hashes": [ 552 | "sha256:49b3f5b064b6e3afc3316421a3f25f66c137ae88f068abbf72830170033c5e16", 553 | "sha256:7e033af76a5e35f58e56da7a91e687706faf4e7bdfb2cbc3f2cca6b9bcda9794" 554 | ], 555 | "markers": "python_version == '2.6' or python_version == '2.7'", 556 | "version": "==3.3.0" 557 | }, 558 | "idna": { 559 | "hashes": [ 560 | "sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407", 561 | "sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c" 562 | ], 563 | "version": "==2.8" 564 | }, 565 | "importlib-metadata": { 566 | "hashes": [ 567 | "sha256:b8de9eff2b35fb037368f28a7df1df4e6436f578fa74423505b6c6a778d5b5dd", 568 | "sha256:c2d6341ff566f609e89a2acb2db190e5e1d23d5409d6cc8d2fe34d72443876d4" 569 | ], 570 | "markers": "python_version < '3.8'", 571 | "version": "==2.1.1" 572 | }, 573 | "importlib-resources": { 574 | "hashes": [ 575 | "sha256:0ed250dbd291947d1a298e89f39afcc477d5a6624770503034b72588601bcc05", 576 | "sha256:42068585cc5e8c2bf0a17449817401102a5125cbfbb26bb0f43cde1568f6f2df" 577 | ], 578 | "version": "==3.3.1" 579 | }, 580 | "ipaddress": { 581 | "hashes": [ 582 | "sha256:6e0f4a39e66cb5bb9a137b00276a2eff74f93b71dcbdad6f10ff7df9d3557fcc", 583 | "sha256:b7f8e0369580bb4a24d5ba1d7cc29660a4a6987763faf1d8a8046830e020e7e2" 584 | ], 585 | "version": "==1.0.23" 586 | }, 587 | "jinja2": { 588 | "hashes": [ 589 | "sha256:065c4f02ebe7f7cf559e49ee5a95fb800a9e4528727aec6f24402a5374c65013", 590 | "sha256:14dd6caf1527abb21f08f86c784eac40853ba93edb79552aa1e4b8aef1b61c7b" 591 | ], 592 | "index": "pypi", 593 | "version": "==2.10.1" 594 | }, 595 | "jmespath": { 596 | "hashes": [ 597 | "sha256:b85d0567b8666149a93172712e68920734333c0ce7e89b78b3e987f71e5ed4f9", 598 | "sha256:cdf6525904cc597730141d61b36f2e4b8ecc257c420fa2f4549bac2c2d0cb72f" 599 | ], 600 | "version": "==0.10.0" 601 | }, 602 | "jsondiff": { 603 | "hashes": [ 604 | "sha256:7e18138aecaa4a8f3b7ac7525b8466234e6378dd6cae702b982c9ed851d2ae21" 605 | ], 606 | "version": "==1.1.2" 607 | }, 608 | "jsonpatch": { 609 | "hashes": [ 610 | "sha256:da3831be60919e8c98564acfc1fa918cb96e7c9750b0428388483f04d0d1c5a7", 611 | "sha256:e930adc932e4d36087dbbf0f22e1ded32185dfb20662f2e3dd848677a5295a14" 612 | ], 613 | "version": "==1.28" 614 | }, 615 | "jsonpickle": { 616 | "hashes": [ 617 | "sha256:0be49cba80ea6f87a168aa8168d717d00c6ca07ba83df3cec32d3b30bfe6fb9a", 618 | "sha256:c1010994c1fbda87a48f8a56698605b598cb0fc6bb7e7927559fc1100e69aeac" 619 | ], 620 | "version": "==2.0.0" 621 | }, 622 | "jsonpointer": { 623 | "hashes": [ 624 | "sha256:c192ba86648e05fdae4f08a17ec25180a9aef5008d973407b581798a83975362", 625 | "sha256:ff379fa021d1b81ab539f5ec467c7745beb1a5671463f9dcc2b2d458bd361c1e" 626 | ], 627 | "version": "==2.0" 628 | }, 629 | "jsonschema": { 630 | "hashes": [ 631 | "sha256:4e5b3cf8216f577bee9ce139cbe72eca3ea4f292ec60928ff24758ce626cd163", 632 | "sha256:c8a85b28d377cc7737e46e2d9f2b4f44ee3c0e1deac6bf46ddefc7187d30797a" 633 | ], 634 | "version": "==3.2.0" 635 | }, 636 | "junit-xml": { 637 | "hashes": [ 638 | "sha256:ec5ca1a55aefdd76d28fcc0b135251d156c7106fa979686a4b48d62b761b4732" 639 | ], 640 | "version": "==1.9" 641 | }, 642 | "markupsafe": { 643 | "hashes": [ 644 | "sha256:00bc623926325b26bb9605ae9eae8a215691f33cae5df11ca5424f06f2d1f473", 645 | "sha256:09027a7803a62ca78792ad89403b1b7a73a01c8cb65909cd876f7fcebd79b161", 646 | "sha256:09c4b7f37d6c648cb13f9230d847adf22f8171b1ccc4d5682398e77f40309235", 647 | "sha256:1027c282dad077d0bae18be6794e6b6b8c91d58ed8a8d89a89d59693b9131db5", 648 | "sha256:13d3144e1e340870b25e7b10b98d779608c02016d5184cfb9927a9f10c689f42", 649 | "sha256:195d7d2c4fbb0ee8139a6cf67194f3973a6b3042d742ebe0a9ed36d8b6f0c07f", 650 | "sha256:22c178a091fc6630d0d045bdb5992d2dfe14e3259760e713c490da5323866c39", 651 | "sha256:24982cc2533820871eba85ba648cd53d8623687ff11cbb805be4ff7b4c971aff", 652 | "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b", 653 | "sha256:2beec1e0de6924ea551859edb9e7679da6e4870d32cb766240ce17e0a0ba2014", 654 | "sha256:3b8a6499709d29c2e2399569d96719a1b21dcd94410a586a18526b143ec8470f", 655 | "sha256:43a55c2930bbc139570ac2452adf3d70cdbb3cfe5912c71cdce1c2c6bbd9c5d1", 656 | "sha256:46c99d2de99945ec5cb54f23c8cd5689f6d7177305ebff350a58ce5f8de1669e", 657 | "sha256:500d4957e52ddc3351cabf489e79c91c17f6e0899158447047588650b5e69183", 658 | "sha256:535f6fc4d397c1563d08b88e485c3496cf5784e927af890fb3c3aac7f933ec66", 659 | "sha256:596510de112c685489095da617b5bcbbac7dd6384aeebeda4df6025d0256a81b", 660 | "sha256:62fe6c95e3ec8a7fad637b7f3d372c15ec1caa01ab47926cfdf7a75b40e0eac1", 661 | "sha256:6788b695d50a51edb699cb55e35487e430fa21f1ed838122d722e0ff0ac5ba15", 662 | "sha256:6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1", 663 | "sha256:6f1e273a344928347c1290119b493a1f0303c52f5a5eae5f16d74f48c15d4a85", 664 | "sha256:6fffc775d90dcc9aed1b89219549b329a9250d918fd0b8fa8d93d154918422e1", 665 | "sha256:717ba8fe3ae9cc0006d7c451f0bb265ee07739daf76355d06366154ee68d221e", 666 | "sha256:79855e1c5b8da654cf486b830bd42c06e8780cea587384cf6545b7d9ac013a0b", 667 | "sha256:7c1699dfe0cf8ff607dbdcc1e9b9af1755371f92a68f706051cc8c37d447c905", 668 | "sha256:7fed13866cf14bba33e7176717346713881f56d9d2bcebab207f7a036f41b850", 669 | "sha256:84dee80c15f1b560d55bcfe6d47b27d070b4681c699c572af2e3c7cc90a3b8e0", 670 | "sha256:88e5fcfb52ee7b911e8bb6d6aa2fd21fbecc674eadd44118a9cc3863f938e735", 671 | "sha256:8defac2f2ccd6805ebf65f5eeb132adcf2ab57aa11fdf4c0dd5169a004710e7d", 672 | "sha256:98bae9582248d6cf62321dcb52aaf5d9adf0bad3b40582925ef7c7f0ed85fceb", 673 | "sha256:98c7086708b163d425c67c7a91bad6e466bb99d797aa64f965e9d25c12111a5e", 674 | "sha256:9add70b36c5666a2ed02b43b335fe19002ee5235efd4b8a89bfcf9005bebac0d", 675 | "sha256:9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c", 676 | "sha256:a6a744282b7718a2a62d2ed9d993cad6f5f585605ad352c11de459f4108df0a1", 677 | "sha256:acf08ac40292838b3cbbb06cfe9b2cb9ec78fce8baca31ddb87aaac2e2dc3bc2", 678 | "sha256:ade5e387d2ad0d7ebf59146cc00c8044acbd863725f887353a10df825fc8ae21", 679 | "sha256:b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2", 680 | "sha256:b1282f8c00509d99fef04d8ba936b156d419be841854fe901d8ae224c59f0be5", 681 | "sha256:b1dba4527182c95a0db8b6060cc98ac49b9e2f5e64320e2b56e47cb2831978c7", 682 | "sha256:b2051432115498d3562c084a49bba65d97cf251f5a331c64a12ee7e04dacc51b", 683 | "sha256:b7d644ddb4dbd407d31ffb699f1d140bc35478da613b441c582aeb7c43838dd8", 684 | "sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6", 685 | "sha256:bf5aa3cbcfdf57fa2ee9cd1822c862ef23037f5c832ad09cfea57fa846dec193", 686 | "sha256:c8716a48d94b06bb3b2524c2b77e055fb313aeb4ea620c8dd03a105574ba704f", 687 | "sha256:caabedc8323f1e93231b52fc32bdcde6db817623d33e100708d9a68e1f53b26b", 688 | "sha256:cd5df75523866410809ca100dc9681e301e3c27567cf498077e8551b6d20e42f", 689 | "sha256:cdb132fc825c38e1aeec2c8aa9338310d29d337bebbd7baa06889d09a60a1fa2", 690 | "sha256:d53bc011414228441014aa71dbec320c66468c1030aae3a6e29778a3382d96e5", 691 | "sha256:d73a845f227b0bfe8a7455ee623525ee656a9e2e749e4742706d80a6065d5e2c", 692 | "sha256:d9be0ba6c527163cbed5e0857c451fcd092ce83947944d6c14bc95441203f032", 693 | "sha256:e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7", 694 | "sha256:e8313f01ba26fbbe36c7be1966a7b7424942f670f38e666995b88d012765b9be", 695 | "sha256:feb7b34d6325451ef96bc0e36e1a6c0c1c64bc1fbec4b854f4529e51887b1621" 696 | ], 697 | "version": "==1.1.1" 698 | }, 699 | "mock": { 700 | "hashes": [ 701 | "sha256:5ce3c71c5545b472da17b72268978914d0252980348636840bd34a00b5cc96c1", 702 | "sha256:b158b6df76edd239b8208d481dc46b6afd45a846b7812ff0ce58971cf5bc8bba" 703 | ], 704 | "index": "pypi", 705 | "version": "==2.0.0" 706 | }, 707 | "more-itertools": { 708 | "hashes": [ 709 | "sha256:38a936c0a6d98a38bcc2d03fdaaedaba9f412879461dd2ceff8d37564d6522e4", 710 | "sha256:c0a5785b1109a6bd7fac76d6837fd1feca158e54e521ccd2ae8bfe393cc9d4fc", 711 | "sha256:fe7a7cae1ccb57d33952113ff4fa1bc5f879963600ed74918f1236e212ee50b9" 712 | ], 713 | "version": "==5.0.0" 714 | }, 715 | "moto": { 716 | "hashes": [ 717 | "sha256:9cb02134148fbe3ed81f11d6ab9bd71bbd6bc2db7e59a45de77fb1d0fedb744e", 718 | "sha256:fc354598cb67cae1b18318b1e98955004bc27e05404a84ffa9c68654334638f2" 719 | ], 720 | "index": "pypi", 721 | "version": "==1.3.8" 722 | }, 723 | "networkx": { 724 | "hashes": [ 725 | "sha256:45e56f7ab6fe81652fb4bc9f44faddb0e9025f469f602df14e3b2551c2ea5c8b" 726 | ], 727 | "version": "==2.2" 728 | }, 729 | "pathlib2": { 730 | "hashes": [ 731 | "sha256:0ec8205a157c80d7acc301c0b18fbd5d44fe655968f5d947b6ecef5290fc35db", 732 | "sha256:6cd9a47b597b37cc57de1c05e56fb1a1c9cc9fab04fe78c29acd090418529868" 733 | ], 734 | "markers": "python_version < '3.6'", 735 | "version": "==2.3.5" 736 | }, 737 | "pbr": { 738 | "hashes": [ 739 | "sha256:5fad80b613c402d5b7df7bd84812548b2a61e9977387a80a5fc5c396492b13c9", 740 | "sha256:b236cde0ac9a6aedd5e3c34517b423cd4fd97ef723849da6b0d2231142d89c00" 741 | ], 742 | "version": "==5.5.1" 743 | }, 744 | "pluggy": { 745 | "hashes": [ 746 | "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0", 747 | "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d" 748 | ], 749 | "version": "==0.13.1" 750 | }, 751 | "py": { 752 | "hashes": [ 753 | "sha256:21b81bda15b66ef5e1a777a21c4dcd9c20ad3efd0b3f817e7a809035269e1bd3", 754 | "sha256:3b80836aa6d1feeaa108e046da6423ab8f6ceda6468545ae8d02d9d58d18818a" 755 | ], 756 | "version": "==1.10.0" 757 | }, 758 | "pyasn1": { 759 | "hashes": [ 760 | "sha256:39c7e2ec30515947ff4e87fb6f456dfc6e84857d34be479c9d4a4ba4bf46aa5d", 761 | "sha256:aef77c9fb94a3ac588e87841208bdec464471d9871bd5050a287cc9a475cd0ba" 762 | ], 763 | "version": "==0.4.8" 764 | }, 765 | "pycparser": { 766 | "hashes": [ 767 | "sha256:2d475327684562c3a96cc71adf7dc8c4f0565175cf86b6d7a404ff4c771f15f0", 768 | "sha256:7582ad22678f0fcd81102833f60ef8d0e57288b6b5fb00323d101be910e35705" 769 | ], 770 | "version": "==2.20" 771 | }, 772 | "pyrsistent": { 773 | "hashes": [ 774 | "sha256:28669905fe725965daa16184933676547c5bb40a5153055a8dee2a4bd7933ad3" 775 | ], 776 | "markers": "python_version < '3'", 777 | "version": "==0.16.0" 778 | }, 779 | "pytest": { 780 | "hashes": [ 781 | "sha256:a9e5e8d7ab9d5b0747f37740276eb362e6a76275d76cebbb52c6049d93b475db", 782 | "sha256:bf47e8ed20d03764f963f0070ff1c8fda6e2671fc5dd562a4d3b7148ad60f5ca" 783 | ], 784 | "index": "pypi", 785 | "version": "==3.9.3" 786 | }, 787 | "python-dateutil": { 788 | "hashes": [ 789 | "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c", 790 | "sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a" 791 | ], 792 | "markers": "python_version >= '2.7'", 793 | "version": "==2.8.1" 794 | }, 795 | "python-jose": { 796 | "hashes": [ 797 | "sha256:4e4192402e100b5fb09de5a8ea6bcc39c36ad4526341c123d401e2561720335b", 798 | "sha256:67d7dfff599df676b04a996520d9be90d6cdb7e6dd10b4c7cacc0c3e2e92f2be" 799 | ], 800 | "version": "==3.2.0" 801 | }, 802 | "pytz": { 803 | "hashes": [ 804 | "sha256:7016b2c4fa075c564b81c37a252a5fccf60d8964aa31b7f5eae59aeb594ae02b", 805 | "sha256:9a43e20aa537cfad8fe7a1715165c91cb4a6935d40947f2d070e4c80f2dcd22b", 806 | "sha256:a1ea35e87a63c7825846d5b5c81d23d668e8a102d3b1b465ce95afe1b3a2e065", 807 | "sha256:aafbf066975fe217ed49d7d197b26903d3b43e9ca2aa6ba0a211081f13c41917" 808 | ], 809 | "index": "pypi", 810 | "version": "==2016.10" 811 | }, 812 | "pyyaml": { 813 | "hashes": [ 814 | "sha256:57acc1d8533cbe51f6662a55434f0dbecfa2b9eaf115bede8f6fd00115a0c0d3", 815 | "sha256:588c94b3d16b76cfed8e0be54932e5729cc185caffaa5a451e7ad2f7ed8b4043", 816 | "sha256:68c8dd247f29f9a0d09375c9c6b8fdc64b60810ebf07ba4cdd64ceee3a58c7b7", 817 | "sha256:70d9818f1c9cd5c48bb87804f2efc8692f1023dac7f1a1a5c61d454043c1d265", 818 | "sha256:86a93cccd50f8c125286e637328ff4eef108400dd7089b46a7be3445eecfa391", 819 | "sha256:a0f329125a926876f647c9fa0ef32801587a12328b4a3c741270464e3e4fa778", 820 | "sha256:a3c252ab0fa1bb0d5a3f6449a4826732f3eb6c0270925548cac342bc9b22c225", 821 | "sha256:b4bb4d3f5e232425e25dda21c070ce05168a786ac9eda43768ab7f3ac2770955", 822 | "sha256:cd0618c5ba5bda5f4039b9398bb7fb6a317bb8298218c3de25c47c4740e4b95e", 823 | "sha256:ceacb9e5f8474dcf45b940578591c7f3d960e82f926c707788a570b51ba59190", 824 | "sha256:fe6a88094b64132c4bb3b631412e90032e8cfe9745a58370462240b8cb7553cd" 825 | ], 826 | "index": "pypi", 827 | "version": "==5.1.1" 828 | }, 829 | "requests": { 830 | "hashes": [ 831 | "sha256:11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4", 832 | "sha256:9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9a590f48c010551dc6c4b31" 833 | ], 834 | "index": "pypi", 835 | "version": "==2.22.0" 836 | }, 837 | "responses": { 838 | "hashes": [ 839 | "sha256:2e5764325c6b624e42b428688f2111fea166af46623cb0127c05f6afb14d3457", 840 | "sha256:ef265bd3200bdef5ec17912fc64a23570ba23597fd54ca75c18650fa1699213d" 841 | ], 842 | "version": "==0.12.1" 843 | }, 844 | "rsa": { 845 | "hashes": [ 846 | "sha256:35c5b5f6675ac02120036d97cf96f1fde4d49670543db2822ba5015e21a18032", 847 | "sha256:4d409f5a7d78530a4a2062574c7bd80311bc3af29b364e293aa9b03eea77714f" 848 | ], 849 | "version": "==4.5" 850 | }, 851 | "s3transfer": { 852 | "hashes": [ 853 | "sha256:6efc926738a3cd576c2a79725fed9afde92378aa5c6a957e3af010cb019fac9d", 854 | "sha256:b780f2411b824cb541dbcd2c713d0cb61c7d1bcadae204cdddda2b35cef493ba" 855 | ], 856 | "version": "==0.2.1" 857 | }, 858 | "scandir": { 859 | "hashes": [ 860 | "sha256:2586c94e907d99617887daed6c1d102b5ca28f1085f90446554abf1faf73123e", 861 | "sha256:2ae41f43797ca0c11591c0c35f2f5875fa99f8797cb1a1fd440497ec0ae4b022", 862 | "sha256:2b8e3888b11abb2217a32af0766bc06b65cc4a928d8727828ee68af5a967fa6f", 863 | "sha256:2c712840c2e2ee8dfaf36034080108d30060d759c7b73a01a52251cc8989f11f", 864 | "sha256:4d4631f6062e658e9007ab3149a9b914f3548cb38bfb021c64f39a025ce578ae", 865 | "sha256:67f15b6f83e6507fdc6fca22fedf6ef8b334b399ca27c6b568cbfaa82a364173", 866 | "sha256:7d2d7a06a252764061a020407b997dd036f7bd6a175a5ba2b345f0a357f0b3f4", 867 | "sha256:8c5922863e44ffc00c5c693190648daa6d15e7c1207ed02d6f46a8dcc2869d32", 868 | "sha256:92c85ac42f41ffdc35b6da57ed991575bdbe69db895507af88b9f499b701c188", 869 | "sha256:b24086f2375c4a094a6b51e78b4cf7ca16c721dcee2eddd7aa6494b42d6d519d", 870 | "sha256:cb925555f43060a1745d0a321cca94bcea927c50114b623d73179189a4e100ac" 871 | ], 872 | "markers": "python_version < '3.5'", 873 | "version": "==1.10.0" 874 | }, 875 | "singledispatch": { 876 | "hashes": [ 877 | "sha256:5b06af87df13818d14f08a028e42f566640aef80805c3b50c5056b086e3c2b9c", 878 | "sha256:833b46966687b3de7f438c761ac475213e53b306740f1abfaa86e1d1aae56aa8" 879 | ], 880 | "markers": "python_version < '3.4'", 881 | "version": "==3.4.0.3" 882 | }, 883 | "six": { 884 | "hashes": [ 885 | "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259", 886 | "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced" 887 | ], 888 | "version": "==1.15.0" 889 | }, 890 | "typing": { 891 | "hashes": [ 892 | "sha256:1187fb9c82fd670d10aa07bbb6cfcfe4bdda42d6fab8d5134f04e8c4d0b71cc9", 893 | "sha256:283d868f5071ab9ad873e5e52268d611e851c870a2ba354193026f2dfb29d8b5" 894 | ], 895 | "markers": "python_version < '3.5'", 896 | "version": "==3.7.4.3" 897 | }, 898 | "urllib3": { 899 | "hashes": [ 900 | "sha256:8d7eaa5a82a1cac232164990f04874c594c9453ec55eef02eab885aa02fc17a2", 901 | "sha256:f5321fbe4bf3fefa0efd0bfe7fb14e90909eb62a48ccda331726b4319897dd5e" 902 | ], 903 | "markers": "python_version == '2.7'", 904 | "version": "==1.25.11" 905 | }, 906 | "websocket-client": { 907 | "hashes": [ 908 | "sha256:0fc45c961324d79c781bab301359d5a1b00b13ad1b10415a4780229ef71a5549", 909 | "sha256:d735b91d6d1692a6a181f2a8c9e0238e5f6373356f561bb9dc4c7af36f452010" 910 | ], 911 | "version": "==0.57.0" 912 | }, 913 | "werkzeug": { 914 | "hashes": [ 915 | "sha256:2de2a5db0baeae7b2d2664949077c2ac63fbd16d98da0ff71837f7d1dea3fd43", 916 | "sha256:6c80b1e5ad3665290ea39320b91e1be1e0d5f60652b964a3070216de83d2e47c" 917 | ], 918 | "version": "==1.0.1" 919 | }, 920 | "wrapt": { 921 | "hashes": [ 922 | "sha256:b62ffa81fb85f4332a4f609cab4ac40709470da05643a082ec1eb88e6d9b97d7" 923 | ], 924 | "version": "==1.12.1" 925 | }, 926 | "xmltodict": { 927 | "hashes": [ 928 | "sha256:50d8c638ed7ecb88d90561beedbf720c9b4e851a9fa6c47ebd64e99d166d8a21", 929 | "sha256:8bbcb45cc982f48b2ca8fe7e7827c5d792f217ecf1792626f808bf41c3b86051" 930 | ], 931 | "version": "==0.12.0" 932 | }, 933 | "zipp": { 934 | "hashes": [ 935 | "sha256:c70410551488251b0fee67b460fb9a536af8d6f9f008ad10ac51f615b6a521b1", 936 | "sha256:e0d9e63797e483a30d27e09fffd308c59a700d365ec34e93cc100844168bf921" 937 | ], 938 | "markers": "python_version < '3.8'", 939 | "version": "==1.2.0" 940 | } 941 | } 942 | } 943 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spot Instances use and management for Kubernetes 2 | 3 | The minion-manager enables the intelligent use of Spot Instances in Kubernetes. 4 | 5 | ## 🚨 ⚠️THIS PROJECT IS NOW BEING ABANDONED ⚠️ 🚨 6 | 7 | We originally developed Minion Manager in 2018 to intelligently manage the use of AWS Spot Instances in Kubernetes. Since then, there have been many changes to how Kubernetes is run and operated in AWS, the most significant being the introduction of [EKS](https://aws.amazon.com/eks/), [Managed Node Groups](https://docs.aws.amazon.com/eks/latest/userguide/managed-node-groups.html), and, most recently, [Karpenter](https://github.com/kubernetes-sigs/karpenter). 8 | 9 | We recommend [using Karpenter to manage Spot Instances](https://aws.amazon.com/blogs/containers/using-amazon-ec2-spot-instances-with-karpenter/). The Minion Manager repository will be archived, and there will be no further updates or releases. 10 | 11 | ## What does it do? 12 | 13 | * The minion-manager operates on autoscaling groups (ASGs). 14 | 15 | * It queries AWS for all autoscaling groups that have the Kubernetes cluster tag and a special tag called "k8s-minion-manager". ASGs which have these tags are operated upon by the minion-manager. 16 | 17 | * It queries AWS to get the pricing information for spot-instances every 10 minutes. 18 | 19 | * It checks whether the given ASGs are using spot-instances or on-demand instances. If the spot-instance price < on-demand instance price, it switches the ASG to use spot-instances and terminates the on-demand instance. 20 | 21 | * If, at any point in time, the spot-instance price spikes and goes above on-demand instance price, it switches the ASG to use on-demand instances. 22 | 23 | ### Prerequisites 24 | 25 | It's best to run the minion-manger on an on-demand instance. 26 | 27 | The IAM role of the node that runs the minion-manager should have the following policies. 28 | 29 | ``` 30 | { 31 | "Sid": "kopsK8sMinionManager", 32 | "Effect": "Allow", 33 | "Action": [ 34 | "ec2:DescribeInstances", 35 | "ec2:TerminateInstances", 36 | "ec2:DescribeSpotPriceHistory", 37 | "ec2:DescribeSpotInstanceRequests", 38 | "autoscaling:CreateLaunchConfiguration", 39 | "autoscaling:DeleteLaunchConfiguration", 40 | "autoscaling:DescribeLaunchConfigurations", 41 | "autoscaling:DescribeAutoScalingGroups", 42 | "autoscaling:TerminateInstanceInAutoScalingGroup", 43 | "autoscaling:UpdateAutoScalingGroup", 44 | "autoscaling:DescribeScalingActivities", 45 | "iam:PassRole" 46 | ], 47 | "Resource": [ 48 | "*" 49 | ] 50 | } 51 | ``` 52 | 53 | ### Installing 54 | 55 | Modify the `deploy/mm.yaml` by 56 | 57 | 1) Add the names of your cluster instead of 58 | 2) Change the namespace where the minion-manager will be run. 59 | 60 | Then, `kubectl apply -f deploy/mm.yaml`. 61 | 62 | **Design:** 63 | 64 | * Only ASGs which have the "k8s-minion-manager" tag are considered by the minion-manager. Other ASGs are left alone. 65 | * Minion-manager queries AWS for ASGs with these tags every "--refresh-interval". Default is 5 minutes. 66 | * The "k8s-minion-manager" tag can have two possible values: 67 | * "use-spot": This will make the minion-manager intelligently use spot instances in the ASG 68 | * "no-spot": This will make the minion-manager always use on-demand instances in the ASG. This is useful when someone wants to temporarily switch to on-demand instances and at a later point switch to "use-spot" 69 | * Note that after changing the tag value, it may take upto 5 minutes for the minion-manager pod to see the changes and make them take effect. 70 | * The "k8s-minion-manager/not-terminate" tag can control ASG instance terminate by the minion-manager. If you want to control when to terminate ASG instances. You can set this tag to `true`. If not set or other value will disable this feature. 71 | 72 | **What happens when:** 73 | 74 | _1. User runs k8s-minion-manager without any ASG having the "k8s-minion-manager" tag?_ 75 | 76 | k8s-minion-manager ignores all ASGs. It simply continues to keep polling AWS for the tags every "refresh-interval" seconds. 77 | 78 | _2. User runs k8s-minion-manager, adds the "k8s-minion-manager" tag and the "use-spot" value to start with. But later wants to not use spot instances._ 79 | 80 | User should then change the key from "use-spot" to "no-spot". This will indicate to the k8s-minion-manager that the ASG should have all on-demand instances and it will make sure of that. 81 | 82 | _3. User runs k8s-minion-manager, adds the "k8s-minion-manager" key and the "use-spot" value to start with. But later simply removes the tag and the value._ 83 | 84 | Once the tag is removed, k8s-minion-manager simply considers the ASG to be off-limits and does not act upon it. The ASG will remain in whatever condition it is in. 85 | 86 | _4. User runs k8s-minion-manager, adds the "k8s-minion-manager" key and the "no-spot" value to start with. But later simply removes the tag and the value._ 87 | 88 | Same as above. The ASG will remain in whatever condition it is in. 89 | 90 | _5. User is running k8s-minion-manager and using spot instances. But now wants to stop using instances forever._ 91 | 92 | This will be a multi-step process: 93 | * Change the value of the "k8-minion-manager" tag to "no-spot". 94 | * Wait for the minion-manager to react to this and switch the instances to on-demand. Look at the AWS console for verifying that all instances are on-demand. 95 | * After the above, remove the "k8s-minion-manager" tag. 96 | * Delete the "k8s-minion-manager" deployment. 97 | 98 | **How do I:** 99 | 100 | _1. Run unit tests: Ensure that your AWS cli is set up correctly. Then simply run `make docker-test`_ 101 | -------------------------------------------------------------------------------- /binaries/kubectl-v1.12.3-linux-amd64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keikoproj/minion-manager/190a15e15bbb9c4c0ac6e4c716a82b01d33377d9/binaries/kubectl-v1.12.3-linux-amd64 -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | MM_REGISTRY_NAMESPACE=${MM_REGISTRY_NAMESPACE:-oss} 4 | MM_REGISTRY_URL=${REGSITRY_URL:-get.applatix.io} 5 | MM_VERSION=${MM_VERSION:-latest} 6 | 7 | docker build -t ${MM_REGISTRY_URL}/${MM_REGISTRY_NAMESPACE}/minion-manager:${MM_VERSION} . 8 | -------------------------------------------------------------------------------- /cloud_broker/__init__.py: -------------------------------------------------------------------------------- 1 | from broker import Broker 2 | -------------------------------------------------------------------------------- /cloud_broker/broker.py: -------------------------------------------------------------------------------- 1 | """ 2 | The Broker object takes a cloud provider name as input and returns the 3 | appropriate object on which subsequent methods can be called. 4 | """ 5 | 6 | from cloud_provider.aws.aws_minion_manager import AWSMinionManager 7 | 8 | 9 | class Broker(object): 10 | """ Create and return cloud provider specific objects """ 11 | 12 | @staticmethod 13 | def get_impl_object(provider, cluster_name, region, refresh_interval_seconds=300, **kwargs): 14 | """ 15 | Given a cloud provider name, return the cloud provider specific 16 | implementation. 17 | """ 18 | if provider.lower() == "aws": 19 | return AWSMinionManager(cluster_name, region, refresh_interval_seconds, **kwargs) 20 | 21 | raise NotImplementedError 22 | -------------------------------------------------------------------------------- /cloud_broker/broker_test.py: -------------------------------------------------------------------------------- 1 | """The file has unit tests for the cloud broker.""" 2 | 3 | import unittest 4 | import pytest 5 | from cloud_broker.broker import Broker 6 | 7 | 8 | class BrokerTest(unittest.TestCase): 9 | """ 10 | Tests for cloud broker. 11 | """ 12 | 13 | def test_get_impl_object(self): 14 | """ 15 | Tests that the get_impl_object method works as expected. 16 | """ 17 | 18 | # Verify that a minion-manager object is returned for "aws" 19 | mgr = Broker.get_impl_object("aws", "mycluster", "us-west-2") 20 | assert mgr is not None, "No minion-manager returned!" 21 | 22 | # For non-aws clouds, a NotImplementedError is returned. 23 | with pytest.raises(NotImplementedError): 24 | mgr = Broker.get_impl_object("google", "mycluster", "") 25 | -------------------------------------------------------------------------------- /cloud_provider/__init__.py: -------------------------------------------------------------------------------- 1 | from base import MinionManagerBase 2 | -------------------------------------------------------------------------------- /cloud_provider/aws/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keikoproj/minion-manager/190a15e15bbb9c4c0ac6e4c716a82b01d33377d9/cloud_provider/aws/__init__.py -------------------------------------------------------------------------------- /cloud_provider/aws/asg_mm.py: -------------------------------------------------------------------------------- 1 | """ Metadata for each Autoscaling group in AWS. """ 2 | MINION_MANAGER_LABEL = 'k8s-minion-manager' 3 | NOT_TERMINATE_LABEL = 'k8s-minion-manager/not-terminate' 4 | 5 | 6 | class AWSAutoscalinGroupMM(object): 7 | """This class has metadata associated with an autoscaling group.""" 8 | 9 | def __init__(self): 10 | # 'asg_info' is populated with the returned value of 11 | # describe_autoscaling_groups() API. 12 | self.asg_info = None 13 | 14 | # 'lc_info' is the LaunchConfiguration info returned by 15 | # describe_launch_configurations() API. 16 | self.lc_info = None 17 | 18 | # 'bid_info' is a simple dictionary with keys 'type' and 'bid_price'. 19 | self.bid_info = {} 20 | 21 | # Metadata about all instances running in this ASG, keyed by instance-id. 22 | self.instance_info = {} 23 | 24 | def get_name(self): 25 | """ Convenience method to get the name of the ASG. """ 26 | return self.asg_info.AutoScalingGroupName 27 | 28 | def set_asg_info(self, asg_info): 29 | """ Sets the asg_info. """ 30 | assert asg_info is not None, "Can't set ASG info to None!" 31 | self.asg_info = asg_info 32 | for tag in self.asg_info['Tags']: 33 | if tag.get('Key') == MINION_MANAGER_LABEL: 34 | if tag['Value'] not in ("use-spot", "no-spot"): 35 | tag['Value'] = 'no-spot' 36 | elif tag.get('Key') == NOT_TERMINATE_LABEL: 37 | if tag['Value'].lower() == 'true': 38 | tag['Value'] = True 39 | else: 40 | tag['Value'] = False 41 | 42 | def set_lc_info(self, lc_info): 43 | """ Sets the lc_info. """ 44 | assert lc_info is not None, "Can't set lc_info info to None!" 45 | self.lc_info = lc_info 46 | 47 | def set_bid_info(self, bid_info): 48 | """ Sets the bif_info. """ 49 | assert bid_info is not None, "Can't set bid_info info to None!" 50 | self.bid_info = bid_info 51 | 52 | def get_asg_info(self): 53 | """ Returns the asg_info. """ 54 | return self.asg_info 55 | 56 | def get_lc_info(self): 57 | """ Returns the lc_info. """ 58 | return self.lc_info 59 | 60 | def get_bid_info(self): 61 | """ Returns the bid_info. """ 62 | return self.bid_info 63 | 64 | def add_instances(self, instances): 65 | """Adds the given instances to the 'instances' array if they're not 66 | present. 67 | """ 68 | for instance in instances: 69 | if instance.InstanceId not in self.instance_info: 70 | self.instance_info[instance.InstanceId] = instance 71 | 72 | def remove_instance(self, instance_id): 73 | """Removes the given instance from the 'instances' array.""" 74 | self.instance_info.pop(instance_id, None) 75 | 76 | def get_instance_info(self): 77 | """ Returns the instances. """ 78 | return self.instance_info 79 | 80 | def get_instances(self): 81 | """ Returns the 'instance' objects. """ 82 | return self.instance_info.values() 83 | 84 | def get_mm_tag(self): 85 | for tag in self.asg_info['Tags']: 86 | if tag.get('Key') == MINION_MANAGER_LABEL: 87 | return tag['Value'].lower() 88 | return "no-spot" 89 | 90 | def get_instance_name(self, instance): 91 | """ Returns the name of the instance """ 92 | if "Tags" not in instance: 93 | return None 94 | for t in instance.Tags: 95 | if t["Key"] == "Name": 96 | return t["Value"] 97 | return None 98 | 99 | def is_instance_running(self, instance): 100 | """ Returns whether the instance is running """ 101 | if "State" not in instance: 102 | return False 103 | 104 | if "Name" not in instance["State"]: 105 | return False 106 | 107 | if instance["State"]["Name"].lower() != "running": 108 | return False 109 | 110 | return True 111 | 112 | def not_terminate_instance(self): 113 | """ Returns if the ASG is configure to not terminate instances """ 114 | for tag in self.asg_info['Tags']: 115 | if tag.get('Key') == NOT_TERMINATE_LABEL: 116 | return tag['Value'] 117 | return False 118 | -------------------------------------------------------------------------------- /cloud_provider/aws/aws_bid_advisor.py: -------------------------------------------------------------------------------- 1 | """BidAdvisor implementation for AWS.""" 2 | 3 | import csv 4 | from datetime import datetime, timedelta 5 | import logging 6 | import threading 7 | import time 8 | 9 | import boto3 10 | import requests 11 | from retrying import retry 12 | from constants import SECONDS_PER_MINUTE 13 | 14 | 15 | logging.basicConfig(format="%(asctime)s %(levelname)s %(name)s " + 16 | "%(threadName)s: %(message)s", 17 | datefmt="%Y-%m-%dT%H:%M:%S", level=logging.INFO) 18 | logger = logging.getLogger("aws.minion-manager.bid-advisor") 19 | 20 | # Info about AWS Pricing API: 21 | # https://aws.amazon.com/blogs/aws/new-aws-price-list-api/ 22 | # Info about reading the csv: 23 | # http://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/reading-an-offer.html 24 | HOURLY_TERM_CODE = 'JRTCKXETXF' 25 | RATE_CODE = '6YS6EN2CT7' 26 | 27 | def aws_pricing_url(region): 28 | """ 29 | retruns URL per region, Using the Bulk API 30 | """ 31 | base_url = "https://pricing.us-east-1.amazonaws.com" 32 | url = "{0}/offers/v1.0/aws/AmazonEC2/current/{1}/index.csv".format(base_url, region) 33 | return url 34 | 35 | # The pricing API provided above only uses long region names and not the short 36 | # one (like us-west-2). And, there 37 | # doesn't seem to be any API that maps the short names to the long names. 38 | # Therefore, we have to maintain this mapping ourselves. 39 | 40 | AWS_REGIONS = { 41 | 'ap-northeast-1': "Asia Pacific (Tokyo)", 42 | 'ap-northeast-2': "Asia Pacific (Seoul)", 43 | 'ap-southeast-1': "Asia Pacific (Singapore)", 44 | 'ap-southeast-2': "Asia Pacific (Sydney)", 45 | 'ca-central-1': "Canada (Central)", 46 | 'ap-south-1': "Asia Pacific (Mumbai)", 47 | 'eu-central-1': "EU (Frankfurt)", 48 | 'eu-west-1': "EU (Ireland)", 49 | 'eu-west-2': "EU (London)", 50 | 'sa-east-1': "South America (Sao Paulo)", 51 | 'us-east-1': "US East (N. Virginia)", 52 | 'us-east-2': "US East (Ohio)", 53 | 'us-west-1': "US West (N. California)", 54 | 'us-west-2': "US West (Oregon)" 55 | } 56 | 57 | # This is returned in case the BidAdvisor is unable to compare the 58 | # spot-instance price and on-demand price. 59 | DEFAULT_BID = {"type": "on-demand"} 60 | 61 | 62 | class AWSBidAdvisor(object): 63 | """ 64 | The AWSBidAdvisor object is responsible for keeping track of instance 65 | prices for on-demand as well as spot instances. It exposes a method 66 | called get_bid() that returns the bid information. The AWSMinionManager 67 | object can then chose to use the bid information or not. 68 | """ 69 | 70 | def __init__(self, on_demand_refresh_interval, spot_refresh_interval, 71 | region): 72 | # This dictionary stores pricing information about on-demand instances 73 | # for all instance types. 74 | # E.g. {'d2.2xlarge': '1.3800000000', 'g2.8xlarge': '2.6000000000', 75 | # 'm3.large': '0.1330000000',...} 76 | self.on_demand_price_dict = {} 77 | 78 | # This list stores pricing information obtained from AWS. This 79 | # includes AZ, instance-type, price. Also, this list is sorted by time 80 | # and has guaranteed 1000 elements. 81 | # [{'Timestamp': datetime.datetime(2017, 1, 10, 21, 55, 29, 82 | # tzinfo=tzutc()), 'ProductDescription': 'Linux/UNIX', 'InstanceType': 83 | # 'c3.2xlarge', 'SpotPrice': '0.089100', 'AvailabilityZone': 84 | # 'us-west-2a'}, ...] 85 | self.spot_price_list = [] 86 | 87 | self.ec2 = boto3.Session().client('ec2', region_name=region) 88 | 89 | # The interval at which the on-demand pricing information should be 90 | # refreshed. The on-demand pricing doesn't change often. It should be 91 | # fine to have this in the order of few hours. 92 | self.on_demand_refresh_interval = on_demand_refresh_interval 93 | 94 | # The interval at which the spot-pricing information should be 95 | # refreshed. This information can change frequently. This refresh 96 | # interval therefore should be in the order of few minutes. 97 | self.spot_refresh_interval = spot_refresh_interval 98 | 99 | self.region = region 100 | self.terminate_thread = False 101 | self.all_bid_advisor_threads = [] 102 | 103 | self.lock = threading.Lock() 104 | 105 | class OnDemandUpdater(threading.Thread): 106 | """ 107 | This thread periodically updates the on-demand instance pricing. 108 | """ 109 | def __init__(self, bid_advisor): 110 | threading.Thread.__init__(self) 111 | assert bid_advisor, "BidAdvisor can't be None" 112 | self.bid_advisor = bid_advisor 113 | 114 | def parse_price_row(self, row): 115 | region_full_name = AWS_REGIONS[self.bid_advisor.region] 116 | if HOURLY_TERM_CODE + "." + RATE_CODE in row["RateCode"] and \ 117 | "OnDemand" in row["TermType"] and \ 118 | "On Demand" in row["PriceDescription"] and \ 119 | region_full_name in row["Location"] and \ 120 | row["Operating System"] == "Linux" and \ 121 | row["Pre Installed S/W"] == "NA" and \ 122 | row["Tenancy"] == "Shared": 123 | price = row["PricePerUnit"] 124 | instance_type = row["Instance Type"] 125 | old_price = self.bid_advisor.on_demand_price_dict.get(instance_type, None) 126 | if old_price is None: 127 | self.bid_advisor.on_demand_price_dict[instance_type] = price 128 | else: 129 | if float(price) == 0.00: 130 | logger.info("Found on-demand instance price of 0 for {}. Ignoring ...".format(instance_type)) 131 | elif float(price) > float(old_price): 132 | logger.info("Found alternate price for {}. Old price {}, new price {}. Updated!".format( 133 | instance_type, old_price, price)) 134 | self.bid_advisor.on_demand_price_dict[instance_type] = price 135 | 136 | @retry(wait_exponential_multiplier=1000, stop_max_attempt_number=3) 137 | def get_on_demand_pricing(self): 138 | """ Issues the AWS api for getting on-demand pricing info. """ 139 | resp = requests.get(url=aws_pricing_url(self.bid_advisor.region), stream=True) 140 | line_iterator = resp.iter_lines() 141 | line = None 142 | for line in line_iterator: 143 | # Ignore lines till the PriceDescription is reached. 144 | if "PriceDescription" in line: 145 | line = line.replace('"', '') 146 | break 147 | assert line, "Failed while iteration over on-demand price info" 148 | reader = csv.DictReader(line_iterator, fieldnames=line.split(',')) 149 | for row in reader: 150 | self.parse_price_row(row) 151 | 152 | logger.info("On-demand pricing info updated") 153 | 154 | def run(self): 155 | """ Main method of the OnDemandUpdater thread. """ 156 | orig_interval = self.bid_advisor.on_demand_refresh_interval 157 | while self.bid_advisor.terminate_thread is False: 158 | try: 159 | self.get_on_demand_pricing() 160 | self.bid_advisor.on_demand_refresh_interval = orig_interval 161 | except Exception as ex: 162 | logger.info("Error while getting on-demand price " + 163 | "info: " + str(ex)) 164 | logger.info("Retrying after 2 minutes") 165 | self.bid_advisor.on_demand_refresh_interval = 2 * SECONDS_PER_MINUTE 166 | finally: 167 | time.sleep(self.bid_advisor.on_demand_refresh_interval) 168 | 169 | class SpotInstancePriceUpdater(threading.Thread): 170 | """ 171 | This thread periodically updates the spot instance pricing. 172 | """ 173 | def __init__(self, bid_advisor): 174 | threading.Thread.__init__(self) 175 | assert bid_advisor, "BidAdvisor can't be None" 176 | self.bid_advisor = bid_advisor 177 | 178 | @retry(wait_exponential_multiplier=1000, stop_max_attempt_number=3) 179 | def ec2_get_spot_price_history(self): 180 | ec2 = self.bid_advisor.ec2 181 | hour_ago = datetime.now() - timedelta(hours=1) 182 | spot_price_info = [] 183 | next_token = '' 184 | while True: 185 | try: 186 | response = ec2.describe_spot_price_history( 187 | ProductDescriptions=['Linux/UNIX (Amazon VPC)'], 188 | StartTime=hour_ago, NextToken=next_token) 189 | if response is None: 190 | raise Exception("Failed to get spot-instance prices") 191 | spot_price_info += response['SpotPriceHistory'] 192 | if response['NextToken']: 193 | next_token = response['NextToken'] 194 | else: 195 | return spot_price_info 196 | except Exception as ex: 197 | raise Exception("Failed to get spot instance pricing info: " + str(ex)) 198 | 199 | def get_spot_price_info(self): 200 | """ Issues AWS apis to get spot instance prices. """ 201 | spot_price_info = self.ec2_get_spot_price_history() 202 | with self.bid_advisor.lock: 203 | self.bid_advisor.spot_price_list = spot_price_info 204 | logger.info("Spot instance pricing info updated") 205 | 206 | def run(self): 207 | """ Main method of the SpotInstancePriceUpdater thread. """ 208 | while self.bid_advisor.terminate_thread is False: 209 | try: 210 | self.get_spot_price_info() 211 | except Exception as ex: 212 | raise Exception("Error while getting spot-instance " + 213 | "price info: " + str(ex)) 214 | finally: 215 | time.sleep(self.bid_advisor.spot_refresh_interval) 216 | 217 | def run(self): 218 | """ Main method of the AWSBidAdvisor. """ 219 | if self.all_bid_advisor_threads: 220 | logger.debug("BidAdvisor already running!") 221 | return 222 | 223 | logger.info("Starting the BidAdvisor") 224 | 225 | # The on_demand_thread and spot_instance_thread are run in Daemon mode. 226 | # These threads will be run forever but shouldn't cause problems when 227 | # the minion-manager process is terminated. 228 | on_demand_thread = self.OnDemandUpdater(self) 229 | on_demand_thread.setDaemon(True) 230 | self.all_bid_advisor_threads.append(on_demand_thread) 231 | 232 | spot_instance_thread = self.SpotInstancePriceUpdater(self) 233 | spot_instance_thread.setDaemon(True) 234 | self.all_bid_advisor_threads.append(spot_instance_thread) 235 | 236 | on_demand_thread.start() 237 | spot_instance_thread.start() 238 | 239 | # Wait for the threads to get pricing information. 240 | while True: 241 | logger.info("Waiting for initial pricing information...") 242 | try: 243 | with self.lock: 244 | if self.on_demand_price_dict and self.spot_price_list: 245 | return 246 | finally: 247 | time.sleep(SECONDS_PER_MINUTE) 248 | 249 | def basic_bid_strategy(self, spot_price, on_demand_price, bid_options): 250 | """ 251 | Implements a very basic bid strategy. Checks if the spot instance price 252 | less than or equal to 80% of on-demand price. If so, selects the spot 253 | price. Otherwise chooses the on-demand price. 254 | 255 | If the spot instance price is closer to the on-demand price, on-demand 256 | instances are chosen for reliability reasons (on-demand instances won't 257 | be terminated with price hikes). 258 | 259 | TODO: BidStrategy should be it's own class. And basic_bid_strategy 260 | should be one implementation of that class. There could be other 261 | more interesting strategies too. 262 | 263 | :param spot_price: The price for spot-instances. 264 | :param on_demand_price: The price for on-demand instances. 265 | :param bid_options: Any options that the bidding strategy should need. 266 | :return bid_info: A dictionary with necessary bidding information. 267 | """ 268 | bid_info = {} 269 | threshold = bid_options["spot_to_on_demand_threshold"] 270 | 271 | if spot_price <= threshold * on_demand_price: 272 | bid_info["price"] = str(on_demand_price) 273 | bid_info["type"] = "spot" 274 | else: 275 | # On-demand nodes do not require price information. 276 | bid_info["price"] = "" 277 | bid_info["type"] = "on-demand" 278 | return bid_info 279 | 280 | def get_current_price(self): 281 | """ 282 | Returns the current price for on-demand and spot-instances. 283 | """ 284 | price_map = {} 285 | with self.lock: 286 | price_map["on-demand"] = self.on_demand_price_dict 287 | price_map["spot"] = self.spot_price_list 288 | return price_map 289 | 290 | def get_on_demand_price(self, instance_type): 291 | """ 292 | Returns the price for on-demand instances of the given type. 293 | """ 294 | if instance_type in self.on_demand_price_dict.keys(): 295 | return float(self.on_demand_price_dict[instance_type]) 296 | 297 | return None 298 | 299 | def get_spot_instance_price(self, instance_type, zone): 300 | """ 301 | Returns the spot-instance price for the given instance_type and zone. 302 | """ 303 | # The spot price list is sorted by time. Find the latest instance 304 | # for the zone and instance_type and use that as the spot price. 305 | for price_info in self.spot_price_list: 306 | if price_info["InstanceType"] == instance_type and \ 307 | price_info["AvailabilityZone"] == zone: 308 | return float(price_info["SpotPrice"]) 309 | return None 310 | 311 | def get_max_spot_prices_from_zones(self, instance_type, zones): 312 | max_spot_price = 0.0 313 | for zone in zones: 314 | tmp = self.get_spot_instance_price(instance_type, zone) 315 | if tmp > max_spot_price: 316 | max_spot_price = tmp 317 | 318 | return max_spot_price 319 | 320 | def get_new_bid(self, zones, instance_type): 321 | """ 322 | Compare the last known spot-instance and on-demand instance prices and 323 | return a dict with the best possible bid options. If the pricing info. 324 | hasn't been collected yet, the default is to use on-demand instances. 325 | 326 | If the input has multiple zones, consider the highest bid from among 327 | the gives zones. 328 | 329 | :param zones: The availability zones in which to check pricing. 330 | :param instance_type: The type of the EC2 instance. 331 | :return bid_info: A dictionary with necessary bidding information. 332 | """ 333 | 334 | with self.lock: 335 | if not self.on_demand_price_dict or not self.spot_price_list: 336 | logger.info("Pricing data not available! Using DEFAULT_BID") 337 | return DEFAULT_BID 338 | 339 | spot_price = self.get_max_spot_prices_from_zones(instance_type, zones) 340 | 341 | on_demand_price = self.get_on_demand_price(instance_type) 342 | 343 | if spot_price is None: 344 | logger.error("Spot price info not found. Using DEFAULT_BID") 345 | return DEFAULT_BID 346 | if on_demand_price is None: 347 | logger.error("On demand price info not found. " + 348 | "Using DEFAULT_BID") 349 | return DEFAULT_BID 350 | 351 | logger.info("Using spot_instance price %f, on-demand price %f " + 352 | "for instance type: %s, zones: %s", 353 | spot_price, on_demand_price, instance_type, zones) 354 | 355 | bid_options = {"spot_to_on_demand_threshold": 0.8} 356 | return self.basic_bid_strategy(spot_price, on_demand_price, 357 | bid_options) 358 | 359 | def shutdown(self): 360 | """ Sets the flag to terminate all threads. """ 361 | self.terminate_thread = True 362 | for thread in self.all_bid_advisor_threads: 363 | thread.join() 364 | 365 | del self.all_bid_advisor_threads[:] 366 | logger.info("BidAdvisor has left the building!") 367 | -------------------------------------------------------------------------------- /cloud_provider/aws/aws_bid_advisor_test.py: -------------------------------------------------------------------------------- 1 | """The file has unit tests for the AWSBidAdvisor.""" 2 | 3 | import unittest 4 | from mock import patch, MagicMock 5 | import datetime 6 | from dateutil.tz import tzutc 7 | from cloud_provider.aws.aws_bid_advisor import AWSBidAdvisor 8 | 9 | REFRESH_INTERVAL = 10 10 | REGION = 'us-west-2' 11 | MOCK_SPOT_PRICE={'NextToken': '', 'SpotPriceHistory': [{'AvailabilityZone': 'us-west-2b', 'InstanceType': 'm5.4xlarge', 'ProductDescription': 'Linux/UNIX', 'SpotPrice': '0.300000', 'Timestamp': datetime.datetime(2019, 7, 13, 20, 30, 22, tzinfo=tzutc())}, {'AvailabilityZone': 'us-west-2c', 'InstanceType': 'm5.4xlarge', 'ProductDescription': 'Linux/UNIX', 'SpotPrice': '0.291400', 'Timestamp': datetime.datetime(2019, 7, 13, 20, 13, 34, tzinfo=tzutc())}, {'AvailabilityZone': 'us-west-2a', 'InstanceType': 'm5.4xlarge', 'ProductDescription': 'Linux/UNIX', 'SpotPrice': '0.320100', 'Timestamp': datetime.datetime(2019, 7, 13, 18, 33, 30, tzinfo=tzutc())}, {'AvailabilityZone': 'us-west-2c', 'InstanceType': 'm3.medium', 'ProductDescription': 'Linux/UNIX', 'SpotPrice': '0.006700', 'Timestamp': datetime.datetime(2019, 7, 13, 17, 7, 9, tzinfo=tzutc())}, {'AvailabilityZone': 'us-west-2b', 'InstanceType': 'm3.medium', 'ProductDescription': 'Linux/UNIX', 'SpotPrice': '0.006700', 'Timestamp': datetime.datetime(2019, 7, 13, 17, 7, 9, tzinfo=tzutc())}, {'AvailabilityZone': 'us-west-2a', 'InstanceType': 'm3.medium', 'ProductDescription': 'Linux/UNIX', 'SpotPrice': '0.006700', 'Timestamp': datetime.datetime(2019, 7, 13, 17, 7, 9, tzinfo=tzutc())}, {'AvailabilityZone': 'us-west-2b', 'InstanceType': 'm5.4xlarge', 'ProductDescription': 'Linux/UNIX', 'SpotPrice': '0.300400', 'Timestamp': datetime.datetime(2019, 7, 13, 15, 46, 1, tzinfo=tzutc())}, {'AvailabilityZone': 'us-west-2c', 'InstanceType': 'm5.4xlarge', 'ProductDescription': 'Linux/UNIX', 'SpotPrice': '0.291500', 'Timestamp': datetime.datetime(2019, 7, 13, 14, 47, 14, tzinfo=tzutc())}, {'AvailabilityZone': 'us-west-2a', 'InstanceType': 'm5.4xlarge', 'ProductDescription': 'Linux/UNIX', 'SpotPrice': '0.321600', 'Timestamp': datetime.datetime(2019, 7, 13, 13, 40, 47, tzinfo=tzutc())}, {'AvailabilityZone': 'us-west-2d', 'InstanceType': 'm5.4xlarge', 'ProductDescription': 'Linux/UNIX', 'SpotPrice': '0.270400', 'Timestamp': datetime.datetime(2019, 7, 13, 6, 23, 5, tzinfo=tzutc())}, {'AvailabilityZone': 'us-west-2c', 'InstanceType': 'm3.medium', 'ProductDescription': 'Linux/UNIX', 'SpotPrice': '0.006700', 'Timestamp': datetime.datetime(2019, 7, 12, 17, 7, 5, tzinfo=tzutc())}, {'AvailabilityZone': 'us-west-2b', 'InstanceType': 'm3.medium', 'ProductDescription': 'Linux/UNIX', 'SpotPrice': '0.006700', 'Timestamp': datetime.datetime(2019, 7, 12, 17, 7, 5, tzinfo=tzutc())}, {'AvailabilityZone': 'us-west-2a', 'InstanceType': 'm3.medium', 'ProductDescription': 'Linux/UNIX', 'SpotPrice': '0.006700', 'Timestamp': datetime.datetime(2019, 7, 12, 17, 7, 5, tzinfo=tzutc())}], 'ResponseMetadata': {'RequestId': 'f428bcba-016f-476f-b9ed-755f71af2d36', 'HTTPStatusCode': 200, 'HTTPHeaders': {'content-type': 'text/xml;charset=UTF-8', 'content-length': '4341', 'vary': 'accept-encoding', 'date': 'Sun, 14 Jul 2019 00:45:52 GMT', 'server': 'AmazonEC2'}, 'RetryAttempts': 0}} 12 | 13 | 14 | class AWSBidAdvisorTest(unittest.TestCase): 15 | """ 16 | Tests for AWSBidAdvisor. 17 | """ 18 | @patch.object(AWSBidAdvisor.SpotInstancePriceUpdater, 'ec2_get_spot_price_history', MagicMock(return_value=MOCK_SPOT_PRICE)) 19 | def test_ba_lifecycle(self): 20 | """ 21 | Tests that the AWSBidVisor starts threads and stops them correctly. 22 | """ 23 | bidadv = AWSBidAdvisor(REFRESH_INTERVAL, REFRESH_INTERVAL, REGION) 24 | assert len(bidadv.all_bid_advisor_threads) == 0 25 | bidadv.run() 26 | assert len(bidadv.all_bid_advisor_threads) == 2 27 | bidadv.shutdown() 28 | assert len(bidadv.all_bid_advisor_threads) == 0 29 | 30 | def test_ba_on_demand_pricing(self): 31 | """ 32 | Tests that the AWSBidVisor correctly gets the on-demand pricing. 33 | """ 34 | bidadv = AWSBidAdvisor(REFRESH_INTERVAL, REFRESH_INTERVAL, REGION) 35 | assert len(bidadv.on_demand_price_dict) == 0 36 | updater = bidadv.OnDemandUpdater(bidadv) 37 | updater.get_on_demand_pricing() 38 | assert len(bidadv.on_demand_price_dict) > 0 39 | 40 | @patch.object(AWSBidAdvisor.SpotInstancePriceUpdater, 'ec2_get_spot_price_history', MagicMock(return_value=MOCK_SPOT_PRICE)) 41 | def test_ba_spot_pricing(self): 42 | """ 43 | Tests that the AWSBidVisor correctly gets the spot instance pricing. 44 | """ 45 | bidadv = AWSBidAdvisor(REFRESH_INTERVAL, REFRESH_INTERVAL, REGION) 46 | assert len(bidadv.spot_price_list) == 0 47 | updater = bidadv.SpotInstancePriceUpdater(bidadv) 48 | updater.get_spot_price_info() 49 | assert len(bidadv.spot_price_list) > 0 50 | 51 | @patch.object(AWSBidAdvisor.SpotInstancePriceUpdater, 'ec2_get_spot_price_history', MagicMock(return_value=MOCK_SPOT_PRICE)) 52 | def test_ba_price_update(self): 53 | """ 54 | Tests that the AXBidVisor actually updates the pricing info. 55 | """ 56 | bidadv = AWSBidAdvisor(REFRESH_INTERVAL, REFRESH_INTERVAL, REGION) 57 | od_updater = bidadv.OnDemandUpdater(bidadv) 58 | od_updater.get_on_demand_pricing() 59 | 60 | sp_updater = bidadv.SpotInstancePriceUpdater(bidadv) 61 | sp_updater.get_spot_price_info() 62 | 63 | # Verify that the pricing info was populated. 64 | assert len(bidadv.on_demand_price_dict) > 0 65 | assert len(bidadv.spot_price_list) > 0 66 | 67 | # Make the price dicts empty to check if they get updated. 68 | bidadv.on_demand_price_dict = {} 69 | bidadv.spot_price_list = {} 70 | 71 | od_updater.get_on_demand_pricing() 72 | sp_updater.get_spot_price_info() 73 | 74 | # Verify that the pricing info is populated again. 75 | assert len(bidadv.on_demand_price_dict) > 0 76 | assert len(bidadv.spot_price_list) > 0 77 | 78 | def test_ba_get_bid(self): 79 | """ 80 | Tests that the bid_advisor's get_new_bid() method returns correct 81 | bid information. 82 | """ 83 | bidadv = AWSBidAdvisor(REFRESH_INTERVAL, REFRESH_INTERVAL, REGION) 84 | 85 | instance_type = "m3.large" 86 | zones = ["us-west-2b"] 87 | # Manually populate the prices so that spot-instance prices are chosen. 88 | bidadv.on_demand_price_dict["m3.large"] = "100" 89 | bidadv.spot_price_list = [{'InstanceType': instance_type, 90 | 'SpotPrice': '80', 91 | 'AvailabilityZone': "us-west-2b"}] 92 | bid_info = bidadv.get_new_bid(zones, instance_type) 93 | assert bid_info is not None, "BidAdvisor didn't return any " + \ 94 | "now bid information." 95 | assert bid_info["type"] == "spot" 96 | assert isinstance(bid_info["price"], str) 97 | 98 | # Manually populate the prices so that on-demand instances are chosen. 99 | bidadv.spot_price_list = [{'InstanceType': instance_type, 100 | 'SpotPrice': '85', 101 | 'AvailabilityZone': "us-west-2b"}] 102 | bid_info = bidadv.get_new_bid(zones, instance_type) 103 | assert bid_info is not None, "BidAdvisor didn't return any now " + \ 104 | "bid information." 105 | assert bid_info["type"] == "on-demand" 106 | 107 | def test_ba_get_bid_no_data(self): 108 | """ 109 | Tests that the BidAdvisor returns the default if the pricing 110 | information hasn't be obtained yet. 111 | """ 112 | bidadv = AWSBidAdvisor(REFRESH_INTERVAL, REFRESH_INTERVAL, REGION) 113 | bid_info = bidadv.get_new_bid(['us-west-2a'], 'm3.large') 114 | assert bid_info["type"] == "on-demand" 115 | 116 | @patch.object(AWSBidAdvisor.SpotInstancePriceUpdater, 'ec2_get_spot_price_history', MagicMock(return_value=MOCK_SPOT_PRICE)) 117 | def test_ba_get_current_price(self): 118 | """ 119 | Tests that the BidAdvisor returns the most recent price information. 120 | """ 121 | bidadv = AWSBidAdvisor(REFRESH_INTERVAL, REFRESH_INTERVAL, REGION) 122 | 123 | od_updater = bidadv.OnDemandUpdater(bidadv) 124 | od_updater.get_on_demand_pricing() 125 | 126 | sp_updater = bidadv.SpotInstancePriceUpdater(bidadv) 127 | sp_updater.get_spot_price_info() 128 | 129 | # Verify that the pricing info was populated. 130 | assert len(bidadv.on_demand_price_dict) > 0 131 | assert len(bidadv.spot_price_list) > 0 132 | 133 | price_info_map = bidadv.get_current_price() 134 | assert price_info_map["spot"] is not None 135 | assert price_info_map["on-demand"] is not None 136 | 137 | def test_ba_parse_row(self): 138 | """ 139 | Tests that the BidAdvisor parses the rows in on-demand price information. 140 | """ 141 | bidadv = AWSBidAdvisor(REFRESH_INTERVAL, REFRESH_INTERVAL, REGION) 142 | 143 | od_updater = bidadv.OnDemandUpdater(bidadv) 144 | row = {} 145 | row['RateCode'] = "JRTCKXETXF.6YS6EN2CT7" 146 | row["TermType"] = "OnDemand" 147 | row["PriceDescription"] = "On Demand Linux" 148 | row["Location"] = "US West (Oregon)" 149 | row["Operating System"] = "Linux" 150 | row["Pre Installed S/W"] = "NA" 151 | row["Tenancy"] = "Shared" 152 | row["PricePerUnit"] = "0.453" 153 | row["Instance Type"] = "m5.4xlarge" 154 | 155 | od_updater.parse_price_row(row) 156 | assert od_updater.bid_advisor.on_demand_price_dict['m5.4xlarge'] == "0.453" 157 | 158 | od_updater.parse_price_row(row) 159 | assert od_updater.bid_advisor.on_demand_price_dict['m5.4xlarge'] == "0.453" 160 | 161 | row["PricePerUnit"] = "0.658" 162 | od_updater.parse_price_row(row) 163 | assert od_updater.bid_advisor.on_demand_price_dict['m5.4xlarge'] == "0.658" 164 | 165 | row["PricePerUnit"] = "0.00" 166 | od_updater.parse_price_row(row) 167 | assert od_updater.bid_advisor.on_demand_price_dict['m5.4xlarge'] == "0.658" 168 | 169 | row['RateCode'] = "Some Random RateCode" 170 | od_updater.parse_price_row(row) 171 | -------------------------------------------------------------------------------- /cloud_provider/aws/aws_minion_manager.py: -------------------------------------------------------------------------------- 1 | """Minion Manager implementation for AWS.""" 2 | 3 | import logging 4 | import re 5 | import sys 6 | import os 7 | import time 8 | import base64 9 | from datetime import datetime 10 | from threading import Timer, Semaphore 11 | import boto3 12 | from botocore.exceptions import ClientError 13 | from retrying import retry 14 | from bunch import bunchify 15 | import pytz 16 | import shlex 17 | import subprocess 18 | from constants import SECONDS_PER_MINUTE, SECONDS_PER_HOUR 19 | from cloud_provider.aws.aws_bid_advisor import AWSBidAdvisor 20 | from cloud_provider.aws.price_info_reporter import AWSPriceReporter 21 | from kubernetes import client, config 22 | from kubernetes.client.rest import ApiException 23 | from ..base import MinionManagerBase 24 | from .asg_mm import AWSAutoscalinGroupMM, MINION_MANAGER_LABEL 25 | 26 | logger = logging.getLogger("aws_minion_manager") 27 | logging.basicConfig(format="%(asctime)s %(levelname)s %(name)s " + 28 | "%(threadName)s: %(message)s", 29 | datefmt="%Y-%m-%dT%H:%M:%S", 30 | stream=sys.stdout, level=logging.INFO) 31 | logging.getLogger('boto3').setLevel(logging.WARNING) 32 | logging.getLogger('botocore').setLevel(logging.WARNING) 33 | 34 | 35 | class AWSMinionManager(MinionManagerBase): 36 | """ 37 | This class implements the minion-manager functionality for AWS. 38 | """ 39 | 40 | def __init__(self, cluster_name, region, refresh_interval_seconds=300, **kwargs): 41 | super(AWSMinionManager, self).__init__(region) 42 | self._cluster_name = cluster_name 43 | aws_profile = kwargs.get("aws_profile", None) 44 | if aws_profile: 45 | boto_session = boto3.Session(region_name=region, 46 | profile_name=aws_profile) 47 | else: 48 | boto_session = boto3.Session(region_name=region) 49 | 50 | self.incluster = kwargs.get("incluster", True) 51 | self._ac_client = boto_session.client('autoscaling') 52 | self._ec2_client = boto_session.client('ec2') 53 | self._events_only = kwargs.get("events_only", False) 54 | 55 | self._refresh_interval_seconds = refresh_interval_seconds 56 | self._asg_metas = [] 57 | self.instance_type = None 58 | # Setting default termination to one instance at a time 59 | self.terminate_percentage = 1 60 | 61 | self.on_demand_kill_threads = {} 62 | self.minions_ready_checker_thread = None 63 | 64 | self.bid_advisor = AWSBidAdvisor( 65 | on_demand_refresh_interval=4 * SECONDS_PER_HOUR, 66 | spot_refresh_interval=15 * SECONDS_PER_MINUTE, region=region) 67 | 68 | self.price_reporter = AWSPriceReporter( 69 | self._ec2_client, self.bid_advisor, self._asg_metas) 70 | 71 | @staticmethod 72 | @retry(wait_exponential_multiplier=1000, stop_max_attempt_number=3) 73 | def describe_asg_with_retries(ac_client, asgs=[]): 74 | """ 75 | AWS describe_auto_scaling_groups with retries. 76 | """ 77 | response = ac_client.describe_auto_scaling_groups( 78 | AutoScalingGroupNames=asgs) 79 | return bunchify(response) 80 | 81 | @staticmethod 82 | @retry(wait_exponential_multiplier=1000, stop_max_attempt_number=3) 83 | def describe_asg_activities_with_retries(ac_client, asg): 84 | """ 85 | AWS describe_auto_scaling_groups with retries. 86 | """ 87 | response = ac_client.describe_scaling_activities( 88 | AutoScalingGroupName=asg) 89 | return bunchify(response) 90 | 91 | @staticmethod 92 | @retry(wait_exponential_multiplier=1000, stop_max_attempt_number=3) 93 | def get_instances_with_retries(ec2_client, instance_ids): 94 | """ 95 | AWS describe_instances with retries. 96 | """ 97 | response = ec2_client.describe_instances( 98 | InstanceIds=instance_ids) 99 | return bunchify(response) 100 | 101 | @staticmethod 102 | @retry(wait_exponential_multiplier=1000, stop_max_attempt_number=3) 103 | def get_asgs_with_tags(cluster_name, ac_client): 104 | """ 105 | Get AWS describe_auto_scaling_groups with k8s-minion-manager tags. 106 | """ 107 | response = {} 108 | response["AutoScalingGroups"] = [] 109 | resp = ac_client.describe_auto_scaling_groups(MaxRecords=100) 110 | for r in resp["AutoScalingGroups"]: 111 | is_candidate = False 112 | # skipping if ASG is using LaunchTemplate as it is not supported 113 | if not r.get("LaunchConfigurationName"): 114 | logger.warn("Skipping: asg %s is using LaunchTemplate", r.get("AutoScalingGroupName")) 115 | continue 116 | # Scan for KubernetesCluster name. If the value matches the cluster_name 117 | # provided in the input, set 'is_candidate'. 118 | for tag in r['Tags']: 119 | if tag['Key'] == 'KubernetesCluster' and tag['Value'] == cluster_name: 120 | is_candidate = True 121 | if not is_candidate: 122 | continue 123 | for tag in r['Tags']: 124 | if tag['Key'] == MINION_MANAGER_LABEL: 125 | response["AutoScalingGroups"].append(r) 126 | break 127 | return bunchify(response) 128 | 129 | @staticmethod 130 | @retry(wait_exponential_multiplier=1000, stop_max_attempt_number=3) 131 | def describe_spot_request_with_retries(ec2_client, request_ids): 132 | response = ec2_client.describe_spot_instance_requests( 133 | SpotInstanceRequestIds=request_ids) 134 | return bunchify(response) 135 | 136 | def discover_asgs(self): 137 | """ Query AWS and get metadata about all required ASGs. """ 138 | response = AWSMinionManager.get_asgs_with_tags(self._cluster_name, self._ac_client) 139 | for asg in response.AutoScalingGroups: 140 | asg_mm = AWSAutoscalinGroupMM() 141 | asg_mm.set_asg_info(asg) 142 | self._asg_metas.append(asg_mm) 143 | logger.info("Adding asg %s (%s). Can manager terminate instance: %s", asg_mm.get_name(), 144 | asg_mm.get_mm_tag(), "no " if asg_mm.not_terminate_instance() else "yes") 145 | 146 | def populate_current_config(self): 147 | """ 148 | Queries AWS to get current bid_price for all ASGs and stores it 149 | in AWSAutoscalinGroupMM. 150 | """ 151 | @retry(wait_exponential_multiplier=1000, stop_max_attempt_number=3) 152 | def _describe_launch_configuration(): 153 | response = self._ac_client.describe_launch_configurations( 154 | LaunchConfigurationNames=[asg.LaunchConfigurationName]) 155 | assert len(response["LaunchConfigurations"]) == 1 156 | return bunchify(response).LaunchConfigurations[0] 157 | 158 | for asg_meta in self._asg_metas: 159 | asg = asg_meta.asg_info 160 | 161 | # Get current launch configuration. 162 | launch_config = _describe_launch_configuration() 163 | asg_meta.set_lc_info(launch_config) 164 | bid_info = {} 165 | if "SpotPrice" in launch_config.keys(): 166 | bid_info["type"] = "spot" 167 | bid_info["price"] = launch_config.SpotPrice 168 | else: 169 | bid_info["type"] = "on-demand" 170 | asg_meta.set_bid_info(bid_info) 171 | logger.info("ASG %s using launch-config %s with bid-info %s", 172 | asg.AutoScalingGroupName, 173 | launch_config.LaunchConfigurationName, bid_info) 174 | 175 | def log_k8s_event(self, asg_name, price="", useSpot=False): 176 | msg_str = '{"apiVersion":"v1alpha1","spotPrice":"' + price + '", "useSpot": ' + str(useSpot).lower() + '}' 177 | event_namespace = os.getenv('EVENT_NAMESPACE', 'default') 178 | if not self.incluster: 179 | logger.info(msg_str) 180 | return 181 | 182 | try: 183 | config.load_incluster_config() 184 | v1 = client.CoreV1Api() 185 | event_timestamp = datetime.now(pytz.utc) 186 | event_name = "spot-instance-update" 187 | new_event = client.V1Event( 188 | count=1, 189 | first_timestamp=event_timestamp, 190 | involved_object=client.V1ObjectReference( 191 | kind="SpotPriceInfo", 192 | name=asg_name, 193 | namespace=event_namespace, 194 | ), 195 | last_timestamp=event_timestamp, 196 | metadata=client.V1ObjectMeta( 197 | generate_name=event_name, 198 | ), 199 | message=msg_str, 200 | reason="SpotRecommendationGiven", 201 | source=client.V1EventSource( 202 | component="minion-manager", 203 | ), 204 | type="Normal", 205 | ) 206 | 207 | v1.create_namespaced_event(namespace=event_namespace, body=new_event) 208 | logger.info("Spot price info event logged") 209 | except Exception as e: 210 | logger.info("Failed to log event: " + str(e)) 211 | 212 | def get_new_bid_info(self, asg_meta): 213 | """ get new bid price. """ 214 | new_bid_info = self.bid_advisor.get_new_bid( 215 | zones=asg_meta.asg_info.AvailabilityZones, 216 | instance_type=asg_meta.lc_info.InstanceType) 217 | return new_bid_info 218 | 219 | def update_needed(self, asg_meta): 220 | """ Checks if an ASG needs to be updated. """ 221 | try: 222 | asg_tag = asg_meta.get_mm_tag() 223 | bid_info = asg_meta.get_bid_info() 224 | current_price = self.get_new_bid_info(asg_meta).get("price") or "" 225 | 226 | if asg_tag == "no-spot": 227 | if bid_info["type"] == "spot": 228 | logger.info("ASG %s configured with on-demand but currently using spot. Update needed", asg_meta.get_name()) 229 | # '{"apiVersion":"v1alpha1","spotPrice":bid_info["price"], "useSpot": False}' 230 | self.log_k8s_event(asg_meta.get_name(), current_price, False) 231 | return True 232 | elif bid_info["type"] == "on-demand": 233 | logger.info("ASG %s configured with on-demand and currently using on-demand. No update needed", asg_meta.get_name()) 234 | # '{"apiVersion":"v1alpha1","spotPrice":"", "useSpot": False}' 235 | self.log_k8s_event(asg_meta.get_name(), "", False) 236 | return False 237 | 238 | # The asg_tag is "spot". 239 | if bid_info["type"] == "on-demand": 240 | logger.info("ASG %s configured with spot but currently using on-demand. Update needed", asg_meta.get_name()) 241 | # '{"apiVersion":"v1alpha1","spotPrice":"", "useSpot": true}' 242 | self.log_k8s_event(asg_meta.get_name(), current_price, True) 243 | return True 244 | else: 245 | # Continue to use spot 246 | self.log_k8s_event(asg_meta.get_name(), current_price, True) 247 | assert bid_info["type"] == "spot" 248 | if self.check_scaling_group_instances(asg_meta): 249 | # Desired # of instances running. No updates needed. 250 | logger.info("Desired number of instances running in ASG %s. No update needed", asg_meta.get_name()) 251 | return False 252 | else: 253 | # Desired # of instances are not running. 254 | logger.info("Desired number of instance not running in ASG %s. Update needed", asg_meta.get_name()) 255 | return True 256 | except Exception as ex: 257 | logger.error("Failed while checking minions in %s: %s", 258 | asg_meta.get_name(), str(ex)) 259 | return False 260 | 261 | def are_bids_equal(self, cur_bid_info, new_bid_info): 262 | """ 263 | Returns True if the new bid_info is the same as the current one. 264 | False otherwise. 265 | """ 266 | if cur_bid_info["type"] != new_bid_info["type"]: 267 | return False 268 | # If you're here, it means that the bid types are equal. 269 | if cur_bid_info["type"] == "on-demand": 270 | return True 271 | 272 | if cur_bid_info["price"] == new_bid_info["price"]: 273 | return True 274 | 275 | return False 276 | 277 | @retry(wait_exponential_multiplier=1000, stop_max_attempt_number=3) 278 | def create_lc_with_spot(self, new_lc_name, launch_config, spot_price): 279 | """ Creates a launch-config for using spot-instances. """ 280 | try: 281 | if hasattr(launch_config, "AssociatePublicIpAddress"): 282 | response = self._ac_client.create_launch_configuration( 283 | LaunchConfigurationName=new_lc_name, 284 | ImageId=launch_config.ImageId, 285 | KeyName=launch_config.KeyName, 286 | SecurityGroups=launch_config.SecurityGroups, 287 | ClassicLinkVPCSecurityGroups=launch_config. 288 | ClassicLinkVPCSecurityGroups, 289 | UserData=base64.b64decode(launch_config.UserData), 290 | InstanceType=launch_config.InstanceType, 291 | BlockDeviceMappings=launch_config.BlockDeviceMappings, 292 | InstanceMonitoring=launch_config.InstanceMonitoring, 293 | SpotPrice=spot_price, 294 | IamInstanceProfile=launch_config.IamInstanceProfile, 295 | EbsOptimized=launch_config.EbsOptimized, 296 | AssociatePublicIpAddress=launch_config. 297 | AssociatePublicIpAddress) 298 | else: 299 | response = self._ac_client.create_launch_configuration( 300 | LaunchConfigurationName=new_lc_name, 301 | ImageId=launch_config.ImageId, 302 | KeyName=launch_config.KeyName, 303 | SecurityGroups=launch_config.SecurityGroups, 304 | ClassicLinkVPCSecurityGroups=launch_config. 305 | ClassicLinkVPCSecurityGroups, 306 | UserData=base64.b64decode(launch_config.UserData), 307 | InstanceType=launch_config.InstanceType, 308 | BlockDeviceMappings=launch_config.BlockDeviceMappings, 309 | InstanceMonitoring=launch_config.InstanceMonitoring, 310 | SpotPrice=spot_price, 311 | IamInstanceProfile=launch_config.IamInstanceProfile, 312 | EbsOptimized=launch_config.EbsOptimized) 313 | assert response is not None, \ 314 | "Failed to create launch-config {}".format(new_lc_name) 315 | assert response["HTTPStatusCode"] == 200, \ 316 | "Failed to create launch-config {}".format(new_lc_name) 317 | logger.info("Created LaunchConfig for spot instances: %s", 318 | new_lc_name) 319 | except ClientError as ce: 320 | if "AlreadyExists" in str(ce): 321 | logger.info("LaunchConfig %s already exists. Reusing it.", 322 | new_lc_name) 323 | return 324 | raise ce 325 | 326 | @retry(wait_exponential_multiplier=1000, stop_max_attempt_number=3) 327 | def create_lc_on_demand(self, new_lc_name, launch_config): 328 | """ Creates a launch-config for using on-demand instances. """ 329 | try: 330 | if hasattr(launch_config, "AssociatePublicIpAddress"): 331 | response = self._ac_client.create_launch_configuration( 332 | LaunchConfigurationName=new_lc_name, 333 | ImageId=launch_config.ImageId, 334 | KeyName=launch_config.KeyName, 335 | SecurityGroups=launch_config.SecurityGroups, 336 | ClassicLinkVPCSecurityGroups=launch_config. 337 | ClassicLinkVPCSecurityGroups, 338 | UserData=base64.b64decode(launch_config.UserData), 339 | InstanceType=launch_config.InstanceType, 340 | BlockDeviceMappings=launch_config.BlockDeviceMappings, 341 | InstanceMonitoring=launch_config.InstanceMonitoring, 342 | IamInstanceProfile=launch_config.IamInstanceProfile, 343 | EbsOptimized=launch_config.EbsOptimized, 344 | AssociatePublicIpAddress=launch_config. 345 | AssociatePublicIpAddress) 346 | else: 347 | response = self._ac_client.create_launch_configuration( 348 | LaunchConfigurationName=new_lc_name, 349 | ImageId=launch_config.ImageId, 350 | KeyName=launch_config.KeyName, 351 | SecurityGroups=launch_config.SecurityGroups, 352 | ClassicLinkVPCSecurityGroups=launch_config. 353 | ClassicLinkVPCSecurityGroups, 354 | UserData=base64.b64decode(launch_config.UserData), 355 | InstanceType=launch_config.InstanceType, 356 | BlockDeviceMappings=launch_config.BlockDeviceMappings, 357 | InstanceMonitoring=launch_config.InstanceMonitoring, 358 | IamInstanceProfile=launch_config.IamInstanceProfile, 359 | EbsOptimized=launch_config.EbsOptimized) 360 | assert response is not None, \ 361 | "Failed to create launch-config {}".format(new_lc_name) 362 | assert response["HTTPStatusCode"] == 200, \ 363 | "Failed to create launch-config {}".format(new_lc_name) 364 | logger.info("Created LaunchConfig for on-demand instances: %s", 365 | new_lc_name) 366 | except ClientError as ce: 367 | if "AlreadyExists" in str(ce): 368 | logger.info("LaunchConfig %s already exists. Reusing it.", 369 | new_lc_name) 370 | return 371 | raise ce 372 | 373 | def update_scaling_group(self, asg_meta, new_bid_info): 374 | """ 375 | Updates the AWS AutoScalingGroup. Makes the next_bid_info as the new 376 | bid_info. 377 | """ 378 | if self._events_only: 379 | logger.info("Minion-manager configured for only generating events. No changes to launch config will be made.") 380 | return 381 | 382 | logger.info("Updating ASG: %s, Bid: %s", asg_meta.get_name(), 383 | new_bid_info) 384 | launch_config = asg_meta.get_lc_info() 385 | 386 | orig_launch_config_name = launch_config.LaunchConfigurationName 387 | assert new_bid_info.get("type", None) is not None, \ 388 | "Bid info has no bid type" 389 | if new_bid_info["type"] == "spot": 390 | spot_price = new_bid_info["price"] 391 | else: 392 | spot_price = None 393 | logger.info("ASG(%s): New bid price %s", asg_meta.get_name(), 394 | spot_price) 395 | 396 | if launch_config.LaunchConfigurationName[-2:] == "-0": 397 | new_lc_name = launch_config.LaunchConfigurationName[:-2] 398 | else: 399 | new_lc_name = launch_config.LaunchConfigurationName + "-0" 400 | logger.info("ASG(%s): New launch-config name: %s", 401 | asg_meta.get_name(), new_lc_name) 402 | 403 | if spot_price is None: 404 | self.create_lc_on_demand(new_lc_name, launch_config) 405 | else: 406 | self.create_lc_with_spot(new_lc_name, launch_config, spot_price) 407 | 408 | @retry(wait_exponential_multiplier=1000, stop_max_attempt_number=3) 409 | def _update_asg_in_aws(asg_name, launch_config_name): 410 | self._ac_client.update_auto_scaling_group( 411 | AutoScalingGroupName=asg_name, 412 | LaunchConfigurationName=launch_config_name) 413 | logger.info("Updated ASG %s with new LaunchConfig: %s", 414 | asg_name, launch_config_name) 415 | 416 | _update_asg_in_aws(asg_meta.get_name(), new_lc_name) 417 | 418 | @retry(wait_exponential_multiplier=1000, stop_max_attempt_number=3) 419 | def _delete_launch_config(lc_name): 420 | self._ac_client.delete_launch_configuration( 421 | LaunchConfigurationName=lc_name) 422 | logger.info("Deleted launch-configuration %s", lc_name) 423 | 424 | _delete_launch_config(orig_launch_config_name) 425 | 426 | # Update asg_meta. 427 | launch_config.LaunchConfigurationName = new_lc_name 428 | if spot_price is None: 429 | launch_config.pop('SpotPrice', None) 430 | else: 431 | launch_config['SpotPrice'] = spot_price 432 | asg_meta.set_lc_info(launch_config) 433 | asg_meta.set_bid_info(new_bid_info) 434 | 435 | logger.info("Updated ASG %s, new launch-config %s, bid-info %s", 436 | asg_meta.get_name(), launch_config.LaunchConfigurationName, 437 | new_bid_info) 438 | return 439 | 440 | def wait_for_all_running(self, asg_meta): 441 | """ 442 | Wating for all instances in ASG to be running state. 443 | """ 444 | asg_name = asg_meta.get_name() 445 | all_done = False 446 | while not all_done: 447 | resp = self._ac_client.describe_auto_scaling_groups( 448 | AutoScalingGroupNames=[asg_name]) 449 | desired_instances = resp["AutoScalingGroups"][0]["DesiredCapacity"] 450 | running_instances = 0 451 | for i in resp["AutoScalingGroups"][0]["Instances"]: 452 | if i["HealthStatus"] == "Healthy": 453 | running_instances += 1 454 | 455 | if running_instances == desired_instances: 456 | logger.info("ASG %s has all running instances", asg_name) 457 | all_done = True 458 | else: 459 | logger.info("Desired %s, Running %s", 460 | desired_instances, running_instances) 461 | all_done = False 462 | time.sleep(60) 463 | 464 | def get_name_for_instance(self, instance): 465 | config.load_incluster_config() 466 | v1 = client.CoreV1Api() 467 | for item in v1.list_node().items: 468 | if instance.InstanceId in item.spec.provider_id: 469 | logger.info("Instance name for %s in Kubernetes clusters is %s", 470 | instance.InstanceId, item.metadata.name) 471 | return item.metadata.name 472 | return None 473 | 474 | def cordon_node(self, instance): 475 | """" Runs 'kubectl drain' to actually drain the node.""" 476 | instance_name = self.get_name_for_instance(instance) 477 | if instance_name: 478 | try: 479 | cmd = "kubectl drain " + instance_name + " --ignore-daemonsets=true --delete-local-data=true --force --grace-period=-1" 480 | subprocess.check_call(shlex.split(cmd)) 481 | logger.info("Drained instance %s", instance_name) 482 | except Exception as ex: 483 | logger.info("Failed to drain node: " + str(ex) + ". Will try to uncordon") 484 | cmd = "kubectl uncordon " + instance_name 485 | subprocess.check_call(shlex.split(cmd)) 486 | logger.info("Uncordoned node " + instance_name) 487 | else: 488 | logger.info("Instance %s not found in Kubernetes cluster. Will not drain the instance.", 489 | instance.InstanceId) 490 | return True 491 | 492 | @retry(wait_exponential_multiplier=1000, stop_max_attempt_number=3) 493 | def run_or_die(self, instance, asg_meta, asg_semaphore): 494 | """ Terminates the given instance. """ 495 | zones = asg_meta.asg_info.AvailabilityZones 496 | bid_info = self.bid_advisor.get_new_bid(zones, instance.InstanceType) 497 | is_spot_instance = 'InstanceLifecycle' in instance 498 | is_on_demand_instance = not is_spot_instance 499 | with asg_semaphore: 500 | try: 501 | # If the instance is spot and the ASG is spot: don't kill the instance. 502 | if asg_meta.get_mm_tag() == "use-spot" and is_spot_instance: 503 | logger.info("Instance %s (%s) is spot and ASG %s is spot. Ignoring termination.", 504 | asg_meta.get_instance_name(instance), instance.InstanceId, asg_meta.get_name()) 505 | return False 506 | 507 | # If the instance is on-demand and the ASG is on-demand: don't kill the instance. 508 | if asg_meta.get_mm_tag() == "no-spot" and is_on_demand_instance: 509 | logger.info("Instance %s (%s) is on-demand and ASG %s is on-demand. Ignoring termination.", 510 | asg_meta.get_instance_name(instance), instance.InstanceId, asg_meta.get_name()) 511 | return False 512 | 513 | # If the instance is on-demand and ASG is spot; check if the bid recommendation. If the bid_recommendation is spot, terminate the instance. 514 | if asg_meta.get_mm_tag() == "use-spot" and is_on_demand_instance: 515 | if bid_info["type"] == "on-demand": 516 | logger.info("Instance %s (%s) is on-demand and ASG %s is spot. However, current recommendation is to use on-demand instances. Ignoring termination.", 517 | asg_meta.get_instance_name(instance), instance.InstanceId, asg_meta.get_name()) 518 | return False 519 | 520 | # Cordon and drain the node first 521 | self.cordon_node(instance) 522 | 523 | # Terminate EC2 uisng autoscaling client 524 | self._ac_client.terminate_instance_in_auto_scaling_group(InstanceId=instance.InstanceId, 525 | ShouldDecrementDesiredCapacity=False) 526 | logger.info("Terminated instance %s", instance.InstanceId) 527 | asg_meta.remove_instance(instance.InstanceId) 528 | logger.info("Removed instance %s from ASG %s", instance.InstanceId, asg_meta.get_name()) 529 | logger.info("Sleeping 180s before checking ASG") 530 | time.sleep(180) 531 | self.wait_for_all_running(asg_meta) 532 | return True 533 | except Exception as ex: 534 | logger.error("Failed in run_or_die: %s", str(ex)) 535 | finally: 536 | self.on_demand_kill_threads.pop(instance.InstanceId, None) 537 | 538 | def set_semaphore(self, asg_meta): 539 | """ 540 | Update no of instances can be terminated based on percentage. 541 | """ 542 | asg_name = asg_meta.get_name() 543 | asg_semaphore = 'semaphore' + asg_name 544 | resp = self._ac_client.describe_auto_scaling_groups(AutoScalingGroupNames=[asg_name]) 545 | desired_instances = resp["AutoScalingGroups"][0]["DesiredCapacity"] 546 | if self.terminate_percentage > 100: 547 | self.terminate_percentage = 100 548 | elif self.terminate_percentage <= 0: 549 | self.terminate_percentage = 1 550 | # Get no of instance can parallel be rotated 551 | svalue = int(round(desired_instances * (self.terminate_percentage/100.0))) 552 | if svalue == 0: 553 | svalue = 1 554 | logger.info("Maximum %d instance will be rotated at a time for ASG %s", svalue, asg_name) 555 | asg_semaphore = Semaphore(value=svalue) 556 | return asg_semaphore 557 | 558 | def schedule_instance_termination(self, asg_meta): 559 | """ 560 | Checks whether any of the instances in the asg need to be terminated. 561 | """ 562 | instances = asg_meta.get_instances() 563 | if len(instances) == 0: 564 | return 565 | 566 | # Check if ASG set not to terminate instance 567 | if asg_meta.not_terminate_instance(): 568 | return 569 | 570 | # Check if the minion-manager is only configured to log events. 571 | if self._events_only: 572 | logger.info("Minion-manager configured for only generating events. No instances will be terminated.") 573 | return 574 | 575 | # If the ASG is configured to use "no-spot" or the required tag does not exist, 576 | # do not schedule any instance termination. 577 | asg_tag = asg_meta.get_mm_tag() 578 | 579 | # Setting Semaphore per ASG base on instance count and terminate_percentage 580 | asg_semaphore = self.set_semaphore(asg_meta) 581 | 582 | for instance in instances: 583 | # On-demand instances don't have the InstanceLifecycle field in 584 | # their responses. Spot instances have InstanceLifecycle=spot. 585 | 586 | # If the instance type and the ASG tag match, do not terminate the instance. 587 | is_spot = 'InstanceLifecycle' in instance 588 | if is_spot and asg_tag == "use-spot": 589 | logger.debug("Instance %s is spot and ASG %s is configured for spot. Ignoring termination request", instance.InstanceId, asg_meta.get_name()) 590 | continue 591 | 592 | if asg_tag == "no-spot" and not is_spot: 593 | logger.debug("Instance %s is on-demand and ASG %s is configured for on-demand. Ignoring termination request", instance.InstanceId, asg_meta.get_name()) 594 | continue 595 | 596 | if not asg_meta.is_instance_running(instance): 597 | logger.debug("Instance %s not running. Ignoring termination request", instance.InstanceId) 598 | continue 599 | 600 | launch_time = instance.LaunchTime 601 | current_time = datetime.utcnow().replace(tzinfo=pytz.utc) 602 | elapsed_seconds = (current_time - launch_time). \ 603 | total_seconds() 604 | 605 | # If the instance is running for hours, only the seconds in 606 | # the current hour need to be used. 607 | # elapsed_seconds_in_hour = elapsed_seconds % \ 608 | # SECONDS_PER_HOUR 609 | # Start a thread that will check whether the instance 610 | # should continue running ~40 minutes later. 611 | 612 | # Earlier, the instances were terminated at approx. the boundary of 1 hour since 613 | # EC2 prices were for every hour. However, it has changed now and pricing is 614 | # per minute. 615 | # seconds_before_check = abs((40.0 + randint(0, 19)) * 616 | # SECONDS_PER_MINUTE - 617 | # elapsed_seconds_in_hour) 618 | # TODO: Make this time configurable! 619 | seconds_before_check = 10 620 | instance_id = instance.InstanceId 621 | if instance_id in self.on_demand_kill_threads.keys(): 622 | continue 623 | 624 | logger.info("Scheduling termination thread for %s (%s) in ASG %s (%s) after %s seconds", 625 | asg_meta.get_instance_name(instance), instance_id, asg_meta.get_name(), asg_tag, seconds_before_check) 626 | args = [instance, asg_meta, asg_semaphore] 627 | timed_thread = Timer(seconds_before_check, self.run_or_die, 628 | args=args) 629 | timed_thread.setDaemon(True) 630 | timed_thread.start() 631 | self.on_demand_kill_threads[instance_id] = timed_thread 632 | return 633 | 634 | def populate_instances(self, asg_meta): 635 | """ Populates info about all instances running in the given ASG. """ 636 | response = AWSMinionManager.describe_asg_with_retries( 637 | self._ac_client, [asg_meta.get_name()]) 638 | instance_ids = [] 639 | asg = response.AutoScalingGroups[0] 640 | for instance in asg.Instances: 641 | instance_ids.append(instance.InstanceId) 642 | 643 | if len(instance_ids) <= 0: 644 | return 645 | 646 | response = self.get_instances_with_retries(self._ec2_client, instance_ids) 647 | running_instances = [] 648 | for resv in response.Reservations: 649 | for instance in resv.Instances: 650 | if asg_meta.is_instance_running(instance): 651 | running_instances.append(instance) 652 | asg_meta.add_instances(running_instances) 653 | 654 | def minion_manager_work(self): 655 | """ The main work for dealing with spot-instances happens here. """ 656 | logger.info("Running minion-manager...") 657 | if self._events_only: 658 | logger.info("Only logging events\n") 659 | while True: 660 | try: 661 | # Iterate over all asgs and update them if needed. 662 | for asg_meta in self._asg_metas: 663 | # Populate info. about all instances in the ASG 664 | self.populate_instances(asg_meta) 665 | 666 | # Check if any of these are instances that need to be terminated. 667 | self.schedule_instance_termination(asg_meta) 668 | 669 | if not self.update_needed(asg_meta): 670 | continue 671 | 672 | # Some update is needed. This can mean: 673 | # 1. The desired # of instances are not running 674 | # 2. The ASG tag and the type of running instances do not match. 675 | # 3. 676 | bid_info = asg_meta.get_bid_info() 677 | if asg_meta.get_mm_tag() == "no-spot" and bid_info["type"] == "spot": 678 | new_bid_info = self.create_on_demand_bid_info() 679 | logger.info("ASG %s configured with no-spot but currently using spot. Updating...", asg_meta.get_name()) 680 | self.update_scaling_group(asg_meta, new_bid_info) 681 | continue 682 | 683 | new_bid_info = self.get_new_bid_info(asg_meta) 684 | 685 | # Change ASG to on-demand if insufficient capacity 686 | if self.check_insufficient_capacity(asg_meta): 687 | new_bid_info = self.create_on_demand_bid_info() 688 | logger.info("ASG %s spot instance have not sufficient resource. Updating to on-demand...", asg_meta.get_name()) 689 | self.update_scaling_group(asg_meta, new_bid_info) 690 | continue 691 | 692 | # Update ASGs iff new bid is different from current bid. 693 | if self.are_bids_equal(asg_meta.bid_info, new_bid_info): 694 | logger.info("No change in bid info for %s", 695 | asg_meta.get_name()) 696 | continue 697 | logger.info("Got new bid info from BidAdvisor: %s", new_bid_info) 698 | 699 | self.update_scaling_group(asg_meta, new_bid_info) 700 | except Exception as ex: 701 | logger.exception("Failed while checking instances in ASG: " + 702 | str(ex)) 703 | finally: 704 | # Cooling off period. TODO: Make this configurable! 705 | time.sleep(self._refresh_interval_seconds) 706 | 707 | try: 708 | # Discover and populate the correct ASGs. 709 | del self._asg_metas[:] 710 | self.discover_asgs() 711 | self.populate_current_config() 712 | except Exception as ex: 713 | raise Exception("Failed to discover/populate current ASG info: " + str(ex)) 714 | 715 | def create_on_demand_bid_info(self): 716 | new_bid_info = {} 717 | new_bid_info["type"] = "on-demand" 718 | new_bid_info["price"] = "" 719 | return new_bid_info 720 | 721 | def run(self): 722 | """Entrypoint for the AWS specific minion-manager.""" 723 | logger.info("Running AWS Minion Manager") 724 | 725 | try: 726 | # Discover and populate the correct ASGs. 727 | self.discover_asgs() 728 | self.populate_current_config() 729 | except Exception as ex: 730 | raise Exception("Failed to discover/populate current ASG info: " + 731 | str(ex)) 732 | 733 | self.bid_advisor.run() 734 | 735 | self.price_reporter.run() 736 | 737 | self.minion_manager_work() 738 | return 739 | 740 | def check_scaling_group_instances(self, scaling_group): 741 | """ 742 | Checks whether desired number of instances are running in an ASG. 743 | Also, schedules termination of "on-demand" instances. 744 | """ 745 | asg_meta = scaling_group 746 | attempts_to_converge = 3 747 | while attempts_to_converge > 0: 748 | asg_info = asg_meta.get_asg_info() 749 | response = AWSMinionManager.describe_asg_with_retries( 750 | self._ac_client, [asg_info.AutoScalingGroupName]) 751 | asg = response.AutoScalingGroups[0] 752 | 753 | if asg.DesiredCapacity <= len(asg.Instances): 754 | # The DesiredCapacity can be <= actual number of instances. 755 | # This can happen during scale down. The autoscaler may have 756 | # reduced the DesiredCapacity. But it can take sometime before 757 | # the instances are actually terminated. If this check happens 758 | # during that time, the DesiredCapacity may be < actual number 759 | # of instances. 760 | return True 761 | else: 762 | # It is possible that the autoscaler may have just increased 763 | # the DesiredCapacity but AWS is still in the process of 764 | # spinning up new instances. To given enough time to AWS to 765 | # spin up these new instances (i.e. for the desired state and 766 | # actual state to converge), sleep for 1 minute and try again. 767 | # If the state doesn't converge even after retries, return 768 | # False. 769 | logger.info("Desired number of instances not running in asg %s." + 770 | "Desired %d, actual %d", asg_meta.get_name(), asg.DesiredCapacity, 771 | len(asg.Instances)) 772 | attempts_to_converge = attempts_to_converge - 1 773 | 774 | # Wait for sometime before checking again. 775 | time.sleep(60) 776 | return False 777 | 778 | def check_insufficient_capacity(self, scaling_group): 779 | """ 780 | Checks whether not completed ASG activities got not have sufficient capacity error message. 781 | """ 782 | # This error message from https://docs.aws.amazon.com/autoscaling/ec2/userguide/ts-as-capacity.html#ts-as-capacity-1 783 | INSUFFICIENT_CAPACITY_MESSAGE = ['We currently do not have sufficient', 784 | 'capacity in the Availability Zone you requested'] 785 | 786 | WAITING_SPOT_INSTANCE_MESSAGE = ['Placed Spot instance request:', 'Waiting for instance(s)'] 787 | 788 | asg_info = scaling_group.get_asg_info() 789 | response = AWSMinionManager.describe_asg_activities_with_retries( 790 | self._ac_client, asg_info.AutoScalingGroupName) 791 | activities = response.Activities 792 | 793 | for activity in activities: 794 | if activity.Progress == 100: 795 | continue 796 | if 'StatusMessage' in activity and len([message for message in INSUFFICIENT_CAPACITY_MESSAGE if message in activity.StatusMessage]) == len(INSUFFICIENT_CAPACITY_MESSAGE): 797 | return True 798 | 799 | # Check spot request status code 800 | if 'StatusMessage' in activity and len([message for message in WAITING_SPOT_INSTANCE_MESSAGE if message in activity.StatusMessage]) == len(WAITING_SPOT_INSTANCE_MESSAGE): 801 | spot_req_regex = re.compile('Placed Spot instance request: (?Psir-[a-zA-Z0-9]+)\. Waiting for instance\(s\)') 802 | spot_req_re_result = spot_req_regex.search(activity.StatusMessage) 803 | if spot_req_re_result is not None and \ 804 | self.check_spot_request_insufficient_capacity(spot_req_re_result.group('spot_req_id')): 805 | return True 806 | 807 | return False 808 | 809 | def check_spot_request_insufficient_capacity(self, spot_request): 810 | OVERSUBSCRIBED_MESSAGE = 'capacity-oversubscribed' 811 | CAPACITY_NOT_AVAILABLE = 'capacity-not-available' 812 | 813 | response = AWSMinionManager.describe_spot_request_with_retries(self._ec2_client, [spot_request]) 814 | requests = response.SpotInstanceRequests 815 | for request in requests: 816 | if 'Status' in request and 'Code' in request.Status: 817 | if OVERSUBSCRIBED_MESSAGE == request.Status.Code or CAPACITY_NOT_AVAILABLE == request.Status.Code: 818 | return True 819 | 820 | return False 821 | 822 | def get_asg_metas(self): 823 | """ Return all asg_meta """ 824 | return self._asg_metas 825 | -------------------------------------------------------------------------------- /cloud_provider/aws/aws_minion_manager_test.py: -------------------------------------------------------------------------------- 1 | """The file has unit tests for the AWSMinionManager.""" 2 | 3 | import unittest 4 | import mock 5 | import pytest 6 | import subprocess 7 | import shlex 8 | from cloud_provider.aws.aws_minion_manager import AWSMinionManager 9 | from cloud_provider.aws.aws_bid_advisor import AWSBidAdvisor 10 | from moto import mock_autoscaling, mock_sts, mock_ec2 11 | import boto3 12 | from bunch import bunchify 13 | import time 14 | 15 | 16 | class AWSMinionManagerTest(unittest.TestCase): 17 | """ 18 | Tests for the AWSMinionManager. 19 | """ 20 | cluster_name = "cluster" 21 | cluster_id = "abcd-c0ffeec0ffee" 22 | cluster_name_id = cluster_name + "-" + cluster_id 23 | asg_name = cluster_name_id + "-asg" 24 | lc_name = cluster_name_id + "-lc" 25 | insufficient_resource_message = "We currently do not have sufficient p2.xlarge capacity in the Availability Zone you requested (us-west-2b). Our system will be working on provisioning additional capacity. You can currently get p2.xlarge capacity by not specifying an Availability Zone in your request or choosing us-west-2c, us-west-2a." 26 | asg_waiting_for_spot_instance = 'Placed Spot instance request: sir-3j8r1t2p. Waiting for instance(s)' 27 | 28 | session = boto3.Session(region_name="us-west-2") 29 | autoscaling = session.client("autoscaling") 30 | ec2 = session.client("ec2") 31 | 32 | @mock_autoscaling 33 | @mock_sts 34 | def delete_mock_asgs(self): 35 | """ Deletes the moto resources. """ 36 | self.autoscaling.delete_auto_scaling_group( 37 | AutoScalingGroupName=self.asg_name, 38 | ForceDelete=True 39 | ) 40 | 41 | self.autoscaling.delete_launch_configuration( 42 | LaunchConfigurationName=self.lc_name, 43 | ) 44 | 45 | @mock_ec2 46 | def get_ami(self): 47 | """ 48 | Getting Mock Ami 49 | """ 50 | response = self.ec2.describe_images() 51 | assert response["ResponseMetadata"]["HTTPStatusCode"] == 200 52 | ami = response['Images'][0]['ImageId'] 53 | return ami 54 | 55 | @mock_autoscaling 56 | @mock_sts 57 | def create_mock_asgs(self, minion_manager_tag="use-spot", not_terminate=False): 58 | """ 59 | Creates mocked AWS resources. 60 | """ 61 | if minion_manager_tag == "use-spot": 62 | response = self.autoscaling.create_launch_configuration( 63 | LaunchConfigurationName=self.lc_name, ImageId=self.get_ami(), 64 | SpotPrice="0.100", KeyName='kubernetes-some-key') 65 | else: 66 | response = self.autoscaling.create_launch_configuration( 67 | LaunchConfigurationName=self.lc_name, ImageId=self.get_ami(), 68 | KeyName='kubernetes-some-key') 69 | resp = bunchify(response) 70 | assert resp.ResponseMetadata.HTTPStatusCode == 200 71 | 72 | asg_tags = [{'ResourceId': self.cluster_name_id, 73 | 'Key': 'KubernetesCluster', 'Value': self.cluster_name_id}, 74 | {'ResourceId': self.cluster_name_id, 75 | 'Key': 'k8s-minion-manager', 'Value': minion_manager_tag}, 76 | {'ResourceId': self.cluster_name_id, 77 | 'PropagateAtLaunch': True, 78 | 'Key': 'Name', 'Value': "my-instance-name"}, 79 | ] 80 | 81 | if not_terminate: 82 | asg_tags.append({'ResourceId': self.cluster_name_id, 83 | 'Key': 'k8s-minion-manager/not-terminate', 'Value': 'True'}) 84 | 85 | response = self.autoscaling.create_auto_scaling_group( 86 | AutoScalingGroupName=self.asg_name, 87 | LaunchConfigurationName=self.lc_name, MinSize=3, MaxSize=3, 88 | DesiredCapacity=3, 89 | AvailabilityZones=['us-west-2a'], 90 | Tags=asg_tags 91 | ) 92 | resp = bunchify(response) 93 | assert resp.ResponseMetadata.HTTPStatusCode == 200 94 | 95 | def basic_setup_and_test(self, minion_manager_tag="use-spot", not_terminate=False): 96 | """ 97 | Creates the mock setup for tests, creates the aws_mm object and does 98 | some basic sanity tests before returning it. 99 | """ 100 | self.create_mock_asgs(minion_manager_tag, not_terminate) 101 | aws_mm = AWSMinionManager(self.cluster_name_id, "us-west-2", refresh_interval_seconds=50, incluster=False) 102 | assert len(aws_mm.get_asg_metas()) == 0, \ 103 | "ASG Metadata already populated?" 104 | 105 | aws_mm.discover_asgs() 106 | assert aws_mm.get_asg_metas() is not None, "ASG Metadata not populated" 107 | assert len(aws_mm.get_asg_metas()) == 1, "ASG not discovered" 108 | 109 | for asg in aws_mm.get_asg_metas(): 110 | assert asg.asg_info.AutoScalingGroupName == self.asg_name 111 | 112 | aws_mm.populate_current_config() 113 | return aws_mm 114 | 115 | @mock_autoscaling 116 | @mock_sts 117 | def test_discover_asgs(self): 118 | """ 119 | Tests that the discover_asgs method works as expected. 120 | """ 121 | self.basic_setup_and_test() 122 | 123 | @mock_autoscaling 124 | @mock_sts 125 | @mock_ec2 126 | def test_populate_instances(self): 127 | """ 128 | Tests that existing info. about ASGs is populated correctly. 129 | """ 130 | aws_mm = self.basic_setup_and_test() 131 | asg = aws_mm.get_asg_metas()[0] 132 | 133 | orig_instance_count = len(asg.get_instance_info()) 134 | aws_mm.populate_instances(asg) 135 | assert len(asg.get_instance_info()) == orig_instance_count + 3 136 | 137 | instance = asg.get_instance_info().itervalues().next() 138 | assert asg.get_instance_name(instance) == "my-instance-name" 139 | 140 | assert asg.is_instance_running(instance) == True 141 | # Simulate that the instance has been terminated. 142 | instance.State.Code = 32 143 | instance.State.Name = "shutting-down" 144 | assert asg.is_instance_running(instance) == False 145 | 146 | @mock_autoscaling 147 | @mock_sts 148 | def test_populate_current_config(self): 149 | """ 150 | Tests that existing instances are correctly populated by the 151 | populate_instances() method. 152 | """ 153 | aws_mm = self.basic_setup_and_test() 154 | for asg_meta in aws_mm.get_asg_metas(): 155 | assert asg_meta.get_lc_info().LaunchConfigurationName == \ 156 | self.lc_name 157 | assert asg_meta.get_bid_info()["type"] == "spot" 158 | assert asg_meta.get_bid_info()["price"] == "0.100" 159 | 160 | @mock_autoscaling 161 | @mock_sts 162 | @pytest.mark.skip( 163 | reason="Moto doesn't have some fields in it's LaunchConfig.") 164 | def test_update_cluster_spot(self): 165 | """ 166 | Tests that the AWSMinionManager correctly creates launch-configs and 167 | updates the ASG. 168 | 169 | Note: Moto doesn't have the ClassicLinkVPCSecurityGroups and 170 | IamInstanceProfile fields in it's LaunchConfig. Running the test below 171 | required manually commenting out these fields in the call to 172 | create_launch_configuration :( 173 | """ 174 | awsmm = self.basic_setup_and_test() 175 | bid_info = {} 176 | bid_info["type"] = "spot" 177 | bid_info["price"] = "10" 178 | awsmm.update_scaling_group(awsmm.get_asg_metas()[0], bid_info) 179 | 180 | @mock_autoscaling 181 | @mock_sts 182 | @pytest.mark.skip( 183 | reason="Moto doesn't have some fields in it's LaunchConfig.") 184 | def test_update_cluster_on_demand(self): 185 | """ 186 | Tests that the AWSMinionManager correctly creates launch-configs and 187 | updates the ASG. 188 | 189 | Note: Moto doesn't have the ClassicLinkVPCSecurityGroups and 190 | IamInstanceProfile fields in it's LaunchConfig. Running the test below 191 | required manually commenting out these fields in the call to 192 | create_launch_configuration :( 193 | """ 194 | awsmm = self.basic_setup_and_test() 195 | bid_info = {"type": "on-demand"} 196 | awsmm.update_scaling_group(awsmm.get_asg_metas()[0], bid_info) 197 | 198 | @mock_autoscaling 199 | @mock_sts 200 | @mock_ec2 201 | def test_update_needed(self): 202 | """ 203 | Tests that the AWSMinionManager correctly checks if updates are needed. 204 | """ 205 | # Try to use spot-instances. 206 | awsmm = self.basic_setup_and_test("use-spot") 207 | asg_meta = awsmm.get_asg_metas()[0] 208 | # Moto returns that all instances are running. No updates needed. 209 | assert awsmm.update_needed(asg_meta) is False 210 | # Simulate that the running instances are on-demand instances 211 | bid_info = {"type": "on-demand"} 212 | asg_meta.set_bid_info(bid_info) 213 | assert awsmm.update_needed(asg_meta) is True 214 | # Simulate that the running instances are spot instances 215 | bid_info = {"type": "spot"} 216 | asg_meta.set_bid_info(bid_info) 217 | assert awsmm.update_needed(asg_meta) is False 218 | 219 | # Try to ony use on-demand instances. 220 | awsmm = self.basic_setup_and_test("no-spot") 221 | asg_meta = awsmm.get_asg_metas()[0] 222 | assert awsmm.update_needed(asg_meta) is False 223 | 224 | # Simulate that the running instances are on-demand instances 225 | bid_info = {"type": "on-demand"} 226 | asg_meta.set_bid_info(bid_info) 227 | assert awsmm.update_needed(asg_meta) is False 228 | 229 | # Simulate that the running instances are spot-instances. 230 | bid_info = {"type": "spot"} 231 | asg_meta.set_bid_info(bid_info) 232 | assert awsmm.update_needed(asg_meta) is True 233 | 234 | @mock_autoscaling 235 | @mock_sts 236 | def test_bid_equality(self): 237 | """ 238 | Tests that 2 bids are considered equal when their type and price match. 239 | Not equal otherwise. 240 | """ 241 | a_bid = {} 242 | a_bid["type"] = "on-demand" 243 | b_bid = {} 244 | b_bid["type"] = "on-demand" 245 | b_bid["price"] = "100" 246 | awsmm = self.basic_setup_and_test() 247 | assert awsmm.are_bids_equal(a_bid, b_bid) is True 248 | 249 | # Change type of new bid to "spot". 250 | b_bid["type"] = "spot" 251 | assert awsmm.are_bids_equal(a_bid, b_bid) is False 252 | 253 | # Change the type of a_bid to "spot" but a different price. 254 | a_bid["type"] = "spot" 255 | a_bid["price"] = "90" 256 | assert awsmm.are_bids_equal(a_bid, b_bid) is False 257 | 258 | a_bid["price"] = "100" 259 | assert awsmm.are_bids_equal(a_bid, b_bid) is True 260 | 261 | @mock_autoscaling 262 | @mock_ec2 263 | @mock_sts 264 | def test_awsmm_instances(self): 265 | """ 266 | Tests that the AWSMinionManager correctly tracks running instances. 267 | """ 268 | awsmm = self.basic_setup_and_test() 269 | asg_meta = awsmm.get_asg_metas()[0] 270 | assert awsmm.check_scaling_group_instances(asg_meta) 271 | 272 | # Update the desired # of instances in the ASG. Verify that 273 | # minion-manager continues to account for the new instances. 274 | self.autoscaling.update_auto_scaling_group( 275 | AutoScalingGroupName=self.asg_name, MaxSize=4, DesiredCapacity=4) 276 | assert awsmm.check_scaling_group_instances(asg_meta) 277 | 278 | @mock_autoscaling 279 | @mock_ec2 280 | @mock_sts 281 | def test_instance_termination(self): 282 | """ 283 | Tests that the AWSMinionManager schedules instance termination. 284 | """ 285 | def _instance_termination_test_helper(minion_manager_tag, expected_kill_threads): 286 | awsmm = self.basic_setup_and_test(minion_manager_tag) 287 | assert len(awsmm.on_demand_kill_threads) == 0 288 | asg_meta = awsmm.get_asg_metas()[0] 289 | # Set instanceType since moto's instances don't have it. 290 | instance_type = "m3.medium" 291 | zone = "us-west-2b" 292 | awsmm.bid_advisor.on_demand_price_dict[instance_type] = "100" 293 | awsmm.bid_advisor.spot_price_list = [{'InstanceType': instance_type, 294 | 'SpotPrice': '80', 295 | 'AvailabilityZone': zone}] 296 | for instance in asg_meta.get_instances(): 297 | instance.InstanceType = instance_type 298 | awsmm.populate_instances(asg_meta) 299 | awsmm.schedule_instance_termination(asg_meta) 300 | assert len(awsmm.on_demand_kill_threads) == expected_kill_threads 301 | 302 | time.sleep(15) 303 | assert len(awsmm.on_demand_kill_threads) == 0 304 | 305 | _instance_termination_test_helper("use-spot", 3) 306 | _instance_termination_test_helper("no-spot", 0) 307 | _instance_termination_test_helper("abcd", 0) 308 | 309 | @mock_autoscaling 310 | @mock_ec2 311 | @mock_sts 312 | def test_instance_not_termination(self): 313 | """ 314 | Tests that the AWSMinionManager won't terminate instance with not-terminate tag. 315 | """ 316 | def _instance_termination_test_helper(minion_manager_tag, expected_kill_threads): 317 | awsmm = self.basic_setup_and_test(minion_manager_tag, True) 318 | # Inject `k8s-minion-manager/not-terminate` to awsmm 319 | 320 | assert len(awsmm.on_demand_kill_threads) == 0 321 | asg_meta = awsmm.get_asg_metas()[0] 322 | # Set instanceType since moto's instances don't have it. 323 | instance_type = "m3.medium" 324 | zone = "us-west-2b" 325 | awsmm.bid_advisor.on_demand_price_dict[instance_type] = "100" 326 | awsmm.bid_advisor.spot_price_list = [{'InstanceType': instance_type, 327 | 'SpotPrice': '80', 328 | 'AvailabilityZone': zone}] 329 | for instance in asg_meta.get_instances(): 330 | instance.InstanceType = instance_type 331 | awsmm.populate_instances(asg_meta) 332 | awsmm.schedule_instance_termination(asg_meta) 333 | assert len(awsmm.on_demand_kill_threads) == expected_kill_threads 334 | 335 | time.sleep(15) 336 | assert len(awsmm.on_demand_kill_threads) == 0 337 | 338 | _instance_termination_test_helper("use-spot", 0) 339 | 340 | # PriceReporter tests 341 | @mock_autoscaling 342 | @mock_ec2 343 | @mock_sts 344 | @mock.patch.object(AWSBidAdvisor, 'get_spot_instance_price') 345 | def test_price_reporter_basic(self, get_spot_instance_price_mock): 346 | """ 347 | Tests that the PriceReporter populates the pricing info. 348 | """ 349 | get_spot_instance_price_mock.return_value = "0.100" 350 | 351 | awsmm = self.basic_setup_and_test() 352 | asg_meta = awsmm.get_asg_metas()[0] 353 | awsmm.populate_instances(asg_meta) 354 | assert awsmm.price_reporter is not None 355 | 356 | assert len(awsmm.price_reporter.price_info) == 0 357 | awsmm.price_reporter.price_reporter_work() 358 | assert len(awsmm.price_reporter.price_info) == \ 359 | len(asg_meta.get_instances()) 360 | # Call price_reporter_work again. There should now be two values. 361 | awsmm.price_reporter.price_reporter_work() 362 | instance = asg_meta.get_instances()[0] 363 | assert len(awsmm.price_reporter.price_info[ 364 | instance.InstanceId]) == 2 365 | 366 | # Setting semaphore Value 367 | @mock_autoscaling 368 | @mock_ec2 369 | @mock_sts 370 | def test_set_semaphore(self): 371 | """ 372 | Testing Semaphore value based on terminate percentage 373 | """ 374 | def _semaphore_helper(minion_manager_tag, percentage, outcome): 375 | awsmm = self.basic_setup_and_test(minion_manager_tag) 376 | asg_meta = awsmm.get_asg_metas()[0] 377 | awsmm.terminate_percentage = percentage 378 | get_semaphore = awsmm.set_semaphore(asg_meta) 379 | assert get_semaphore._Semaphore__value == outcome 380 | 381 | _semaphore_helper('use-spot', 1, 1) 382 | _semaphore_helper('use-spot', 30, 1) 383 | _semaphore_helper('use-spot', 60, 2) 384 | _semaphore_helper('use-spot', 100, 3) 385 | 386 | @mock.patch('subprocess.check_call') 387 | @mock.patch('cloud_provider.aws.aws_minion_manager.AWSMinionManager.get_name_for_instance') 388 | @mock_autoscaling 389 | @mock_ec2 390 | @mock_sts 391 | def test_cordon(self, mock_get_name_for_instance, mock_check_call): 392 | awsmm = self.basic_setup_and_test() 393 | mock_get_name_for_instance.return_value = "ip-of-fake-node-name" 394 | awsmm.cordon_node("ip-of-fake-node") 395 | mock_check_call.assert_called_with(['kubectl', 'drain', 'ip-of-fake-node-name', 396 | '--ignore-daemonsets=true', '--delete-local-data=true', '--force', '--grace-period=-1']) 397 | 398 | mock_check_call.side_effect = [Exception("Test"), True] 399 | awsmm.cordon_node("ip-of-fake-node") 400 | mock_check_call.assert_called_with(['kubectl', 'uncordon', 'ip-of-fake-node-name']) 401 | 402 | @mock.patch('cloud_provider.aws.aws_minion_manager.AWSMinionManager.describe_asg_activities_with_retries') 403 | @mock_autoscaling 404 | @mock_ec2 405 | @mock_sts 406 | def test_asg_activities_all_done(self, mock_get_name_for_instance): 407 | mock_get_name_for_instance.return_value = bunchify({'Activities': [{'StatusMessage': 'dummy ok message', 'Progress': 100}, {'StatusMessage': 'dummy ok message2', 'Progress': 100}]}) 408 | 409 | awsmm = self.basic_setup_and_test() 410 | asg_meta = awsmm.get_asg_metas()[0] 411 | assert not awsmm.check_insufficient_capacity(asg_meta) 412 | 413 | 414 | @mock.patch('cloud_provider.aws.aws_minion_manager.AWSMinionManager.describe_asg_activities_with_retries') 415 | @mock_autoscaling 416 | @mock_ec2 417 | @mock_sts 418 | def test_asg_activity_without_statusMessage(self, mock_get_name_for_instance): 419 | mock_get_name_for_instance.return_value = bunchify({'Activities': [{'Progress': 20}, {'StatusMessage': 'dummy ok message2', 'Progress': 100}]}) 420 | 421 | awsmm = self.basic_setup_and_test() 422 | asg_meta = awsmm.get_asg_metas()[0] 423 | assert not awsmm.check_insufficient_capacity(asg_meta) 424 | 425 | @mock.patch('cloud_provider.aws.aws_minion_manager.AWSMinionManager.describe_asg_activities_with_retries') 426 | @mock_autoscaling 427 | @mock_ec2 428 | @mock_sts 429 | def test_asg_done_activity_with_insufficient_resource(self, mock_get_name_for_instance): 430 | mock_get_name_for_instance.return_value = bunchify({'Activities': [{'StatusMessage': self.insufficient_resource_message, 'Progress': 100}]}) 431 | 432 | awsmm = self.basic_setup_and_test() 433 | asg_meta = awsmm.get_asg_metas()[0] 434 | assert not awsmm.check_insufficient_capacity(asg_meta) 435 | 436 | @mock.patch('cloud_provider.aws.aws_minion_manager.AWSMinionManager.describe_asg_activities_with_retries') 437 | @mock_autoscaling 438 | @mock_ec2 439 | @mock_sts 440 | def test_asg_activity_with_insufficient_resource(self, mock_get_name_for_instance): 441 | mock_get_name_for_instance.return_value = bunchify({'Activities': [{'StatusMessage': self.insufficient_resource_message, 'Progress': 20}]}) 442 | 443 | awsmm = self.basic_setup_and_test() 444 | asg_meta = awsmm.get_asg_metas()[0] 445 | assert awsmm.check_insufficient_capacity(asg_meta) 446 | 447 | @mock.patch('cloud_provider.aws.aws_minion_manager.AWSMinionManager.describe_spot_request_with_retries') 448 | @mock.patch('cloud_provider.aws.aws_minion_manager.AWSMinionManager.describe_asg_activities_with_retries') 449 | @mock_autoscaling 450 | @mock_ec2 451 | @mock_sts 452 | def test_spot_request_capacity_oversubscribed(self, mock_get_name_for_instance, mock_spot_request): 453 | mock_get_name_for_instance.return_value = bunchify({'Activities': [{'StatusMessage': self.asg_waiting_for_spot_instance, 'Progress': 20}]}) 454 | mock_spot_request.return_value = bunchify({'SpotInstanceRequests': [{'Status': {'Code': 'capacity-oversubscribed'}}]}) 455 | 456 | awsmm = self.basic_setup_and_test() 457 | asg_meta = awsmm.get_asg_metas()[0] 458 | assert awsmm.check_insufficient_capacity(asg_meta) 459 | 460 | @mock.patch('cloud_provider.aws.aws_minion_manager.AWSMinionManager.describe_spot_request_with_retries') 461 | @mock.patch('cloud_provider.aws.aws_minion_manager.AWSMinionManager.describe_asg_activities_with_retries') 462 | @mock_autoscaling 463 | @mock_ec2 464 | @mock_sts 465 | def test_spot_request_capacity_not_available(self, mock_get_name_for_instance, mock_spot_request): 466 | mock_get_name_for_instance.return_value = bunchify({'Activities': [{'StatusMessage': self.asg_waiting_for_spot_instance, 'Progress': 20}]}) 467 | mock_spot_request.return_value = bunchify({'SpotInstanceRequests': [{'Status': {'Code': 'capacity-not-available'}}]}) 468 | 469 | awsmm = self.basic_setup_and_test() 470 | asg_meta = awsmm.get_asg_metas()[0] 471 | assert awsmm.check_insufficient_capacity(asg_meta) 472 | 473 | @mock.patch('cloud_provider.aws.aws_minion_manager.AWSMinionManager.describe_spot_request_with_retries') 474 | @mock.patch('cloud_provider.aws.aws_minion_manager.AWSMinionManager.describe_asg_activities_with_retries') 475 | @mock_autoscaling 476 | @mock_ec2 477 | @mock_sts 478 | def test_spot_request_other_message(self, mock_get_name_for_instance, mock_spot_request): 479 | mock_get_name_for_instance.return_value = bunchify({'Activities': [{'StatusMessage': self.asg_waiting_for_spot_instance, 'Progress': 20}]}) 480 | mock_spot_request.return_value = bunchify({'SpotInstanceRequests': [{'Status': {'Code': 'other-message'}}]}) 481 | 482 | awsmm = self.basic_setup_and_test() 483 | asg_meta = awsmm.get_asg_metas()[0] 484 | assert not awsmm.check_insufficient_capacity(asg_meta) 485 | -------------------------------------------------------------------------------- /cloud_provider/aws/price_info_reporter.py: -------------------------------------------------------------------------------- 1 | """ Keeps track of the pricing info for each running instance in the ASGs. """ 2 | 3 | import sys 4 | import logging 5 | import time 6 | from threading import Thread 7 | from datetime import datetime 8 | from collections import deque 9 | 10 | from bunch import bunchify 11 | from retrying import retry 12 | from constants import SECONDS_PER_MINUTE 13 | from flask import Flask, jsonify 14 | 15 | logger = logging.getLogger("aws_minion_manager") 16 | logging.basicConfig(format="%(asctime)s %(levelname)s %(name)s " + 17 | "%(threadName)s: %(message)s", 18 | datefmt="%Y-%m-%dT%H:%M:%S", 19 | stream=sys.stdout, level=logging.INFO) 20 | logging.getLogger('boto3').setLevel(logging.WARNING) 21 | logging.getLogger('botocore').setLevel(logging.WARNING) 22 | 23 | 24 | class AWSPriceReporter(object): 25 | """ 26 | This class keeps track of the pricing info. of each running AWS instance 27 | in the ASG. 28 | """ 29 | # ec2_client is the boto ec2 client. 30 | ec2_client = None 31 | 32 | # bid_advisor is the AWSBidAdvisor object used for getting some price info. 33 | bid_advisor = None 34 | 35 | # 'asg_metas' is a list of AWSAutoscalinGroupMM objects that the 36 | # price-updater will work on. 37 | asg_metas = [] 38 | 39 | # The collector_thread is a Thread that periodically queries AWS and 40 | # updates the pricing info in memory. 41 | collector_thread = None 42 | 43 | # The api_thread is the Thread that responds to REST endpoints. 44 | api_thread = None 45 | 46 | # price_info is the dictionary about each instance and it's pricing 47 | # info. 48 | price_info = {} 49 | 50 | def __init__(self, ec2_client, bid_advisor, asg_metas): 51 | self.ec2_client = ec2_client 52 | self.bid_advisor = bid_advisor 53 | self.asg_metas = asg_metas 54 | self.collector_thread = Thread(target=self.price_reporter_main, 55 | name="PriceReporter") 56 | self.collector_thread.setDaemon(True) 57 | 58 | self.api_thread = Thread(target=self.price_reporter_api, 59 | name="PriceReporterAPI") 60 | self.api_thread.setDaemon(True) 61 | 62 | def get_price_info(self): 63 | """ Returns the price_info dict. """ 64 | return self.price_info 65 | 66 | @retry(wait_exponential_multiplier=1000, stop_max_attempt_number=3) 67 | def get_instance_price(self, instance): 68 | """ 69 | Given an Instance object, gets the price of that instance based on the 70 | InstanceType, AZ and StartTime. 71 | """ 72 | current_time = datetime.now() 73 | if 'InstanceLifecycle' not in instance: 74 | return {str(current_time): self.bid_advisor.get_on_demand_price( 75 | instance.InstanceType)} 76 | 77 | query_time = current_time 78 | query_time = query_time.replace(minute=instance.LaunchTime.minute) 79 | query_time = query_time.replace(second=instance.LaunchTime.second) 80 | query_time = query_time.replace( 81 | microsecond=instance.LaunchTime.microsecond) 82 | if current_time.minute >= instance.LaunchTime.minute: 83 | query_time = query_time.replace(hour=current_time.hour) 84 | else: 85 | query_time = query_time.replace(hour=current_time.hour - 1) 86 | 87 | response = self.ec2_client.describe_spot_price_history( 88 | EndTime=query_time, 89 | InstanceTypes=[instance.InstanceType], 90 | ProductDescriptions=['Linux/UNIX (Amazon VPC)'], 91 | AvailabilityZone=instance.Placement.AvailabilityZone, 92 | StartTime=query_time 93 | ) 94 | assert response is not None, "Failed to get spot-instance prices" 95 | resp = bunchify(response) 96 | if len(resp.SpotPriceHistory) > 0: 97 | return {str(current_time): resp.SpotPriceHistory[0].SpotPrice} 98 | else: 99 | return {str(current_time): "-1"} 100 | 101 | def price_reporter_work(self): 102 | """ 103 | Performs one price check and updates the price_info. 104 | """ 105 | for asg_meta in self.asg_metas: 106 | asg_instance_info = asg_meta.get_instance_info() 107 | if not asg_instance_info: 108 | logger.info("Instance info not populated!") 109 | continue 110 | 111 | for instance_id, instance in asg_instance_info.iteritems(): 112 | price_data = self.get_instance_price(instance) 113 | if instance_id in self.price_info: 114 | self.price_info[instance.InstanceId].append(price_data) 115 | else: 116 | price_value_queue = deque(maxlen=24) 117 | self.price_info[instance.InstanceId] = price_value_queue 118 | price_value_queue.append(price_data) 119 | 120 | def price_reporter_main(self): 121 | """ Periodically updates the pricing info. """ 122 | while True: 123 | try: 124 | # Price check is done every 20 minutes. 125 | if len(self.asg_metas) == 0: 126 | logger.info("ASGs not set") 127 | continue 128 | self.price_reporter_work() 129 | except Exception as exc: 130 | # Log an error and swallow the exception. 131 | logger.error("Failed while getting instance pricing " + 132 | "information: " + str(exc)) 133 | finally: 134 | time.sleep(60 * SECONDS_PER_MINUTE) 135 | 136 | def price_reporter_api(self): 137 | """ Thread that responds to the Flask api endpoints. """ 138 | app = Flask("AWSPriceReporterAPI") 139 | 140 | @app.route('/') 141 | def _return_price_info(): 142 | """ Returns a json comprising the price-information. """ 143 | try: 144 | output = {} 145 | for instance, values in self.price_info.iteritems(): 146 | output[instance] = list(values) 147 | return jsonify(output) 148 | except Exception as exc: 149 | logger.info("Failed while reporting price info: " + str(exc)) 150 | 151 | app.run(host='0.0.0.0') 152 | 153 | def run(self): 154 | """ Main method of the price-updater. """ 155 | assert self.collector_thread is not None, \ 156 | "PriceReporter thread not found" 157 | assert self.api_thread is not None, \ 158 | "PriceReporterAPI thread not found" 159 | self.collector_thread.start() 160 | logger.info("PriceReporter thread started!") 161 | 162 | self.api_thread.start() 163 | logger.info("PriceReporterAPI thread started!") 164 | return 165 | -------------------------------------------------------------------------------- /cloud_provider/base.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Define the base class for the minion-manager. Cloud provider specific 5 | implementations should derive from this. 6 | """ 7 | 8 | import abc 9 | 10 | 11 | class MinionManagerBase(object): 12 | """ Base class for MinionManager. """ 13 | __metaclass__ = abc.ABCMeta 14 | _region = None 15 | 16 | def __init__(self, region): 17 | self._region = region 18 | 19 | @abc.abstractmethod 20 | def run(self): 21 | """Main method for the minion-manager functionality.""" 22 | return 23 | 24 | @abc.abstractmethod 25 | def check_scaling_group_instances(self, scaling_group): 26 | """ 27 | Checks whether desired number of instances are running in a scaling 28 | group. 29 | """ 30 | return 31 | 32 | @abc.abstractmethod 33 | def update_scaling_group(self, scaling_group, new_bid_info): 34 | """ 35 | Updates the scaling group config. 36 | """ 37 | return 38 | -------------------------------------------------------------------------------- /constants.py: -------------------------------------------------------------------------------- 1 | """Constants used by the minion-manager.""" 2 | 3 | SECONDS_PER_MINUTE = 60 4 | SECONDS_PER_HOUR = 3600 5 | -------------------------------------------------------------------------------- /deploy/mm.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceAccount 3 | metadata: 4 | namespace: 5 | name: mm-sa 6 | --- 7 | kind: ClusterRoleBinding 8 | apiVersion: rbac.authorization.k8s.io/v1 9 | metadata: 10 | namespace: 11 | name: mm-rolebinding 12 | subjects: 13 | - kind: ServiceAccount 14 | name: mm-sa 15 | namespace: 16 | roleRef: 17 | kind: ClusterRole 18 | name: cluster-admin 19 | apiGroup: rbac.authorization.k8s.io 20 | --- 21 | apiVersion: extensions/v1beta1 22 | kind: Deployment 23 | metadata: 24 | namespace: 25 | name: minion-manager 26 | spec: 27 | replicas: 1 28 | template: 29 | metadata: 30 | labels: 31 | app: minion-manager 32 | spec: 33 | tolerations: 34 | - effect: NoSchedule 35 | key: node-role.kubernetes.io/master 36 | nodeSelector: 37 | kubernetes.io/role: master 38 | serviceAccountName: mm-sa 39 | containers: 40 | - name: minion-manager 41 | image: argoproj/k8s-minion-manager:v0.6 42 | command: ["python", "./minion_manager.py", "--region", "us-west-2", "--cluster-name", ""] 43 | resources: 44 | requests: 45 | cpu: 50m 46 | memory: 80Mi 47 | -------------------------------------------------------------------------------- /minion_manager.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """The main entry point for the minion-manager.""" 4 | 5 | import argparse 6 | import sys 7 | import logging 8 | 9 | from cloud_broker import Broker 10 | 11 | logger = logging.getLogger("minion_manager") 12 | logging.basicConfig(format="%(asctime)s %(levelname)s %(name)s " + 13 | "%(threadName)s: %(message)s", 14 | datefmt="%Y-%m-%dT%H:%M:%S", 15 | stream=sys.stdout, level=logging.INFO) 16 | 17 | 18 | def run(): 19 | """Parses user provided arguments and validates them. 20 | Asserts if any of the provided arguments is incorrect. 21 | """ 22 | parser = argparse.ArgumentParser(description="Manage the minions in a K8S cluster") 23 | parser.add_argument("--region", help="Region in which the cluster exists", 24 | required=True) 25 | parser.add_argument("--cloud", default="aws", choices=['aws'], type=str.lower, 26 | help="Cloud provider (only AWS as of now)") 27 | parser.add_argument("--profile", help="Credentials profile to use") 28 | parser.add_argument("--refresh-interval-seconds", default="300", 29 | help="Interval in seconds at which to query AWS") 30 | parser.add_argument("--cluster-name", required=True, 31 | help="Name of the Kubernetes cluster. Get's used for identifying ASGs") 32 | parser.add_argument("--events-only", action='store_true', required=False, 33 | help="Whether minion-manager should only emit events and *not* actually do spot/on-demand changes to launch-config") 34 | 35 | usr_args = parser.parse_args() 36 | 37 | logger.info("Starting minion-manager for cluster: %s, in region %s for cloud provider %s", 38 | usr_args.cluster_name, 39 | usr_args.region, 40 | usr_args.cloud) 41 | 42 | if usr_args.cloud == "aws": 43 | minion_manager = Broker.get_impl_object( 44 | usr_args.cloud, usr_args.cluster_name, usr_args.region, int(usr_args.refresh_interval_seconds), 45 | aws_profile=usr_args.profile, events_only=usr_args.events_only) 46 | minion_manager.run() 47 | 48 | # A journey of a thousand miles ... 49 | if __name__ == "__main__": 50 | run() 51 | --------------------------------------------------------------------------------