{"action":"created","comment":{"url":"https://api.github.com/repos/2gis/k8s-handle/pulls/comments/225417126","pull_request_review_id":165008146,"id":225417126,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyNTQxNzEyNg==","diff_hunk":"@@ -88,27 +96,55 @@ def main():\n         context = config.load_context_section(args['section'])\n         render = templating.Renderer(settings.TEMPLATES_DIR)\n         resources = render.generate_by_context(context)\n-        # INFO rvadim: https://github.com/kubernetes-client/python/issues/430#issuecomment-359483997\n \n         if args.get('dry_run'):\n             return\n \n+        if os.environ.get('K8S_HOST') or os.environ.get('K8S_CA'):\n+            log.warning(\"K8S_HOST and K8S_CA environment variables support is deprecated \"\n+                        \"and will be discontinued in the future. Use K8S_MASTER_URI and K8S_CA_BASE64 instead.\")\n+\n+        k8s_master_uri = args.get('k8s_master_uri') or context.get('k8s_master_uri') or os.environ.get(\n+            'K8S_MASTER_URI') or os.environ.get('K8S_HOST')\n+        k8s_ca_base64 = args.get('k8s_ca_base64') or context.get('k8s_ca_base64') or os.environ.get(\n+            'K8S_CA_BASE64') or os.environ.get('K8S_CA')\n+        k8s_token = args.get('k8s_token') or context.get('k8s_token') or os.environ.get('K8S_TOKEN')\n+        k8s_handle_debug = args.get('k8s_handle_debug') or context.get('k8s_handle_debug') in [True, 'true', 'True']\n+\n+        # INFO rvadim: https://github.com/kubernetes-client/python/issues/430#issuecomment-359483997\n         if args.get('use_kubeconfig'):\n+            # NOTE furiousassault: unfortunately, there are no mutually exclusive groups in argparse\n+            if k8s_master_uri or k8s_ca_base64 or k8s_token:\n+                log.info('CLI/Env connection parameters are ignored when --use-kubeconfig '\n+                         'option is specified.')\n+\n             load_kube_config()\n             namespace = list_kube_config_contexts()[1].get('context').get('namespace')\n-\n-            if not namespace:\n-                raise RuntimeError(\"Unable to determine namespace of current context\")\n-\n             settings.K8S_NAMESPACE = namespace\n         else:\n-            Configuration.set_default(get_client_config(context))\n-            check_required_vars(context, ['k8s_master_uri', 'k8s_token', 'k8s_ca_base64', 'k8s_namespace'])\n+            for parameter, value in {\n+                'K8S master uri': k8s_master_uri,\n+                'K8S CA BASE64': k8s_ca_base64,\n+                'K8S token': k8s_token\n+            }.items():\n+                if not value:\n+                    raise RuntimeError('{0} parameter is not set. '\n+                                       'Please, provide {0} via CLI, config or env.'.format(parameter))\n+\n+            configuration = client.Configuration()","path":"k8s-handle.py","position":100,"original_position":100,"commit_id":"fda263ae3b42046395f864398e875b5d47d3f3c4","original_commit_id":"fda263ae3b42046395f864398e875b5d47d3f3c4","user":{"login":"furiousassault","id":37325304,"node_id":"MDQ6VXNlcjM3MzI1MzA0","avatar_url":"https://avatars3.githubusercontent.com/u/37325304?v=4","gravatar_id":"","url":"https://api.github.com/users/furiousassault","html_url":"https://github.com/furiousassault","followers_url":"https://api.github.com/users/furiousassault/followers","following_url":"https://api.github.com/users/furiousassault/following{/other_user}","gists_url":"https://api.github.com/users/furiousassault/gists{/gist_id}","starred_url":"https://api.github.com/users/furiousassault/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/furiousassault/subscriptions","organizations_url":"https://api.github.com/users/furiousassault/orgs","repos_url":"https://api.github.com/users/furiousassault/repos","events_url":"https://api.github.com/users/furiousassault/events{/privacy}","received_events_url":"https://api.github.com/users/furiousassault/received_events","type":"User","site_admin":false},"body":"@rvadim а от заворачивания в функцию из другого модуля с одним вхождением, на которую написаны тесты, у которых суть\r\n```\r\na = 3\r\nassert a == 3\r\n``` суть становится лучше? Код просто становится более многословным, никаких других эффектов нет. \r\n\r\nТестируется в данный момент оператор присваивания и то, что логика конструктора сводится к нему. Оператор присвоения не нуждается в тестах, версия k8s клиента у нас фиксированная, логика конструктора этого объекта измениться не может. \r\nПоэтому смысла в тестировании этой инициализации нет.\r\n\r\nТаким, образом, понимаю, хочется просто вынести \"чтобы было не в main\". Спорно. Обдумаю.","created_at":"2018-10-16T06:57:24Z","updated_at":"2018-10-16T06:57:24Z","html_url":"https://github.com/2gis/k8s-handle/pull/48#discussion_r225417126","pull_request_url":"https://api.github.com/repos/2gis/k8s-handle/pulls/48","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/2gis/k8s-handle/pulls/comments/225417126"},"html":{"href":"https://github.com/2gis/k8s-handle/pull/48#discussion_r225417126"},"pull_request":{"href":"https://api.github.com/repos/2gis/k8s-handle/pulls/48"}},"in_reply_to_id":225400218},"pull_request":{"url":"https://api.github.com/repos/2gis/k8s-handle/pulls/48","id":222877700,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIyODc3NzAw","html_url":"https://github.com/2gis/k8s-handle/pull/48","diff_url":"https://github.com/2gis/k8s-handle/pull/48.diff","patch_url":"https://github.com/2gis/k8s-handle/pull/48.patch","issue_url":"https://api.github.com/repos/2gis/k8s-handle/issues/48","number":48,"state":"open","locked":false,"title":"I-46 - Accept connection parameters from CLI and env variables.","user":{"login":"furiousassault","id":37325304,"node_id":"MDQ6VXNlcjM3MzI1MzA0","avatar_url":"https://avatars3.githubusercontent.com/u/37325304?v=4","gravatar_id":"","url":"https://api.github.com/users/furiousassault","html_url":"https://github.com/furiousassault","followers_url":"https://api.github.com/users/furiousassault/followers","following_url":"https://api.github.com/users/furiousassault/following{/other_user}","gists_url":"https://api.github.com/users/furiousassault/gists{/gist_id}","starred_url":"https://api.github.com/users/furiousassault/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/furiousassault/subscriptions","organizations_url":"https://api.github.com/users/furiousassault/orgs","repos_url":"https://api.github.com/users/furiousassault/repos","events_url":"https://api.github.com/users/furiousassault/events{/privacy}","received_events_url":"https://api.github.com/users/furiousassault/received_events","type":"User","site_admin":false},"body":"Closes #46 \r\n\r\nИмплементация поддержки CLI/Env параметров соединения с K8S.\r\nКомментарии не по функциональности:\r\nМетоды  `get_client_config` и `check_required_vars` и соответствующие им тесты убрал, т.к. одно вхождение, а отделение их ради тестов не очень полезно, логика в них примитивная.\r\nТаким образом, формальное тестовое покрытие снизилось, за счет того что логика перекочевала в main, эффективное же практически не изменилось.\r\nС другой стороны, в целом логику приоритетов хотелось бы в дальнейшем всё же под тесты внести.\r\n\r\nЧасть глобальных переменных из settings перекочевала в main, ввиду того, что нет нужды держать их глобальными. Логика их заполнения также усложнилась и стала связана с контекстом  из main, поэтому перенёс туда.\r\n\r\nImplementation of CLI/Env settings of the connection parameters support.\r\nNotes:\r\nSlightly decreased formal test coverage, though almost without effective coverage loss.\r\nSome global connection variables from settings.py moved to k8s-handle.py, due to the more complex logic of their evaluation and because of single usage. `get_client_config` and `check_required_vars` functions were abolished as well due to single usage.\r\n\r\nPull requests with `main()` testability increasing changes are planned after the #43.","created_at":"2018-10-15T11:50:30Z","updated_at":"2018-10-16T06:57:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"693247093fc22fa85ed2e46d79e108d3d228868b","assignee":null,"assignees":[],"requested_reviewers":[{"login":"dekhtyarev","id":17539237,"node_id":"MDQ6VXNlcjE3NTM5MjM3","avatar_url":"https://avatars1.githubusercontent.com/u/17539237?v=4","gravatar_id":"","url":"https://api.github.com/users/dekhtyarev","html_url":"https://github.com/dekhtyarev","followers_url":"https://api.github.com/users/dekhtyarev/followers","following_url":"https://api.github.com/users/dekhtyarev/following{/other_user}","gists_url":"https://api.github.com/users/dekhtyarev/gists{/gist_id}","starred_url":"https://api.github.com/users/dekhtyarev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dekhtyarev/subscriptions","organizations_url":"https://api.github.com/users/dekhtyarev/orgs","repos_url":"https://api.github.com/users/dekhtyarev/repos","events_url":"https://api.github.com/users/dekhtyarev/events{/privacy}","received_events_url":"https://api.github.com/users/dekhtyarev/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/2gis/k8s-handle/pulls/48/commits","review_comments_url":"https://api.github.com/repos/2gis/k8s-handle/pulls/48/comments","review_comment_url":"https://api.github.com/repos/2gis/k8s-handle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/2gis/k8s-handle/issues/48/comments","statuses_url":"https://api.github.com/repos/2gis/k8s-handle/statuses/fda263ae3b42046395f864398e875b5d47d3f3c4","head":{"label":"2gis:I-46a","ref":"I-46a","sha":"fda263ae3b42046395f864398e875b5d47d3f3c4","user":{"login":"2gis","id":1481435,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE0ODE0MzU=","avatar_url":"https://avatars2.githubusercontent.com/u/1481435?v=4","gravatar_id":"","url":"https://api.github.com/users/2gis","html_url":"https://github.com/2gis","followers_url":"https://api.github.com/users/2gis/followers","following_url":"https://api.github.com/users/2gis/following{/other_user}","gists_url":"https://api.github.com/users/2gis/gists{/gist_id}","starred_url":"https://api.github.com/users/2gis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/2gis/subscriptions","organizations_url":"https://api.github.com/users/2gis/orgs","repos_url":"https://api.github.com/users/2gis/repos","events_url":"https://api.github.com/users/2gis/events{/privacy}","received_events_url":"https://api.github.com/users/2gis/received_events","type":"Organization","site_admin":false},"repo":{"id":132988618,"node_id":"MDEwOlJlcG9zaXRvcnkxMzI5ODg2MTg=","name":"k8s-handle","full_name":"2gis/k8s-handle","private":false,"owner":{"login":"2gis","id":1481435,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE0ODE0MzU=","avatar_url":"https://avatars2.githubusercontent.com/u/1481435?v=4","gravatar_id":"","url":"https://api.github.com/users/2gis","html_url":"https://github.com/2gis","followers_url":"https://api.github.com/users/2gis/followers","following_url":"https://api.github.com/users/2gis/following{/other_user}","gists_url":"https://api.github.com/users/2gis/gists{/gist_id}","starred_url":"https://api.github.com/users/2gis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/2gis/subscriptions","organizations_url":"https://api.github.com/users/2gis/orgs","repos_url":"https://api.github.com/users/2gis/repos","events_url":"https://api.github.com/users/2gis/events{/privacy}","received_events_url":"https://api.github.com/users/2gis/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/2gis/k8s-handle","description":"Easy CI/CD for Kubernetes clusters with python and jinja2","fork":false,"url":"https://api.github.com/repos/2gis/k8s-handle","forks_url":"https://api.github.com/repos/2gis/k8s-handle/forks","keys_url":"https://api.github.com/repos/2gis/k8s-handle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/2gis/k8s-handle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/2gis/k8s-handle/teams","hooks_url":"https://api.github.com/repos/2gis/k8s-handle/hooks","issue_events_url":"https://api.github.com/repos/2gis/k8s-handle/issues/events{/number}","events_url":"https://api.github.com/repos/2gis/k8s-handle/events","assignees_url":"https://api.github.com/repos/2gis/k8s-handle/assignees{/user}","branches_url":"https://api.github.com/repos/2gis/k8s-handle/branches{/branch}","tags_url":"https://api.github.com/repos/2gis/k8s-handle/tags","blobs_url":"https://api.github.com/repos/2gis/k8s-handle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/2gis/k8s-handle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/2gis/k8s-handle/git/refs{/sha}","trees_url":"https://api.github.com/repos/2gis/k8s-handle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/2gis/k8s-handle/statuses/{sha}","languages_url":"https://api.github.com/repos/2gis/k8s-handle/languages","stargazers_url":"https://api.github.com/repos/2gis/k8s-handle/stargazers","contributors_url":"https://api.github.com/repos/2gis/k8s-handle/contributors","subscribers_url":"https://api.github.com/repos/2gis/k8s-handle/subscribers","subscription_url":"https://api.github.com/repos/2gis/k8s-handle/subscription","commits_url":"https://api.github.com/repos/2gis/k8s-handle/commits{/sha}","git_commits_url":"https://api.github.com/repos/2gis/k8s-handle/git/commits{/sha}","comments_url":"https://api.github.com/repos/2gis/k8s-handle/comments{/number}","issue_comment_url":"https://api.github.com/repos/2gis/k8s-handle/issues/comments{/number}","contents_url":"https://api.github.com/repos/2gis/k8s-handle/contents/{+path}","compare_url":"https://api.github.com/repos/2gis/k8s-handle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/2gis/k8s-handle/merges","archive_url":"https://api.github.com/repos/2gis/k8s-handle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/2gis/k8s-handle/downloads","issues_url":"https://api.github.com/repos/2gis/k8s-handle/issues{/number}","pulls_url":"https://api.github.com/repos/2gis/k8s-handle/pulls{/number}","milestones_url":"https://api.github.com/repos/2gis/k8s-handle/milestones{/number}","notifications_url":"https://api.github.com/repos/2gis/k8s-handle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/2gis/k8s-handle/labels{/name}","releases_url":"https://api.github.com/repos/2gis/k8s-handle/releases{/id}","deployments_url":"https://api.github.com/repos/2gis/k8s-handle/deployments","created_at":"2018-05-11T04:19:49Z","updated_at":"2018-10-15T04:32:43Z","pushed_at":"2018-10-16T04:58:28Z","git_url":"git://github.com/2gis/k8s-handle.git","ssh_url":"git@github.com:2gis/k8s-handle.git","clone_url":"https://github.com/2gis/k8s-handle.git","svn_url":"https://github.com/2gis/k8s-handle","homepage":null,"size":85,"stargazers_count":31,"watchers_count":31,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":12,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":3,"open_issues":12,"watchers":31,"default_branch":"master"}},"base":{"label":"2gis:master","ref":"master","sha":"0cb88e534466feb097731df23bc175f17d91ae8f","user":{"login":"2gis","id":1481435,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE0ODE0MzU=","avatar_url":"https://avatars2.githubusercontent.com/u/1481435?v=4","gravatar_id":"","url":"https://api.github.com/users/2gis","html_url":"https://github.com/2gis","followers_url":"https://api.github.com/users/2gis/followers","following_url":"https://api.github.com/users/2gis/following{/other_user}","gists_url":"https://api.github.com/users/2gis/gists{/gist_id}","starred_url":"https://api.github.com/users/2gis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/2gis/subscriptions","organizations_url":"https://api.github.com/users/2gis/orgs","repos_url":"https://api.github.com/users/2gis/repos","events_url":"https://api.github.com/users/2gis/events{/privacy}","received_events_url":"https://api.github.com/users/2gis/received_events","type":"Organization","site_admin":false},"repo":{"id":132988618,"node_id":"MDEwOlJlcG9zaXRvcnkxMzI5ODg2MTg=","name":"k8s-handle","full_name":"2gis/k8s-handle","private":false,"owner":{"login":"2gis","id":1481435,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE0ODE0MzU=","avatar_url":"https://avatars2.githubusercontent.com/u/1481435?v=4","gravatar_id":"","url":"https://api.github.com/users/2gis","html_url":"https://github.com/2gis","followers_url":"https://api.github.com/users/2gis/followers","following_url":"https://api.github.com/users/2gis/following{/other_user}","gists_url":"https://api.github.com/users/2gis/gists{/gist_id}","starred_url":"https://api.github.com/users/2gis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/2gis/subscriptions","organizations_url":"https://api.github.com/users/2gis/orgs","repos_url":"https://api.github.com/users/2gis/repos","events_url":"https://api.github.com/users/2gis/events{/privacy}","received_events_url":"https://api.github.com/users/2gis/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/2gis/k8s-handle","description":"Easy CI/CD for Kubernetes clusters with python and jinja2","fork":false,"url":"https://api.github.com/repos/2gis/k8s-handle","forks_url":"https://api.github.com/repos/2gis/k8s-handle/forks","keys_url":"https://api.github.com/repos/2gis/k8s-handle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/2gis/k8s-handle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/2gis/k8s-handle/teams","hooks_url":"https://api.github.com/repos/2gis/k8s-handle/hooks","issue_events_url":"https://api.github.com/repos/2gis/k8s-handle/issues/events{/number}","events_url":"https://api.github.com/repos/2gis/k8s-handle/events","assignees_url":"https://api.github.com/repos/2gis/k8s-handle/assignees{/user}","branches_url":"https://api.github.com/repos/2gis/k8s-handle/branches{/branch}","tags_url":"https://api.github.com/repos/2gis/k8s-handle/tags","blobs_url":"https://api.github.com/repos/2gis/k8s-handle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/2gis/k8s-handle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/2gis/k8s-handle/git/refs{/sha}","trees_url":"https://api.github.com/repos/2gis/k8s-handle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/2gis/k8s-handle/statuses/{sha}","languages_url":"https://api.github.com/repos/2gis/k8s-handle/languages","stargazers_url":"https://api.github.com/repos/2gis/k8s-handle/stargazers","contributors_url":"https://api.github.com/repos/2gis/k8s-handle/contributors","subscribers_url":"https://api.github.com/repos/2gis/k8s-handle/subscribers","subscription_url":"https://api.github.com/repos/2gis/k8s-handle/subscription","commits_url":"https://api.github.com/repos/2gis/k8s-handle/commits{/sha}","git_commits_url":"https://api.github.com/repos/2gis/k8s-handle/git/commits{/sha}","comments_url":"https://api.github.com/repos/2gis/k8s-handle/comments{/number}","issue_comment_url":"https://api.github.com/repos/2gis/k8s-handle/issues/comments{/number}","contents_url":"https://api.github.com/repos/2gis/k8s-handle/contents/{+path}","compare_url":"https://api.github.com/repos/2gis/k8s-handle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/2gis/k8s-handle/merges","archive_url":"https://api.github.com/repos/2gis/k8s-handle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/2gis/k8s-handle/downloads","issues_url":"https://api.github.com/repos/2gis/k8s-handle/issues{/number}","pulls_url":"https://api.github.com/repos/2gis/k8s-handle/pulls{/number}","milestones_url":"https://api.github.com/repos/2gis/k8s-handle/milestones{/number}","notifications_url":"https://api.github.com/repos/2gis/k8s-handle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/2gis/k8s-handle/labels{/name}","releases_url":"https://api.github.com/repos/2gis/k8s-handle/releases{/id}","deployments_url":"https://api.github.com/repos/2gis/k8s-handle/deployments","created_at":"2018-05-11T04:19:49Z","updated_at":"2018-10-15T04:32:43Z","pushed_at":"2018-10-16T04:58:28Z","git_url":"git://github.com/2gis/k8s-handle.git","ssh_url":"git@github.com:2gis/k8s-handle.git","clone_url":"https://github.com/2gis/k8s-handle.git","svn_url":"https://github.com/2gis/k8s-handle","homepage":null,"size":85,"stargazers_count":31,"watchers_count":31,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":12,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":3,"open_issues":12,"watchers":31,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/2gis/k8s-handle/pulls/48"},"html":{"href":"https://github.com/2gis/k8s-handle/pull/48"},"issue":{"href":"https://api.github.com/repos/2gis/k8s-handle/issues/48"},"comments":{"href":"https://api.github.com/repos/2gis/k8s-handle/issues/48/comments"},"review_comments":{"href":"https://api.github.com/repos/2gis/k8s-handle/pulls/48/comments"},"review_comment":{"href":"https://api.github.com/repos/2gis/k8s-handle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/2gis/k8s-handle/pulls/48/commits"},"statuses":{"href":"https://api.github.com/repos/2gis/k8s-handle/statuses/fda263ae3b42046395f864398e875b5d47d3f3c4"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"furiousassault"}}