yaml

package
Version: v3.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2021 License: Apache-2.0 Imports: 59 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseYamlObjects

func ParseYamlObjects(ctx *pulumi.Context, objs []map[string]interface{}, transformations []Transformation,
	resourcePrefix string, opts ...pulumi.ResourceOption,
) (map[string]pulumi.Resource, error)

Types

type ConfigFile

type ConfigFile struct {
	pulumi.ResourceState

	Resources map[string]pulumi.Resource
}

ConfigFile creates a set of Kubernetes resources from a Kubernetes YAML file.

## Example Usage ### Local File

“`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
})

} “` ### YAML with Transformations

“`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
})

} “`

func NewConfigFile

func NewConfigFile(ctx *pulumi.Context,
	name string, args *ConfigFileArgs, opts ...pulumi.ResourceOption) (*ConfigFile, error)

NewConfigFile registers a new resource with the given unique name, arguments, and options.

func (*ConfigFile) GetResource

func (cf *ConfigFile) GetResource(gvk, name, namespace string) pulumi.Resource

GetResource returns a resource defined by a built-in Kubernetes group/version/kind, name and namespace. For example, GetResource("v1/Pod", "foo", "") would return a Pod called "foo" from the "default" namespace.

type ConfigFileArgs

type ConfigFileArgs struct {
	// File is a path or URL that uniquely identifies a file.
	File string
	// Transformations is an optional list of transformations to apply to Kubernetes resource definitions
	// before registering with the engine.
	Transformations []Transformation
	// ResourcePrefix is an optional prefix for the auto-generated resource names. For example, a resource named `bar`
	// created with resource prefix of `"foo"` would produce a resource named `"foo-bar"`.
	ResourcePrefix string
	// Skip await logic for all resources in this YAML. Resources will be marked ready as soon as they are created.
	// Warning: This option should not be used if you have resources depending on Outputs from the YAML.
	SkipAwait bool
}

The set of arguments for constructing a ConfigFile resource.

type ConfigGroup

type ConfigGroup struct {
	pulumi.ResourceState

	Resources map[string]pulumi.Resource
}

ConfigGroup creates a set of Kubernetes resources from Kubernetes YAML. The YAML text may be supplied using any of the following formats:

1. Using a filename or a list of filenames: 2. Using a file pattern or a list of file patterns: 3. Using a literal string containing YAML, or a list of such strings: 4. Any combination of files, patterns, or YAML strings:

## Example Usage ### Local File

“`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.NewConfigGroup(ctx, "example",
        &yaml.ConfigGroupArgs{
            Files: []string{"foo.yaml"},
        },
    )
    if err != nil {
        return err
    }

    return nil
})

} “` ### Multiple Local Files

“`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.NewConfigGroup(ctx, "example",
        &yaml.ConfigGroupArgs{
            Files: []string{"foo.yaml", "bar.yaml"},
        },
    )
    if err != nil {
        return err
    }

    return nil
})

} “` ### Local File Pattern

“`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.NewConfigGroup(ctx, "example",
        &yaml.ConfigGroupArgs{
            Files: []string{"yaml/*.yaml"},
        },
    )
    if err != nil {
        return err
    }

    return nil
})

} “` ### Multiple Local File Patterns

“`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.NewConfigGroup(ctx, "example",
        &yaml.ConfigGroupArgs{
            Files: []string{"yaml/*.yaml", "bar/*.yaml"},
        },
    )
    if err != nil {
        return err
    }

    return nil
})

} “` ### Literal YAML String

“`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.NewConfigGroup(ctx, "example",
        &yaml.ConfigGroupArgs{
            YAML: []string{
                `

apiVersion: v1 kind: Namespace metadata:

name: foo

`,

            },
        })
    if err != nil {
        return err
    }

    return nil
})

} “` ### YAML with Transformations

“`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.NewConfigGroup(ctx, "example",
        &yaml.ConfigGroupArgs{
            Files: []string{"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
})

} “`

func NewConfigGroup

func NewConfigGroup(ctx *pulumi.Context,
	name string, args *ConfigGroupArgs, opts ...pulumi.ResourceOption) (*ConfigGroup, error)

NewConfigGroup registers a new resource with the given unique name, arguments, and options.

func (*ConfigGroup) GetResource

func (cf *ConfigGroup) GetResource(gvk, name, namespace string) pulumi.Resource

GetResource returns a resource defined by a built-in Kubernetes group/version/kind, name and namespace. For example, GetResource("v1/Pod", "foo", "") would return a Pod called "foo" from the "default" namespace.

type ConfigGroupArgs

type ConfigGroupArgs struct {
	// Files is a set of paths, globs, or URLs that uniquely identify files.
	Files []string
	// YAML is list of strings containing Kubernetes resource definitions in YAML.
	YAML []string
	// Objs is a collection of object maps representing Kubernetes resources.
	Objs []map[string]interface{}
	// Transformations is an optional list of transformations to apply to Kubernetes resource definitions
	// before registering with the engine.
	Transformations []Transformation
	// ResourcePrefix is an optional prefix for the auto-generated resource names. For example, a resource named `bar`
	// created with resource prefix of `"foo"` would produce a resource named `"foo-bar"`.
	ResourcePrefix string
	// Skip await logic for all resources in this YAML. Resources will be marked ready as soon as they are created.
	// Warning: This option should not be used if you have resources depending on Outputs from the YAML.
	SkipAwait bool
}

The set of arguments for constructing a ConfigGroup resource.

type Transformation

type Transformation = func(state map[string]interface{}, opts ...pulumi.ResourceOption)

Transformation is the callback signature for YAML-related resources. A transformation is passed a map of resource arguments, resource options, and can modify the state prior to the resource actually being created. The effect will be as though those properties were passed in place of the original call to the resource constructor. Important: any values set on the state must be prompt (not Output values).

func AddSkipAwaitTransformation added in v3.4.0

func AddSkipAwaitTransformation(transformations []Transformation) []Transformation

AddSkipAwaitTransformation adds a transformation to set the "pulumi.com/skipAwait" annotation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL