Skip to content

Commit 7af4e77

Browse files
committed
fix failed tests for fn framework generator
1 parent 67a0b43 commit 7af4e77

File tree

10 files changed

+261
-30
lines changed

10 files changed

+261
-30
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ check-license: $(MYGOBIN)/addlicense
127127

128128
.PHONY: lint
129129
lint: $(MYGOBIN)/golangci-lint $(MYGOBIN)/goimports $(builtinplugins)
130-
./hack/for-each-module.sh "make lint" 46
130+
./hack/for-each-module.sh "make lint"
131131

132132
.PHONY: apidiff
133133
apidiff: go-apidiff ## Run the go-apidiff to verify any API differences compared with origin/master
@@ -145,11 +145,11 @@ test-unit-all: \
145145
# This target is used by our Github Actions CI to run unit tests for all non-plugin modules in multiple GOOS environments.
146146
.PHONY: test-unit-non-plugin
147147
test-unit-non-plugin:
148-
./hack/for-each-module.sh "make test" "./plugin/*" 17
148+
./hack/for-each-module.sh "make test" "./plugin/*" 18
149149

150150
.PHONY: build-non-plugin-all
151151
build-non-plugin-all:
152-
./hack/for-each-module.sh "make build" "./plugin/*" 17
152+
./hack/for-each-module.sh "make build" "./plugin/*" 18
153153

154154
.PHONY: test-unit-kustomize-plugins
155155
test-unit-kustomize-plugins:

api/krusty/fnplugin_test.go

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import (
1515
"sigs.k8s.io/kustomize/kyaml/filesys"
1616
)
1717

18+
const (
19+
repoRootDir = "../../"
20+
)
21+
1822
const generateDeploymentDotSh = `#!/bin/sh
1923
2024
cat <<EOF
@@ -504,7 +508,6 @@ func skipIfNoDocker(t *testing.T) {
504508
}
505509

506510
func TestFnContainerGenerator(t *testing.T) {
507-
t.Skip("it may failed by arm architecture")
508511
skipIfNoDocker(t)
509512
th := kusttest_test.MakeHarness(t)
510513
o := th.MakeOptionsPluginsEnabled()
@@ -514,51 +517,58 @@ func TestFnContainerGenerator(t *testing.T) {
514517
resources:
515518
- deployment.yaml
516519
generators:
517-
- project-service-set.yaml
520+
- service-set.yaml
518521
`)
519522
// Create generator config
520-
th.WriteF(filepath.Join(tmpDir.String(), "project-service-set.yaml"), `
521-
apiVersion: blueprints.cloud.google.com/v1alpha1
522-
kind: ProjectServiceSet
523+
th.WriteF(filepath.Join(tmpDir.String(), "service-set.yaml"), `
524+
apiVersion: kustomize.sigs.k8s.io/v1alpha1
525+
kind: ServiceGenerator
523526
metadata:
524-
name: demo
527+
name: simplegenerator
525528
annotations:
526529
config.kubernetes.io/function: |
527530
container:
528-
image: gcr.io/kpt-fn/enable-gcp-services:v0.1.0
531+
image: gcr.io/kustomize-functions/e2econtainersimplegenerator
529532
spec:
530-
services:
531-
- compute.googleapis.com
532-
projectID: foo
533+
port: 8081
533534
`)
534535
// Create another resource just to make sure everything is added
535536
th.WriteF(filepath.Join(tmpDir.String(), "deployment.yaml"), `
536537
apiVersion: apps/v1
537538
kind: Deployment
538539
metadata:
539-
name: foo
540+
name: simplegenerator
540541
`)
542+
543+
build := exec.Command("docker", "build", ".",
544+
"-f", "./cmd/config/internal/commands/e2e/e2econtainersimplegenerator/Dockerfile",
545+
"-t", "gcr.io/kustomize-functions/e2econtainersimplegenerator",
546+
)
547+
build.Dir = repoRootDir
548+
assert.NoError(t, build.Run())
549+
541550
m := th.Run(tmpDir.String(), o)
542551
actual, err := m.AsYaml()
543552
assert.NoError(t, err)
544553
assert.Equal(t, `apiVersion: apps/v1
545554
kind: Deployment
546555
metadata:
547-
name: foo
556+
name: simplegenerator
548557
---
549-
apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1
558+
apiVersion: v1
550559
kind: Service
551560
metadata:
552-
annotations:
553-
blueprints.cloud.google.com/ownerReference: blueprints.cloud.google.com/ProjectServiceSet/demo
554-
config.kubernetes.io/function: |
555-
container:
556-
image: gcr.io/kpt-fn/enable-gcp-services:v0.1.0
557-
name: demo-compute
561+
labels:
562+
app: simplegenerator
563+
name: simplegenerator-svc
558564
spec:
559-
projectRef:
560-
external: foo
561-
resourceID: compute.googleapis.com
565+
ports:
566+
- name: http
567+
port: 8081
568+
protocol: TCP
569+
targetPort: 8081
570+
selector:
571+
app: simplegenerator
562572
`, string(actual))
563573
}
564574

@@ -594,7 +604,7 @@ metadata:
594604
"-f", "./cmd/config/internal/commands/e2e/e2econtainerconfig/Dockerfile",
595605
"-t", "gcr.io/kustomize-functions/e2econtainerconfig",
596606
)
597-
build.Dir = "../../" // Repo root
607+
build.Dir = repoRootDir
598608
assert.NoError(t, build.Run())
599609
m := th.Run(tmpDir.String(), o)
600610
actual, err := m.AsYaml()
@@ -691,8 +701,8 @@ generators:
691701
- gener.yaml
692702
`)))
693703
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "gener.yaml"), []byte(`
694-
apiVersion: v1
695-
kind: ConfigMap
704+
apiVersion: kustomize.sigs.k8s.io/v1alpha1
705+
kind: EnvTemplateGenerator
696706
metadata:
697707
name: e2econtainerenvgenerator
698708
annotations:
@@ -713,7 +723,7 @@ template: |
713723
"-f", "./cmd/config/internal/commands/e2e/e2econtainerenvgenerator/Dockerfile",
714724
"-t", "gcr.io/kustomize-functions/e2econtainerenvgenerator",
715725
)
716-
build.Dir = "../../" // Repo root
726+
build.Dir = repoRootDir
717727
assert.NoError(t, build.Run())
718728

719729
m, err := b.Run(
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2019 The Kubernetes Authors.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
FROM golang:1.20-bullseye
5+
ENV CGO_ENABLED=0
6+
WORKDIR /go/src/
7+
8+
# download modules
9+
# COPY go.mod go.mod
10+
# COPY go.sum go.sum
11+
# RUN go mod download
12+
13+
COPY . .
14+
RUN go build -v -o /usr/local/bin/function ./cmd/config/internal/commands/e2e/e2econtainersimplegenerator
15+
16+
FROM alpine:latest
17+
COPY --from=0 /usr/local/bin/function /usr/local/bin/function
18+
CMD ["function"]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright 2019 The Kubernetes Authors.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
include ../../../../../../Makefile-modules.mk
5+
6+
.PHONY: image
7+
image:
8+
docker build . -t gcr.io/kustomize-functions/e2econtainersimplegenerator
9+
docker push gcr.io/kustomize-functions/e2econtainersimplegenerator
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright 2019 The Kubernetes Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Package main contains a function to be used for e2e testing.
5+
// See https://github.com/kubernetes-sigs/kustomize/blob/master/cmd/config/docs/api-conventions/functions-spec.md
6+
package main
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module sigs.k8s.io/kustomize/cmd/config/internal/commands/e2e/e2econtainersimplegenerator
2+
3+
go 1.20
4+
5+
require sigs.k8s.io/kustomize/kyaml v0.14.2
6+
7+
require (
8+
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
9+
github.com/davecgh/go-spew v1.1.1 // indirect
10+
github.com/go-errors/errors v1.4.2 // indirect
11+
github.com/go-openapi/jsonpointer v0.19.6 // indirect
12+
github.com/go-openapi/jsonreference v0.20.2 // indirect
13+
github.com/go-openapi/swag v0.22.3 // indirect
14+
github.com/golang/protobuf v1.5.3 // indirect
15+
github.com/google/gnostic-models v0.6.8 // indirect
16+
github.com/google/go-cmp v0.5.9 // indirect
17+
github.com/google/gofuzz v1.2.0 // indirect
18+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
19+
github.com/josharian/intern v1.0.0 // indirect
20+
github.com/mailru/easyjson v0.7.7 // indirect
21+
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
22+
github.com/spf13/cobra v1.7.0 // indirect
23+
github.com/spf13/pflag v1.0.5 // indirect
24+
github.com/xlab/treeprint v1.2.0 // indirect
25+
golang.org/x/sys v0.8.0 // indirect
26+
google.golang.org/protobuf v1.30.0 // indirect
27+
gopkg.in/yaml.v2 v2.4.0 // indirect
28+
gopkg.in/yaml.v3 v3.0.1 // indirect
29+
k8s.io/kube-openapi v0.0.0-20230601164746-7562a1006961 // indirect
30+
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect
31+
sigs.k8s.io/yaml v1.3.0 // indirect
32+
)
33+
34+
replace sigs.k8s.io/kustomize/kyaml => ../../../../../../kyaml
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
2+
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
3+
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
4+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
5+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
7+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8+
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
9+
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
10+
github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE=
11+
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
12+
github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE=
13+
github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
14+
github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
15+
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
16+
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
17+
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
18+
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
19+
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
20+
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
21+
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
22+
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
23+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
24+
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
25+
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
26+
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
27+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
28+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
29+
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
30+
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
31+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
32+
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
33+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
34+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
35+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
36+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
37+
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
38+
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
39+
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
40+
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
41+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
42+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
43+
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
44+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
45+
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
46+
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
47+
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
48+
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
49+
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
50+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
51+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
52+
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
53+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
54+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
55+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
56+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
57+
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
58+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
59+
github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=
60+
github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
61+
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
62+
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
63+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
64+
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
65+
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
66+
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
67+
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
68+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
69+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
70+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
71+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
72+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
73+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
74+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
75+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
76+
k8s.io/kube-openapi v0.0.0-20230601164746-7562a1006961 h1:pqRVJGQJz6oeZby8qmPKXYIBjyrcv7EHCe/33UkZMYA=
77+
k8s.io/kube-openapi v0.0.0-20230601164746-7562a1006961/go.mod h1:l8HTwL5fqnlns4jOveW1L75eo7R9KFHxiE0bsPGy428=
78+
k8s.io/utils v0.0.0-20230505201702-9f6742963106 h1:EObNQ3TW2D+WptiYXlApGNLVy0zm/JIBVY9i+M4wpAU=
79+
k8s.io/utils v0.0.0-20230505201702-9f6742963106/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
80+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
81+
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
82+
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2019 The Kubernetes Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package main
5+
6+
import (
7+
"fmt"
8+
"os"
9+
10+
"sigs.k8s.io/kustomize/kyaml/fn/framework"
11+
"sigs.k8s.io/kustomize/kyaml/fn/framework/command"
12+
"sigs.k8s.io/kustomize/kyaml/kio"
13+
"sigs.k8s.io/kustomize/kyaml/yaml"
14+
)
15+
16+
type App struct {
17+
Metadata struct {
18+
Name string `yaml:"name"`
19+
} `yaml:"metadata"`
20+
Spec struct {
21+
Port int `yaml:"port" json:"port"`
22+
} `yaml:"spec" json:"spec"`
23+
}
24+
25+
func generateService(name string, sourcePort int, targetPort int) (*yaml.RNode, error) {
26+
serviceName := name + "-svc"
27+
svc, err := yaml.Parse(fmt.Sprintf(`apiVersion: v1
28+
kind: Service
29+
metadata:
30+
labels:
31+
app: %s
32+
name: %s
33+
spec:
34+
selector:
35+
app: %s
36+
ports:
37+
- name: http
38+
port: %d
39+
protocol: TCP
40+
targetPort: %d
41+
`, name, serviceName, name, sourcePort, targetPort))
42+
if err != nil {
43+
return nil, fmt.Errorf("failed to generate resource: %w", err)
44+
}
45+
return svc, nil
46+
}
47+
48+
func main() {
49+
config := new(App)
50+
fn := func(items []*yaml.RNode) ([]*yaml.RNode, error) {
51+
var newNodes []*yaml.RNode
52+
resourceName := config.Metadata.Name
53+
for range items {
54+
// generate Service
55+
service, err := generateService(resourceName, config.Spec.Port, config.Spec.Port)
56+
if err != nil {
57+
return nil, err
58+
}
59+
newNodes = append(newNodes, service)
60+
}
61+
items = newNodes
62+
63+
return items, nil
64+
}
65+
p := framework.SimpleProcessor{Config: config, Filter: kio.FilterFunc(fn)}
66+
cmd := command.Build(p, command.StandaloneDisabled, false)
67+
command.AddGenerateDockerfile(cmd)
68+
if err := cmd.Execute(); err != nil {
69+
os.Exit(1)
70+
}
71+
}

go.work

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use (
55
./cmd/config
66
./cmd/config/internal/commands/e2e/e2econtainerconfig
77
./cmd/config/internal/commands/e2e/e2econtainerenvgenerator
8+
./cmd/config/internal/commands/e2e/e2econtainersimplegenerator
89
./cmd/depprobcheck
910
./cmd/gorepomod
1011
./cmd/k8scopy

hack/for-each-module.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fi
1515

1616
cmd=$1
1717
skip_pattern="${2-}"
18-
expected_module_count=${3:-46}
18+
expected_module_count=${3:-47}
1919

2020
seen=()
2121
# Hack scripts must be run from the root of the repository.

0 commit comments

Comments
 (0)