Skip to content

Commit 1fef331

Browse files
authored
Merge branch 'main' into chore/more-linters
2 parents 6dfdcdd + 01a18c6 commit 1fef331

File tree

3 files changed

+81
-10
lines changed

3 files changed

+81
-10
lines changed

tests/framework/resourcemanager.go

+54
Original file line numberDiff line numberDiff line change
@@ -683,3 +683,57 @@ func countNumberOfReadyParents(parents []v1.RouteParentStatus) int {
683683

684684
return readyCount
685685
}
686+
687+
func (rm *ResourceManager) WaitForAppsToBeReadyWithPodCount(namespace string, podCount int) error {
688+
ctx, cancel := context.WithTimeout(context.Background(), rm.TimeoutConfig.CreateTimeout)
689+
defer cancel()
690+
691+
return rm.WaitForAppsToBeReadyWithCtxWithPodCount(ctx, namespace, podCount)
692+
}
693+
694+
func (rm *ResourceManager) WaitForAppsToBeReadyWithCtxWithPodCount(
695+
ctx context.Context,
696+
namespace string,
697+
podCount int,
698+
) error {
699+
if err := rm.WaitForPodsToBeReadyWithCount(ctx, namespace, podCount); err != nil {
700+
return err
701+
}
702+
703+
if err := rm.waitForHTTPRoutesToBeReady(ctx, namespace); err != nil {
704+
return err
705+
}
706+
707+
if err := rm.waitForGRPCRoutesToBeReady(ctx, namespace); err != nil {
708+
return err
709+
}
710+
711+
return rm.waitForGatewaysToBeReady(ctx, namespace)
712+
}
713+
714+
// WaitForPodsToBeReady waits for all Pods in the specified namespace to be ready or
715+
// until the provided context is canceled.
716+
func (rm *ResourceManager) WaitForPodsToBeReadyWithCount(ctx context.Context, namespace string, count int) error {
717+
return wait.PollUntilContextCancel(
718+
ctx,
719+
500*time.Millisecond,
720+
true, /* poll immediately */
721+
func(ctx context.Context) (bool, error) {
722+
var podList core.PodList
723+
if err := rm.K8sClient.List(ctx, &podList, client.InNamespace(namespace)); err != nil {
724+
return false, err
725+
}
726+
727+
var podsReady int
728+
for _, pod := range podList.Items {
729+
for _, cond := range pod.Status.Conditions {
730+
if cond.Type == core.PodReady && cond.Status == core.ConditionTrue {
731+
podsReady++
732+
}
733+
}
734+
}
735+
736+
return podsReady == count, nil
737+
},
738+
)
739+
}

tests/suite/graceful_recovery_test.go

+27-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const (
2828

2929
// Since checkContainerLogsForErrors may experience interference from previous tests (as explained in the function
3030
// documentation), this test is recommended to be run separate from other nfr tests.
31-
var _ = Describe("Graceful Recovery test", Ordered, Label("nfr", "graceful-recovery"), func() {
31+
var _ = Describe("Graceful Recovery test", Ordered, Label("functional", "graceful-recovery"), func() {
3232
files := []string{
3333
"graceful-recovery/cafe.yaml",
3434
"graceful-recovery/cafe-secret.yaml",
@@ -38,8 +38,10 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("nfr", "graceful-recov
3838

3939
var ns core.Namespace
4040

41-
teaURL := "https://cafe.example.com/tea"
42-
coffeeURL := "http://cafe.example.com/coffee"
41+
baseHTTPURL := "http://cafe.example.com"
42+
baseHTTPSURL := "https://cafe.example.com"
43+
teaURL := baseHTTPSURL + "/tea"
44+
coffeeURL := baseHTTPURL + "/coffee"
4345

4446
var ngfPodName string
4547

@@ -56,6 +58,12 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("nfr", "graceful-recov
5658
Expect(podNames).To(HaveLen(1))
5759

5860
ngfPodName = podNames[0]
61+
if portFwdPort != 0 {
62+
coffeeURL = fmt.Sprintf("%s:%d/coffee", baseHTTPURL, portFwdPort)
63+
}
64+
if portFwdHTTPSPort != 0 {
65+
teaURL = fmt.Sprintf("%s:%d/tea", baseHTTPSURL, portFwdHTTPSPort)
66+
}
5967
})
6068

6169
BeforeEach(func() {
@@ -67,7 +75,7 @@ var _ = Describe("Graceful Recovery test", Ordered, Label("nfr", "graceful-recov
6775

6876
Expect(resourceManager.Apply([]client.Object{&ns})).To(Succeed())
6977
Expect(resourceManager.ApplyFromFiles(files, ns.Name)).To(Succeed())
70-
Expect(resourceManager.WaitForAppsToBeReady(ns.Name)).To(Succeed())
78+
Expect(resourceManager.WaitForAppsToBeReadyWithPodCount(ns.Name, 2)).To(Succeed())
7179

7280
Eventually(
7381
func() error {
@@ -101,7 +109,7 @@ func runRecoveryTest(teaURL, coffeeURL, ngfPodName, containerName string, files
101109
)
102110

103111
if containerName != nginxContainerName {
104-
// Since we have already deployed resources and ran resourceManager.WaitForAppsToBeReady(ns.Name) earlier,
112+
// Since we have already deployed resources and ran resourceManager.WaitForAppsToBeReadyWithPodCount earlier,
105113
// we know that the applications are ready at this point. This could only be the case if NGF has written
106114
// statuses, which could only be the case if NGF has the leader lease. Since there is only one instance
107115
// of NGF in this test, we can be certain that this is the correct leaseholder name.
@@ -140,7 +148,7 @@ func runRecoveryTest(teaURL, coffeeURL, ngfPodName, containerName string, files
140148
Should(Succeed())
141149

142150
Expect(resourceManager.ApplyFromFiles(files, ns.Name)).To(Succeed())
143-
Expect(resourceManager.WaitForAppsToBeReady(ns.Name)).To(Succeed())
151+
Expect(resourceManager.WaitForAppsToBeReadyWithPodCount(ns.Name, 2)).To(Succeed())
144152

145153
Eventually(
146154
func() error {
@@ -265,7 +273,11 @@ func checkContainerLogsForErrors(ngfPodName string) {
265273
Expect(line).ToNot(ContainSubstring("[alert]"), line)
266274
Expect(line).ToNot(ContainSubstring("[emerg]"), line)
267275
if strings.Contains(line, "[error]") {
268-
Expect(line).To(ContainSubstring("connect() failed (111: Connection refused)"), line)
276+
expectedError1 := "connect() failed (111: Connection refused)"
277+
// FIXME(salonichf5) remove this error message check
278+
// when https://github.com/nginxinc/nginx-gateway-fabric/issues/2090 is completed.
279+
expectedError2 := "no live upstreams while connecting to upstream"
280+
Expect(line).To(Or(ContainSubstring(expectedError1), ContainSubstring(expectedError2)))
269281
}
270282
}
271283

@@ -275,7 +287,14 @@ func checkContainerLogsForErrors(ngfPodName string) {
275287
&core.PodLogOptions{Container: ngfContainerName},
276288
)
277289
Expect(err).ToNot(HaveOccurred())
278-
Expect(logs).ToNot(ContainSubstring("\"level\":\"error\""), logs)
290+
291+
for _, line := range strings.Split(logs, "\n") {
292+
if *plusEnabled && strings.Contains(line, "\"level\":\"error\"") {
293+
Expect(line).To(ContainSubstring("Usage reporting must be enabled when using NGINX Plus"), line)
294+
} else {
295+
Expect(line).ToNot(ContainSubstring("\"level\":\"error\""), line)
296+
}
297+
}
279298
}
280299

281300
func checkLeaderLeaseChange(originalLeaseName string) error {

tests/suite/system_suite_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ var _ = BeforeSuite(func() {
259259
"upgrade", // - running upgrade test (this test will deploy its own version)
260260
"longevity-teardown", // - running longevity teardown (deployment will already exist)
261261
"telemetry", // - running telemetry test (NGF will be deployed as part of the test)
262-
"graceful-recovery", // - running graceful recovery test (this test will deploy its own version)
263262
"scale", // - running scale test (this test will deploy its own version)
264263
}
265264
for _, s := range skipSubstrings {
@@ -299,6 +298,5 @@ func isNFR(labelFilter string) bool {
299298
strings.Contains(labelFilter, "longevity") ||
300299
strings.Contains(labelFilter, "performance") ||
301300
strings.Contains(labelFilter, "upgrade") ||
302-
strings.Contains(labelFilter, "graceful-recovery") ||
303301
strings.Contains(labelFilter, "scale")
304302
}

0 commit comments

Comments
 (0)