Skip to content

Commit 0eb6f26

Browse files
committed
fix test
1 parent d0d4dd1 commit 0eb6f26

File tree

8 files changed

+90
-61
lines changed

8 files changed

+90
-61
lines changed

internal/adc/client/client.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,6 @@ func (c *Client) Sync(ctx context.Context) (map[string]types.ADCExecutionErrors,
195195
cfg[config.Name] = config
196196
}
197197

198-
if len(cfg) == 0 {
199-
log.Warn("no adc configs provided")
200-
return nil, nil
201-
}
202-
203198
log.Debugw("syncing resources with multiple configs", zap.Any("configs", cfg))
204199

205200
failedMap := map[string]types.ADCExecutionErrors{}

internal/provider/api7ee/provider.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ type api7eeProvider struct {
5454

5555
provider.Options
5656

57+
syncCh chan struct{}
58+
5759
client *adcclient.Client
5860
}
5961

@@ -75,6 +77,7 @@ func New(updater status.Updater, readier readiness.ReadinessManager, opts ...pro
7577
translator: &translator.Translator{},
7678
updater: updater,
7779
readier: readier,
80+
syncCh: make(chan struct{}, 1),
7881
}, nil
7982
}
8083

@@ -219,6 +222,8 @@ func (d *api7eeProvider) Start(ctx context.Context) error {
219222
for {
220223
synced := false
221224
select {
225+
case <-d.syncCh:
226+
synced = true
222227
case <-ticker.C:
223228
synced = true
224229
case <-ctx.Done():
@@ -232,15 +237,26 @@ func (d *api7eeProvider) Start(ctx context.Context) error {
232237
}
233238
}
234239

240+
func (d *api7eeProvider) syncNotify() {
241+
select {
242+
case d.syncCh <- struct{}{}:
243+
default:
244+
}
245+
}
246+
235247
func (d *api7eeProvider) sync(ctx context.Context) error {
236248
statusesMap, err := d.client.Sync(ctx)
237249
d.handleADCExecutionErrors(statusesMap)
238250
return err
239251
}
240252

241253
func (d *api7eeProvider) handleADCExecutionErrors(statusesMap map[string]types.ADCExecutionErrors) {
254+
if len(statusesMap) == 0 {
255+
return
256+
}
242257
statusUpdateMap := d.resolveADCExecutionErrors(statusesMap)
243258
d.handleStatusUpdate(statusUpdateMap)
259+
log.Debugw("handled ADC execution errors", zap.Any("status_record", statusesMap), zap.Any("status_update", statusUpdateMap))
244260
}
245261

246262
func (d *api7eeProvider) NeedLeaderElection() bool {
@@ -259,8 +275,10 @@ func (d *api7eeProvider) updateConfigForGatewayProxy(tctx *provider.TranslateCon
259275
d.client.ConfigManager.DeleteConfig(nnk)
260276
return nil
261277
}
262-
278+
referrers := tctx.GatewayProxyReferrers[utils.NamespacedName(gp)]
279+
d.client.ConfigManager.SetConfigRefs(nnk, referrers)
263280
d.client.ConfigManager.UpdateConfig(nnk, *config)
281+
d.syncNotify()
264282
return nil
265283
}
266284

internal/provider/api7ee/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (d *api7eeProvider) updateStatus(nnk types.NamespacedNameKind, condition me
110110
}),
111111
})
112112
case types.KindHTTPRoute:
113-
parentRefs := d.client.ConfigManager.GetParentRefs(nnk)
113+
parentRefs := d.client.ConfigManager.GetConfigRefsByResourceKey(nnk)
114114
gatewayRefs := map[types.NamespacedNameKind]struct{}{}
115115
for _, parentRef := range parentRefs {
116116
if parentRef.Kind == types.KindGateway {

internal/provider/apisix/provider.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,7 @@ func (d *apisixProvider) Start(ctx context.Context) error {
263263
func (d *apisixProvider) sync(ctx context.Context) error {
264264
statusesMap, err := d.client.Sync(ctx)
265265
d.handleADCExecutionErrors(statusesMap)
266-
if err != nil {
267-
return err
268-
}
269-
return nil
266+
return err
270267
}
271268

272269
func (d *apisixProvider) syncNotify() {
@@ -277,8 +274,12 @@ func (d *apisixProvider) syncNotify() {
277274
}
278275

279276
func (d *apisixProvider) handleADCExecutionErrors(statusesMap map[string]types.ADCExecutionErrors) {
277+
if len(statusesMap) == 0 {
278+
return
279+
}
280280
statusUpdateMap := d.resolveADCExecutionErrors(statusesMap)
281281
d.handleStatusUpdate(statusUpdateMap)
282+
log.Debugw("handled ADC execution errors", zap.Any("status_record", statusesMap), zap.Any("status_update", statusUpdateMap))
282283
}
283284

284285
func (d *apisixProvider) NeedLeaderElection() bool {
@@ -297,7 +298,8 @@ func (d *apisixProvider) updateConfigForGatewayProxy(tctx *provider.TranslateCon
297298
d.client.ConfigManager.DeleteConfig(nnk)
298299
return nil
299300
}
300-
301+
referrers := tctx.GatewayProxyReferrers[utils.NamespacedName(gp)]
302+
d.client.ConfigManager.SetConfigRefs(nnk, referrers)
301303
d.client.ConfigManager.UpdateConfig(nnk, *config)
302304
d.syncNotify()
303305
return nil

internal/provider/apisix/status.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ func (d *apisixProvider) updateStatus(nnk types.NamespacedNameKind, condition me
110110
}),
111111
})
112112
case types.KindHTTPRoute:
113-
parentRefs := d.client.ConfigManager.GetParentRefs(nnk)
113+
parentRefs := d.client.ConfigManager.GetConfigRefsByResourceKey(nnk)
114+
log.Debugw("updating HTTPRoute status", zap.Any("parentRefs", parentRefs))
114115
gatewayRefs := map[types.NamespacedNameKind]struct{}{}
115116
for _, parentRef := range parentRefs {
116117
if parentRef.Kind == types.KindGateway {

internal/provider/common/configmanager.go

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,55 @@ import (
2222
)
2323

2424
type ConfigManager[K comparable, T any] struct {
25-
mu sync.Mutex
26-
parentRefs map[K][]K
27-
configs map[K]T
25+
mu sync.Mutex
26+
resourceConfigKeys map[K][]K
27+
configs map[K]T
28+
configRefs map[K][]K
2829
}
2930

3031
func NewConfigManager[K comparable, T any]() *ConfigManager[K, T] {
3132
return &ConfigManager[K, T]{
32-
parentRefs: make(map[K][]K),
33-
configs: make(map[K]T),
33+
resourceConfigKeys: make(map[K][]K),
34+
configs: make(map[K]T),
35+
configRefs: make(map[K][]K),
3436
}
3537
}
3638

37-
func (s *ConfigManager[K, T]) GetParentRefs(key K) []K {
39+
func (s *ConfigManager[K, T]) GetConfigRefs(key K) []K {
3840
s.mu.Lock()
3941
defer s.mu.Unlock()
40-
return s.parentRefs[key]
42+
return s.configRefs[key]
4143
}
4244

43-
func (s *ConfigManager[K, T]) SetParentRefs(key K, refs []K) {
45+
func (s *ConfigManager[K, T]) GetConfigRefsByResourceKey(key K) []K {
4446
s.mu.Lock()
4547
defer s.mu.Unlock()
46-
s.parentRefs[key] = refs
48+
configKeys, ok := s.resourceConfigKeys[key]
49+
if !ok {
50+
return nil
51+
}
52+
refs := make([]K, 0, len(configKeys))
53+
for _, k := range configKeys {
54+
if ref, ok := s.configRefs[k]; ok {
55+
refs = append(refs, ref...)
56+
}
57+
}
58+
return refs
59+
}
60+
61+
func (s *ConfigManager[K, T]) SetConfigRefs(key K, refs []K) {
62+
s.mu.Lock()
63+
defer s.mu.Unlock()
64+
s.configRefs[key] = refs
4765
}
4866

4967
func (s *ConfigManager[K, T]) Get(key K) map[K]T {
5068
s.mu.Lock()
5169
defer s.mu.Unlock()
5270

53-
parentRefs := s.parentRefs[key]
54-
configs := make(map[K]T, len(parentRefs))
55-
for _, parent := range parentRefs {
71+
resourceConfigKeys := s.resourceConfigKeys[key]
72+
configs := make(map[K]T, len(resourceConfigKeys))
73+
for _, parent := range resourceConfigKeys {
5674
if cfg, ok := s.configs[parent]; ok {
5775
configs[parent] = cfg
5876
}
@@ -85,15 +103,15 @@ func (s *ConfigManager[K, T]) Update(
85103
defer s.mu.Unlock()
86104

87105
parentRefSet := make(map[K]struct{})
88-
oldParentRefs := s.parentRefs[key]
106+
oldParentRefs := s.resourceConfigKeys[key]
89107
newRefs := make([]K, 0, len(mapRefs))
90108

91109
for k, v := range mapRefs {
92110
newRefs = append(newRefs, k)
93111
s.configs[k] = v
94112
parentRefSet[k] = struct{}{}
95113
}
96-
s.parentRefs[key] = newRefs
114+
s.resourceConfigKeys[key] = newRefs
97115
discard = make(map[K]T)
98116
for _, old := range oldParentRefs {
99117
if _, stillUsed := parentRefSet[old]; !stillUsed {
@@ -115,12 +133,14 @@ func (s *ConfigManager[K, T]) Set(key K, cfg T) {
115133
func (s *ConfigManager[K, T]) Delete(key K) {
116134
s.mu.Lock()
117135
defer s.mu.Unlock()
118-
delete(s.parentRefs, key)
136+
delete(s.resourceConfigKeys, key)
119137
delete(s.configs, key)
138+
delete(s.configRefs, key)
120139
}
121140

122141
func (s *ConfigManager[K, T]) DeleteConfig(key K) {
123142
s.mu.Lock()
124143
defer s.mu.Unlock()
125-
delete(s.parentRefs, key)
144+
delete(s.configs, key)
145+
delete(s.configRefs, key)
126146
}

test/e2e/crds/v2/status.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,12 @@ spec:
191191
s.RetryAssertion(func() string {
192192
output, _ := s.GetOutputFromString("ar", "default", "-o", "yaml")
193193
return output
194-
}).WithTimeout(80 * time.Second).
195-
Should(
196-
And(
197-
ContainSubstring(`status: "False"`),
198-
ContainSubstring(`reason: SyncFailed`),
199-
),
200-
)
194+
}).Should(
195+
And(
196+
ContainSubstring(`status: "False"`),
197+
ContainSubstring(`reason: SyncFailed`),
198+
),
199+
)
201200

202201
By("update service to original spec")
203202
serviceYaml, err = s.GetOutputFromString("svc", framework.ProviderType, "-o", "yaml")
@@ -214,13 +213,12 @@ spec:
214213
s.RetryAssertion(func() string {
215214
output, _ := s.GetOutputFromString("ar", "default", "-o", "yaml")
216215
return output
217-
}).WithTimeout(80 * time.Second).
218-
Should(
219-
And(
220-
ContainSubstring(`status: "True"`),
221-
ContainSubstring(`reason: Accepted`),
222-
),
223-
)
216+
}).Should(
217+
And(
218+
ContainSubstring(`status: "True"`),
219+
ContainSubstring(`reason: Accepted`),
220+
),
221+
)
224222

225223
By("check route in APISIX")
226224
s.RequestAssert(&scaffold.RequestAssert{

test/e2e/gatewayapi/status.go

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ spec:
9696
time.Sleep(5 * time.Second)
9797

9898
By("create Gateway")
99-
err = s.CreateResourceFromString(fmt.Sprintf(defaultGateway, gatewayClassName))
99+
err = s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultGateway, gatewayClassName), s.Namespace())
100100
Expect(err).NotTo(HaveOccurred(), "creating Gateway")
101101
time.Sleep(5 * time.Second)
102102

@@ -106,9 +106,6 @@ spec:
106106
Expect(gwyaml).To(ContainSubstring(`status: "True"`), "checking Gateway condition status")
107107
Expect(gwyaml).To(ContainSubstring("message: the gateway has been accepted by the apisix-ingress-controller"), "checking Gateway condition message")
108108
})
109-
AfterEach(func() {
110-
_ = s.DeleteResource("Gateway", "apisix")
111-
})
112109

113110
It("dataplane unavailable", func() {
114111
if os.Getenv("PROVIDER_TYPE") == framework.ProviderTypeAPI7EE {
@@ -147,13 +144,12 @@ spec:
147144
s.RetryAssertion(func() string {
148145
output, _ := s.GetOutputFromString("httproute", "httpbin", "-o", "yaml")
149146
return output
150-
}).WithTimeout(80 * time.Second).
151-
Should(
152-
And(
153-
ContainSubstring(`status: "False"`),
154-
ContainSubstring(`reason: SyncFailed`),
155-
),
156-
)
147+
}).Should(
148+
And(
149+
ContainSubstring(`status: "False"`),
150+
ContainSubstring(`reason: SyncFailed`),
151+
),
152+
)
157153

158154
By("update service to original spec")
159155
serviceYaml, err = s.GetOutputFromString("svc", framework.ProviderType, "-o", "yaml")
@@ -170,13 +166,12 @@ spec:
170166
s.RetryAssertion(func() string {
171167
output, _ := s.GetOutputFromString("httproute", "httpbin", "-o", "yaml")
172168
return output
173-
}).WithTimeout(80 * time.Second).
174-
Should(
175-
And(
176-
ContainSubstring(`status: "True"`),
177-
ContainSubstring(`reason: Accepted`),
178-
),
179-
)
169+
}).Should(
170+
And(
171+
ContainSubstring(`status: "True"`),
172+
ContainSubstring(`reason: Accepted`),
173+
),
174+
)
180175

181176
By("check route in APISIX")
182177
s.RequestAssert(&scaffold.RequestAssert{

0 commit comments

Comments
 (0)