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) return util.CreateTemplate(category, name, content)
} }
func Update(category string) error { func Update() error {
err := Clean() err := Clean()
if err != nil { if err != nil {
return err return err
} }
return util.InitTemplates(category, templates) return util.InitTemplates(category, templates)
} }
@ -50,6 +51,6 @@ func Clean() error {
return util.Clean(category) return util.Clean(category)
} }
func GetCategory() string { func Category() string {
return category return category
} }

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

@ -39,7 +39,32 @@ CMD ["./{{.ExeFile}}"{{.Argument}}]
` `
) )
func Clean() error {
return util.Clean(category)
}
func GenTemplates(_ *cli.Context) error { 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{ return util.InitTemplates(category, map[string]string{
dockerTemplateFile: dockerTemplate, dockerTemplateFile: dockerTemplate,
}) })

@ -476,7 +476,7 @@ var (
Flags: []cli.Flag{ Flags: []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "category,c", 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, Action: tpl.UpdateTemplates,
@ -487,7 +487,7 @@ var (
Flags: []cli.Flag{ Flags: []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "category,c", 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{ cli.StringFlag{
Name: "name,n", Name: "name,n",

@ -16,30 +16,7 @@ const (
portLimit = 32767 portLimit = 32767
) )
var errUnknownServiceType = errors.New("unknown service type") type Deployment struct {
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 Name string
Namespace string Namespace string
Image string Image string
@ -56,7 +33,6 @@ type (
MinReplicas int MinReplicas int
MaxReplicas int MaxReplicas int
} }
)
func DeploymentCommand(c *cli.Context) error { func DeploymentCommand(c *cli.Context) error {
nodePort := c.Int("nodePort") 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 { func GenTemplates(_ *cli.Context) error {
return util.InitTemplates(category, map[string]string{ return util.InitTemplates(category, map[string]string{
deployTemplateFile: deploymentTemplate, deployTemplateFile: deploymentTemplate,
jobTemplateFile: jobTmeplate, 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, errTemplateFile: template.Error,
} }
func Category() string {
return category
}
func Clean() error {
return util.Clean(category)
}
func GenTemplates(_ *cli.Context) error { func GenTemplates(_ *cli.Context) error {
return util.InitTemplates(category, templates) return util.InitTemplates(category, templates)
} }
@ -66,18 +74,10 @@ func RevertTemplate(name string) error {
return util.CreateTemplate(category, name, content) return util.CreateTemplate(category, name, content)
} }
func Clean() error { func Update() error {
return util.Clean(category)
}
func Update(category string) error {
err := Clean() err := Clean()
if err != nil { if err != nil {
return err return err
} }
return util.InitTemplates(category, templates) 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.Equal(t, string(data), modifyData)
assert.Nil(t, Update(category)) assert.Nil(t, Update())
data, err = ioutil.ReadFile(file) data, err = ioutil.ReadFile(file)
assert.Nil(t, err) assert.Nil(t, err)

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

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

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

Loading…
Cancel
Save