Skip to content

Commit 2e83bc2

Browse files
committed
Fix to deployTargetsbyPlugin for model.Application
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
1 parent bc3f537 commit 2e83bc2

File tree

13 files changed

+759
-507
lines changed

13 files changed

+759
-507
lines changed

pkg/app/pipectl/cmd/migrate/database.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/pipe-cd/pipecd/pkg/app/server/service/apiservice"
2424
"github.com/pipe-cd/pipecd/pkg/cli"
25+
"github.com/pipe-cd/pipecd/pkg/model"
2526
)
2627

2728
type database struct {
@@ -87,11 +88,34 @@ func (c *database) migrateApplication(ctx context.Context, client apiservice.Cli
8788
// Migrate database for the application.
8889
if _, err := client.UpdateApplicationDeployTargets(ctx, &apiservice.UpdateApplicationDeployTargetsRequest{
8990
ApplicationId: appID,
90-
DeployTargets: []string{provider},
91+
DeployTargetsByPlugin: map[string]*model.DeployTargets{
92+
convertApplicationKindToPluginName(app.Application.Kind): {
93+
DeployTargets: []string{provider},
94+
},
95+
},
9196
}); err != nil {
9297
logger.Error("failed to update application deploy targets", zap.Error(err), zap.String("application", appID))
9398
return err
9499
}
95100

96101
return nil
97102
}
103+
104+
// NOTE: Convention for Application plugins migration
105+
// The plugins name for this migration task are defined based on the Application Kind
106+
// Eg: KubernetesApp -> kubernetes | ECSApp -> ecs | ...
107+
func convertApplicationKindToPluginName(k model.ApplicationKind) string {
108+
switch k {
109+
case model.ApplicationKind_KUBERNETES:
110+
return "kubernetes"
111+
case model.ApplicationKind_CLOUDRUN:
112+
return "cloudrun"
113+
case model.ApplicationKind_ECS:
114+
return "ecs"
115+
case model.ApplicationKind_LAMBDA:
116+
return "lambda"
117+
case model.ApplicationKind_TERRAFORM:
118+
return "terraform"
119+
}
120+
return "" // Unexpected
121+
}

pkg/app/piped/trigger/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func buildDeployment(
9595
GitPath: app.GitPath,
9696
CloudProvider: app.CloudProvider,
9797
PlatformProvider: app.PlatformProvider,
98-
DeployTargets: app.DeployTargets,
98+
DeployTargetsByPlugin: app.DeployTargetsByPlugin,
9999
Labels: app.Labels,
100100
Status: model.DeploymentStatus_DEPLOYMENT_PENDING,
101101
StatusReason: "The deployment is waiting to be planned",

pkg/app/pipedv1/trigger/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func buildDeployment(
9595
GitPath: app.GitPath,
9696
CloudProvider: app.CloudProvider,
9797
PlatformProvider: app.PlatformProvider,
98-
DeployTargets: app.DeployTargets,
98+
DeployTargetsByPlugin: app.DeployTargetsByPlugin,
9999
Labels: app.Labels,
100100
Status: model.DeploymentStatus_DEPLOYMENT_PENDING,
101101
StatusReason: "The deployment is waiting to be planned",

pkg/app/server/grpcapi/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type apiApplicationStore interface {
4747
Disable(ctx context.Context, id string) error
4848
UpdateConfigFilename(ctx context.Context, id, filename string) error
4949
UpdateConfiguration(ctx context.Context, id, pipedID, platformProvider, configFilename string) error
50-
UpdateDeployTargets(ctx context.Context, id string, targets []string) error
50+
UpdateDeployTargets(ctx context.Context, id string, dp map[string]*model.DeployTargets) error
5151
}
5252

5353
type apiDeploymentStore interface {
@@ -478,7 +478,7 @@ func (a *API) UpdateApplicationDeployTargets(ctx context.Context, req *apiservic
478478
a.logger.Warn("requested application does not belong to your project", zap.String("applicationID", app.Id), zap.String("requestProjectID", key.ProjectId), zap.String("applicationProjectID", app.ProjectId))
479479
return nil, status.Error(codes.PermissionDenied, fmt.Sprintf("requested application %s does not belong to your project", req.GetApplicationId()))
480480
}
481-
if err := a.applicationStore.UpdateDeployTargets(ctx, req.GetApplicationId(), req.GetDeployTargets()); err != nil {
481+
if err := a.applicationStore.UpdateDeployTargets(ctx, req.GetApplicationId(), req.GetDeployTargetsByPlugin()); err != nil {
482482
return nil, gRPCStoreError(err, fmt.Sprintf("failed to update application %s deploy targets", req.ApplicationId))
483483
}
484484
return &apiservice.UpdateApplicationDeployTargetsResponse{}, nil

pkg/app/server/service/apiservice/service.pb.go

Lines changed: 422 additions & 406 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/app/server/service/apiservice/service.pb.validate.go

Lines changed: 49 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/app/server/service/apiservice/service.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ message RenameApplicationConfigFileResponse {
183183

184184
message UpdateApplicationDeployTargetsRequest {
185185
string application_id = 1 [(validate.rules).string.min_len = 1];
186-
repeated string deploy_targets = 2 [(validate.rules).repeated = {min_items: 1}];
186+
map<string, model.DeployTargets> deploy_targets_by_plugin = 2 [(validate.rules).map.min_pairs = 1];
187187
}
188188

189189
message UpdateApplicationDeployTargetsResponse {}

pkg/model/application.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ func (a *Application) IsOutOfSync() bool {
8686
return a.SyncState.Status == ApplicationSyncStatus_OUT_OF_SYNC
8787
}
8888

89+
func (a *Application) GetDeployTargets() []string {
90+
var deployTargets []string
91+
for _, t := range a.DeployTargetsByPlugin {
92+
for _, v := range t.GetDeployTargets() {
93+
deployTargets = append(deployTargets, v)
94+
}
95+
}
96+
return deployTargets
97+
}
98+
8999
func (a *Application) SetUpdatedAt(t int64) {
90100
a.UpdatedAt = t
91101
}

web/model/application_pb.d.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ export class Application extends jspb.Message {
3232
getPlatformProvider(): string;
3333
setPlatformProvider(value: string): Application;
3434

35-
getDeployTargetsList(): Array<string>;
36-
setDeployTargetsList(value: Array<string>): Application;
37-
clearDeployTargetsList(): Application;
38-
addDeployTargets(value: string, index?: number): Application;
35+
getDeployTargetsByPluginMap(): jspb.Map<string, pkg_model_deployment_pb.DeployTargets>;
36+
clearDeployTargetsByPluginMap(): Application;
3937

4038
getDescription(): string;
4139
setDescription(value: string): Application;
@@ -94,7 +92,7 @@ export namespace Application {
9492
gitPath?: pkg_model_common_pb.ApplicationGitPath.AsObject,
9593
cloudProvider: string,
9694
platformProvider: string,
97-
deployTargetsList: Array<string>,
95+
deployTargetsByPluginMap: Array<[string, pkg_model_deployment_pb.DeployTargets.AsObject]>,
9896
description: string,
9997
labelsMap: Array<[string, string]>,
10098
mostRecentlySuccessfulDeployment?: ApplicationDeploymentReference.AsObject,

web/model/application_pb.js

Lines changed: 21 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)