Skip to content

Commit ed28c89

Browse files
authored
Change type definition for DeployTargetsByPlugin (#5555)
* Define DeployTargetsByPlugin Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> * Fix to deployTargetsbyPlugin for model.Application Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> * Fix to deployTargetsbyPlugin for model.Deployment Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> * Fix for lint/web Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> * Fix for lint/go Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> --------- Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
1 parent 1e2231f commit ed28c89

File tree

26 files changed

+1457
-849
lines changed

26 files changed

+1457
-849
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/plugin/kubernetes/deployment/rollback.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ func (a *DeploymentService) executeK8sRollbackStage(ctx context.Context, lp logp
7373
}
7474

7575
// Get the deploy target config.
76-
deployTargetConfig, err := kubeconfig.FindDeployTarget(a.pluginConfig, input.GetDeployment().GetDeployTargets()[0]) // TODO: check if there is a deploy target
76+
targets, err := input.GetDeployment().GetDeployTargets(a.pluginConfig.Name)
77+
if err != nil {
78+
lp.Errorf("Failed while finding deploy target config (%v)", err)
79+
return model.StageStatus_STAGE_FAILURE
80+
}
81+
82+
deployTargetConfig, err := kubeconfig.FindDeployTarget(a.pluginConfig, targets[0]) // TODO: consider multiple targets
7783
if err != nil {
7884
lp.Errorf("Failed while unmarshalling deploy target config (%v)", err)
7985
return model.StageStatus_STAGE_FAILURE

pkg/app/pipedv1/plugin/kubernetes/deployment/sync.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ func (a *DeploymentService) executeK8sSyncStage(ctx context.Context, lp logpersi
7373
}
7474

7575
// Get the deploy target config.
76-
deployTargetConfig, err := kubeconfig.FindDeployTarget(a.pluginConfig, input.GetDeployment().GetDeployTargets()[0]) // TODO: check if there is a deploy target
76+
targets, err := input.GetDeployment().GetDeployTargets(a.pluginConfig.Name)
77+
if err != nil {
78+
lp.Errorf("Failed while finding deploy target config (%v)", err)
79+
return model.StageStatus_STAGE_FAILURE
80+
}
81+
deployTargetConfig, err := kubeconfig.FindDeployTarget(a.pluginConfig, targets[0]) // TODO: consider multiple targets
7782
if err != nil {
7883
lp.Errorf("Failed while unmarshalling deploy target config (%v)", err)
7984
return model.StageStatus_STAGE_FAILURE

pkg/app/pipedv1/plugin/kubernetes/deployment/sync_test.go

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ func TestDeploymentService_executeK8sSyncStage(t *testing.T) {
5252
Deployment: &model.Deployment{
5353
PipedId: "piped-id",
5454
ApplicationId: "app-id",
55-
DeployTargets: []string{"default"},
55+
DeployTargetsByPlugin: map[string]*model.DeployTargets{
56+
"kubernetes": {
57+
DeployTargets: []string{"default"},
58+
},
59+
},
5660
},
5761
Stage: &model.PipelineStage{
5862
Id: "stage-id",
@@ -125,7 +129,11 @@ func TestDeploymentService_executeK8sSyncStage_withInputNamespace(t *testing.T)
125129
Deployment: &model.Deployment{
126130
PipedId: "piped-id",
127131
ApplicationId: "app-id",
128-
DeployTargets: []string{"default"},
132+
DeployTargetsByPlugin: map[string]*model.DeployTargets{
133+
"kubernetes": {
134+
DeployTargets: []string{"default"},
135+
},
136+
},
129137
},
130138
Stage: &model.PipelineStage{
131139
Id: "stage-id",
@@ -199,7 +207,11 @@ func TestDeploymentService_executeK8sSyncStage_withPrune(t *testing.T) {
199207
Deployment: &model.Deployment{
200208
PipedId: "piped-id",
201209
ApplicationId: "app-id",
202-
DeployTargets: []string{"default"},
210+
DeployTargetsByPlugin: map[string]*model.DeployTargets{
211+
"kubernetes": {
212+
DeployTargets: []string{"default"},
213+
},
214+
},
203215
},
204216
Stage: &model.PipelineStage{
205217
Id: "stage-id",
@@ -255,7 +267,11 @@ func TestDeploymentService_executeK8sSyncStage_withPrune(t *testing.T) {
255267
Deployment: &model.Deployment{
256268
PipedId: "piped-id",
257269
ApplicationId: "app-id",
258-
DeployTargets: []string{"default"},
270+
DeployTargetsByPlugin: map[string]*model.DeployTargets{
271+
"kubernetes": {
272+
DeployTargets: []string{"default"},
273+
},
274+
},
259275
},
260276
Stage: &model.PipelineStage{
261277
Id: "stage-id",
@@ -314,7 +330,11 @@ func TestDeploymentService_executeK8sSyncStage_withPrune_changesNamespace(t *tes
314330
Deployment: &model.Deployment{
315331
PipedId: "piped-id",
316332
ApplicationId: "app-id",
317-
DeployTargets: []string{"default"},
333+
DeployTargetsByPlugin: map[string]*model.DeployTargets{
334+
"kubernetes": {
335+
DeployTargets: []string{"default"},
336+
},
337+
},
318338
},
319339
Stage: &model.PipelineStage{
320340
Id: "stage-id",
@@ -367,7 +387,11 @@ func TestDeploymentService_executeK8sSyncStage_withPrune_changesNamespace(t *tes
367387
Deployment: &model.Deployment{
368388
PipedId: "piped-id",
369389
ApplicationId: "app-id",
370-
DeployTargets: []string{"default"},
390+
DeployTargetsByPlugin: map[string]*model.DeployTargets{
391+
"kubernetes": {
392+
DeployTargets: []string{"default"},
393+
},
394+
},
371395
},
372396
Stage: &model.PipelineStage{
373397
Id: "stage-id",
@@ -443,7 +467,11 @@ func TestDeploymentService_executeK8sSyncStage_withPrune_clusterScoped(t *testin
443467
Deployment: &model.Deployment{
444468
PipedId: "piped-id",
445469
ApplicationId: "prepare-app-id",
446-
DeployTargets: []string{"default"},
470+
DeployTargetsByPlugin: map[string]*model.DeployTargets{
471+
"kubernetes": {
472+
DeployTargets: []string{"default"},
473+
},
474+
},
447475
},
448476
Stage: &model.PipelineStage{
449477
Id: "stage-id",
@@ -481,7 +509,11 @@ func TestDeploymentService_executeK8sSyncStage_withPrune_clusterScoped(t *testin
481509
Deployment: &model.Deployment{
482510
PipedId: "piped-id",
483511
ApplicationId: "app-id",
484-
DeployTargets: []string{"default"},
512+
DeployTargetsByPlugin: map[string]*model.DeployTargets{
513+
"kubernetes": {
514+
DeployTargets: []string{"default"},
515+
},
516+
},
485517
},
486518
Stage: &model.PipelineStage{
487519
Id: "stage-id",
@@ -527,7 +559,11 @@ func TestDeploymentService_executeK8sSyncStage_withPrune_clusterScoped(t *testin
527559
Deployment: &model.Deployment{
528560
PipedId: "piped-id",
529561
ApplicationId: "app-id",
530-
DeployTargets: []string{"default"},
562+
DeployTargetsByPlugin: map[string]*model.DeployTargets{
563+
"kubernetes": {
564+
DeployTargets: []string{"default"},
565+
},
566+
},
531567
},
532568
Stage: &model.PipelineStage{
533569
Id: "stage-id",

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

0 commit comments

Comments
 (0)