Skip to content

Commit

Permalink
use append semantics for otherFields
Browse files Browse the repository at this point in the history
  • Loading branch information
EronWright committed May 24, 2024
1 parent 49dff94 commit 61789d5
Show file tree
Hide file tree
Showing 9 changed files with 871 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public U metadata(ObjectMetaArgs metadata) {
*
*/
public U otherFields(Map<String, ?> fields) {
var map = new LinkedHashMap<String, Output<?>>();
var map = $.otherFields != null ? new LinkedHashMap($.otherFields) : new LinkedHashMap<String, Output>();
for (var entry : fields.entrySet()) {
var value = entry.getValue();
map.put(entry.getKey(), (value instanceof Output) ? (Output) value : Output.of(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public U metadata(ObjectMetaPatchArgs metadata) {
*
*/
public U otherFields(Map<String, ?> fields) {
var map = new LinkedHashMap<String, Output<?>>();
var map = $.otherFields != null ? new LinkedHashMap($.otherFields) : new LinkedHashMap<String, Output>();
for (var entry : fields.entrySet()) {
var value = entry.getValue();
map.put(entry.getKey(), (value instanceof Output) ? (Output) value : Output.of(value));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// *** WARNING: this file was generated by pulumi-java-gen. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***

package com.pulumi.kubernetes.apiextensions;

import java.util.Optional;
import java.util.concurrent.ExecutionException;

import javax.annotation.Nullable;

import com.pulumi.core.Output;
import com.pulumi.core.annotations.Export;
import com.pulumi.core.annotations.ResourceType;
import com.pulumi.core.internal.Codegen;
import com.pulumi.core.internal.Internal;
import com.pulumi.core.internal.OutputInternal;
import com.pulumi.kubernetes.Utilities;
import com.pulumi.kubernetes.meta.v1.outputs.ObjectMeta;
import com.pulumi.resources.ResourceArgs;

/**
* CustomResource represents an instance of a CustomResourceDefinition (CRD). For example, the
* CoreOS Prometheus operator exposes a CRD `monitoring.coreos.com/ServiceMonitor`; to
* instantiate this as a Pulumi resource, one could call `new CustomResource`, passing the
* `ServiceMonitor` resource definition as an argument.
*/
@ResourceType(type="kubernetes:apiextensions:CustomResource")
public class CustomResource extends com.pulumi.resources.CustomResource {
/**
* APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
*
*/
@Export(name="apiVersion", refs={String.class}, tree="[0]")
private Output<String> apiVersion;

/**
* @return APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
*
*/
public Output<String> apiVersion() {
return this.apiVersion;
}

/**
* Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
*
*/
@Export(name="kind", refs={String.class}, tree="[0]")
private Output<String> kind;

/**
* @return Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
*
*/
public Output<String> kind() {
return this.kind;
}

/**
* Standard object&#39;s metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
*
*/
@Export(name="metadata", refs={ObjectMeta.class}, tree="[0]")
private Output<ObjectMeta> metadata;

/**
* @return Standard object&#39;s metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
*
*/
public Output<ObjectMeta> metadata() {
return this.metadata;
}

/**
*
* @param name The _unique_ name of the resulting resource.
*/
public CustomResource(String name) {
this(name, CustomResourceArgs.Empty);
}

/**
*
* @param name The _unique_ name of the resulting resource.
* @param args The arguments to use to populate this resource's properties.
*/
public CustomResource(String name, @Nullable CustomResourceArgsBase args) {
this(name, args, null);
}

/**
*
* @param name The _unique_ name of the resulting resource.
* @param args The arguments to use to populate this resource's properties.
* @param options A bag of options that control this resource's behavior.
*/
public CustomResource(String name, @Nullable CustomResourceArgsBase args, @Nullable com.pulumi.resources.CustomResourceOptions options) {
super(makeType(args), name, makeArgs(args), makeResourceOptions(options, Codegen.empty()));
}

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("");
String kind = args.kind().map(Internal::of).map(CustomResource::getOutputValue).orElse("");
return String.format("kubernetes:%s:%s", apiVersion, kind);
}

private static String getOutputValue(OutputInternal<String> o) {
try {
return o.getValueOrDefault("").get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}

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;
}
return Util.generateResourceArgs(args, args.otherFields().get());
}

private static com.pulumi.resources.CustomResourceOptions makeResourceOptions(
@Nullable com.pulumi.resources.CustomResourceOptions options, @Nullable Output<String> id) {
var defaultOptions = com.pulumi.resources.CustomResourceOptions.builder()
.version(Utilities.getVersion())
.build();
return com.pulumi.resources.CustomResourceOptions.merge(defaultOptions, options, id);
}

/**
* 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);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// *** WARNING: this file was generated by pulumi-java-gen. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***

package com.pulumi.kubernetes.apiextensions;

/**
* The set of arguments for constructing a CustomResource resource.
*
* NOTE: This type is fairly loose, since other than `apiVersion` and `kind`,
* there are no fields required across all CRDs. Use otherFields(...) to specify
* additional fields.
*/
public final class CustomResourceArgs extends CustomResourceArgsBase {

public static final CustomResourceArgs Empty = new CustomResourceArgs();

public static Builder builder() {
return new Builder();
}

public static Builder builder(CustomResourceArgs defaults) {
return new Builder(defaults);
}

public static final class Builder extends CustomResourceArgsBase.Builder<CustomResourceArgs, Builder> {
public Builder() {
super(new CustomResourceArgs());
}

public Builder(CustomResourceArgs defaults) {
super(new CustomResourceArgs(), defaults);
}
}
}

This file was deleted.

Loading

0 comments on commit 61789d5

Please sign in to comment.