1. Packages
  2. Kubernetes
  3. API Docs
  4. kustomize
  5. Directory
Kubernetes v4.18.3 published on Thursday, Oct 31, 2024 by Pulumi

kubernetes.kustomize.Directory

Explore with Pulumi AI

kubernetes logo
Kubernetes v4.18.3 published on Thursday, Oct 31, 2024 by Pulumi
    A newer version of this resource is available as kubernetes.kustomize/v2.Directory.

    Directory is a component representing a collection of resources described by a kustomize directory (kustomization).

    This resource is provided for the following languages: Node.js (JavaScript, TypeScript), Python, Go, and .NET (C#, F#, VB).

    Example Usage

    Local Kustomize Directory

    using System.Threading.Tasks;
    using Pulumi;
    using Pulumi.Kubernetes.Kustomize;
    
    class KustomizeStack : Stack
    {
        public KustomizeStack()
        {
            var helloWorld = new Directory("helloWorldLocal", new DirectoryArgs
            {
                Directory = "./helloWorld",
            });
        }
    }
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/kustomize"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := kustomize.NewDirectory(ctx, "helloWorldLocal",
    			kustomize.DirectoryArgs{
    				Directory: pulumi.String("./helloWorld"),
    			},
    		)
    		if err != nil {
    			return err
    		}
    
    		return nil
    	})
    }
    

    Coming soon!

    from pulumi_kubernetes.kustomize import Directory
    
    hello_world = Directory(
        "hello-world-local",
        directory="./helloWorld",
    )
    
    import * as k8s from "@pulumi/kubernetes";
    
    const helloWorld = new k8s.kustomize.Directory("helloWorldLocal", {
        directory: "./helloWorld",
    });
    

    Coming soon!

    Kustomize Directory from a Git Repo

    using System.Threading.Tasks;
    using Pulumi;
    using Pulumi.Kubernetes.Kustomize;
    
    class KustomizeStack : Stack
    {
        public KustomizeStack()
        {
            var helloWorld = new Directory("helloWorldRemote", new DirectoryArgs
            {
                Directory = "https://github.com/kubernetes-sigs/kustomize/tree/v3.3.1/examples/helloWorld",
            });
        }
    }
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/kustomize"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := kustomize.NewDirectory(ctx, "helloWorldRemote",
    			kustomize.DirectoryArgs{
    				Directory: pulumi.String("https://github.com/kubernetes-sigs/kustomize/tree/v3.3.1/examples/helloWorld"),
    			},
    		)
    		if err != nil {
    			return err
    		}
    
    		return nil
    	})
    }
    

    Coming soon!

    from pulumi_kubernetes.kustomize import Directory
    
    hello_world = Directory(
        "hello-world-remote",
        directory="https://github.com/kubernetes-sigs/kustomize/tree/v3.3.1/examples/helloWorld",
    )
    
    import * as k8s from "@pulumi/kubernetes";
    
    const helloWorld = new k8s.kustomize.Directory("helloWorldRemote", {
        directory: "https://github.com/kubernetes-sigs/kustomize/tree/v3.3.1/examples/helloWorld",
    });
    

    Coming soon!

    Kustomize Directory with Transformations

    using System.Collections.Generic;
    using System.Collections.Immutable;
    using System.Threading.Tasks;
    using Pulumi;
    using Pulumi.Kubernetes.Kustomize;
    
    class KustomizeStack : Stack
    {
        public KustomizeStack()
        {
            var helloWorld = new Directory("helloWorldRemote", new DirectoryArgs
            {
                Directory = "https://github.com/kubernetes-sigs/kustomize/tree/v3.3.1/examples/helloWorld",
                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;
            }
        }
    }
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/kustomize"
    	"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/yaml"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := kustomize.NewDirectory(ctx, "helloWorldRemote",
    			kustomize.DirectoryArgs{
    				Directory: pulumi.String("https://github.com/kubernetes-sigs/kustomize/tree/v3.3.1/examples/helloWorld"),
    				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
    	})
    }
    

    Coming soon!

    from pulumi_kubernetes.helm.v3 import Chart, ChartOpts, FetchOpts
    
    # 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"
    
    
    hello_world = Directory(
        "hello-world-remote",
        directory="https://github.com/kubernetes-sigs/kustomize/tree/v3.3.1/examples/helloWorld",
        transformations=[make_service_private, alias, omit_resource],
    )
    
    import * as k8s from "@pulumi/kubernetes";
    
    const helloWorld = new k8s.kustomize.Directory("helloWorldRemote", {
        directory: "https://github.com/kubernetes-sigs/kustomize/tree/v3.3.1/examples/helloWorld",
        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"
                }
            },
        ],
    });
    

    Coming soon!

    Create Directory Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new Directory(name: string, args: DirectoryOpts, opts?: ComponentResourceOptions);
    @overload
    def Directory(directory,
                  opts=None,
                  transformations=None,
                  resource_prefix=None)
    
    @overload
    def Directory(directory,
                  opts=None,
                  transformations=None,
                  resource_prefix=None)
    func NewDirectory(ctx *Context, name string, args DirectoryArgs, opts ...ResourceOption) (*Directory, error)
    public Directory(string name, DirectoryArgs args, ComponentResourceOptions? opts = null)
    public Directory(String name, DirectoryArgs args)
    public Directory(String name, DirectoryArgs args, ComponentResourceOptions options)
    
    type: kubernetes:kustomize:Directory
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args DirectoryOpts
    The arguments to resource properties.
    opts ComponentResourceOptions
    Bag of options to control resource's behavior.
    directory
    opts
    transformations
    resource_prefix
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args DirectoryArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args DirectoryArgs
    The arguments to resource properties.
    opts ComponentResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args DirectoryArgs
    The arguments to resource properties.
    options ComponentResourceOptions
    Bag of options to control resource's behavior.

    Directory Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    The Directory resource accepts the following input properties:

    Directory string
    The directory containing the kustomization to apply. The value can be a local directory or a folder in a git repository. Example: ./helloWorld Example: https://github.com/kubernetes-sigs/kustomize/tree/master/examples/helloWorld
    ResourcePrefix string
    An optional prefix for the auto-generated resource names. Example: A resource created with resourcePrefix="foo" would produce a resource named "foo-resourceName".
    Transformations List<object>
    A set of transformations to apply to Kubernetes resource definitions before registering with engine.
    Directory string
    The directory containing the kustomization to apply. The value can be a local directory or a folder in a git repository. Example: ./helloWorld Example: https://github.com/kubernetes-sigs/kustomize/tree/master/examples/helloWorld
    ResourcePrefix string
    An optional prefix for the auto-generated resource names. Example: A resource created with resourcePrefix="foo" would produce a resource named "foo-resourceName".
    Transformations []interface{}
    A set of transformations to apply to Kubernetes resource definitions before registering with engine.
    directory String
    The directory containing the kustomization to apply. The value can be a local directory or a folder in a git repository. Example: ./helloWorld Example: https://github.com/kubernetes-sigs/kustomize/tree/master/examples/helloWorld
    resourcePrefix String
    An optional prefix for the auto-generated resource names. Example: A resource created with resourcePrefix="foo" would produce a resource named "foo-resourceName".
    transformations List<Object>
    A set of transformations to apply to Kubernetes resource definitions before registering with engine.
    directory string
    The directory containing the kustomization to apply. The value can be a local directory or a folder in a git repository. Example: ./helloWorld Example: https://github.com/kubernetes-sigs/kustomize/tree/master/examples/helloWorld
    resourcePrefix string
    An optional prefix for the auto-generated resource names. Example: A resource created with resourcePrefix="foo" would produce a resource named "foo-resourceName".
    transformations any[]
    A set of transformations to apply to Kubernetes resource definitions before registering with engine.
    directory str
    The directory containing the kustomization to apply. The value can be a local directory or a folder in a git repository. Example: ./helloWorld Example: https://github.com/kubernetes-sigs/kustomize/tree/master/examples/helloWorld
    resource_prefix str
    An optional prefix for the auto-generated resource names. Example: A resource created with resourcePrefix="foo" would produce a resource named "foo-resourceName".
    transformations Sequence[Any]
    A set of transformations to apply to Kubernetes resource definitions before registering with engine.
    directory String
    The directory containing the kustomization to apply. The value can be a local directory or a folder in a git repository. Example: ./helloWorld Example: https://github.com/kubernetes-sigs/kustomize/tree/master/examples/helloWorld
    resourcePrefix String
    An optional prefix for the auto-generated resource names. Example: A resource created with resourcePrefix="foo" would produce a resource named "foo-resourceName".
    transformations List<Any>
    A set of transformations to apply to Kubernetes resource definitions before registering with engine.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the Directory resource produces the following output properties:

    Package Details

    Repository
    Kubernetes pulumi/pulumi-kubernetes
    License
    Apache-2.0
    kubernetes logo
    Kubernetes v4.18.3 published on Thursday, Oct 31, 2024 by Pulumi