Skip to content

Commit 80ad8d8

Browse files
committed
address more comments
1 parent 1b9b748 commit 80ad8d8

File tree

2 files changed

+18
-45
lines changed

2 files changed

+18
-45
lines changed

test/e2e/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type config struct {
3838
// to avoid conflict when running tests synchronously.
3939
func initConfig(testSuffix string) *config {
4040
testGroup := "bar" + testSuffix
41-
installName := "kube" + testGroup + testSuffix
41+
installName := "kube" + testGroup
4242
testNamespace := installName + "-system"
4343

4444
return &config{

test/e2e/e2e.go

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ import (
3131
e2einternal "github.com/kubernetes-sigs/kubebuilder/test/internal/e2e"
3232
. "github.com/onsi/ginkgo"
3333
. "github.com/onsi/gomega"
34-
35-
"k8s.io/apimachinery/pkg/util/wait"
3634
)
3735

3836
// RunE2ETests checks configuration parameters (specified through flags) and then runs
@@ -53,7 +51,6 @@ var _ = Describe("main workflow", func() {
5351
defer cleanup(kubebuilderTest, c.workDir, c.controllerImageName)
5452

5553
var controllerPodName string
56-
var e error
5754

5855
By("init project")
5956
initOptions := []string{"--domain", c.domain}
@@ -71,10 +68,12 @@ var _ = Describe("main workflow", func() {
7168
Expect(err).NotTo(HaveOccurred())
7269

7370
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.
7573
// 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"))
7877
Expect(err).NotTo(HaveOccurred())
7978

8079
imageOptions := []string{"-t", c.controllerImageName}
@@ -93,35 +92,31 @@ var _ = Describe("main workflow", func() {
9392
Expect(err).NotTo(HaveOccurred())
9493

9594
By("validate the controller-manager pod running as expected")
96-
verifyContollerUp := func() (bool, error) {
97-
e = nil
95+
verifyContollerUp := func() error {
9896
// 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 }}"}
10099
podOutput, err := kubebuilderTest.RunKubectlCommand(framework.GetKubectlArgs(getOptions))
101100
Expect(err).NotTo(HaveOccurred())
102101
// TODO: validate pod replicas if not default to 1
103102
podNames := framework.ParseCmdOutput(podOutput)
104103
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))
107105
}
108106
controllerPodName = podNames[0]
107+
Expect(controllerPodName).Should(HavePrefix(c.installName+"-controller-manager"))
109108

110109
// Validate pod status
111110
getOptions = []string{"get", "pods", controllerPodName, "-n", c.namespace, "-o", "jsonpath={.status.phase}"}
112111
status, err := kubebuilderTest.RunKubectlCommand(framework.GetKubectlArgs(getOptions))
113112
Expect(err).NotTo(HaveOccurred())
114113
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)
117115
}
118116

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
124118
}
119+
Eventually(verifyContollerUp, 1*time.Minute, 500*time.Millisecond).Should(BeNil())
125120

126121
By("creating resource object")
127122
inputFile = filepath.Join(kubebuilderTest.Dir, "hack", "sample", strings.ToLower(c.kind)+".yaml")
@@ -130,22 +125,15 @@ var _ = Describe("main workflow", func() {
130125
Expect(err).NotTo(HaveOccurred())
131126

132127
By("validate the created resource object gets reconciled in controller")
133-
verifyResourceReconciled := func() (bool, error) {
128+
controllerContainerLogs := func() string {
134129
// Check container log to validate that the created resource object gets reconciled in controller
135130
logOptions := []string{"logs", controllerPodName, "-n", c.namespace}
136131
logOutput, err := kubebuilderTest.RunKubectlCommand(framework.GetKubectlArgs(logOptions))
137132
Expect(err).NotTo(HaveOccurred())
138133

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
148135
}
136+
Eventually(controllerContainerLogs, 1*time.Minute, 500*time.Millisecond).Should(ContainSubstring(fmt.Sprintf("to reconcile %s-example", strings.ToLower(c.kind))))
149137

150138
By("creating other kind of resource object")
151139
inputFile = filepath.Join(kubebuilderTest.Dir, "hack", "sample", "deployment.yaml")
@@ -159,22 +147,7 @@ var _ = Describe("main workflow", func() {
159147
Expect(err).NotTo(HaveOccurred())
160148

161149
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"))
178151
})
179152
})
180153

0 commit comments

Comments
 (0)