-
Notifications
You must be signed in to change notification settings - Fork 115
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
CustomResource for Java SDK #3020
Conversation
Does the PR have any schema changes?Looking good! No breaking changes found. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3020 +/- ##
==========================================
- Coverage 36.47% 36.43% -0.04%
==========================================
Files 70 70
Lines 9163 9167 +4
==========================================
- Hits 3342 3340 -2
- Misses 5492 5497 +5
- Partials 329 330 +1 ☔ View full report in Codecov by Sentry. |
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.
No strong opinion on this, but FWIW, I noticed that the dotnet provider doesn't have an "untyped" option, you always have to subclass the CustomResourceArgs
class, so there's precedent here for just doing what's easiest if we're shy about adding the dependency.
...pkg/gen/java-templates/src/main/java/com/pulumi/kubernetes/apiextensions/CustomResource.java
Outdated
Show resolved
Hide resolved
I'm advocating for supporting the untyped option because the typed option is heavyweight to use, given you must develop or generate custom input/output types. I don't have any concerns about using bytebuddy but felt I should solicit feedback. If at some point in the future we enhance the core SDK to support dynamic input values, I do believe the codegen stuff will simply fall away. |
sdk/java/src/main/java/com/pulumi/kubernetes/apiextensions/CustomResource.java
Show resolved
Hide resolved
...pkg/gen/java-templates/src/main/java/com/pulumi/kubernetes/apiextensions/CustomResource.java
Outdated
Show resolved
Hide resolved
This looks good! Assuming this can't be schematized so needs an overlay. This is unfortunate but may be an easy-ish fix in the Java SDK that can unlock this and other scenarios, let's maybe track it and consider that for Java SDK GA?
|
This PR has been shipped in release v4.13.1. |
Proposed changes
Implements
CustomResource
for Java SDK as an overlay, for parity with other SDKs. An overlay is necessary for this reason.Features
Supports two usage modes. Note that each SDK is slightly different in which mode(s) it supports.
CustomResource
directly and set arbitrary fields on the object.CustomResource
to create a strongly-typed wrapper representing a CRD.A "Patch" variant is also provided.
Provides a "getter" method in both untyped and typed mode. Note that the patch variant doesn't have a getter in most SDKs.
Summary of Changes
examples/java/customresource
apiextensions.CustomResource
apiextensions.CustomResourcePatch
net.bytebuddy:byte-buddy:1.14.15
com.google.guava:guava:32.1.2-jre
(used by core already)TODOs:
Get
method (untyped and typed)Related issues (optional)
Closes #2787
API
CustomResource
- to be used directly or subclassed to expose typed output propertiesCustomResourceArgs
- the final class to be used directly in the untyped use-caseCustomResourceArgsBase
- the abstract base class for custom resource args, to expose typed input propertiesCustomResourceArgsBase.Builder<T,B>
- the base class for your custom args builderCustomResourcePatch
- to be used directly or subclassed to expose typed output propertiesCustomResourcePatchArgs
- the final class to be used directly in the untyped use-caseCustomResourcePatchArgsBase
- the abstract base class for custom resource args, to expose typed input propertiesCustomResourcePatchArgsBase.Builder<T,B>
- the base class for your custom args builderImplementation Details
Working with Untyped Inputs
The core Pulumi Java SDK has no support for dynamic inputs; it relies exclusively on reflection of the supplied
InputArgs
subclass (see:InputArgs::toMapAsync
). To support the "untyped" mode, this implementation codegens a class at runtime using bytebuddy.Builder Inheritance
The Java SDK leans on the fluent builder pattern, and there are special challenges in designing a builder that is amenable to inheritance. This implementation uses generics as seen here.
Example
Here's an example program to deploy two cert-manager issuers.
issuer1
is untyped, and callsotherFields(...)
on the builder to set thespec
.issuer2
is typed, callsspec(...)
on a subclassed builder to set thespec
, and uses the typedspec
output. Note that theapiVersion
andkind
are set automatically.The code seen in
Inputs
andOutputs
section would, in practice, be generated by pulumi-java-gen based on a schema file.The untyped and typed getter variants are also demonstrated.
Gives the expected output: