forked from kgateway-dev/kgateway
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstatus.go
117 lines (102 loc) · 5.14 KB
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package assertions
import (
"time"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/onsi/gomega/gstruct"
errors "github.com/rotisserie/eris"
"github.com/solo-io/gloo/test/gomega/matchers"
"github.com/solo-io/gloo/test/helpers"
"github.com/solo-io/gloo/test/kube2e/helper"
"github.com/solo-io/solo-kit/pkg/api/v1/resources/core"
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
)
// Checks GetNamespacedStatuses status for gloo installation namespace
func (p *Provider) EventuallyResourceStatusMatchesWarningReasons(getter helpers.InputResourceGetter, desiredStatusReasons []string, desiredReporter string, timeout ...time.Duration) {
ginkgo.GinkgoHelper()
currentTimeout, pollingInterval := helper.GetTimeouts(timeout...)
gomega.Eventually(func(g gomega.Gomega) {
statusWarningsMatcher := matchers.MatchStatusInNamespace(
p.glooGatewayContext.InstallNamespace,
gomega.And(matchers.HaveWarningStateWithReasonSubstrings(desiredStatusReasons...), matchers.HaveReportedBy(desiredReporter)),
)
status, err := getResourceNamespacedStatus(getter)
g.Expect(err).NotTo(gomega.HaveOccurred(), "failed to get resource namespaced status")
g.Expect(status).ToNot(gomega.BeNil())
g.Expect(status).To(gomega.HaveValue(statusWarningsMatcher))
}, currentTimeout, pollingInterval).Should(gomega.Succeed())
}
func (p *Provider) EventuallyResourceStatusMatchesRejectedReasons(getter helpers.InputResourceGetter, desiredStatusReasons []string, desiredReporter string, timeout ...time.Duration) {
ginkgo.GinkgoHelper()
currentTimeout, pollingInterval := helper.GetTimeouts(timeout...)
gomega.Eventually(func(g gomega.Gomega) {
statusRejectionsMatcher := matchers.MatchStatusInNamespace(
p.glooGatewayContext.InstallNamespace,
gomega.And(matchers.HaveRejectedStateWithReasonSubstrings(desiredStatusReasons...), matchers.HaveReportedBy(desiredReporter)),
)
status, err := getResourceNamespacedStatus(getter)
g.Expect(err).NotTo(gomega.HaveOccurred(), "failed to get resource namespaced status")
g.Expect(status).ToNot(gomega.BeNil())
g.Expect(status).To(gomega.HaveValue(statusRejectionsMatcher))
}, currentTimeout, pollingInterval).Should(gomega.Succeed())
}
func (p *Provider) EventuallyResourceStatusMatchesState(
getter helpers.InputResourceGetter,
desiredState core.Status_State,
desiredReporter string,
timeout ...time.Duration,
) {
currentTimeout, pollingInterval := helper.GetTimeouts(timeout...)
p.Gomega.Eventually(func(g gomega.Gomega) {
statusStateMatcher := matchers.MatchStatusInNamespace(
p.glooGatewayContext.InstallNamespace,
gomega.And(matchers.HaveState(desiredState), matchers.HaveReportedBy(desiredReporter)),
)
status, err := getResourceNamespacedStatus(getter)
g.Expect(err).NotTo(gomega.HaveOccurred(), "failed to get resource namespaced status")
g.Expect(status).ToNot(gomega.BeNil())
g.Expect(status).To(gomega.HaveValue(statusStateMatcher))
}, currentTimeout, pollingInterval).Should(gomega.Succeed())
}
func (p *Provider) EventuallyResourceStatusMatchesSubResource(
getter helpers.InputResourceGetter,
desiredSubresourceName string,
desiredSubresource matchers.SoloKitSubresourceStatus,
timeout ...time.Duration,
) {
currentTimeout, pollingInterval := helper.GetTimeouts(timeout...)
p.Gomega.Eventually(func(g gomega.Gomega) {
subResourceStatusMatcher := matchers.HaveSubResourceStatusState(desiredSubresourceName, desiredSubresource)
status, err := getResourceNamespacedStatus(getter)
g.Expect(err).NotTo(gomega.HaveOccurred(), "failed to get resource namespaced status")
g.Expect(status).ToNot(gomega.BeNil())
g.Expect(status).To(gomega.HaveValue(subResourceStatusMatcher))
}, currentTimeout, pollingInterval).Should(gomega.Succeed())
}
func getResourceNamespacedStatus(getter helpers.InputResourceGetter) (*core.NamespacedStatuses, error) {
resource, err := getter()
if err != nil {
return &core.NamespacedStatuses{}, errors.Wrapf(err, "failed to get resource")
}
namespacedStatuses := resource.GetNamespacedStatuses()
// In newer versions of Gloo Edge we provide a default "empty" status, which allows us to patch it to perform updates
// As a result, a nil check isn't enough to determine that that status hasn't been reported
if namespacedStatuses == nil || namespacedStatuses.GetStatuses() == nil {
return &core.NamespacedStatuses{}, errors.Wrapf(err, "waiting for %v status to be non-empty", resource.GetMetadata().GetName())
}
return namespacedStatuses, nil
}
// AssertHTTPRouteStatusContainsSubstring asserts that at least one of the HTTPRoute's route parent statuses contains
// the given message substring.
func (p *Provider) AssertHTTPRouteStatusContainsSubstring(route *gwv1.HTTPRoute, message string) {
matcher := matchers.HaveKubeGatewayRouteStatus(&matchers.KubeGatewayRouteStatus{
Custom: gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
"Parents": gomega.ContainElement(gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
"Conditions": gomega.ContainElement(gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
"Message": matchers.ContainSubstrings([]string{message}),
})),
})),
}),
})
p.Gomega.Expect(route.Status.RouteStatus).To(gomega.HaveValue(matcher))
}