def chart_updater( git_url, git_branch, git_path, git_user, git_email, git_timeout, git_ssh_identity, helm_repo_url, helm_repo_user, helm_repo_password, sync_interval, annotation_prefix, ): git = Git( git_url, git_branch, git_path, git_user, git_email, git_timeout, git_ssh_identity, ) chart = HelmRepo(helm_repo_url, helm_repo_user, helm_repo_password) updater = Updater(git, chart, sync_interval, annotation_prefix, event=event) updater.start() serve(app, host="0.0.0.0", port=3030)
def test_does_not_crash_on_exception(): GIT_REPO = "[email protected]:rossumai/_non_existing_repo_" with patch("chart_updater.git.run") as run: run.side_effect = subprocess.TimeoutExpired("cmd", 1) updater = Updater(Git(GIT_REPO), HelmRepo(HELM_REPO_URL)) updater.update_loop(one_shot=True) run.assert_called_once()
def test_chart_no_relevant_annotations(empty_git_repo, requests_mock): _add_manifest(MANIFEST_NO_RELEVANT_ANNOTATIONS) _init_commit() requests_mock.get(HELM_REPO_INDEX, text=CHART_REPO_INDEX_WITH_NEW_CHARTS) updater = Updater(Git(empty_git_repo), HelmRepo(HELM_REPO_URL)) updater.update_loop(one_shot=True) assert _get_manifest() == MANIFEST_NO_RELEVANT_ANNOTATIONS
def test_no_chart_tag(empty_git_repo): _add_manifest(MANIFEST_WITHOUT_CHART_VERSION_PATTERN) _init_commit() updater = Updater(Git(empty_git_repo), HelmRepo("mock://")) updater.update_loop(one_shot=True) assert _get_manifest() == MANIFEST_WITHOUT_CHART_VERSION_PATTERN assert re.search(INITIAL_COMMIT_RE, _last_commit())
def test_no_annotation(empty_git_repo): _add_manifest(MANIFEST_WITHOUT_ANNOTATION) _init_commit() updater = Updater(Git(empty_git_repo), HelmRepo("mock://")) updater.update_loop(one_shot=True) assert _get_manifest() == MANIFEST_WITHOUT_ANNOTATION assert re.search(INITIAL_COMMIT_RE, _last_commit())
def test_chart_updated_flux2(empty_git_repo, requests_mock): _add_manifest(MANIFEST_WITH_FLUX2) _init_commit() requests_mock.get(HELM_REPO_INDEX, text=CHART_REPO_INDEX_WITH_NEW_CHARTS) updater = Updater(Git(empty_git_repo), HelmRepo(HELM_REPO_URL)) updater.update_loop(one_shot=True) assert _get_manifest() == UPDATED_MANIFEST_WITH_FLUX2 assert re.search(CHART_RELEASE_COMMIT_RE, _last_commit())
def test_multiple_images_updated(empty_git_repo, requests_mock): _add_manifest(MANIFEST_WITH_MULTIPLE_IMAGES) _init_commit() requests_mock.get(HELM_REPO_INDEX, text=CHART_REPO_INDEX_WITH_NEW_CHARTS) updater = Updater(Git(empty_git_repo), HelmRepo(HELM_REPO_URL)) updater.update_loop(one_shot=True) assert _get_manifest() == UPDATED_MANIFEST_WITH_MULTIPLE_IMAGES assert re.search(MULTIPLE_IMAGES_RELEASE_COMMIT_RE, _last_commit())
def test_no_new_chart(empty_git_repo, requests_mock): _add_manifest(MANIFEST_WITH_GLOB_PATTERN) _init_commit() requests_mock.get(HELM_REPO_INDEX, text=CHART_REPO_INDEX_WITH_OLD_CHARTS) updater = Updater(Git(empty_git_repo), HelmRepo(HELM_REPO_URL)) updater.update_loop(one_shot=True) assert _get_manifest() == MANIFEST_WITH_GLOB_PATTERN assert re.search(INITIAL_COMMIT_RE, _last_commit())
def test_chart_updated_manifest_inside_path(empty_git_repo, requests_mock): mkdir("deploy") _add_manifest(MANIFEST_WITH_GLOB_PATTERN, path="deploy/helmrelease.yaml") _init_commit() requests_mock.get(HELM_REPO_INDEX, text=CHART_REPO_INDEX_WITH_NEW_CHARTS) updater = Updater(Git(empty_git_repo, git_path="deploy/"), HelmRepo(HELM_REPO_URL)) updater.update_loop(one_shot=True) assert (_get_manifest("deploy/helmrelease.yaml") == UPDATED_MANIFEST_WITH_GLOB_PATTERN) assert re.search(CHART_RELEASE_COMMIT_RE, _last_commit())
def test_chart_not_updated_manifest_outside_of_path(empty_git_repo, requests_mock): mkdir("deploy") _add_manifest(MANIFEST_WITH_GLOB_PATTERN) _init_commit() requests_mock.get(HELM_REPO_INDEX, text=CHART_REPO_INDEX_WITH_NEW_CHARTS) updater = Updater(Git(empty_git_repo, git_path="deploy/"), HelmRepo(HELM_REPO_URL)) updater.update_loop(one_shot=True) assert _get_manifest() == MANIFEST_WITH_GLOB_PATTERN assert re.search(INITIAL_COMMIT_RE, _last_commit())
def test_does_not_crash_for_empty_annotation(empty_git_repo, requests_mock): _add_manifest(MANIFEST_EMPTY, path="1-empty.yaml") _add_manifest(MANIFEST_WITH_SINGLE_IMAGE, path="2-helmrelease.yaml") _init_commit() requests_mock.get(HELM_REPO_INDEX, text=CHART_REPO_INDEX_WITH_NEW_CHARTS) updater = Updater(Git(empty_git_repo), HelmRepo(HELM_REPO_URL)) updater.update_loop(one_shot=True) assert _get_manifest("1-empty.yaml") == MANIFEST_EMPTY assert _get_manifest( "2-helmrelease.yaml") == UPDATED_MANIFEST_WITH_SINGLE_IMAGE assert re.search(SINGLE_IMAGE_RELEASE_COMMIT_RE, _last_commit())
def test_git_over_ssh(): GIT_REPO = "[email protected]:rossumai/_non_existing_repo_" with NamedTemporaryFile(mode="w") as tmp, patch("chart_updater.git.run") as run: run.return_value = Mock(returncode=111, stdout="Some error") updater = Updater( Git(GIT_REPO, git_ssh_identity=tmp.name), HelmRepo(HELM_REPO_URL) ) updater.update_loop(one_shot=True) run.assert_called_once() assert run.call_args.args[0][0:3] == ["git", "clone", GIT_REPO] assert ( run.call_args.kwargs["env"]["GIT_SSH_COMMAND"] == f"ssh -i {tmp.name} -o StrictHostKeyChecking=yes" )
def test_does_not_crash_for_multidoc(empty_git_repo, requests_mock): mkdir("deploy") _add_manifest(MANIFEST_WITH_MULTIPLE_DOCUMENTS, path="deploy/1-multi.yaml") _add_manifest(MANIFEST_WITH_SINGLE_IMAGE, path="deploy/2-helmrelease.yaml") _init_commit() requests_mock.get(HELM_REPO_INDEX, text=CHART_REPO_INDEX_WITH_NEW_CHARTS) updater = Updater(Git(empty_git_repo), HelmRepo(HELM_REPO_URL)) updater.update_loop(one_shot=True) assert _get_manifest( "deploy/1-multi.yaml") == MANIFEST_WITH_MULTIPLE_DOCUMENTS assert (_get_manifest("deploy/2-helmrelease.yaml") == UPDATED_MANIFEST_WITH_SINGLE_IMAGE) assert re.search(SINGLE_IMAGE_RELEASE_COMMIT_RE, _last_commit())
def test_git_over_https(monkeypatch): GIT_AUTHUSER = "******" GIT_AUTHKEY = "test_pw" GIT_REPO = ( "https://${GIT_AUTHUSER}:${GIT_AUTHKEY}@github.com/rossumai/_non_existing_repo_" ) GIT_REPO_RESOLVED = ( f"https://{GIT_AUTHUSER}:{GIT_AUTHKEY}@github.com/rossumai/_non_existing_repo_" ) monkeypatch.setenv("GIT_AUTHUSER", GIT_AUTHUSER) monkeypatch.setenv("GIT_AUTHKEY", GIT_AUTHKEY) with patch("chart_updater.git.run") as run: run.return_value = Mock(returncode=111, stdout="Some error") updater = Updater(Git(GIT_REPO), HelmRepo(HELM_REPO_URL)) updater.update_loop(one_shot=True) run.assert_called_once() assert run.call_args.args[0][0:3] == ["git", "clone", GIT_REPO_RESOLVED]