imagetag

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: Apache-2.0 Imports: 8 Imported by: 3

Documentation

Overview

Package imagetag contains two kio.Filter implementations to cover the functionality of the kustomize imagetag transformer.

Filter updates fields based on a FieldSpec and an ImageTag.

LegacyFilter doesn't use a FieldSpec, and instead only updates image references if the field is name image and it is underneath a field called either containers or initContainers.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	// imageTag is the tag we want to apply to the inputs
	// The name of the image is used as a key, and other fields
	// can specify a new name, tag, etc.
	ImageTag types.Image `json:"imageTag,omitempty" yaml:"imageTag,omitempty"`

	// FsSlice contains the FieldSpecs to locate an image field,
	// e.g. Path: "spec/myContainers[]/image"
	FsSlice types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
	// contains filtered or unexported fields
}

Filter modifies an "image tag", the value used to specify the name, tag, version digest etc. of (docker) container images used by a pod template.

Example
err := kio.Pipeline{
	Inputs: []kio.Reader{&kio.ByteReader{Reader: bytes.NewBufferString(`
apiVersion: example.com/v1
kind: Foo
metadata:
  name: instance
spec:
  containers:
  - name: FooBar
    image: nginx
---
apiVersion: example.com/v1
kind: Bar
metadata:
  name: instance
spec:
  containers:
  - name: BarFoo
    image: nginx:1.2.1
`)}},
	Filters: []kio.Filter{Filter{
		ImageTag: types.Image{
			Name:    "nginx",
			NewName: "apache",
			Digest:  "12345",
		},
		FsSlice: []types.FieldSpec{
			{
				Path: "spec/containers[]/image",
			},
		},
	}},
	Outputs: []kio.Writer{kio.ByteWriter{Writer: os.Stdout}},
}.Execute()
if err != nil {
	log.Fatal(err)
}
Output:

apiVersion: example.com/v1
kind: Foo
metadata:
  name: instance
spec:
  containers:
  - name: FooBar
    image: apache@12345
---
apiVersion: example.com/v1
kind: Bar
metadata:
  name: instance
spec:
  containers:
  - name: BarFoo
    image: apache@12345

func (Filter) Filter

func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error)

func (*Filter) WithMutationTracker added in v0.11.0

func (f *Filter) WithMutationTracker(callback func(key, value, tag string, node *yaml.RNode))

WithMutationTracker registers a callback which will be invoked each time a field is mutated

type LegacyFilter

type LegacyFilter struct {
	ImageTag types.Image `json:"imageTag,omitempty" yaml:"imageTag,omitempty"`
}

LegacyFilter is an implementation of the kio.Filter interface that scans through the provided kyaml data structure and updates any values of any image fields that is inside a sequence under a field called either containers or initContainers. The field is only update if it has a value that matches and image reference and the name of the image is a match with the provided ImageTag.

Example
err := kio.Pipeline{
	Inputs: []kio.Reader{&kio.ByteReader{Reader: bytes.NewBufferString(`
apiVersion: example.com/v1
kind: Foo
metadata:
  name: instance
spec:
  containers:
  - name: FooBar
    image: nginx
---
apiVersion: example.com/v1
kind: Bar
metadata:
  name: instance
spec:
  containers:
  - name: BarFoo
    image: nginx:1.2.1
`)}},
	Filters: []kio.Filter{LegacyFilter{
		ImageTag: types.Image{
			Name:    "nginx",
			NewName: "apache",
			Digest:  "12345",
		},
	}},
	Outputs: []kio.Writer{kio.ByteWriter{Writer: os.Stdout}},
}.Execute()
if err != nil {
	log.Fatal(err)
}
Output:

apiVersion: example.com/v1
kind: Foo
metadata:
  name: instance
spec:
  containers:
  - name: FooBar
    image: apache@12345
---
apiVersion: example.com/v1
kind: Bar
metadata:
  name: instance
spec:
  containers:
  - name: BarFoo
    image: apache@12345

func (LegacyFilter) Filter

func (lf LegacyFilter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error)

Jump to

Keyboard shortcuts

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