Skip to content

Commit

Permalink
chore: filter out config files in kpt fn render output
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzzzzzzz committed Feb 27, 2023
1 parent c6ab4d1 commit 07b5996
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
77 changes: 77 additions & 0 deletions integration/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,83 @@ spec:
ports:
- protocol: TCP
containerPort: 80
`},
{
description: "kpt render with data config file",
args: []string{"--offline=true"},
config: `apiVersion: skaffold/v4beta2
kind: Config
metadata:
name: getting-started-kustomize
manifests:
kpt:
- set-annotations
`,
input: map[string]string{"set-annotations/Kptfile": `apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: example
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-annotations:v0.1.4
configPath: fn-config.yaml`,
"set-annotations/fn-config.yaml": `apiVersion: fn.kpt.dev/v1alpha1
kind: SetAnnotations
metadata: # kpt-merge: /my-func-config
name: my-func-config
annotations:
config.kubernetes.io/local-config: "true"
internal.kpt.dev/upstream-identifier: 'fn.kpt.dev|SetAnnotations|default|my-func-config'
annotations:
color: orange
fruit: apple
`,
"set-annotations/resources.yaml": `apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
spec:
replicas: 3 # kpt-set: ${nginx-replicas}
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: "nginx:1.16.1" # kpt-set: nginx:${tag}
ports:
- protocol: TCP
containerPort: 80`},
expectedOut: `apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
annotations:
color: orange
fruit: apple
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
annotations:
color: orange
fruit: apple
labels:
app: nginx
spec:
containers:
- name: nginx
image: "nginx:1.16.1"
ports:
- protocol: TCP
containerPort: 80
`},
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/skaffold/render/renderer/kpt/kpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ func (r *Kpt) Render(ctx context.Context, out io.Writer, builds []graph.Artifact
reader := kio.ByteReader{Reader: bytes.NewBuffer(buf)}
b := bytes.NewBuffer([]byte{})
writer := kio.ByteWriter{Writer: b}
// Kpt fn render outputs Kptfile content in result, we don't want this in our manifestList as Kptfile resource cannot be deployed to k8s cluster.
// Kpt fn render outputs Kptfile and Config data files content in result, we don't want them in our manifestList as these cannot be deployed to k8s cluster.
pipeline := kio.Pipeline{Filters: []kio.Filter{framework.ResourceMatcherFunc(func(node *yaml.RNode) bool {
return node.GetKind() != kptfile.KptFileKind
meta, _ := node.GetMeta()
return node.GetKind() != kptfile.KptFileKind && meta.Annotations["config.kubernetes.io/local-config"] != "true"
})},
Inputs: []kio.Reader{&reader},
Outputs: []kio.Writer{writer},
Expand Down

0 comments on commit 07b5996

Please sign in to comment.