-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[functions] Allow functions to pass runtime specific options #5400
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
Conversation
|
This conflicts with #5398, will need rebased if that is merged first |
...ions/runtime/src/main/java/org/apache/pulsar/functions/runtime/KubernetesRuntimeFactory.java
Outdated
Show resolved
Hide resolved
|
okay @jerrypeng I changed that, will see if I can get the tests happy, let me know if you have any other feedback! |
|
@addisonj Can you rebase this pull request? |
|
I started in on re-working this... the changes introduced in #5404 broke one of the assumptions this made, which was that we create new instances of the functionAuthProvider, with a specific one for any overridden namespace. @jerrypeng do you see any problem with pushing the creation of the FunctionAuthProvider (via reflection) into the KubernetesRuntimeFactory? Or should we move the namespace used elsewhere? This provides a lot more flexibility to end users as being able to isolate various tenants to their own k8s namespace for functions can be use for finer grain isolation of underlying resources. Would love to get this one through this week, but just want to make sure I am aligned in how to go about this |
e106734 to
74e73cc
Compare
|
rerun java8 tests |
|
rerun integration tests |
|
@jerrypeng @sijie I reworked this to account for the changes from #5404, I think it seems pretty reasonable. If you could give another review and let me know if there is anything else you want to see here. |
|
@addisonj LGTM. Great change! btw can you rebase this pull request? |
|
rerun java8 tests |
|
@sijie @jerrypeng this is ready for another look, let me know if you have any questions! |
...unctions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionRuntimeManager.java
Outdated
Show resolved
Hide resolved
...e/src/main/java/org/apache/pulsar/functions/runtime/kubernetes/KubernetesRuntimeFactory.java
Outdated
Show resolved
Hide resolved
...e/src/main/java/org/apache/pulsar/functions/runtime/kubernetes/KubernetesRuntimeFactory.java
Outdated
Show resolved
Hide resolved
...e/src/main/java/org/apache/pulsar/functions/runtime/kubernetes/KubernetesRuntimeFactory.java
Outdated
Show resolved
Hide resolved
...ime/src/main/java/org/apache/pulsar/functions/runtime/BasicKubernetesManifestCustomizer.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@addisonj thanks for working on this! We need something like this. I left a couple of comments on changes I don't think is relevant to this PR.
I would recommend we have a generic interface for customizing runtime configurations. The current implementation really deals with kubernetes but I see this feature could be useful for other runtimes.
I would suggest we have a base interface something like below:
interface RuntimeCustomizer {
public void init(Function.FunctionDetails funcDetails)
}
and all customizers would be based on this. The customizer would be created and initialized in FunctionRuntimeManager and the customizer would be passed into the configured runtime regardless of what runtime it is. In the runtime e.g. kubernetes we can check if this object implements a specific customizer for the runtime e.g. KubernetesRuntimeCustomizer. This will allow the customizer to be more generic. For thread and process runtime factory, for now we can pass in the customizer but just ignore it, maybe later we can add support for it.
Another thing is do we need this new customizer interface? or can we reuse the "KubernetesFunctionAuthProvider/FunctionAuthProvider" interface? All we really need is pass in custom options to the init method. This interface allows rewriting the whole statefulset.
|
I considered such an approach, but wasn't sure if that was something that made sense for other providers. Will take a look at refactoring this to support that. However, I do believe the changes (or som other changes) to KubernetesFunctionAuthProvider are necessary such that the namespace in which the secret is created can be overridden by the customizer. |
|
@addisonj also see if modiying "KubernetesFunctionAuthProvider/FunctionAuthProvider" interface to take in custom options can satisfy your use case. |
|
Perhaps I am missing something, but I think there is a mismatch here. The In other words, the Perhaps the Let me know if I am missing something. |
...s/runtime/src/main/java/org/apache/pulsar/functions/auth/KubernetesFunctionAuthProvider.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes to these methods allow us the flexibility we need to have implementations of this interface, primarily the KubernetesSecretTokenAuthProvider, have all context it needs to make sure that secrets it generates match the kubenetes namespace the function actually gets deployed too.
This also seems like a reasonable thing to do so that implementations of this interface can have more context about the function for custom implementations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change allows implementations of this interface to provide a more specific FunctionAuthProvider, which reduces the need for casting
|
@jerrypeng I ended up re-working this a fair amount to be more in-line with some of your ideas. Primarily:
To make this work, it required a few changes to some of the interfaces, primarily:
|
...r-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/RuntimeCustomizer.java
Outdated
Show resolved
Hide resolved
|
@addisonj thanks for taking the time to rework some of this PR! It looks really good. I left some comments. |
This commit adds a new argument for functions, customRuntimeOptions, which is passed to funcions (as well as sources/sinks) that enables the ability to customize the runtime via the `RuntimeCustomizer` class. This is added primarily to support the `KubernetesManifestCustomizer` interface. This interface has a default implementation, which allows for changing the namespace, labels, and annotations per function. For the other runtimes (Process and Thread runtimes) the `RuntimeCustomizer` is basically a no-op but is plumbed through for future customizations. This interface is also pluggable, allowing for more customizable implementations. For example, the functions for a given tenant could be mapped to different pools of compute for isolation.
|
@jerrypeng changes made, let me know if you have anything else, glad it shaped up well :) |
|
rerun integration tests |
1 similar comment
|
rerun integration tests |
jerrypeng
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@addisonj LGTM thanks again for working on this!
|
@sijie if you have a second to merge this, that would be awesome :) |
|
@addisonj great contribution! |
…5400) This commit adds a new argument for functions, customRuntimeOptions, which is passed to funcions (as well as sources/sinks) that enables the ability to customize the runtime. This is added primarily to support the `KubernetesManifestCustomizer` interface. This interface is intended, as the name indicates, allows for customizing how the kubernetes manifests are generated before they are sent off to the k8s cluster. This interface has a default implementation, which allows for changing the namespace, labels, nodeSelector labels, and toleratations per function. This interface is also pluggable, allowing for more customized implementations. For example, the functions for a given tenant could be mapped to different pools of compute for isolation. For the CLI and protobufs, the modifications just involve plumbing through the new option, `customRuntimeOptions` through the relevant code. For kubernetes runtime, the modifications are fairly straight forward, adding a new configuration option, `kubernetesManifestCustomizerClassName` and `kubernetesManifestCustomizerConfig` which are options under the kubernetes runtime.
*Motivation* apache#5400 introduces `customRuntimeOptions` in function details. But the description was wrong. The mistake was probably introduced by bad merges. *Modification* Fix the argument and description for `deadletterTopic` and `customRuntimeOptions`. *Tests* Add a unit test to ensure the parameters are set correctly.
…ng (apache#6101) *Motivation* Related to apache#6084 apache#5400 introduces `customRuntimeOptions` in function details. But the description was wrong. The mistake was probably introduced by bad merges. *Modification* Fix the argument and description for `deadletterTopic` and `customRuntimeOptions`.
…ng (apache#6101) *Motivation* Related to apache#6084 apache#5400 introduces `customRuntimeOptions` in function details. But the description was wrong. The mistake was probably introduced by bad merges. *Modification* Fix the argument and description for `deadletterTopic` and `customRuntimeOptions`. (cherry picked from commit c6e258d)
…ng (#6101) *Motivation* Related to #6084 #5400 introduces `customRuntimeOptions` in function details. But the description was wrong. The mistake was probably introduced by bad merges. *Modification* Fix the argument and description for `deadletterTopic` and `customRuntimeOptions`. (cherry picked from commit c6e258d)
…ng (apache#6101) *Motivation* Related to apache#6084 apache#5400 introduces `customRuntimeOptions` in function details. But the description was wrong. The mistake was probably introduced by bad merges. *Modification* Fix the argument and description for `deadletterTopic` and `customRuntimeOptions`. (cherry picked from commit c6e258d)
…ng (apache#6101) *Motivation* Related to apache#6084 apache#5400 introduces `customRuntimeOptions` in function details. But the description was wrong. The mistake was probably introduced by bad merges. *Modification* Fix the argument and description for `deadletterTopic` and `customRuntimeOptions`.
Motivation
This commit adds a new argument for functions, customRuntimeOptions, which is passed to
funcions (as well as sources/sinks) that enables the ability to
customize the runtime.
This is added primarily to support the
KubernetesManifestCustomizerinterface. This interface is intended, as the name indicates, allows for
customizing how the kubernetes manifests are generated before they
are sent off to the k8s cluster.
This interface has a default implementation, which allows for
changing the namespace, labels, nodeSelector labels, and toleratations per function.
This interface is also pluggable, allowing for more customized
implementations. For example, the functions for a given tenant could be
mapped to different pools of compute for isolation.
Modifications
For the CLI and protobufs, the modifications just involve plumbing through the new option,
customRuntimeOptionsthrough the relevant code.For kubernetes runtime, the modifications are fairly straight forward, adding a new configuration option,
kubernetesManifestCustomizerClassNameandkubernetesManifestCustomizerConfigwhich are options under the kubernetes runtime.Verifying this change
This commit adds some tests:
Does this pull request potentially affect one of the following parts:
If
yeswas chosen, please highlight the changescustom-runtime-optionsflags to the create/update commands for functions, sources, and sinks, which populates the above protobuf fieldDocumentation