mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-17 01:39:06 +00:00
Support for framework.Selector substitutions
This commit is contained in:
@@ -6,6 +6,7 @@ package framework_test
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"text/template"
|
||||
|
||||
@@ -786,3 +787,106 @@ metadata:
|
||||
// annotations:
|
||||
// a: b
|
||||
}
|
||||
|
||||
func ExampleSelector_templatizeKinds() {
|
||||
type api struct {
|
||||
KindName string `yaml:"kindName"`
|
||||
}
|
||||
rl := &framework.ResourceList{
|
||||
FunctionConfig: &api{KindName: "Deployment"},
|
||||
Reader: bytes.NewBufferString(`
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: foo
|
||||
namespace: default
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: bar
|
||||
namespace: default
|
||||
`),
|
||||
Writer: os.Stdout,
|
||||
}
|
||||
if err := rl.Read(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var err error
|
||||
s := &framework.Selector{
|
||||
TemplatizeValues: true,
|
||||
Kinds: []string{"{{ .KindName }}"},
|
||||
}
|
||||
rl.Items, err = s.GetMatches(rl)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := rl.Write(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// apiVersion: apps/v1
|
||||
// kind: Deployment
|
||||
// metadata:
|
||||
// name: foo
|
||||
// namespace: default
|
||||
// annotations:
|
||||
// config.kubernetes.io/index: '0'
|
||||
}
|
||||
|
||||
func ExampleSelector_templatizeAnnotations() {
|
||||
type api struct {
|
||||
Value string `yaml:"vaue"`
|
||||
}
|
||||
rl := &framework.ResourceList{
|
||||
FunctionConfig: &api{Value: "bar"},
|
||||
Reader: bytes.NewBufferString(`
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: foo
|
||||
namespace: default
|
||||
annotations:
|
||||
key: foo
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: bar
|
||||
namespace: default
|
||||
annotations:
|
||||
key: bar
|
||||
`),
|
||||
Writer: os.Stdout,
|
||||
}
|
||||
if err := rl.Read(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var err error
|
||||
s := &framework.Selector{
|
||||
TemplatizeValues: true,
|
||||
Annotations: map[string]string{"key": "{{ .Value }}"},
|
||||
}
|
||||
rl.Items, err = s.GetMatches(rl)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := rl.Write(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// apiVersion: apps/v1
|
||||
// kind: Deployment
|
||||
// metadata:
|
||||
// name: bar
|
||||
// namespace: default
|
||||
// annotations:
|
||||
// key: bar
|
||||
// config.kubernetes.io/index: '1'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user