-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR implements a new `ConfigFile` resource (v2) as a Pulumi multi-language component (MLC). The new resource is offered side-by-side with the existing (v1) resource; it is not a drop-in replacement at this time. Some notable differences with respect to the previous (overlay) implementations: 1. Implemented as an MLC to have a consistent implementation across SDKs and to extend support for YAML and Java. 2. The component name is used as a prefix for the child resource names. Use the `resourcePrefix` property to override. Note that the `resourcePrefix` is not applied to the Kubernetes object names. 4. Transformations aren't supported (yet). Support for Pulumi-style transformation is being tracked [here](pulumi/pulumi#12996), and Kubernetes-style transformation may come in future. 5. The `file` property is required and the file must exist. Closes #2785
- Loading branch information
1 parent
6951ed5
commit c59ddff
Showing
22 changed files
with
1,236 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
ConfigFile creates a set of Kubernetes resources from a Kubernetes YAML file. | ||
|
||
{{% examples %}} | ||
## Example Usage | ||
{{% example %}} | ||
### Local File | ||
|
||
```typescript | ||
import * as k8s from "@pulumi/kubernetes"; | ||
|
||
const example = new k8s.yaml.v2.ConfigFile("example", { | ||
file: "foo.yaml", | ||
}); | ||
``` | ||
```python | ||
from pulumi_kubernetes.yaml.v2 import ConfigFile | ||
|
||
example = ConfigFile( | ||
"example", | ||
file="foo.yaml", | ||
) | ||
``` | ||
```csharp | ||
using System.Threading.Tasks; | ||
using Pulumi; | ||
using Pulumi.Kubernetes.Yaml.V2; | ||
|
||
class YamlStack : Stack | ||
{ | ||
public YamlStack() | ||
{ | ||
var helloWorld = new ConfigFile("example", new ConfigFileArgs | ||
{ | ||
File = "foo.yaml", | ||
}); | ||
} | ||
} | ||
``` | ||
```go | ||
package main | ||
|
||
import ( | ||
yamlv2 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/yaml/v2" | ||
"github.com/pulumi/pulumi/sdk/v3/go/pulumi" | ||
) | ||
|
||
func main() { | ||
pulumi.Run(func(ctx *pulumi.Context) error { | ||
_, err := yamlv2.NewConfigFile(ctx, "example", | ||
&yamlv2.ConfigFileArgs{ | ||
File: "foo.yaml", | ||
}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}) | ||
} | ||
``` | ||
{{% /example %}} | ||
{% /examples %}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2016-2024, Pulumi Corporation. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package v2 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/clients" | ||
providerresource "github.com/pulumi/pulumi-kubernetes/provider/v4/pkg/provider/resource" | ||
"github.com/pulumi/pulumi/sdk/v3/go/pulumi" | ||
"github.com/pulumi/pulumi/sdk/v3/go/pulumi/internals" | ||
pulumiprovider "github.com/pulumi/pulumi/sdk/v3/go/pulumi/provider" | ||
) | ||
|
||
type ConfigFileProvider struct { | ||
clientSet *clients.DynamicClientSet | ||
} | ||
|
||
type ConfigFileArgs struct { | ||
File pulumi.StringInput `pulumi:"file"` | ||
ResourcePrefix pulumi.StringInput `pulumi:"resourcePrefix,optional"` | ||
SkipAwait pulumi.BoolInput `pulumi:"skipAwait,optional"` | ||
} | ||
|
||
type ConfigFileState struct { | ||
pulumi.ResourceState | ||
Resources pulumi.ArrayOutput `pulumi:"resources"` | ||
} | ||
|
||
var _ providerresource.ResourceProvider = &ConfigFileProvider{} | ||
|
||
func NewConfigFileProvider(opts *providerresource.ResourceProviderOptions) providerresource.ResourceProvider { | ||
return &ConfigFileProvider{ | ||
clientSet: opts.ClientSet, | ||
} | ||
} | ||
|
||
func (k *ConfigFileProvider) Construct(ctx *pulumi.Context, typ, name string, inputs pulumiprovider.ConstructInputs, options pulumi.ResourceOption) (*pulumiprovider.ConstructResult, error) { | ||
comp := &ConfigFileState{} | ||
err := ctx.RegisterComponentResource(typ, name, comp, options) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
args := &ConfigFileArgs{} | ||
if err := inputs.CopyTo(args); err != nil { | ||
return nil, fmt.Errorf("setting args: %w", err) | ||
} | ||
|
||
// Check if all the required args are known, and print a warning if not. | ||
result, err := internals.UnsafeAwaitOutput(ctx.Context(), pulumi.All( | ||
args.File, args.ResourcePrefix, args.SkipAwait)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !result.Known { | ||
msg := fmt.Sprintf("%s:%s -- Required input properties have unknown values. Preview is incomplete.\n", typ, name) | ||
_ = ctx.Log.Warn(msg, nil) | ||
} | ||
|
||
// Parse the manifest(s) and register the resources. | ||
|
||
comp.Resources = pulumi.All(args.File, args.ResourcePrefix, args.SkipAwait).ApplyTWithContext(ctx.Context(), func(_ context.Context, args []any) (pulumi.ArrayOutput, error) { | ||
// make type assertions to get each value (or the zero value) | ||
file, _ := args[0].(string) | ||
resourcePrefix, hasResourcePrefix := args[1].(string) | ||
skipAwait, _ := args[2].(bool) | ||
|
||
if !hasResourcePrefix { | ||
// use the name of the ConfigFile as the resource prefix to ensure uniqueness | ||
// across multiple instances of the component resource. | ||
resourcePrefix = name | ||
} | ||
|
||
return ParseDecodeYamlFiles(ctx, &ParseArgs{ | ||
Files: []string{file}, | ||
ResourcePrefix: resourcePrefix, | ||
SkipAwait: skipAwait, | ||
}, false, k.clientSet, pulumi.Parent(comp)) | ||
}).(pulumi.ArrayOutput) | ||
|
||
// issue: https://github.com/pulumi/pulumi/issues/15527 | ||
_, _ = internals.UnsafeAwaitOutput(ctx.Context(), comp.Resources) | ||
|
||
return pulumiprovider.NewConstructResult(comp) | ||
} |
Oops, something went wrong.