Skip to content

Commit 343cab3

Browse files
committed
Fix Observed Generation for Gateway Status (nginx#351)
Use the Gateway's real generation in the Observed Generation field of the Gateway's status instead of "123".
1 parent d98ce0d commit 343cab3

File tree

6 files changed

+45
-25
lines changed

6 files changed

+45
-25
lines changed

internal/state/change_processor_test.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ var _ = Describe("ChangeProcessor", func() {
282282
expectedConf := state.Configuration{}
283283
expectedStatuses := state.Statuses{
284284
GatewayStatus: &state.GatewayStatus{
285-
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-1"},
285+
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-1"},
286+
ObservedGeneration: gw1.Generation,
286287
ListenerStatuses: map[string]state.ListenerStatus{
287288
"listener-80-1": {
288289
Valid: false,
@@ -386,7 +387,8 @@ var _ = Describe("ChangeProcessor", func() {
386387
ObservedGeneration: gc.Generation,
387388
},
388389
GatewayStatus: &state.GatewayStatus{
389-
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-1"},
390+
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-1"},
391+
ObservedGeneration: gw1.Generation,
390392
ListenerStatuses: map[string]state.ListenerStatus{
391393
"listener-80-1": {
392394
Valid: true,
@@ -494,7 +496,8 @@ var _ = Describe("ChangeProcessor", func() {
494496
ObservedGeneration: gc.Generation,
495497
},
496498
GatewayStatus: &state.GatewayStatus{
497-
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-1"},
499+
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-1"},
500+
ObservedGeneration: gw1.Generation,
498501
ListenerStatuses: map[string]state.ListenerStatus{
499502
"listener-80-1": {
500503
Valid: true,
@@ -603,7 +606,8 @@ var _ = Describe("ChangeProcessor", func() {
603606
ObservedGeneration: gc.Generation,
604607
},
605608
GatewayStatus: &state.GatewayStatus{
606-
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-1"},
609+
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-1"},
610+
ObservedGeneration: gw1Updated.Generation,
607611
ListenerStatuses: map[string]state.ListenerStatus{
608612
"listener-80-1": {
609613
Valid: true,
@@ -711,7 +715,8 @@ var _ = Describe("ChangeProcessor", func() {
711715
ObservedGeneration: gcUpdated.Generation,
712716
},
713717
GatewayStatus: &state.GatewayStatus{
714-
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-1"},
718+
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-1"},
719+
ObservedGeneration: gw1Updated.Generation,
715720
ListenerStatuses: map[string]state.ListenerStatus{
716721
"listener-80-1": {
717722
Valid: true,
@@ -818,7 +823,8 @@ var _ = Describe("ChangeProcessor", func() {
818823
ObservedGeneration: gcUpdated.Generation,
819824
},
820825
GatewayStatus: &state.GatewayStatus{
821-
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-1"},
826+
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-1"},
827+
ObservedGeneration: gw1Updated.Generation,
822828
ListenerStatuses: map[string]state.ListenerStatus{
823829
"listener-80-1": {
824830
Valid: true,
@@ -918,7 +924,8 @@ var _ = Describe("ChangeProcessor", func() {
918924
ObservedGeneration: gcUpdated.Generation,
919925
},
920926
GatewayStatus: &state.GatewayStatus{
921-
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-1"},
927+
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-1"},
928+
ObservedGeneration: gw1Updated.Generation,
922929
ListenerStatuses: map[string]state.ListenerStatus{
923930
"listener-80-1": {
924931
Valid: true,
@@ -1038,7 +1045,8 @@ var _ = Describe("ChangeProcessor", func() {
10381045
ObservedGeneration: gcUpdated.Generation,
10391046
},
10401047
GatewayStatus: &state.GatewayStatus{
1041-
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-2"},
1048+
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-2"},
1049+
ObservedGeneration: gw2.Generation,
10421050
ListenerStatuses: map[string]state.ListenerStatus{
10431051
"listener-80-1": {
10441052
Valid: true,
@@ -1101,7 +1109,8 @@ var _ = Describe("ChangeProcessor", func() {
11011109
ObservedGeneration: gcUpdated.Generation,
11021110
},
11031111
GatewayStatus: &state.GatewayStatus{
1104-
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-2"},
1112+
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-2"},
1113+
ObservedGeneration: gw2.Generation,
11051114
ListenerStatuses: map[string]state.ListenerStatus{
11061115
"listener-80-1": {
11071116
Valid: true,
@@ -1133,7 +1142,8 @@ var _ = Describe("ChangeProcessor", func() {
11331142
expectedConf := state.Configuration{}
11341143
expectedStatuses := state.Statuses{
11351144
GatewayStatus: &state.GatewayStatus{
1136-
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-2"},
1145+
NsName: types.NamespacedName{Namespace: "test", Name: "gateway-2"},
1146+
ObservedGeneration: gw2.Generation,
11371147
ListenerStatuses: map[string]state.ListenerStatus{
11381148
"listener-80-1": {
11391149
Valid: false,

internal/state/statuses.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ type Statuses struct {
2323

2424
// GatewayStatus holds the status of the winning Gateway resource.
2525
type GatewayStatus struct {
26+
// ListenerStatuses holds the statuses of listeners defined on the Gateway.
2627
ListenerStatuses ListenerStatuses
27-
NsName types.NamespacedName
28+
// NsName is the namespaced name of the winning Gateway resource.
29+
NsName types.NamespacedName
30+
// ObservedGeneration is the generation of the resource that was processed.
31+
ObservedGeneration int64
2832
}
2933

3034
// IgnoredGatewayStatuses holds the statuses of the ignored Gateway resources.
@@ -98,8 +102,9 @@ func buildStatuses(graph *graph) Statuses {
98102
}
99103

100104
statuses.GatewayStatus = &GatewayStatus{
101-
NsName: client.ObjectKeyFromObject(graph.Gateway.Source),
102-
ListenerStatuses: listenerStatuses,
105+
NsName: client.ObjectKeyFromObject(graph.Gateway.Source),
106+
ListenerStatuses: listenerStatuses,
107+
ObservedGeneration: graph.Gateway.Source.Generation,
103108
}
104109
}
105110

internal/state/statuses_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ func TestBuildStatuses(t *testing.T) {
5959

6060
gw := &v1beta1.Gateway{
6161
ObjectMeta: metav1.ObjectMeta{
62-
Namespace: "test",
63-
Name: "gateway",
62+
Namespace: "test",
63+
Name: "gateway",
64+
Generation: 2,
6465
},
6566
}
6667

@@ -107,6 +108,7 @@ func TestBuildStatuses(t *testing.T) {
107108
AttachedRoutes: 1,
108109
},
109110
},
111+
ObservedGeneration: 2,
110112
},
111113
IgnoredGatewayStatuses: map[types.NamespacedName]IgnoredGatewayStatus{
112114
{Namespace: "test", Name: "ignored-gateway"}: {ObservedGeneration: 1},
@@ -152,6 +154,7 @@ func TestBuildStatuses(t *testing.T) {
152154
AttachedRoutes: 1,
153155
},
154156
},
157+
ObservedGeneration: 2,
155158
},
156159
IgnoredGatewayStatuses: map[types.NamespacedName]IgnoredGatewayStatus{
157160
{Namespace: "test", Name: "ignored-gateway"}: {ObservedGeneration: 1},
@@ -211,6 +214,7 @@ func TestBuildStatuses(t *testing.T) {
211214
AttachedRoutes: 1,
212215
},
213216
},
217+
ObservedGeneration: 2,
214218
},
215219
IgnoredGatewayStatuses: map[types.NamespacedName]IgnoredGatewayStatus{
216220
{Namespace: "test", Name: "ignored-gateway"}: {ObservedGeneration: 1},

internal/status/gateway.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ func prepareGatewayStatus(gatewayStatus state.GatewayStatus, transitionTime meta
5050
}
5151

5252
cond := metav1.Condition{
53-
Type: string(v1beta1.ListenerConditionReady),
54-
Status: status,
55-
// FIXME(pleshakov) Set the observed generation to the last processed generation of the Gateway resource.
56-
ObservedGeneration: 123,
53+
Type: string(v1beta1.ListenerConditionReady),
54+
Status: status,
55+
ObservedGeneration: gatewayStatus.ObservedGeneration,
5756
LastTransitionTime: transitionTime,
5857
Reason: string(reason),
5958
Message: "", // FIXME(pleshakov) Come up with a good message

internal/status/gateway_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func TestPrepareGatewayStatus(t *testing.T) {
2323
AttachedRoutes: 1,
2424
},
2525
},
26+
ObservedGeneration: 1,
2627
}
2728

2829
transitionTime := metav1.NewTime(time.Now())
@@ -41,7 +42,7 @@ func TestPrepareGatewayStatus(t *testing.T) {
4142
{
4243
Type: string(v1beta1.ListenerConditionReady),
4344
Status: metav1.ConditionFalse,
44-
ObservedGeneration: 123,
45+
ObservedGeneration: 1,
4546
LastTransitionTime: transitionTime,
4647
Reason: string(v1beta1.ListenerReasonInvalid),
4748
},
@@ -59,7 +60,7 @@ func TestPrepareGatewayStatus(t *testing.T) {
5960
{
6061
Type: string(v1beta1.ListenerConditionReady),
6162
Status: metav1.ConditionTrue,
62-
ObservedGeneration: 123,
63+
ObservedGeneration: 1,
6364
LastTransitionTime: transitionTime,
6465
Reason: string(v1beta1.ListenerReasonReady),
6566
},

internal/status/updater_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ var _ = Describe("Updater", func() {
8585
AttachedRoutes: 1,
8686
},
8787
},
88+
ObservedGeneration: generation,
8889
},
8990
IgnoredGatewayStatuses: map[types.NamespacedName]state.IgnoredGatewayStatus{
9091
{Namespace: "test", Name: "ignored-gateway"}: {
@@ -138,7 +139,7 @@ var _ = Describe("Updater", func() {
138139
}
139140
}
140141

141-
createExpectedGw = func(status metav1.ConditionStatus, reason string) *v1beta1.Gateway {
142+
createExpectedGw = func(status metav1.ConditionStatus, generation int64, reason string) *v1beta1.Gateway {
142143
return &v1beta1.Gateway{
143144
ObjectMeta: metav1.ObjectMeta{
144145
Namespace: "test",
@@ -162,7 +163,7 @@ var _ = Describe("Updater", func() {
162163
{
163164
Type: string(v1beta1.ListenerConditionReady),
164165
Status: status,
165-
ObservedGeneration: 123,
166+
ObservedGeneration: generation,
166167
LastTransitionTime: fakeClockTime,
167168
Reason: reason,
168169
},
@@ -306,7 +307,7 @@ var _ = Describe("Updater", func() {
306307

307308
It("should have the updated status of Gateway in the API server", func() {
308309
latestGw := &v1beta1.Gateway{}
309-
expectedGw := createExpectedGw(metav1.ConditionTrue, string(v1beta1.ListenerReasonReady))
310+
expectedGw := createExpectedGw(metav1.ConditionTrue, 1, string(v1beta1.ListenerReasonReady))
310311

311312
err := client.Get(context.Background(), types.NamespacedName{Namespace: "test", Name: "gateway"}, latestGw)
312313
Expect(err).Should(Not(HaveOccurred()))
@@ -370,7 +371,7 @@ var _ = Describe("Updater", func() {
370371

371372
It("should have the updated status of Gateway in the API server", func() {
372373
latestGw := &v1beta1.Gateway{}
373-
expectedGw := createExpectedGw(metav1.ConditionFalse, string(v1beta1.ListenerReasonInvalid))
374+
expectedGw := createExpectedGw(metav1.ConditionFalse, 2, string(v1beta1.ListenerReasonInvalid))
374375

375376
err := client.Get(
376377
context.Background(),

0 commit comments

Comments
 (0)