Skip to content

make global rules compatible with dashboard #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/apisix/global_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package apisix
import (
"context"
"encoding/json"
"fmt"

"go.uber.org/zap"

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

//Overwrite global rule ID with the plugin name
if len(obj.Plugins) == 0 { //This case will not happen as its handled at schema validation level
return nil, fmt.Errorf("global rule must have at least one plugin")
}

//This is checked on dashboard that global rule id should be the plugin name
for pluginName := range obj.Plugins {
obj.ID = pluginName
break
}

log.Debugw("try to create global_rule",
zap.String("id", obj.ID),
zap.Any("plugins", obj.Plugins),
Expand Down
2 changes: 2 additions & 0 deletions samples/deploy/crd/v1/ApisixGlobalRule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ spec:
ingressClassName:
type: string
plugins:
minItems: 1
maxItems: 1
type: array
items:
type: object
Expand Down
Loading