Skip to content

Commit

Permalink
reactor ServiceEntryGenerator
Browse files Browse the repository at this point in the history
Signed-off-by: charlie <qianglin98@qq.com>
  • Loading branch information
Charlie17Li committed Feb 1, 2023
1 parent f846557 commit c7fd187
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
26 changes: 1 addition & 25 deletions pkg/ingress/mcp/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,7 @@ type ServiceEntryGenerator struct {

func (c ServiceEntryGenerator) Generate(proxy *model.Proxy, push *model.PushContext, w *model.WatchedResource,
updates *model.PushRequest) ([]*any.Any, model.XdsLogDetails, error) {
resources := make([]*any.Any, 0)
configs := push.AllServiceEntries
for _, config := range configs {
body, err := types.MarshalAny(config.Spec.(*networking.ServiceEntry))
if err != nil {
return nil, model.DefaultXdsLogDetails, err
}
createTime, err := types.TimestampProto(config.CreationTimestamp)
if err != nil {
return nil, model.DefaultXdsLogDetails, err
}
resource := &mcp.Resource{
Body: body,
Metadata: &mcp.Metadata{
Name: path.Join(config.Namespace, config.Name),
CreateTime: createTime,
},
}
mcpAny, err := ptypes.MarshalAny(resource)
if err != nil {
return nil, model.DefaultXdsLogDetails, err
}
resources = append(resources, mcpAny)
}
return resources, model.DefaultXdsLogDetails, nil
return generate(proxy, push.AllServiceEntries, w, updates)
}

func (c ServiceEntryGenerator) GenerateDeltas(proxy *model.Proxy, push *model.PushContext, updates *model.PushRequest,
Expand Down
13 changes: 13 additions & 0 deletions pkg/ingress/mcp/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ func TestGenerate(t *testing.T) {
generator: WasmpluginGenerator{},
isErr: false,
},
{
name: "ServiceEntry",
fn: func() *model.PushContext {
ctx := model.NewPushContext()
cfg := config.Config{
Spec: &networking.ServiceEntry{},
}
ctx.AllServiceEntries = []config.Config{cfg}
return ctx
},
generator: ServiceEntryGenerator{},
isErr: false,
},
{
name: "WasmPlugin with wrong config",
fn: func() (*model.PushContext, any) {
Expand Down

0 comments on commit c7fd187

Please sign in to comment.