Skip to content

Commit

Permalink
Merge pull request #22 from beclab/fix/nats-export
Browse files Browse the repository at this point in the history
fix: change nats export to array
  • Loading branch information
eball authored Aug 2, 2024
2 parents 06348c5 + 3e648a2 commit cfd4f3e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
26 changes: 14 additions & 12 deletions config/crds/apr.bytetrade.io_middlewarerequests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,20 @@ spec:
items:
properties:
export:
properties:
appName:
type: string
pub:
description: default is deny
type: string
sub:
type: string
required:
- pub
- sub
type: object
items:
properties:
appName:
type: string
pub:
description: default is deny
type: string
sub:
type: string
required:
- pub
- sub
type: object
type: array
name:
type: string
permission:
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/apr/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ type Subject struct {
//// default allow for appName equals spec.App, others is deny
//Sub string `json:"sub"`
// Permissions indicates the permission that app can perform on this subject
Permission Permission `json:"permission"`
Export *Permission `json:"export,omitempty"`
Permission Permission `json:"permission"`
Export []Permission `json:"export,omitempty"`
}

type Permission struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/apr/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions pkg/workload/nats/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,24 @@ func getAllowPubSubSubjectFromMR(request *aprv1.MiddlewareRequest, namespace str
pub string
sub string
}

appExportMap := make(map[string][]export)
for _, mr := range mrs.Items {
if mr.Spec.Middleware != aprv1.TypeNats {
continue
}
for _, s := range mr.Spec.Nats.Subjects {
if s.Export != nil && s.Export.AppName != "" {
appExportMap[s.Export.AppName] = append(appExportMap[s.Export.AppName],
for _, e := range s.Export {
appExportMap[e.AppName] = append(appExportMap[e.AppName],
export{
subjectName: MakeRealSubjectName(s.Name, mr.Spec.AppNamespace),
appName: s.Export.AppName,
pub: s.Export.Pub,
sub: s.Export.Sub,
appName: e.AppName,
pub: e.Pub,
sub: e.Sub,
},
)
}

}
}
klog.Infof("appExportMap: %#v", appExportMap)
Expand Down

0 comments on commit cfd4f3e

Please sign in to comment.