Skip to content

Commit 4a601d7

Browse files
authored
BIE-V2支持纯粹的YAML (#469)
* BIE-V2支持纯粹的YAML * BIE-V2支持纯粹的YAML
1 parent 2c43fa0 commit 4a601d7

File tree

3 files changed

+116
-28
lines changed

3 files changed

+116
-28
lines changed

api/yaml.go

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,11 @@ func (api *API) generateSecret(ns string, r runtime.Object) (interface{}, error)
228228
return nil, common.Error(common.ErrRequestParamInvalid, common.Field("error", "secret name is already in use"))
229229
}
230230

231-
return api.Facade.CreateSecret(ns, secret)
231+
res, err := api.Facade.CreateSecret(ns, secret)
232+
if err != nil {
233+
return nil, err
234+
}
235+
return api.ToFilteredSecretView(res), nil
232236
}
233237

234238
func (api *API) updateSecret(ns string, r runtime.Object) (interface{}, error) {
@@ -256,7 +260,11 @@ func (api *API) updateSecret(ns string, r runtime.Object) (interface{}, error) {
256260
secret.Version = oldSecret.Version
257261
secret.UpdateTimestamp = time.Now()
258262

259-
return api.Facade.UpdateSecret(ns, secret)
263+
res, err := api.Facade.UpdateSecret(ns, secret)
264+
if err != nil {
265+
return nil, err
266+
}
267+
return api.ToSecretView(res), nil
260268
}
261269

262270
func (api *API) deleteSecret(ns string, r runtime.Object) (string, error) {
@@ -382,6 +390,9 @@ func (api *API) generateCommonSecret(ns string, s *corev1.Secret) (*specV1.Secre
382390
return nil, err
383391
}
384392
secret.Namespace = ns
393+
secret.Labels = common.AddSystemLabel(secret.Labels, map[string]string{
394+
specV1.SecretLabel: specV1.SecretConfig,
395+
})
385396
return secret, nil
386397
}
387398

@@ -441,7 +452,7 @@ func (api *API) generateConfig(ns, userId string, r runtime.Object) (interface{}
441452
return nil, err
442453
}
443454

444-
return config, nil
455+
return api.ToConfigurationView(config)
445456
}
446457

447458
func (api *API) updateConfig(ns, userId string, r runtime.Object) (interface{}, error) {
@@ -485,7 +496,12 @@ func (api *API) updateConfig(ns, userId string, r runtime.Object) (interface{},
485496
config.UpdateTimestamp = time.Now()
486497
config.CreationTimestamp = res.CreationTimestamp
487498

488-
return api.Facade.UpdateConfig(ns, config)
499+
res, err = api.Facade.UpdateConfig(ns, config)
500+
if err != nil {
501+
return nil, err
502+
}
503+
504+
return api.ToConfigurationView(res)
489505
}
490506

491507
func (api *API) deleteConfig(ns string, r runtime.Object) (string, error) {
@@ -520,7 +536,6 @@ func (api *API) deleteConfig(ns string, r runtime.Object) (string, error) {
520536
common.Field("name", cfg.Name))
521537
}
522538

523-
//TODO: should remove file(bos/aws) of a function Config
524539
return cfg.Name, api.Facade.DeleteConfig(ns, cfg.Name)
525540
}
526541

@@ -640,7 +655,7 @@ func (api *API) generateApplication(ns string, r runtime.Object) (interface{}, e
640655
return nil, err
641656
}
642657

643-
return app, nil
658+
return api.ToApplicationView(app)
644659
}
645660

646661
func (api *API) updateApplication(ns string, r runtime.Object) (interface{}, error) {
@@ -674,7 +689,12 @@ func (api *API) updateApplication(ns string, r runtime.Object) (interface{}, err
674689
app.Version = oldApp.Version
675690
app.CreationTimestamp = oldApp.CreationTimestamp
676691

677-
return api.Facade.UpdateApp(ns, oldApp, app, nil)
692+
app, err = api.Facade.UpdateApp(ns, oldApp, app, nil)
693+
if err != nil {
694+
return nil, errors.Trace(err)
695+
}
696+
697+
return api.ToApplicationView(app)
678698
}
679699

680700
func (api *API) deleteApplication(ns string, r runtime.Object) (string, error) {
@@ -904,6 +924,15 @@ func (api *API) generateCommonAppInfo(ns string, podSpec *corev1.PodSpec) (*spec
904924
if !isRegistrySecret(*registry) {
905925
return nil, common.Error(common.ErrRequestParamInvalid, common.Field("error", "imagePullSecrets is not registry type"))
906926
}
927+
secretVolume := specV1.Volume{
928+
Name: v.Name,
929+
VolumeSource: specV1.VolumeSource{
930+
Secret: &specV1.ObjectReference{
931+
Name: v.Name,
932+
},
933+
},
934+
}
935+
volumes = append(volumes, secretVolume)
907936
}
908937

909938
var svcs []specV1.Service

api/yaml_app_test.go

Lines changed: 78 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,14 @@ func TestAPI_CreateDeployApp(t *testing.T) {
394394
},
395395
},
396396
},
397+
{
398+
Name: "myregistrykey",
399+
VolumeSource: specV1.VolumeSource{
400+
Secret: &specV1.ObjectReference{
401+
Name: "myregistrykey",
402+
},
403+
},
404+
},
397405
},
398406
Replica: 1,
399407
Workload: "deployment",
@@ -412,8 +420,8 @@ func TestAPI_CreateDeployApp(t *testing.T) {
412420
}
413421
sApp.EXPECT().Get("default", "nginx", "").Return(nil, nil).Times(1)
414422
sConfig.EXPECT().Get("default", "common-cm", "").Return(cfg, nil).Times(2)
415-
sSecret.EXPECT().Get("default", "dcell", "").Return(secret, nil).Times(2)
416-
sSecret.EXPECT().Get("default", "myregistrykey", "").Return(registry, nil).Times(2)
423+
sSecret.EXPECT().Get("default", "dcell", "").Return(secret, nil).Times(4)
424+
sSecret.EXPECT().Get("default", "myregistrykey", "").Return(registry, nil).Times(4)
417425
sFacade.EXPECT().CreateApp("default", nil, gomock.Any(), nil).Return(deployApp, nil).Times(1)
418426

419427
buf := new(bytes.Buffer)
@@ -429,7 +437,7 @@ func TestAPI_CreateDeployApp(t *testing.T) {
429437
router.ServeHTTP(re, req)
430438
assert.Equal(t, http.StatusOK, re.Code)
431439

432-
var resApp []specV1.Application
440+
var resApp []gmodels.ApplicationView
433441
body, err := ioutil.ReadAll(re.Body)
434442
assert.NilError(t, err)
435443
err = json.Unmarshal(body, &resApp)
@@ -440,7 +448,8 @@ func TestAPI_CreateDeployApp(t *testing.T) {
440448
resapp, err := api.generateDeployApp("default", deploy)
441449
resapp.Services[0].Resources.Limits = nil
442450
resapp.Services[0].Resources.Requests = nil
443-
assert.DeepEqual(t, &resApp[0], resapp)
451+
appView, _ := api.ToApplicationView(resapp)
452+
assert.DeepEqual(t, &resApp[0], appView)
444453
}
445454

446455
func TestAPI_CreateDaemonSetApp(t *testing.T) {
@@ -538,6 +547,14 @@ func TestAPI_CreateDaemonSetApp(t *testing.T) {
538547
},
539548
},
540549
},
550+
{
551+
Name: "myregistrykey",
552+
VolumeSource: specV1.VolumeSource{
553+
Secret: &specV1.ObjectReference{
554+
Name: "myregistrykey",
555+
},
556+
},
557+
},
541558
},
542559
Workload: "daemonset",
543560
}
@@ -555,8 +572,8 @@ func TestAPI_CreateDaemonSetApp(t *testing.T) {
555572
}
556573
sApp.EXPECT().Get("default", "nginx", "").Return(nil, nil).Times(1)
557574
sConfig.EXPECT().Get("default", "common-cm", "").Return(cfg, nil).Times(2)
558-
sSecret.EXPECT().Get("default", "dcell", "").Return(secret, nil).Times(2)
559-
sSecret.EXPECT().Get("default", "myregistrykey", "").Return(registry, nil).Times(2)
575+
sSecret.EXPECT().Get("default", "dcell", "").Return(secret, nil).Times(4)
576+
sSecret.EXPECT().Get("default", "myregistrykey", "").Return(registry, nil).Times(4)
560577
sFacade.EXPECT().CreateApp("default", nil, gomock.Any(), nil).Return(dsApp, nil).Times(1)
561578

562579
buf := new(bytes.Buffer)
@@ -572,7 +589,7 @@ func TestAPI_CreateDaemonSetApp(t *testing.T) {
572589
router.ServeHTTP(re, req)
573590
assert.Equal(t, http.StatusOK, re.Code)
574591

575-
var resApp []specV1.Application
592+
var resApp []gmodels.ApplicationView
576593
body, err := ioutil.ReadAll(re.Body)
577594
assert.NilError(t, err)
578595
err = json.Unmarshal([]byte(body), &resApp)
@@ -581,7 +598,8 @@ func TestAPI_CreateDaemonSetApp(t *testing.T) {
581598
resources := api.parseK8SYaml([]byte(testAppDs))
582599
ds, _ := resources[0].(*appv1.DaemonSet)
583600
resapp, err := api.generateDaemonSetApp("default", ds)
584-
assert.DeepEqual(t, &resApp[0], resapp)
601+
appView, _ := api.ToApplicationView(resapp)
602+
assert.DeepEqual(t, &resApp[0], appView)
585603
}
586604

587605
func TestAPI_CreateJobApp(t *testing.T) {
@@ -642,7 +660,7 @@ func TestAPI_CreateJobApp(t *testing.T) {
642660
router.ServeHTTP(re, req)
643661
assert.Equal(t, http.StatusOK, re.Code)
644662

645-
var resApp []specV1.Application
663+
var resApp []gmodels.ApplicationView
646664
body, err := ioutil.ReadAll(re.Body)
647665
assert.NilError(t, err)
648666
err = json.Unmarshal([]byte(body), &resApp)
@@ -652,7 +670,10 @@ func TestAPI_CreateJobApp(t *testing.T) {
652670
job, _ := resources[0].(*batchv1.Job)
653671
resapp, err := api.generateJobApp("default", job)
654672
resapp.Services[0].Resources = nil
655-
assert.DeepEqual(t, &resApp[0], resapp)
673+
appView, _ := api.ToApplicationView(resapp)
674+
appView.Volumes = nil
675+
appView.Registries = nil
676+
assert.DeepEqual(t, &resApp[0], appView)
656677
}
657678

658679
func TestAPI_UpdateDeployApp(t *testing.T) {
@@ -747,6 +768,14 @@ func TestAPI_UpdateDeployApp(t *testing.T) {
747768
},
748769
},
749770
},
771+
{
772+
Name: "myregistrykey",
773+
VolumeSource: specV1.VolumeSource{
774+
Secret: &specV1.ObjectReference{
775+
Name: "myregistrykey",
776+
},
777+
},
778+
},
750779
},
751780
Replica: 1,
752781
Workload: "deployment",
@@ -826,6 +855,14 @@ func TestAPI_UpdateDeployApp(t *testing.T) {
826855
},
827856
},
828857
},
858+
{
859+
Name: "myregistrykey",
860+
VolumeSource: specV1.VolumeSource{
861+
Secret: &specV1.ObjectReference{
862+
Name: "myregistrykey",
863+
},
864+
},
865+
},
829866
},
830867
Replica: 1,
831868
Workload: "deployment",
@@ -845,8 +882,8 @@ func TestAPI_UpdateDeployApp(t *testing.T) {
845882

846883
sApp.EXPECT().Get("default", "nginx", "").Return(expectApp, nil).Times(1)
847884
sConfig.EXPECT().Get("default", "common-cm", "").Return(cfg, nil).Times(2)
848-
sSecret.EXPECT().Get("default", "dcell", "").Return(secret, nil).Times(2)
849-
sSecret.EXPECT().Get("default", "myregistrykey", "").Return(registry, nil).Times(2)
885+
sSecret.EXPECT().Get("default", "dcell", "").Return(secret, nil).Times(4)
886+
sSecret.EXPECT().Get("default", "myregistrykey", "").Return(registry, nil).Times(4)
850887
sFacade.EXPECT().UpdateApp("default", expectApp, gomock.Any(), nil).Return(updateApp, nil).Times(1)
851888

852889
buf := new(bytes.Buffer)
@@ -862,7 +899,7 @@ func TestAPI_UpdateDeployApp(t *testing.T) {
862899
router.ServeHTTP(re, req)
863900
assert.Equal(t, http.StatusOK, re.Code)
864901

865-
var resApp []specV1.Application
902+
var resApp []gmodels.ApplicationView
866903
body, err := ioutil.ReadAll(re.Body)
867904
assert.NilError(t, err)
868905
err = json.Unmarshal(body, &resApp)
@@ -873,7 +910,8 @@ func TestAPI_UpdateDeployApp(t *testing.T) {
873910
resapp, err := api.generateDeployApp("default", deploy)
874911
resapp.Services[0].Resources.Limits = nil
875912
resapp.Services[0].Resources.Requests = nil
876-
assert.DeepEqual(t, &resApp[0], resapp)
913+
appView, _ := api.ToApplicationView(resapp)
914+
assert.DeepEqual(t, &resApp[0], appView)
877915
}
878916

879917
func TestAPI_UpdateDsApp(t *testing.T) {
@@ -971,6 +1009,14 @@ func TestAPI_UpdateDsApp(t *testing.T) {
9711009
},
9721010
},
9731011
},
1012+
{
1013+
Name: "myregistrykey",
1014+
VolumeSource: specV1.VolumeSource{
1015+
Secret: &specV1.ObjectReference{
1016+
Name: "myregistrykey",
1017+
},
1018+
},
1019+
},
9741020
},
9751021
Workload: "daemonset",
9761022
}
@@ -1052,6 +1098,14 @@ func TestAPI_UpdateDsApp(t *testing.T) {
10521098
},
10531099
},
10541100
},
1101+
{
1102+
Name: "myregistrykey",
1103+
VolumeSource: specV1.VolumeSource{
1104+
Secret: &specV1.ObjectReference{
1105+
Name: "myregistrykey",
1106+
},
1107+
},
1108+
},
10551109
},
10561110
Workload: "daemonset",
10571111
}
@@ -1070,8 +1124,8 @@ func TestAPI_UpdateDsApp(t *testing.T) {
10701124

10711125
sApp.EXPECT().Get("default", "nginx", "").Return(dsApp, nil).Times(1)
10721126
sConfig.EXPECT().Get("default", "common-cm", "").Return(cfg, nil).Times(2)
1073-
sSecret.EXPECT().Get("default", "dcell", "").Return(secret, nil).Times(2)
1074-
sSecret.EXPECT().Get("default", "myregistrykey", "").Return(registry, nil).Times(2)
1127+
sSecret.EXPECT().Get("default", "dcell", "").Return(secret, nil).Times(4)
1128+
sSecret.EXPECT().Get("default", "myregistrykey", "").Return(registry, nil).Times(4)
10751129
sFacade.EXPECT().UpdateApp("default", dsApp, gomock.Any(), nil).Return(updateApp, nil).Times(1)
10761130

10771131
buf := new(bytes.Buffer)
@@ -1087,7 +1141,7 @@ func TestAPI_UpdateDsApp(t *testing.T) {
10871141
router.ServeHTTP(re, req)
10881142
assert.Equal(t, http.StatusOK, re.Code)
10891143

1090-
var resApp []specV1.Application
1144+
var resApp []gmodels.ApplicationView
10911145
body, err := ioutil.ReadAll(re.Body)
10921146
assert.NilError(t, err)
10931147
err = json.Unmarshal(body, &resApp)
@@ -1096,7 +1150,8 @@ func TestAPI_UpdateDsApp(t *testing.T) {
10961150
resources := api.parseK8SYaml([]byte(updateAppDs))
10971151
ds, _ := resources[0].(*appv1.DaemonSet)
10981152
resapp, err := api.generateDaemonSetApp("default", ds)
1099-
assert.DeepEqual(t, &resApp[0], resapp)
1153+
appView, _ := api.ToApplicationView(resapp)
1154+
assert.DeepEqual(t, &resApp[0], appView)
11001155
}
11011156

11021157
func TestAPI_UpdateJobApp(t *testing.T) {
@@ -1181,7 +1236,7 @@ func TestAPI_UpdateJobApp(t *testing.T) {
11811236
router.ServeHTTP(re, req)
11821237
assert.Equal(t, http.StatusOK, re.Code)
11831238

1184-
var resApp []specV1.Application
1239+
var resApp []gmodels.ApplicationView
11851240
body, err := ioutil.ReadAll(re.Body)
11861241
assert.NilError(t, err)
11871242
err = json.Unmarshal(body, &resApp)
@@ -1191,7 +1246,10 @@ func TestAPI_UpdateJobApp(t *testing.T) {
11911246
job, _ := resources[0].(*batchv1.Job)
11921247
resapp, err := api.generateJobApp("default", job)
11931248
resapp.Services[0].Resources = nil
1194-
assert.DeepEqual(t, &resApp[0], resapp)
1249+
appView, _ := api.ToApplicationView(resapp)
1250+
appView.Registries = nil
1251+
appView.Volumes = nil
1252+
assert.DeepEqual(t, &resApp[0], appView)
11951253
}
11961254

11971255
func TestAPI_DeleteApp(t *testing.T) {

api/yaml_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ func TestAPI_CreateSecret(t *testing.T) {
278278
Name: "dcell",
279279
Namespace: "default",
280280
Labels: map[string]string{
281-
"secret": "dcell",
281+
"secret": "dcell",
282+
specV1.SecretLabel: specV1.SecretConfig,
282283
},
283284
Annotations: map[string]string{
284285
"secret": "dcell",

0 commit comments

Comments
 (0)