Skip to content

Commit 0d07570

Browse files
committed
Use constants
1 parent 6d3b319 commit 0d07570

File tree

5 files changed

+28
-21
lines changed

5 files changed

+28
-21
lines changed

internal/status/gateway.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ func prepareGatewayStatus(statuses newstate.ListenerStatuses, transitionTime met
2626
for _, name := range names {
2727
s := statuses[name]
2828

29-
var status, reason string
29+
var (
30+
status metav1.ConditionStatus
31+
reason v1alpha2.ListenerConditionReason
32+
)
3033

3134
if s.Valid {
32-
status = "True"
33-
reason = string(v1alpha2.ListenerReasonReady)
35+
status = metav1.ConditionTrue
36+
reason = v1alpha2.ListenerReasonReady
3437
} else {
35-
status = "False"
36-
reason = string(v1alpha2.ListenerReasonInvalid)
38+
status = metav1.ConditionFalse
39+
reason = v1alpha2.ListenerReasonInvalid
3740
}
3841

3942
cond := metav1.Condition{
@@ -42,7 +45,7 @@ func prepareGatewayStatus(statuses newstate.ListenerStatuses, transitionTime met
4245
// FIXME(pleshakov) Set the observed generation to the last processed generation of the Gateway resource.
4346
ObservedGeneration: 123,
4447
LastTransitionTime: transitionTime,
45-
Reason: reason,
48+
Reason: string(reason),
4649
Message: "", // FIXME(pleshakov) Come up with a good message
4750
}
4851

internal/status/gateway_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestPrepareGatewayStatus(t *testing.T) {
3838
Conditions: []metav1.Condition{
3939
{
4040
Type: string(v1alpha2.ListenerConditionReady),
41-
Status: "False",
41+
Status: metav1.ConditionFalse,
4242
ObservedGeneration: 123,
4343
LastTransitionTime: transitionTime,
4444
Reason: string(v1alpha2.ListenerReasonInvalid),
@@ -56,7 +56,7 @@ func TestPrepareGatewayStatus(t *testing.T) {
5656
Conditions: []metav1.Condition{
5757
{
5858
Type: string(v1alpha2.ListenerConditionReady),
59-
Status: "True",
59+
Status: metav1.ConditionTrue,
6060
ObservedGeneration: 123,
6161
LastTransitionTime: transitionTime,
6262
Reason: string(v1alpha2.ListenerReasonReady),

internal/status/httproute.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ func prepareHTTPRouteStatus(
3232
for _, name := range names {
3333
ps := status.ParentStatuses[name]
3434

35-
var status, reason string
35+
var (
36+
status metav1.ConditionStatus
37+
reason string // FIXME(pleshakov) use RouteConditionReason once we upgrade to v1beta1
38+
)
39+
3640
if ps.Attached {
37-
status = "True"
38-
reason = "Attached"
41+
status = metav1.ConditionTrue
42+
reason = "Accepted" // FIXME(pleshakov): use RouteReasonAccepted once we upgrade to v1beta1
3943
} else {
40-
status = "False"
41-
reason = "Not attached"
44+
status = metav1.ConditionFalse
45+
reason = "Not attached" // FIXME(pleshakov): use a more specific message from the defined constants (available in v1beta1)
4246
}
4347

4448
sectionName := name
@@ -53,7 +57,7 @@ func prepareHTTPRouteStatus(
5357
Conditions: []metav1.Condition{
5458
{
5559
Type: string(v1alpha2.ConditionRouteAccepted),
56-
Status: metav1.ConditionStatus(status),
60+
Status: status,
5761
// FIXME(pleshakov) Set the observed generation to the last processed generation of the HTTPRoute resource.
5862
ObservedGeneration: 123,
5963
LastTransitionTime: transitionTime,

internal/status/httproute_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ func TestPrepareHTTPRouteStatus(t *testing.T) {
4343
Conditions: []metav1.Condition{
4444
{
4545
Type: string(v1alpha2.ConditionRouteAccepted),
46-
Status: "True",
46+
Status: metav1.ConditionTrue,
4747
ObservedGeneration: 123,
4848
LastTransitionTime: transitionTime,
49-
Reason: "Attached",
49+
Reason: "Accepted",
5050
},
5151
},
5252
},
@@ -60,7 +60,7 @@ func TestPrepareHTTPRouteStatus(t *testing.T) {
6060
Conditions: []metav1.Condition{
6161
{
6262
Type: string(v1alpha2.ConditionRouteAccepted),
63-
Status: "False",
63+
Status: metav1.ConditionFalse,
6464
ObservedGeneration: 123,
6565
LastTransitionTime: transitionTime,
6666
Reason: "Not attached",

internal/status/updater_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ var _ = Describe("Updater", func() {
127127
Conditions: []metav1.Condition{
128128
{
129129
Type: string(gatewayv1alpha2.ConditionRouteAccepted),
130-
Status: "True",
130+
Status: metav1.ConditionTrue,
131131
ObservedGeneration: 123,
132132
LastTransitionTime: fakeClockTime,
133-
Reason: "Attached",
133+
Reason: "Accepted",
134134
},
135135
},
136136
},
@@ -199,7 +199,7 @@ var _ = Describe("Updater", func() {
199199

200200
It("should have the updated status of Gateway in the API server", func() {
201201
latestGw := &v1alpha2.Gateway{}
202-
expectedGw := createExpectedGw("True", string(v1alpha2.ListenerReasonReady))
202+
expectedGw := createExpectedGw(metav1.ConditionTrue, string(v1alpha2.ListenerReasonReady))
203203

204204
err := client.Get(context.Background(), types.NamespacedName{Namespace: "test", Name: "gateway"}, latestGw)
205205
Expect(err).Should(Not(HaveOccurred()))
@@ -229,7 +229,7 @@ var _ = Describe("Updater", func() {
229229

230230
It("should have the updated status of Gateway in the API server after updating with canceled context", func() {
231231
latestGw := &v1alpha2.Gateway{}
232-
expectedGw := createExpectedGw("False", string(v1alpha2.ListenerReasonInvalid))
232+
expectedGw := createExpectedGw(metav1.ConditionFalse, string(v1alpha2.ListenerReasonInvalid))
233233

234234
err := client.Get(context.Background(), types.NamespacedName{Namespace: "test", Name: "gateway"}, latestGw)
235235
Expect(err).Should(Not(HaveOccurred()))

0 commit comments

Comments
 (0)