Skip to content

Commit d63e5e5

Browse files
authored
make global rules compatible with dashboard (#14)
1 parent 7c94247 commit d63e5e5

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pkg/apisix/global_rule.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package apisix
1717
import (
1818
"context"
1919
"encoding/json"
20+
"fmt"
2021

2122
"go.uber.org/zap"
2223

@@ -114,6 +115,17 @@ func (r *globalRuleClient) Create(ctx context.Context, obj *v1.GlobalRule, shoul
114115
return v, nil
115116
}
116117

118+
//Overwrite global rule ID with the plugin name
119+
if len(obj.Plugins) == 0 { //This case will not happen as its handled at schema validation level
120+
return nil, fmt.Errorf("global rule must have at least one plugin")
121+
}
122+
123+
//This is checked on dashboard that global rule id should be the plugin name
124+
for pluginName := range obj.Plugins {
125+
obj.ID = pluginName
126+
break
127+
}
128+
117129
log.Debugw("try to create global_rule",
118130
zap.String("id", obj.ID),
119131
zap.Any("plugins", obj.Plugins),

samples/deploy/crd/v1/ApisixGlobalRule.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ spec:
5151
ingressClassName:
5252
type: string
5353
plugins:
54+
minItems: 1
55+
maxItems: 1
5456
type: array
5557
items:
5658
type: object

0 commit comments

Comments
 (0)