Skip to content

Commit

Permalink
codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
EronWright committed May 23, 2024
1 parent be47849 commit 4e4e91d
Showing 1 changed file with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ public CustomResource(String name, @Nullable CustomResourceArgsBase args, @Nulla
super(makeType(args), name, makeArgs(args), makeResourceOptions(options, Codegen.empty()));
}

// private CustomResource(String name, Output<String> id, @Nullable com.pulumi.resources.CustomResourceOptions options) {
// super(makeType(args), name, null, makeResourceOptions(options, id));
// }
protected CustomResource(String name, String apiVersion, String kind, Output<String> id,
@Nullable com.pulumi.resources.CustomResourceOptions options) {
super(String.format("kubernetes:%s:%s", apiVersion, kind), name, null, makeResourceOptions(options, id));
}

private static String makeType(@Nullable CustomResourceArgsBase args) {
String apiVersion = args.apiVersion().map(Internal::of).map(CustomResource::getOutputValue).orElse("");
Expand Down Expand Up @@ -148,12 +149,15 @@ private static ResourceArgs makeArgs(@Nullable CustomResourceArgsBase args) {
if (args == null) {
return null;
}
if (args.otherFields().isEmpty() || args.otherFields().get().isEmpty()) {
// optimization: if there are no "other" fields, we can just return the args as-is.
return args;
}

// collect the input properties from the annotated fields of the user-supplied args,
// plus the dynamic input properties within otherFields.
var imports = ImportMetadata.of(args.getClass());
var importFields =
imports.values().stream()
ImportMetadata.of(args.getClass()).values().stream()
.map(info -> new Field(info.getFieldOutput(args), Either.ofLeft(info.getAnnotation())));
var otherFields =
args.otherFields().orElseGet(Map::of).entrySet().stream()
Expand All @@ -165,7 +169,7 @@ private static ResourceArgs makeArgs(@Nullable CustomResourceArgsBase args) {

try {
// define a dynamic subclass of ResourceArgs with a field for each input property
// and a constructor that takes the property values as arguments.
// and a constructor that takes the property values and assigns them to the fields.
var t = new ByteBuddy().subclass(ResourceArgs.class);
Implementation.Composable c = MethodCall.invoke(ResourceArgs.class.getConstructor());

Expand Down Expand Up @@ -206,15 +210,19 @@ private static com.pulumi.resources.CustomResourceOptions makeResourceOptions(
return com.pulumi.resources.CustomResourceOptions.merge(defaultOptions, options, id);
}

// /**
// * Get an existing Host resource's state with the given name, ID, and optional extra
// * properties used to qualify the lookup.
// *
// * @param name The _unique_ name of the resulting resource.
// * @param id The _unique_ provider ID of the resource to lookup.
// * @param options Optional settings to control the behavior of the CustomResource.
// */
// public static CustomResource get(String name, Output<String> id, @Nullable com.pulumi.resources.CustomResourceOptions options) {
// return new CustomResource(name, id, options);
// }
/**
* Get the state of an existing `CustomResource` resource, as identified by `id`.
* Typically this ID is of the form [namespace]/[name]; if [namespace] is omitted,
* then (per Kubernetes convention) the ID becomes default/[name].
*
* @param name The _unique_ name of the resulting resource.
* @param apiVersion The API version of the CustomResource we wish to select, as defined by the CRD.
* @param kind The kind of the CustomResource we wish to select, as defined by the CRD.
* @param id An ID for the Kubernetes resource to retrieve.
* @param options Optional settings to control the behavior of the CustomResource.
*/
public static CustomResource get(String name, String apiVersion, String kind, Output<String> id,
@Nullable com.pulumi.resources.CustomResourceOptions options) {
return new CustomResource(name, apiVersion, kind, id, options);
}
}

0 comments on commit 4e4e91d

Please sign in to comment.