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

[Issue 9360][pulsar-functions] kubernetes runtime functions create rfc1123 compliant labels #9556

Conversation

jdbeck
Copy link
Contributor

@jdbeck jdbeck commented Feb 10, 2021

Fixes #9360

Motivation

Currently, it's valid to (via pulsar-admin and the admin rest api) specify names that include the colon ':' character. For example, I can create a namespace via pulsar-admin and the rest api as something like 'my:example:namespace'. We've found this useful for purposes of adding structure to object names that is then easier to programmatically parse.

We've been able to use this format with no problems with the ProcessRuntime for deploying functions.

The KubernetesRuntime, however, is currently not compatible with pulsar object names that are not compliant with RFC1123, because KubernetesRuntime attempts to use these object names verbatim in the labels it attaches to the resource specifications.
Trying to use the KubernetesRuntime with the name format described above prevents the functions from deploying successfully.

Modifications

Changed the KubernetesRuntime to translate the names of the pulsar objects to forms that are RFC1123-compliant for k8s resource labels.

The rules for translating the Pulsar object names are:

  • truncate to 63 chars
  • replace any non alphanumeric character ([a-z0-9A-Z]), dashes (-), underscores(_), dot(.) with "-"
  • replace beginning & end non alphanumeric character with "0"

This change added tests and can be verified as follows:

  • Added an extra test to KubernetesRuntimeTest.java to make sure labels are created that are RFC1123-compliant AND also make sure the labels are no bigger than the k8s limit of 63 chars

Does this pull request potentially affect one of the following parts:

  • NONE - should be transparent to anyone using the Kubernetes function runtime.

Documentation

  • NONE needed

@jdbeck
Copy link
Contributor Author

jdbeck commented Feb 10, 2021

/pulsarbot run-failure-checks

1 similar comment
@jdbeck
Copy link
Contributor Author

jdbeck commented Feb 11, 2021

/pulsarbot run-failure-checks

@sijie sijie added area/function type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages labels Feb 11, 2021
@sijie sijie added this to the 2.8.0 milestone Feb 11, 2021
@sijie
Copy link
Member

sijie commented Feb 11, 2021

@freeznet @nlu90 Can you review this pull request?

Copy link
Member

@nlu90 nlu90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if the PR describes the specific rule of updating label values. I add it here for future reference:

  • truncate to 63 chars
  • replace any non alphanumeric character ([a-z0-9A-Z]), dashes (-), underscores(_), dot(.) with "-"
  • replace beginning & end non alphanumeric character with "0"

@sijie sijie added the doc-required Your PR changes impact docs and you will update later. label Feb 16, 2021
@sijie
Copy link
Member

sijie commented Feb 16, 2021

@nlu90 Great suggestion! I have updated the rules to the PR description.

@sijie sijie merged commit 5763c0e into apache:master Feb 16, 2021
Copy link
Contributor

@freeznet freeznet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Anonymitaet
Copy link
Member

Hi @jdbeck

Currently, we have related docs here.

Should we update the doc? I've made some suggestions here. Please correct me if my understanding is wrong, thanks.

@codelipenghui codelipenghui added the cherry-picked/branch-2.7 Archived: 2.7 is end of life label Feb 18, 2021
codelipenghui pushed a commit that referenced this pull request Feb 18, 2021
…c1123 compliant labels (#9556)

Fixes #9360

### Motivation

Currently, it's valid to (via pulsar-admin and the admin rest api) specify names that include the colon ':' character. For example, I can create a namespace via pulsar-admin and the rest api as something like 'my:example:namespace'. We've found this useful for purposes of adding structure to object names that is then easier to programmatically parse.

We've been able to use this format with no problems with the ProcessRuntime for deploying functions.

The KubernetesRuntime, however, is currently not compatible with pulsar object names that are not compliant with RFC1123, because KubernetesRuntime attempts to use these object names verbatim in the labels it attaches to the resource specifications.
Trying to use the KubernetesRuntime with the name format described above prevents the functions from deploying successfully.

### Modifications

Changed the KubernetesRuntime to translate the names of the pulsar objects to forms that are RFC1123-compliant for k8s resource labels. 

The rules for translating the Pulsar object names are:
- truncate to 63 chars
- replace any non alphanumeric character ([a-z0-9A-Z]), dashes (-), underscores(_), dot(.) with "-"
- replace beginning & end non-alphanumeric character with "0"

This change added tests and can be verified as follows:
  - Added an extra test to KubernetesRuntimeTest.java to make sure labels are created that are RFC1123-compliant AND also make sure the labels are no bigger than the k8s limit of 63 chars

(cherry picked from commit 5763c0e)
@jdbeck
Copy link
Contributor Author

jdbeck commented Feb 19, 2021

Hi @Anonymitaet,

That looks good. Your suggestions for the updates are correct.

I'm also wondering if you should mention or link to this document as well: https://pulsar.apache.org/docs/en/next/functions-runtime/

It contains other useful information for making sure you setup your pulsar resources correctly to work within Kubernetes without issue. You could point out the customizable options in CustomRuntimeOptions for 'JobName' and 'JobNamespace'. Having those available can also help a user not run into k8s issues with pod names being too long by default (pf---<function_name>) if you have defined long tenant, namespace, and function names in Pulsar when creating functions on the Kubernetes runtime.

@Anonymitaet
Copy link
Member

Hi @jdbeck many thanks for your explanations, I've updated the doc accordingly, could you please help review #9651? Thanks again

@Anonymitaet
Copy link
Member

Done in #9651

@Anonymitaet Anonymitaet removed the doc-required Your PR changes impact docs and you will update later. label Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/function cherry-picked/branch-2.7 Archived: 2.7 is end of life release/2.7.1 type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Projects
None yet
7 participants