diff --git a/integration/render_test.go b/integration/render_test.go index 9ac417939b9..5dac19d9da5 100644 --- a/integration/render_test.go +++ b/integration/render_test.go @@ -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 `}, } diff --git a/pkg/skaffold/render/renderer/kpt/kpt.go b/pkg/skaffold/render/renderer/kpt/kpt.go index 991b19f8055..81b071b382a 100644 --- a/pkg/skaffold/render/renderer/kpt/kpt.go +++ b/pkg/skaffold/render/renderer/kpt/kpt.go @@ -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},