Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong Helm release name character limit #418

Merged
merged 6 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/docs/user/migration-guide/v2-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

KPOps handles long (more than 53 characters) Helm releases names differently. Helm will not find your (long) old release names anymore. Therefore, it is recommended that you should once destroy your pipeline with KPOps v2 to remove old Helm release names. After a clean destroy, re-deploy your pipeline with the KPOps v3.

For example if you have a component with the Helm release name `example-component-name-too-long-fake-fakefakefakefakefake`. The new release name will shorten the original name to 52 characters and then replace the last 6 characters of the trimmed name with the first 5 characters of the result of SHA-1(helm_release_name).
For example if you have a component with the Helm release name `example-component-name-too-long-fake-fakefakefakefakefake`. The new release name will shorten the original name to 53 characters and then replace the last 6 characters of the trimmed name with the first 5 characters of the result of SHA-1(helm_release_name).

<!-- dprint-ignore-start -->

```console
example-component-name-too-long-fake-fakefakef-0a7fc ----> 52 chars
example-component-name-too-long-fake-fakefakef-0a7fc ----> 53 chars
---------------------------------------------- -----
^Shortened helm_release_name ^first 5 characters of SHA1(helm_release_name)
```
Expand Down
11 changes: 6 additions & 5 deletions kpops/component_handlers/helm_wrapper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
log = logging.getLogger("HelmUtils")

ENCODING = "utf-8"
RELEASE_NAME_MAX_LEN = 52
RELEASE_NAME_MAX_LEN = 53


def create_helm_release_name(name: str, suffix: str = "") -> str:
"""Shortens the long Helm release name.

Creates a 52 character long release name if the name length exceeds the Helm release character length.
It first trims the string and fetches the first RELEASE_NAME_MAX_LEN - len(suffix) characters.
Then it replaces the last 6 characters with the SHA-1 encoded string (with "-") to avoid collision
and append the suffix if given.
Helm has a limit of 53 characters for release names.
If the name exceeds the character limit:
1. trim the string and fetch the first RELEASE_NAME_MAX_LEN - len(suffix) characters.
2. replace the last 6 characters with the SHA-1 encoded string (with "-") to avoid collision
3. append the suffix if given

:param name: The Helm release name to be shortened.
:param suffix: The release suffix to preserve
Expand Down
6 changes: 3 additions & 3 deletions tests/component_handlers/helm_wrapper/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def test_helm_release_name_for_long_names():

actual_release_name = create_helm_release_name(long_release_name)

expected_helm_release_name = "example-component-name-too-long-fake-fakefakef-0a7fc"
expected_helm_release_name = "example-component-name-too-long-fake-fakefakefa-0a7fc"
assert expected_helm_release_name == actual_release_name
assert len(expected_helm_release_name) == 52
assert len(expected_helm_release_name) == 53


def test_helm_release_name_for_install_and_clean_must_be_different():
Expand All @@ -30,4 +30,4 @@ def test_helm_release_name_for_short_names():
actual_helm_release_name = create_helm_release_name(short_release_name)

assert actual_helm_release_name == short_release_name
assert len(actual_helm_release_name) < 53
assert len(actual_helm_release_name) <= 53
2 changes: 1 addition & 1 deletion tests/components/test_kafka_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
CONNECTOR_NAME = "test-connector-with-long-name-0123456789abcdefghijklmnop"
CONNECTOR_FULL_NAME = "${pipeline.name}-" + CONNECTOR_NAME
CONNECTOR_CLEAN_FULL_NAME = CONNECTOR_FULL_NAME + "-clean"
CONNECTOR_CLEAN_RELEASE_NAME = "${pipeline.name}-test-connector-with-lon-612f3-clean"
CONNECTOR_CLEAN_RELEASE_NAME = "${pipeline.name}-test-connector-with-long-612f3-clean"
CONNECTOR_CLASS = "com.bakdata.connect.TestConnector"
RESETTER_NAMESPACE = "test-namespace"

Expand Down
Loading