-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eabb570
commit 453c191
Showing
28 changed files
with
2,571 additions
and
23 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,254 @@ | ||
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.ConfigFile("example", { | ||
file: "foo.yaml", | ||
}); | ||
``` | ||
```python | ||
from pulumi_kubernetes.yaml import ConfigFile | ||
|
||
example = ConfigFile( | ||
"example", | ||
file="foo.yaml", | ||
) | ||
``` | ||
```csharp | ||
using System.Threading.Tasks; | ||
using Pulumi; | ||
using Pulumi.Kubernetes.Yaml; | ||
|
||
class YamlStack : Stack | ||
{ | ||
public YamlStack() | ||
{ | ||
var helloWorld = new ConfigFile("example", new ConfigFileArgs | ||
{ | ||
File = "foo.yaml", | ||
}); | ||
} | ||
} | ||
``` | ||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/yaml" | ||
"github.com/pulumi/pulumi/sdk/v3/go/pulumi" | ||
) | ||
|
||
func main() { | ||
pulumi.Run(func(ctx *pulumi.Context) error { | ||
_, err := yaml.NewConfigFile(ctx, "example", | ||
&yaml.ConfigFileArgs{ | ||
File: "foo.yaml", | ||
}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}) | ||
} | ||
``` | ||
{{% /example %}} | ||
{{% example %}} | ||
### YAML with Transformations | ||
|
||
```typescript | ||
import * as k8s from "@pulumi/kubernetes"; | ||
|
||
const example = new k8s.yaml.ConfigFile("example", { | ||
file: "foo.yaml", | ||
transformations: [ | ||
// Make every service private to the cluster, i.e., turn all services into ClusterIP instead of LoadBalancer. | ||
(obj: any, opts: pulumi.CustomResourceOptions) => { | ||
if (obj.kind === "Service" && obj.apiVersion === "v1") { | ||
if (obj.spec && obj.spec.type && obj.spec.type === "LoadBalancer") { | ||
obj.spec.type = "ClusterIP"; | ||
} | ||
} | ||
}, | ||
|
||
// Set a resource alias for a previous name. | ||
(obj: any, opts: pulumi.CustomResourceOptions) => { | ||
if (obj.kind === "Deployment") { | ||
opts.aliases = [{name: "oldName"}] | ||
} | ||
}, | ||
|
||
// Omit a resource from the Chart by transforming the specified resource definition to an empty List. | ||
(obj: any, opts: pulumi.CustomResourceOptions) => { | ||
if (obj.kind === "Pod" && obj.metadata.name === "test") { | ||
obj.apiVersion = "v1" | ||
obj.kind = "List" | ||
} | ||
}, | ||
], | ||
}); | ||
``` | ||
```python | ||
from pulumi_kubernetes.yaml import ConfigFile | ||
|
||
# Make every service private to the cluster, i.e., turn all services into ClusterIP instead of LoadBalancer. | ||
def make_service_private(obj, opts): | ||
if obj["kind"] == "Service" and obj["apiVersion"] == "v1": | ||
try: | ||
t = obj["spec"]["type"] | ||
if t == "LoadBalancer": | ||
obj["spec"]["type"] = "ClusterIP" | ||
except KeyError: | ||
pass | ||
|
||
|
||
# Set a resource alias for a previous name. | ||
def alias(obj, opts): | ||
if obj["kind"] == "Deployment": | ||
opts.aliases = ["oldName"] | ||
|
||
|
||
# Omit a resource from the Chart by transforming the specified resource definition to an empty List. | ||
def omit_resource(obj, opts): | ||
if obj["kind"] == "Pod" and obj["metadata"]["name"] == "test": | ||
obj["apiVersion"] = "v1" | ||
obj["kind"] = "List" | ||
|
||
|
||
example = ConfigFile( | ||
"example", | ||
file="foo.yaml", | ||
transformations=[make_service_private, alias, omit_resource], | ||
) | ||
``` | ||
```csharp | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Threading.Tasks; | ||
using Pulumi; | ||
using Pulumi.Kubernetes.Yaml; | ||
|
||
class YamlStack : Stack | ||
{ | ||
public YamlStack() | ||
{ | ||
var helloWorld = new ConfigFile("example", new ConfigFileArgs | ||
{ | ||
File = "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 = new List<Input<Alias>> { 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; | ||
} | ||
} | ||
} | ||
``` | ||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/yaml" | ||
"github.com/pulumi/pulumi/sdk/v3/go/pulumi" | ||
) | ||
|
||
func main() { | ||
pulumi.Run(func(ctx *pulumi.Context) error { | ||
_, err := yaml.NewConfigFile(ctx, "example", | ||
&yaml.ConfigFileArgs{ | ||
File: "foo.yaml", | ||
Transformations: []yaml.Transformation{ | ||
// Make every service private to the cluster, i.e., turn all services into ClusterIP | ||
// instead of LoadBalancer. | ||
func(state map[string]interface{}, opts ...pulumi.ResourceOption) { | ||
if state["kind"] == "Service" { | ||
spec := state["spec"].(map[string]interface{}) | ||
spec["type"] = "ClusterIP" | ||
} | ||
}, | ||
|
||
// Set a resource alias for a previous name. | ||
func(state map[string]interface{}, opts ...pulumi.ResourceOption) { | ||
if state["kind"] == "Deployment" { | ||
aliases := pulumi.Aliases([]pulumi.Alias{ | ||
{ | ||
Name: pulumi.String("oldName"), | ||
}, | ||
}) | ||
opts = append(opts, aliases) | ||
} | ||
}, | ||
|
||
// Omit a resource from the Chart by transforming the specified resource definition | ||
// to an empty List. | ||
func(state map[string]interface{}, opts ...pulumi.ResourceOption) { | ||
name := state["metadata"].(map[string]interface{})["name"] | ||
if state["kind"] == "Pod" && name == "test" { | ||
state["apiVersion"] = "core/v1" | ||
state["kind"] = "List" | ||
} | ||
}, | ||
}, | ||
}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}) | ||
} | ||
``` | ||
{{% /example %}} | ||
{% /examples %}} |
Oops, something went wrong.