add category docker & kube (#276)

master
Kevin Wan 4 years ago committed by GitHub
parent 99596a4149
commit da8f76e6bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -38,11 +38,12 @@ func RevertTemplate(name string) error {
return util.CreateTemplate(category, name, content)
}
func Update(category string) error {
func Update() error {
err := Clean()
if err != nil {
return err
}
return util.InitTemplates(category, templates)
}
@ -50,6 +51,6 @@ func Clean() error {
return util.Clean(category)
}
func GetCategory() string {
func Category() string {
return category
}

@ -84,7 +84,7 @@ func TestUpdate(t *testing.T) {
assert.Equal(t, string(data), modifyData)
assert.Nil(t, Update(category))
assert.Nil(t, Update())
data, err = ioutil.ReadFile(file)
assert.Nil(t, err)

@ -39,7 +39,32 @@ CMD ["./{{.ExeFile}}"{{.Argument}}]
`
)
func Clean() error {
return util.Clean(category)
}
func GenTemplates(_ *cli.Context) error {
return initTemplate()
}
func Category() string {
return category
}
func RevertTemplate(name string) error {
return util.CreateTemplate(category, name, dockerTemplate)
}
func Update() error {
err := Clean()
if err != nil {
return err
}
return initTemplate()
}
func initTemplate() error {
return util.InitTemplates(category, map[string]string{
dockerTemplateFile: dockerTemplate,
})

@ -476,7 +476,7 @@ var (
Flags: []cli.Flag{
cli.StringFlag{
Name: "category,c",
Usage: "the category of template, enum [api,rpc,model]",
Usage: "the category of template, enum [api,rpc,model,docker,kube]",
},
},
Action: tpl.UpdateTemplates,
@ -487,7 +487,7 @@ var (
Flags: []cli.Flag{
cli.StringFlag{
Name: "category,c",
Usage: "the category of template, enum [api,rpc,model]",
Usage: "the category of template, enum [api,rpc,model,docker,kube]",
},
cli.StringFlag{
Name: "name,n",

@ -16,47 +16,23 @@ const (
portLimit = 32767
)
var errUnknownServiceType = errors.New("unknown service type")
type (
ServiceType string
KubeRequest struct {
Env string
ServiceName string
ServiceType ServiceType
Namespace string
Schedule string
Replicas int
RevisionHistoryLimit int
Port int
LimitCpu int
LimitMem int
RequestCpu int
RequestMem int
SuccessfulJobsHistoryLimit int
HpaMinReplicas int
HpaMaxReplicas int
}
Deployment struct {
Name string
Namespace string
Image string
Secret string
Replicas int
Revisions int
Port int
NodePort int
UseNodePort bool
RequestCpu int
RequestMem int
LimitCpu int
LimitMem int
MinReplicas int
MaxReplicas int
}
)
type Deployment struct {
Name string
Namespace string
Image string
Secret string
Replicas int
Revisions int
Port int
NodePort int
UseNodePort bool
RequestCpu int
RequestMem int
LimitCpu int
LimitMem int
MinReplicas int
MaxReplicas int
}
func DeploymentCommand(c *cli.Context) error {
nodePort := c.Int("nodePort")
@ -96,9 +72,33 @@ func DeploymentCommand(c *cli.Context) error {
})
}
func Category() string {
return category
}
func Clean() error {
return util.Clean(category)
}
func GenTemplates(_ *cli.Context) error {
return util.InitTemplates(category, map[string]string{
deployTemplateFile: deploymentTemplate,
jobTemplateFile: jobTmeplate,
})
}
func RevertTemplate(name string) error {
return util.CreateTemplate(category, name, deploymentTemplate)
}
func Update() error {
err := Clean()
if err != nil {
return err
}
return util.InitTemplates(category, map[string]string{
deployTemplateFile: deploymentTemplate,
jobTemplateFile: jobTmeplate,
})
}

@ -54,6 +54,14 @@ var templates = map[string]string{
errTemplateFile: template.Error,
}
func Category() string {
return category
}
func Clean() error {
return util.Clean(category)
}
func GenTemplates(_ *cli.Context) error {
return util.InitTemplates(category, templates)
}
@ -66,18 +74,10 @@ func RevertTemplate(name string) error {
return util.CreateTemplate(category, name, content)
}
func Clean() error {
return util.Clean(category)
}
func Update(category string) error {
func Update() error {
err := Clean()
if err != nil {
return err
}
return util.InitTemplates(category, templates)
}
func GetCategory() string {
return category
}

@ -85,7 +85,7 @@ func TestUpdate(t *testing.T) {
assert.Equal(t, string(data), modifyData)
assert.Nil(t, Update(category))
assert.Nil(t, Update())
data, err = ioutil.ReadFile(file)
assert.Nil(t, err)

@ -54,14 +54,15 @@ func Clean() error {
return util.Clean(category)
}
func Update(category string) error {
func Update() error {
err := Clean()
if err != nil {
return err
}
return util.InitTemplates(category, templates)
}
func GetCategory() string {
func Category() string {
return category
}

@ -97,8 +97,7 @@ func TestUpdate(t *testing.T) {
}
assert.Equal(t, "modify", string(data))
err = Update(category)
assert.Nil(t, err)
assert.Nil(t, Update())
data, err = ioutil.ReadFile(mainTpl)
if err != nil {
@ -109,6 +108,6 @@ func TestUpdate(t *testing.T) {
func TestGetCategory(t *testing.T) {
_ = Clean()
result := GetCategory()
result := Category()
assert.Equal(t, category, result)
}

@ -76,12 +76,16 @@ func UpdateTemplates(ctx *cli.Context) (err error) {
}
}()
switch category {
case gogen.GetCategory():
return gogen.Update(category)
case rpcgen.GetCategory():
return rpcgen.Update(category)
case modelgen.GetCategory():
return modelgen.Update(category)
case docker.Category():
return docker.Update()
case gogen.Category():
return gogen.Update()
case kube.Category():
return kube.Update()
case rpcgen.Category():
return rpcgen.Update()
case modelgen.Category():
return modelgen.Update()
default:
err = fmt.Errorf("unexpected category: %s", category)
return
@ -97,11 +101,15 @@ func RevertTemplates(ctx *cli.Context) (err error) {
}
}()
switch category {
case gogen.GetCategory():
case docker.Category():
return docker.RevertTemplate(filename)
case kube.Category():
return kube.RevertTemplate(filename)
case gogen.Category():
return gogen.RevertTemplate(filename)
case rpcgen.GetCategory():
case rpcgen.Category():
return rpcgen.RevertTemplate(filename)
case modelgen.GetCategory():
case modelgen.Category():
return modelgen.RevertTemplate(filename)
default:
err = fmt.Errorf("unexpected category: %s", category)

Loading…
Cancel
Save