Skip to content
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

feat: add context in module interface #898

Merged
merged 1 commit into from
Mar 11, 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
3 changes: 2 additions & 1 deletion pkg/modules/generators/app_configurations_generator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package generators

import (
"context"
"errors"
"fmt"

Expand Down Expand Up @@ -164,7 +165,7 @@ func (g *appConfigurationGenerator) callModules(projectModuleConfigs map[string]

// invoke the plugin
log.Infof("invoke module:%s with request:%s", t, protoRequest.String())
response, err := plugin.Module.Generate(protoRequest)
response, err := plugin.Module.Generate(context.Background(), protoRequest)
if err != nil {
return nil, fmt.Errorf("invoke kusion module: %s failed. %w", t, err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/modules/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Generator interface {

// Module is the interface that we're exposing as a kusion module plugin.
type Module interface {
Generate(req *proto.GeneratorRequest) (*proto.GeneratorResponse, error)
Generate(ctx context.Context, req *proto.GeneratorRequest) (*proto.GeneratorResponse, error)
}

// NewGeneratorFunc is a function that returns a Generator.
Expand All @@ -32,8 +32,8 @@ type GRPCClient struct {
client proto.ModuleClient
}

func (c *GRPCClient) Generate(req *proto.GeneratorRequest) (*proto.GeneratorResponse, error) {
return c.client.Generate(context.Background(), req)
func (c *GRPCClient) Generate(ctx context.Context, req *proto.GeneratorRequest) (*proto.GeneratorResponse, error) {
return c.client.Generate(ctx, req)
}

type GRPCServer struct {
Expand All @@ -49,7 +49,7 @@ func (s *GRPCServer) Generate(ctx context.Context, req *proto.GeneratorRequest)
res = &proto.GeneratorResponse{}
}
}()
res, err = s.Impl.Generate(req)
res, err = s.Impl.Generate(ctx, req)
return
}

Expand Down
Loading