@@ -31,8 +31,6 @@ import (
31
31
e2einternal "github.com/kubernetes-sigs/kubebuilder/test/internal/e2e"
32
32
. "github.com/onsi/ginkgo"
33
33
. "github.com/onsi/gomega"
34
-
35
- "k8s.io/apimachinery/pkg/util/wait"
36
34
)
37
35
38
36
// RunE2ETests checks configuration parameters (specified through flags) and then runs
@@ -53,7 +51,6 @@ var _ = Describe("main workflow", func() {
53
51
defer cleanup (kubebuilderTest , c .workDir , c .controllerImageName )
54
52
55
53
var controllerPodName string
56
- var e error
57
54
58
55
By ("init project" )
59
56
initOptions := []string {"--domain" , c .domain }
@@ -71,10 +68,12 @@ var _ = Describe("main workflow", func() {
71
68
Expect (err ).NotTo (HaveOccurred ())
72
69
73
70
By ("building image" )
74
- // The scaffold test cases generated for core types cannot work without manually modification.
71
+ // The scaffold test cases generated for core types controller cannot work
72
+ // without manually modification.
75
73
// See https://github.com/kubernetes-sigs/kubebuilder/pull/193 for more details
76
- // Skip the test part in build process as we don't care about it here.
77
- err = framework .ReplaceFileConent (`RUN go test(.*)\n` , "" , filepath .Join (c .workDir , "Dockerfile.controller" ))
74
+ // Skip the test for core types controller in build process.
75
+ testCmdWithoutCoreType := "RUN find ./ -not -path './pkg/controller/deployment/*' -name '*_test.go' -print0 | xargs -0n1 dirname | xargs go test\n "
76
+ err = framework .ReplaceFileConent (`RUN go test(.*)\n` , testCmdWithoutCoreType , filepath .Join (c .workDir , "Dockerfile.controller" ))
78
77
Expect (err ).NotTo (HaveOccurred ())
79
78
80
79
imageOptions := []string {"-t" , c .controllerImageName }
@@ -93,35 +92,31 @@ var _ = Describe("main workflow", func() {
93
92
Expect (err ).NotTo (HaveOccurred ())
94
93
95
94
By ("validate the controller-manager pod running as expected" )
96
- verifyContollerUp := func () (bool , error ) {
97
- e = nil
95
+ verifyContollerUp := func () error {
98
96
// Get pod name
99
- getOptions := []string {"get" , "pods" , "-n" , c .namespace , "-o" , "go-template={{ range .items }}{{ if not .metadata.deletionTimestamp }}{{ .metadata.name }}{{ \" \\ n\" }}{{ end }}{{ end }}" }
97
+ // TODO: Use kubectl to format the output with a go-template
98
+ getOptions := []string {"get" , "pods" , "-n" , c .namespace , "-l" , "control-plane=controller-manager" , "-o" , "go-template={{ range .items }}{{ if not .metadata.deletionTimestamp }}{{ .metadata.name }}{{ \" \\ n\" }}{{ end }}{{ end }}" }
100
99
podOutput , err := kubebuilderTest .RunKubectlCommand (framework .GetKubectlArgs (getOptions ))
101
100
Expect (err ).NotTo (HaveOccurred ())
102
101
// TODO: validate pod replicas if not default to 1
103
102
podNames := framework .ParseCmdOutput (podOutput )
104
103
if len (podNames ) != 1 {
105
- e = fmt .Errorf ("expect 1 controller pods running, but got %d" , len (podNames ))
106
- return false , nil
104
+ return fmt .Errorf ("expect 1 controller pods running, but got %d" , len (podNames ))
107
105
}
108
106
controllerPodName = podNames [0 ]
107
+ Expect (controllerPodName ).Should (HavePrefix (c .installName + "-controller-manager" ))
109
108
110
109
// Validate pod status
111
110
getOptions = []string {"get" , "pods" , controllerPodName , "-n" , c .namespace , "-o" , "jsonpath={.status.phase}" }
112
111
status , err := kubebuilderTest .RunKubectlCommand (framework .GetKubectlArgs (getOptions ))
113
112
Expect (err ).NotTo (HaveOccurred ())
114
113
if status != "Running" {
115
- e = fmt .Errorf ("controller pod in %s status" , status )
116
- return false , nil
114
+ return fmt .Errorf ("controller pod in %s status" , status )
117
115
}
118
116
119
- return true , nil
120
- }
121
- varifyErr := wait .PollImmediate (500 * time .Millisecond , 1 * time .Minute , verifyContollerUp )
122
- if varifyErr != nil {
123
- framework .Failf (e .Error ())
117
+ return nil
124
118
}
119
+ Eventually (verifyContollerUp , 1 * time .Minute , 500 * time .Millisecond ).Should (BeNil ())
125
120
126
121
By ("creating resource object" )
127
122
inputFile = filepath .Join (kubebuilderTest .Dir , "hack" , "sample" , strings .ToLower (c .kind )+ ".yaml" )
@@ -130,22 +125,15 @@ var _ = Describe("main workflow", func() {
130
125
Expect (err ).NotTo (HaveOccurred ())
131
126
132
127
By ("validate the created resource object gets reconciled in controller" )
133
- verifyResourceReconciled := func () ( bool , error ) {
128
+ controllerContainerLogs := func () string {
134
129
// Check container log to validate that the created resource object gets reconciled in controller
135
130
logOptions := []string {"logs" , controllerPodName , "-n" , c .namespace }
136
131
logOutput , err := kubebuilderTest .RunKubectlCommand (framework .GetKubectlArgs (logOptions ))
137
132
Expect (err ).NotTo (HaveOccurred ())
138
133
139
- if ! strings .Contains (logOutput , fmt .Sprintf ("to reconcile %s-example" , strings .ToLower (c .kind ))) {
140
- e = fmt .Errorf ("created resource object %s-example not reconciled yet" , strings .ToLower (c .kind ))
141
- return false , nil
142
- }
143
- return true , nil
144
- }
145
- varifyErr = wait .PollImmediate (500 * time .Millisecond , 1 * time .Minute , verifyResourceReconciled )
146
- if varifyErr != nil {
147
- framework .Failf (e .Error ())
134
+ return logOutput
148
135
}
136
+ Eventually (controllerContainerLogs , 1 * time .Minute , 500 * time .Millisecond ).Should (ContainSubstring (fmt .Sprintf ("to reconcile %s-example" , strings .ToLower (c .kind ))))
149
137
150
138
By ("creating other kind of resource object" )
151
139
inputFile = filepath .Join (kubebuilderTest .Dir , "hack" , "sample" , "deployment.yaml" )
@@ -159,22 +147,7 @@ var _ = Describe("main workflow", func() {
159
147
Expect (err ).NotTo (HaveOccurred ())
160
148
161
149
By ("validate other kind of object gets reconciled in controller" )
162
- verifyResourceReconciled = func () (bool , error ) {
163
- // Check container log to validate that the created resource object gets reconciled in controller
164
- logOptions := []string {"logs" , controllerPodName , "-n" , c .namespace }
165
- logOutput , err := kubebuilderTest .RunKubectlCommand (framework .GetKubectlArgs (logOptions ))
166
- Expect (err ).NotTo (HaveOccurred ())
167
-
168
- if ! strings .Contains (logOutput , "to reconcile deployment-example" ) {
169
- e = fmt .Errorf ("created resource object deployment-example not reconciled yet" )
170
- return false , nil
171
- }
172
- return true , nil
173
- }
174
- varifyErr = wait .PollImmediate (500 * time .Millisecond , 1 * time .Minute , verifyResourceReconciled )
175
- if varifyErr != nil {
176
- framework .Failf (e .Error ())
177
- }
150
+ Eventually (controllerContainerLogs , 1 * time .Minute , 500 * time .Millisecond ).Should (ContainSubstring ("to reconcile deployment-example" ))
178
151
})
179
152
})
180
153
0 commit comments