Files
kubevela/pkg/application/modify.go
Hongchao Deng 20a5457d5f refactor pkg/application to use Appfile (#402)
* refactor pkg/application to use Appfile

Signed-off-by: Hongchao Deng <hongchaodeng1@gmail.com>

* fix build

* fix workload

* refactor pkg/application to use Appfile

Signed-off-by: Hongchao Deng <hongchaodeng1@gmail.com>

* rebase

* fix

Signed-off-by: Hongchao Deng <hongchaodeng1@gmail.com>

* e2e

Signed-off-by: Hongchao Deng <hongchaodeng1@gmail.com>

* update design

* add test coverage for appfile

Signed-off-by: Hongchao Deng <hongchaodeng1@gmail.com>

* comment

Signed-off-by: Hongchao Deng <hongchaodeng1@gmail.com>
2020-10-21 13:01:46 +08:00

75 lines
1.5 KiB
Go

package application
import (
"errors"
"strings"
"github.com/oam-dev/kubevela/pkg/appfile"
)
func (app *Application) SetWorkload(componentName, workloadType string, workloadData map[string]interface{}) error {
if app == nil {
return errors.New("app is nil pointer")
}
s, ok := app.Services[componentName]
if !ok {
s = appfile.Service{}
}
s["type"] = workloadType
s["name"] = strings.ToLower(componentName)
for k, v := range workloadData {
s[k] = v
}
app.Services[componentName] = s
return app.Validate()
}
func (app *Application) SetTrait(componentName, traitType string, traitData map[string]interface{}) error {
if app == nil {
return errors.New("app is nil pointer")
}
if traitData == nil {
traitData = make(map[string]interface{})
}
s, ok := app.Services[componentName]
if !ok {
s = appfile.Service{}
}
t, ok := s[traitType]
if !ok {
t = make(map[string]interface{})
}
tm := t.(map[string]interface{})
for k, v := range traitData {
tm[k] = v
}
s[traitType] = t
app.Services[componentName] = s
return app.Validate()
}
func (app *Application) RemoveTrait(componentName, traitType string) error {
if app == nil {
return errors.New("app is nil pointer")
}
s, ok := app.Services[componentName]
if !ok {
return nil
}
delete(s, traitType)
return nil
}
func (app *Application) RemoveComponent(componentName string) error {
if app == nil {
return errors.New("app is nil pointer")
}
delete(app.Services, componentName)
return nil
}