Skip to content

Commit f2ca6c2

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

File tree

4 files changed

+67
-11
lines changed

4 files changed

+67
-11
lines changed

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/model/deployment.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ func (d *Deployment) SetUpdatedAt(t int64) {
214214
d.UpdatedAt = t
215215
}
216216

217+
func (d *Deployment) GetDeployTargets(pluginName string) ([]string, error) {
218+
dps, ok := d.GetDeployTargetsByPlugin()[pluginName]
219+
if !ok || len(dps.GetDeployTargets()) == 0 {
220+
return nil, fmt.Errorf("deploy target not found for plugin %v", pluginName)
221+
}
222+
223+
return dps.GetDeployTargets(), nil
224+
}
225+
217226
// Implement sort.Interface for PipelineStages.
218227
type PipelineStages []*PipelineStage
219228

0 commit comments

Comments
 (0)