mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-30 10:10:44 +02:00
Add generate kubernetes command (#2261)
This commit is contained in:
parent
ac21bb5b19
commit
fa27250605
@ -17,23 +17,60 @@ func init() {
|
||||
Name: "generate",
|
||||
Usage: "Generate project template files after the fact",
|
||||
Subcommands: []*cli.Command{
|
||||
{
|
||||
Name: "kubernetes",
|
||||
Usage: "Generate Kubernetes resource template files",
|
||||
Action: Kubernetes,
|
||||
},
|
||||
{
|
||||
Name: "skaffold",
|
||||
Usage: "Generate Skaffold project template files",
|
||||
Usage: "Generate Skaffold template files",
|
||||
Action: Skaffold,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Skaffold generates Skaffold project template files in the current directory.
|
||||
// Exits on error.
|
||||
func Skaffold(ctx *cli.Context) error {
|
||||
dir, err := os.Getwd()
|
||||
// Kubernetes generates Kubernetes resource template files in the current
|
||||
// working directory. Exits on error.
|
||||
func Kubernetes(ctx *cli.Context) error {
|
||||
service, err := getService()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
vendor, err := getServiceVendor(service)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
g := generator.New(
|
||||
generator.Service(service),
|
||||
generator.Vendor(vendor),
|
||||
generator.Directory("."),
|
||||
generator.Client(strings.HasSuffix(service, "-client")),
|
||||
)
|
||||
|
||||
files := []generator.File{
|
||||
{"plugins.go", tmpl.Plugins},
|
||||
{"resources/clusterrole.yaml", tmpl.KubernetesClusterRole},
|
||||
{"resources/configmap.yaml", tmpl.KubernetesEnv},
|
||||
{"resources/deployment.yaml", tmpl.KubernetesDeployment},
|
||||
{"resources/rolebinding.yaml", tmpl.KubernetesRoleBinding},
|
||||
}
|
||||
|
||||
g.Generate(files)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Skaffold generates Skaffold template files in the current working directory.
|
||||
// Exits on error.
|
||||
func Skaffold(ctx *cli.Context) error {
|
||||
service, err := getService()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
service := dir[strings.LastIndex(dir, "/")+1:]
|
||||
|
||||
vendor, err := getServiceVendor(service)
|
||||
if err != nil {
|
||||
@ -68,6 +105,14 @@ func Skaffold(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getService() (string, error) {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return dir[strings.LastIndex(dir, "/")+1:], nil
|
||||
}
|
||||
|
||||
func getServiceVendor(s string) (string, error) {
|
||||
f, err := os.Open("go.mod")
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user