Skip to content

Commit

Permalink
simplify yaml property
Browse files Browse the repository at this point in the history
  • Loading branch information
EronWright committed Mar 8, 2024
1 parent b8757d7 commit 006dd0d
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 429 deletions.
50 changes: 13 additions & 37 deletions provider/cmd/pulumi-resource-kubernetes/schema.json

Large diffs are not rendered by default.

44 changes: 10 additions & 34 deletions provider/pkg/gen/overlays.go
Original file line number Diff line number Diff line change
Expand Up @@ -1170,35 +1170,21 @@ var yamlConfigGroupV2Resource = pschema.ResourceSpec{
InputProperties: map[string]pschema.PropertySpec{
"files": {
TypeSpec: pschema.TypeSpec{
OneOf: []pschema.TypeSpec{
{
Type: "string",
},
{
Type: "array",
Items: &pschema.TypeSpec{
Type: "string",
},
},
Type: "array",
Items: &pschema.TypeSpec{
Type: "string",
},
},
Description: "Set of paths or a URLs that uniquely identify files.",
Description: "Set of paths and/or URLs to Kubernetes manifest files. Supports glob patterns.",
},
"objs": {
TypeSpec: pschema.TypeSpec{
OneOf: []pschema.TypeSpec{
{
Ref: "pulumi.json#/Any",
},
{
Type: "array",
Items: &pschema.TypeSpec{
Ref: "pulumi.json#/Any",
},
},
Type: "array",
Items: &pschema.TypeSpec{
Ref: "pulumi.json#/Any",
},
},
Description: "Objects representing Kubernetes resources.",
Description: "Objects representing Kubernetes resource configurations.",
},
"resourcePrefix": {
TypeSpec: pschema.TypeSpec{
Expand All @@ -1214,19 +1200,9 @@ var yamlConfigGroupV2Resource = pschema.ResourceSpec{
},
"yaml": {
TypeSpec: pschema.TypeSpec{
OneOf: []pschema.TypeSpec{
{
Type: "string",
},
{
Type: "array",
Items: &pschema.TypeSpec{
Type: "string",
},
},
},
Type: "string",
},
Description: "YAML text containing Kubernetes manifest(s).",
Description: "A Kubernetes YAML manifest containing Kubernetes resource configuration(s).",
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions provider/pkg/provider/yaml/v2/configgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type ConfigGroupProvider struct {

type ConfigGroupArgs struct {
Files pulumi.StringArrayInput `pulumi:"files"`
YAML pulumi.StringArrayInput `pulumi:"yaml,optional"`
YAML pulumi.StringInput `pulumi:"yaml,optional"`
Objects pulumi.MapArrayInput `pulumi:"objs,optional"`
ResourcePrefix pulumi.StringInput `pulumi:"resourcePrefix,optional"`
SkipAwait pulumi.BoolInput `pulumi:"skipAwait,optional"`
Expand Down Expand Up @@ -80,7 +80,7 @@ func (k *ConfigGroupProvider) Construct(ctx *pulumi.Context, typ, name string, i
// make type assertions to get each value (or the zero value)
// note: "objects" contains unwrapped values at this point
files, _ := args[0].([]string)
yaml, _ := args[1].([]string)
yaml, _ := args[1].(string)
objects, _ := args[2].([]map[string]any)
resourcePrefix, hasResourcePrefix := args[3].(string)
skipAwait, _ := args[4].(bool)
Expand Down
4 changes: 2 additions & 2 deletions provider/pkg/provider/yaml/v2/configgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ var _ = Describe("Construct", func() {
Describe("yamls", func() {
Context("when the input is a valid YAML", func() {
BeforeEach(func() {
inputs["yaml"] = resource.NewArrayProperty([]resource.PropertyValue{resource.NewStringProperty(manifest)})
inputs["yaml"] = resource.NewStringProperty(manifest)
})
commonAssertions()
})
Expand Down Expand Up @@ -161,7 +161,7 @@ var _ = Describe("Construct", func() {
Context("when the input value(s) are unknown", func() {
BeforeEach(func() {
req.DryRun = true
inputs["yaml"] = resource.MakeComputed(resource.NewArrayProperty([]resource.PropertyValue{resource.NewStringProperty("")}))
inputs["yaml"] = resource.MakeComputed(resource.NewStringProperty(""))
})

It("should emit a warning", func(ctx context.Context) {
Expand Down
4 changes: 2 additions & 2 deletions provider/pkg/provider/yaml/v2/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (

type ParseArgs struct {
Files []string
YAML []string
YAML string
Objects []unstructured.Unstructured
ResourcePrefix string
SkipAwait bool
Expand All @@ -52,7 +52,7 @@ func ParseDecodeYamlFiles(ctx *pulumi.Context, args *ParseArgs, glob bool, clien
objs = append(objs, args.Objects...)

// Continue by gathering any other YAML from files provided.
yamls := args.YAML
yamls := []string{args.YAML}
for _, file := range args.Files {
// Read the raw YAML file(s) specified in the input file parameter. It might be a URL or a file path.
var yaml []byte
Expand Down
4 changes: 2 additions & 2 deletions provider/pkg/provider/yaml/v2/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ var _ = Describe("ParseDecodeYamlFiles", func() {
Describe("yamls", func() {
Context("when the input is a valid YAML string", func() {
BeforeEach(func() {
args.YAML = []string{manifest}
args.YAML = manifest
})
commonAssertions()
})

Context("when the manifest is empty", func() {
BeforeEach(func() {
args.YAML = []string{`---`}
args.YAML = "---"
})
It("should do nothing", func(ctx context.Context) {
_, err := parse(ctx)
Expand Down
96 changes: 20 additions & 76 deletions sdk/dotnet/Yaml/V2/ConfigGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,74 +109,6 @@ namespace Pulumi.Kubernetes.Yaml.V2
/// }
/// }
/// ```
/// ### YAML with Transformations
/// ```csharp
/// using System.Collections.Generic;
/// using System.Collections.Immutable;
/// using System.Threading.Tasks;
/// using Pulumi;
/// using Pulumi.Kubernetes.Yaml.V2;
///
/// class YamlStack : Stack
/// {
/// public YamlStack()
/// {
/// var helloWorld = new ConfigGroup("example", new ConfigGroupArgs
/// {
/// Files = new[] { "foo.yaml" },
/// Transformations =
/// {
/// LoadBalancerToClusterIP,
/// ResourceAlias,
/// OmitTestPod,
/// }
/// });
///
/// // Make every service private to the cluster, i.e., turn all services into ClusterIP instead of LoadBalancer.
/// ImmutableDictionary<string, object> LoadBalancerToClusterIP(ImmutableDictionary<string, object> obj, CustomResourceOptions opts)
/// {
/// if ((string)obj["kind"] == "Service" && (string)obj["apiVersion"] == "v1")
/// {
/// var spec = (ImmutableDictionary<string, object>)obj["spec"];
/// if (spec != null && (string)spec["type"] == "LoadBalancer")
/// {
/// return obj.SetItem("spec", spec.SetItem("type", "ClusterIP"));
/// }
/// }
///
/// return obj;
/// }
///
/// // Set a resource alias for a previous name.
/// ImmutableDictionary<string, object> ResourceAlias(ImmutableDictionary<string, object> obj, CustomResourceOptions opts)
/// {
/// if ((string)obj["kind"] == "Deployment")
/// {
/// opts.Aliases.Add(new Alias { Name = "oldName" });
/// }
///
/// return obj;
/// }
///
/// // Omit a resource from the Chart by transforming the specified resource definition to an empty List.
/// ImmutableDictionary<string, object> OmitTestPod(ImmutableDictionary<string, object> obj, CustomResourceOptions opts)
/// {
/// var metadata = (ImmutableDictionary<string, object>)obj["metadata"];
/// if ((string)obj["kind"] == "Pod" && (string)metadata["name"] == "test")
/// {
/// return new Dictionary<string, object>
/// {
/// ["apiVersion"] = "v1",
/// ["kind"] = "List",
/// ["items"] = new Dictionary<string, object>(),
/// }.ToImmutableDictionary();
/// }
///
/// return obj;
/// }
/// }
/// }
/// ```
/// {% /examples %}}
/// </summary>
[KubernetesResourceType("kubernetes:yaml/v2:ConfigGroup")]
Expand Down Expand Up @@ -219,17 +151,29 @@ namespace Pulumi.Kubernetes.Types.Inputs.Yaml.V2

public class ConfigGroupArgs : global::Pulumi.ResourceArgs
{
/// <summary>
/// Set of paths or a URLs that uniquely identify files.
/// </summary>
[Input("files")]
public InputUnion<string, ImmutableArray<string>>? Files { get; set; }
private InputList<string>? _files;

/// <summary>
/// Objects representing Kubernetes resources.
/// Set of paths and/or URLs to Kubernetes manifest files. Supports glob patterns.
/// </summary>
public InputList<string> Files
{
get => _files ?? (_files = new InputList<string>());
set => _files = value;
}

[Input("objs")]
public InputUnion<object, ImmutableArray<object>>? Objs { get; set; }
private InputList<object>? _objs;

/// <summary>
/// Objects representing Kubernetes resource configurations.
/// </summary>
public InputList<object> Objs
{
get => _objs ?? (_objs = new InputList<object>());
set => _objs = value;
}

/// <summary>
/// A prefix for the auto-generated resource names. Defaults to the name of the ConfigGroup. Example: A resource created with resourcePrefix="foo" would produce a resource named "foo-resourceName".
Expand All @@ -244,10 +188,10 @@ public class ConfigGroupArgs : global::Pulumi.ResourceArgs
public Input<bool>? SkipAwait { get; set; }

/// <summary>
/// YAML text containing Kubernetes manifest(s).
/// A Kubernetes YAML manifest containing Kubernetes resource configuration(s).
/// </summary>
[Input("yaml")]
public InputUnion<string, ImmutableArray<string>>? Yaml { get; set; }
public Input<string>? Yaml { get; set; }

public ConfigGroupArgs()
{
Expand Down
83 changes: 12 additions & 71 deletions sdk/go/kubernetes/yaml/v2/configGroup.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 006dd0d

Please sign in to comment.