namespace

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: Apache-2.0 Imports: 7 Imported by: 5

Documentation

Overview

Package namespace contains a kio.Filter implementation of the kustomize namespace transformer.

Special cases for known Kubernetes resources have been hardcoded in addition to those defined by the FsSlice.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	// Namespace is the namespace to apply to the inputs
	Namespace string `yaml:"namespace,omitempty"`

	// FsSlice contains the FieldSpecs to locate the namespace field
	FsSlice types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`

	// UnsetOnly means only blank namespace fields will be set
	UnsetOnly bool `json:"unsetOnly" yaml:"unsetOnly"`

	// SetRoleBindingSubjects determines which subject fields in RoleBinding and ClusterRoleBinding
	// objects will have their namespace fields set. Overrides field specs provided for these types, if any.
	// - defaultOnly (default): namespace will be set only on subjects named "default".
	// - allServiceAccounts: namespace will be set on all subjects with "kind: ServiceAccount"
	// - none: all subjects will be skipped.
	SetRoleBindingSubjects RoleBindingSubjectMode `json:"setRoleBindingSubjects" yaml:"setRoleBindingSubjects"`
	// contains filtered or unexported fields
}
Example
package main

import (
	"bytes"
	"log"
	"os"

	"sigs.k8s.io/kustomize/api/filters/namespace"
	"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
	"sigs.k8s.io/kustomize/kyaml/kio"
)

func main() {
	fss := builtinconfig.MakeDefaultConfig().NameSpace
	err := kio.Pipeline{
		Inputs: []kio.Reader{&kio.ByteReader{Reader: bytes.NewBufferString(`
apiVersion: example.com/v1
kind: Foo
metadata:
  name: instance
---
apiVersion: example.com/v1
kind: Bar
metadata:
  name: instance
  namespace: bar
`)}},
		Filters: []kio.Filter{namespace.Filter{Namespace: "app", FsSlice: fss}},
		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
  namespace: app
---
apiVersion: example.com/v1
kind: Bar
metadata:
  name: instance
  namespace: app

func (Filter) Filter

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

func (*Filter) WithMutationTracker added in v0.11.0

func (ns *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 RoleBindingSubjectMode added in v0.12.0

type RoleBindingSubjectMode string
const (
	DefaultSubjectsOnly       RoleBindingSubjectMode = "defaultOnly"
	SubjectModeUnspecified    RoleBindingSubjectMode = ""
	AllServiceAccountSubjects RoleBindingSubjectMode = "allServiceAccounts"
	NoSubjects                RoleBindingSubjectMode = "none"
)

Jump to

Keyboard shortcuts

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