Skip to content

Commit 45dd100

Browse files
committed
fix: support sync global rule in api7ee mode
Signed-off-by: ashing <[email protected]>
1 parent f9cdfb6 commit 45dd100

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

internal/provider/adc/adc.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"context"
2222
"encoding/json"
2323
"os"
24+
"slices"
2425
"sync"
2526
"time"
2627

@@ -351,6 +352,18 @@ func (d *adcClient) sync(ctx context.Context, task Task) error {
351352
return errors.New("no adc configs provided")
352353
}
353354

355+
// for global rules, we need to list all global rules
356+
if slices.Contains(task.ResourceTypes, "global_rule") {
357+
for _, config := range task.configs {
358+
globalRules, err := d.store.GetGlobalRules(config.Name)
359+
if err != nil {
360+
return err
361+
}
362+
task.Resources.GlobalRules = *globalRules
363+
log.Debugw("syncing resources global rules", zap.Any("globalRules", task.Resources.GlobalRules))
364+
}
365+
}
366+
354367
syncFilePath, cleanup, err := prepareSyncFile(task.Resources)
355368
if err != nil {
356369
return err

internal/provider/adc/store.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,28 @@ func (s *Store) GetResources(name string) (*adctypes.Resources, error) {
244244
PluginMetadata: metadata,
245245
}, nil
246246
}
247+
248+
func (s *Store) GetGlobalRules(name string) (*adctypes.GlobalRule, error) {
249+
s.Lock()
250+
defer s.Unlock()
251+
252+
var globalrule adctypes.GlobalRule
253+
targetCache, ok := s.cacheMap[name]
254+
if !ok {
255+
return &globalrule, nil
256+
}
257+
// Get all global rules from cache and merge them
258+
globalRuleItems, _ := targetCache.ListGlobalRules()
259+
if len(globalRuleItems) > 0 {
260+
merged := make(adctypes.Plugins)
261+
for _, item := range globalRuleItems {
262+
for k, v := range item.Plugins {
263+
merged[k] = v
264+
}
265+
}
266+
globalrule = adctypes.GlobalRule(merged)
267+
}
268+
log.Debugw("get resources global rule items", zap.Any("globalRuleItems", globalRuleItems))
269+
270+
return &globalrule, nil
271+
}

test/e2e/crds/v2/globalrule.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ spec:
8888

8989
Context("ApisixGlobalRule Basic Operations", func() {
9090
BeforeEach(func() {
91-
if s.Deployer.Name() == "api7ee" {
92-
Skip("GlobalRule is not supported in api7ee")
93-
}
91+
// if s.Deployer.Name() == "api7ee" {
92+
// Skip("GlobalRule is not supported in api7ee")
93+
// }
9494
By("create GatewayProxy")
9595
gatewayProxy := fmt.Sprintf(gatewayProxyYaml, s.Deployer.GetAdminEndpoint(), s.AdminKey())
9696
err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default")

0 commit comments

Comments
 (0)