Esempio n. 1
0
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)
Esempio n. 2
0
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()
Esempio n. 3
0
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
Esempio n. 4
0
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())
Esempio n. 5
0
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())
Esempio n. 6
0
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())
Esempio n. 7
0
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())
Esempio n. 8
0
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())
Esempio n. 9
0
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())
Esempio n. 10
0
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())
Esempio n. 11
0
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())
Esempio n. 12
0
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"
        )
Esempio n. 13
0
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())
Esempio n. 14
0
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]