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

Implemented the backend of Metadata APIs as MetadataStoreRegistry #5471

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
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
45 changes: 38 additions & 7 deletions pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"context"
"fmt"

"github.com/pipe-cd/pipecd/pkg/app/pipedv1/metadatastore"
"github.com/pipe-cd/pipecd/pkg/app/server/service/pipedservice"
config "github.com/pipe-cd/pipecd/pkg/configv1"
service "github.com/pipe-cd/pipecd/pkg/plugin/pipedservice"
Expand All @@ -32,8 +33,9 @@
cfg *config.PipedSpec
apiClient apiClient

toolRegistry *toolRegistry
Logger *zap.Logger
toolRegistry *toolRegistry
Logger *zap.Logger
metadataStoreRegistry *metadatastore.MetadataStoreRegistry
}

type apiClient interface {
Expand All @@ -46,17 +48,18 @@
service.RegisterPluginServiceServer(server, a)
}

func NewPluginAPI(cfg *config.PipedSpec, apiClient apiClient, toolsDir string, logger *zap.Logger) (*PluginAPI, error) {
func NewPluginAPI(cfg *config.PipedSpec, apiClient apiClient, toolsDir string, logger *zap.Logger, metadataStoreRegistry *metadatastore.MetadataStoreRegistry) (*PluginAPI, error) {

Check warning on line 51 in pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go#L51

Added line #L51 was not covered by tests
toolRegistry, err := newToolRegistry(toolsDir)
if err != nil {
return nil, fmt.Errorf("failed to create tool registry: %w", err)
}

return &PluginAPI{
cfg: cfg,
apiClient: apiClient,
toolRegistry: toolRegistry,
Logger: logger.Named("plugin-api"),
cfg: cfg,
apiClient: apiClient,
toolRegistry: toolRegistry,
Logger: logger.Named("plugin-api"),
metadataStoreRegistry: metadataStoreRegistry,

Check warning on line 62 in pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go#L58-L62

Added lines #L58 - L62 were not covered by tests
}, nil
}

Expand Down Expand Up @@ -112,3 +115,31 @@

return &service.ReportStageLogsFromLastCheckpointResponse{}, nil
}

func (a *PluginAPI) GetStageMetadata(ctx context.Context, req *service.GetStageMetadataRequest) (*service.GetStageMetadataResponse, error) {
return a.metadataStoreRegistry.GetStageMetadata(ctx, req)

Check warning on line 120 in pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go#L119-L120

Added lines #L119 - L120 were not covered by tests
}

func (a *PluginAPI) PutStageMetadata(ctx context.Context, req *service.PutStageMetadataRequest) (*service.PutStageMetadataResponse, error) {
return a.metadataStoreRegistry.PutStageMetadata(ctx, req)

Check warning on line 124 in pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go#L123-L124

Added lines #L123 - L124 were not covered by tests
}

func (a *PluginAPI) PutStageMetadataMulti(ctx context.Context, req *service.PutStageMetadataMultiRequest) (*service.PutStageMetadataMultiResponse, error) {
return a.metadataStoreRegistry.PutStageMetadataMulti(ctx, req)

Check warning on line 128 in pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go#L127-L128

Added lines #L127 - L128 were not covered by tests
}

func (a *PluginAPI) GetDeploymentPluginMetadata(ctx context.Context, req *service.GetDeploymentPluginMetadataRequest) (*service.GetDeploymentPluginMetadataResponse, error) {
return a.metadataStoreRegistry.GetDeploymentPluginMetadata(ctx, req)

Check warning on line 132 in pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go#L131-L132

Added lines #L131 - L132 were not covered by tests
}

func (a *PluginAPI) PutDeploymentPluginMetadata(ctx context.Context, req *service.PutDeploymentPluginMetadataRequest) (*service.PutDeploymentPluginMetadataResponse, error) {
return a.metadataStoreRegistry.PutDeploymentPluginMetadata(ctx, req)

Check warning on line 136 in pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go#L135-L136

Added lines #L135 - L136 were not covered by tests
}

func (a *PluginAPI) PutDeploymentPluginMetadataMulti(ctx context.Context, req *service.PutDeploymentPluginMetadataMultiRequest) (*service.PutDeploymentPluginMetadataMultiResponse, error) {
return a.metadataStoreRegistry.PutDeploymentPluginMetadataMulti(ctx, req)

Check warning on line 140 in pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go#L139-L140

Added lines #L139 - L140 were not covered by tests
}

func (a *PluginAPI) GetDeploymentSharedMetadata(ctx context.Context, req *service.GetDeploymentSharedMetadataRequest) (*service.GetDeploymentSharedMetadataResponse, error) {
return a.metadataStoreRegistry.GetDeploymentSharedMetadata(ctx, req)

Check warning on line 144 in pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/grpcapi/plugin_api.go#L143-L144

Added lines #L143 - L144 were not covered by tests
}
5 changes: 4 additions & 1 deletion pkg/app/pipedv1/cmd/piped/piped.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/controller"
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/controller/controllermetrics"
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/eventwatcher"
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/metadatastore"
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/notifier"
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin"
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/statsreporter"
Expand Down Expand Up @@ -299,10 +300,11 @@
eventLister = store.Lister()
}

metadataStoreRegistry := metadatastore.NewMetadataStoreRegistry(apiClient)

Check warning on line 303 in pkg/app/pipedv1/cmd/piped/piped.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/piped.go#L303

Added line #L303 was not covered by tests
// Start running plugin service server.
{
var (
service, err = grpcapi.NewPluginAPI(cfg, apiClient, p.toolsDir, input.Logger)
service, err = grpcapi.NewPluginAPI(cfg, apiClient, p.toolsDir, input.Logger, metadataStoreRegistry)

Check warning on line 307 in pkg/app/pipedv1/cmd/piped/piped.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/piped.go#L307

Added line #L307 was not covered by tests
opts = []rpc.Option{
rpc.WithPort(p.pluginServicePort),
rpc.WithGracePeriod(p.gracePeriod),
Expand Down Expand Up @@ -400,6 +402,7 @@
commandLister,
notifier,
decrypter,
*metadataStoreRegistry,

Check warning on line 405 in pkg/app/pipedv1/cmd/piped/piped.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/cmd/piped/piped.go#L405

Added line #L405 was not covered by tests
p.gracePeriod,
input.Logger,
tracerProvider,
Expand Down
33 changes: 20 additions & 13 deletions pkg/app/pipedv1/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"google.golang.org/grpc/status"

"github.com/pipe-cd/pipecd/pkg/app/pipedv1/controller/controllermetrics"
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/metadatastore"
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin"
"github.com/pipe-cd/pipecd/pkg/app/server/service/pipedservice"
"github.com/pipe-cd/pipecd/pkg/git"
Expand Down Expand Up @@ -88,12 +89,13 @@
)

type controller struct {
apiClient apiClient
gitClient gitClient
deploymentLister deploymentLister
commandLister commandLister
notifier notifier
secretDecrypter secretDecrypter
apiClient apiClient
gitClient gitClient
deploymentLister deploymentLister
commandLister commandLister
notifier notifier
secretDecrypter secretDecrypter
metadataStoreRegistry metadatastore.MetadataStoreRegistry

// The registry of all plugins.
pluginRegistry plugin.PluginRegistry
Expand Down Expand Up @@ -134,19 +136,21 @@
commandLister commandLister,
notifier notifier,
secretDecrypter secretDecrypter,
metadataStoreRegistry metadatastore.MetadataStoreRegistry,
gracePeriod time.Duration,
logger *zap.Logger,
tracerProvider trace.TracerProvider,
) DeploymentController {

return &controller{
apiClient: apiClient,
gitClient: gitClient,
pluginRegistry: pluginRegistry,
deploymentLister: deploymentLister,
commandLister: commandLister,
notifier: notifier,
secretDecrypter: secretDecrypter,
apiClient: apiClient,
gitClient: gitClient,
pluginRegistry: pluginRegistry,
deploymentLister: deploymentLister,
commandLister: commandLister,
notifier: notifier,
secretDecrypter: secretDecrypter,
metadataStoreRegistry: metadataStoreRegistry,

Check warning on line 153 in pkg/app/pipedv1/controller/controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/controller/controller.go#L146-L153

Added lines #L146 - L153 were not covered by tests

planners: make(map[string]*planner),
donePlanners: make(map[string]time.Time),
Expand Down Expand Up @@ -577,6 +581,8 @@
c.tracerProvider,
)

c.metadataStoreRegistry.Register(d)

Check warning on line 585 in pkg/app/pipedv1/controller/controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/controller/controller.go#L584-L585

Added lines #L584 - L585 were not covered by tests
cleanup := func() {
logger.Info("cleaning up working directory for scheduler", zap.String("working-dir", workingDir))
err := os.RemoveAll(workingDir)
Expand All @@ -594,6 +600,7 @@
go func() {
defer c.wg.Done()
defer cleanup()
defer c.metadataStoreRegistry.Delete(d.Id)

Check warning on line 603 in pkg/app/pipedv1/controller/controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/controller/controller.go#L603

Added line #L603 was not covered by tests
if err := scheduler.Run(ctx); err != nil {
logger.Error("failed to run scheduler", zap.Error(err))
}
Expand Down
10 changes: 3 additions & 7 deletions pkg/app/pipedv1/controller/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

"github.com/pipe-cd/pipecd/pkg/app/pipedv1/controller/controllermetrics"
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/deploysource"
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/metadatastore"
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin"
"github.com/pipe-cd/pipecd/pkg/app/server/service/pipedservice"
config "github.com/pipe-cd/pipecd/pkg/configv1"
Expand Down Expand Up @@ -64,10 +63,8 @@
// The gitClient is used to perform git commands.
gitClient gitClient

// The notifier and metadataStore are used for
// notification features.
notifier notifier
metadataStore metadatastore.MetadataStore
// The notifier is used for notification features.
notifier notifier

// The secretDecrypter is used to decrypt secrets
// which encrypted using PipeCD built-in secret management.
Expand Down Expand Up @@ -118,7 +115,6 @@
pluginRegistry: pluginRegistry,
apiClient: apiClient,
gitClient: gitClient,
metadataStore: metadatastore.NewMetadataStore(apiClient, d),
notifier: notifier,
secretDecrypter: secretDecrypter,
doneDeploymentStatus: d.Status,
Expand Down Expand Up @@ -657,7 +653,7 @@

// getApplicationNotificationMentions returns the list of users groups who should be mentioned in the notification.
func (p *planner) getApplicationNotificationMentions(event model.NotificationEventType) ([]string, []string, error) {
n, ok := p.metadataStore.Shared().Get(model.MetadataKeyDeploymentNotification)
n, ok := p.deployment.Metadata[model.MetadataKeyDeploymentNotification]

Check warning on line 656 in pkg/app/pipedv1/controller/planner.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/controller/planner.go#L656

Added line #L656 was not covered by tests
if !ok {
return []string{}, []string{}, nil
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/app/pipedv1/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

"github.com/pipe-cd/pipecd/pkg/app/pipedv1/controller/controllermetrics"
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/deploysource"
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/metadatastore"
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin"
"github.com/pipe-cd/pipecd/pkg/app/server/service/pipedservice"
config "github.com/pipe-cd/pipecd/pkg/configv1"
Expand All @@ -47,7 +46,6 @@

apiClient apiClient
gitClient gitClient
metadataStore metadatastore.MetadataStore
notifier notifier
secretDecrypter secretDecrypter

Expand Down Expand Up @@ -99,7 +97,6 @@
apiClient: apiClient,
gitClient: gitClient,
pluginRegistry: pluginRegistry,
metadataStore: metadatastore.NewMetadataStore(apiClient, d),
notifier: notifier,
secretDecrypter: secretsDecrypter,
doneDeploymentStatus: d.Status,
Expand Down Expand Up @@ -717,7 +714,7 @@

// getApplicationNotificationMentions returns the list of users groups who should be mentioned in the notification.
func (s *scheduler) getApplicationNotificationMentions(event model.NotificationEventType) ([]string, []string, error) {
n, ok := s.metadataStore.Shared().Get(model.MetadataKeyDeploymentNotification)
n, ok := s.deployment.Metadata[model.MetadataKeyDeploymentNotification]

Check warning on line 717 in pkg/app/pipedv1/controller/scheduler.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/controller/scheduler.go#L717

Added line #L717 was not covered by tests
if !ok {
return []string{}, []string{}, nil
}
Expand Down
Loading
Loading