Skip to content

Conversation

@addisonj
Copy link
Contributor

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 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.

Modifications

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.

Verifying this change

  • Make sure that the change passes the CI checks.

This commit adds some tests:

  • Adds tests for the kubernetes runtime with the default and custom implementation that validates the manifest files generated
  • passes existing unit tests

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

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): no
  • The public API: no
  • The schema: no
  • The default values of configurations: no
  • The wire protocol: yes, only of functions protobufs, adds a new field, customRuntimeOptions, which is a simple string
  • The rest endpoints: no
  • The admin cli options: yes, adds custom-runtime-options flags to the create/update commands for functions, sources, and sinks, which populates the above protobuf field
  • Anything that affects deployment: (yes / no / don't know)

Documentation

  • Does this pull request introduce a new feature? yes
  • If yes, how is the feature documented? yes, docs
  • If a feature is not applicable for documentation, explain why?
  • If a feature is not documented yet in this PR, please create a followup issue for adding the documentation

@addisonj
Copy link
Contributor Author

This conflicts with #5398, will need rebased if that is merged first

@addisonj
Copy link
Contributor Author

okay @jerrypeng I changed that, will see if I can get the tests happy, let me know if you have any other feedback!

@sijie sijie added this to the 2.5.0 milestone Oct 24, 2019
@sijie
Copy link
Member

sijie commented Oct 24, 2019

@addisonj Can you rebase this pull request?

@addisonj
Copy link
Contributor Author

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

@addisonj addisonj force-pushed the k8s_plugin branch 2 times, most recently from e106734 to 74e73cc Compare November 1, 2019 03:41
@addisonj
Copy link
Contributor Author

addisonj commented Nov 1, 2019

rerun java8 tests

@addisonj
Copy link
Contributor Author

addisonj commented Nov 1, 2019

rerun integration tests

@addisonj
Copy link
Contributor Author

addisonj commented Nov 1, 2019

@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.

@sijie
Copy link
Member

sijie commented Nov 5, 2019

@addisonj LGTM. Great change!

btw can you rebase this pull request?

@addisonj
Copy link
Contributor Author

addisonj commented Nov 8, 2019

rerun java8 tests

@addisonj
Copy link
Contributor Author

addisonj commented Nov 8, 2019

@sijie @jerrypeng this is ready for another look, let me know if you have any questions!

Copy link
Contributor

@jerrypeng jerrypeng left a 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.

@addisonj
Copy link
Contributor Author

addisonj commented Nov 9, 2019

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.

@jerrypeng
Copy link
Contributor

@addisonj also see if modiying "KubernetesFunctionAuthProvider/FunctionAuthProvider" interface to take in custom options can satisfy your use case.

@addisonj
Copy link
Contributor Author

addisonj commented Nov 9, 2019

Perhaps I am missing something, but I think there is a mismatch here. The FunctionRuntimeManager can manage the creation of the RuntimeCustomizer, but it couldn't be eagerly in it's constructor or initialization methods. It would need to be during the addAssignment and updateAssignment methods as that is the first place where we get the function details.

In other words, the FunctionRuntimeManager's lifecycle is such that it managed multiple functions and would need to have a factory method to create a RuntimeCustomizer for each function. This is essentially the problem with FunctionAuthProvider as it currently is created once for the whole runtime and instead needs to be per function.

Perhaps the RuntimeCustomizer could be responsible for the lifecycle of the FunctionAuthProvider as well, but their lifecycles would seem intertwined.

Let me know if I am missing something.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

@addisonj
Copy link
Contributor Author

@jerrypeng I ended up re-working this a fair amount to be more in-line with some of your ideas. Primarily:

  • created the RuntimeCustomizer class and had the KubernetesManifestCustomizer extend that class
  • the RuntimeCustomizer now gets created in the FunctionRuntimeManager and is passed to all RuntimeFactory classes
  • reverted the changes to how the FunctionAuthProvider gets created to also be back in FunctionRuntimeManager

To make this work, it required a few changes to some of the interfaces, primarily:

  • The FunctionAuthProvider now takes the FunctionDetails, this gives us all the data we need to effectively have the FunctionAuthProvider call the KubernetesManifestCustomizer so that we could get at the customRuntimeOptions which may change the namespace that secrets are created under. Additionally, this seems like a sane thing to do as now implementors of that interface get more data, which could be useful for different types of implementations
  • Made some small tweaks to the RuntimeFactory such that the returned FunctionAuthProvider and RuntimeCustomzer can be sub-classes of those classes that are specialized by implementing interfaces
  • Changed the KubernetesManifestCustomizer such that it only needs one instance of it as all the data needed to customize is passed via the methods (basically added FunctionDetails being passed to all calls)

@jerrypeng
Copy link
Contributor

@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.
@addisonj
Copy link
Contributor Author

@jerrypeng changes made, let me know if you have anything else, glad it shaped up well :)

@addisonj
Copy link
Contributor Author

rerun integration tests

1 similar comment
@addisonj
Copy link
Contributor Author

rerun integration tests

Copy link
Contributor

@jerrypeng jerrypeng left a 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!

@addisonj
Copy link
Contributor Author

@sijie if you have a second to merge this, that would be awesome :)

@sijie sijie merged commit 320cebe into apache:master Nov 14, 2019
@sijie
Copy link
Member

sijie commented Nov 14, 2019

@addisonj great contribution!

jerrypeng pushed a commit to jerrypeng/incubator-pulsar that referenced this pull request Dec 17, 2019
…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.
sijie added a commit to sijie/pulsar that referenced this pull request Jan 20, 2020
*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.
codelipenghui pushed a commit that referenced this pull request Jan 21, 2020
…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`.
tuteng pushed a commit to AmateurEvents/pulsar that referenced this pull request Feb 23, 2020
…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`.
tuteng pushed a commit to AmateurEvents/pulsar that referenced this pull request Mar 21, 2020
…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)
tuteng pushed a commit that referenced this pull request Apr 13, 2020
…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)
jiazhai pushed a commit to jiazhai/pulsar that referenced this pull request May 18, 2020
…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)
huangdx0726 pushed a commit to huangdx0726/pulsar that referenced this pull request Aug 24, 2020
…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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants