|
|
@ -39,14 +39,11 @@ var (
|
|
|
|
action = flag.String("action", "deploy", "expand | deploy | list | get | delete | update | listtypes | listtypeinstances | types")
|
|
|
|
action = flag.String("action", "deploy", "expand | deploy | list | get | delete | update | listtypes | listtypeinstances | types")
|
|
|
|
name = flag.String("name", "", "Name of template or deployment")
|
|
|
|
name = flag.String("name", "", "Name of template or deployment")
|
|
|
|
service = flag.String("service", "http://localhost:8080", "URL for deployment manager")
|
|
|
|
service = flag.String("service", "http://localhost:8080", "URL for deployment manager")
|
|
|
|
type_registry = flag.String("type_registry", "kubernetes/deployment-manager", "Type registry [owner/repo], defaults to kubernetes/deployment-manager/")
|
|
|
|
type_registry = flag.String("type_registry", "kubernetes/deployment-manager", "Type registry [owner/repo], defaults to kubernetes/deployment-manager")
|
|
|
|
binary = flag.String("binary", "../expandybird/expansion/expansion.py",
|
|
|
|
binary = flag.String("binary", "../expandybird/expansion/expansion.py",
|
|
|
|
"Path to template expansion binary")
|
|
|
|
"Path to template expansion binary")
|
|
|
|
|
|
|
|
|
|
|
|
properties = flag.String("properties", "", "Properties to use when deploying a type")
|
|
|
|
properties = flag.String("properties", "", "Properties to use when deploying a type")
|
|
|
|
repository = flag.String("repository",
|
|
|
|
|
|
|
|
"https://raw.githubusercontent.com/kubernetes/deployment-manager/master/examples",
|
|
|
|
|
|
|
|
"Root of type repository")
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var usage = func() {
|
|
|
|
var usage = func() {
|
|
|
@ -55,13 +52,17 @@ var usage = func() {
|
|
|
|
flag.PrintDefaults()
|
|
|
|
flag.PrintDefaults()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func getGitRegistry() *registry.GithubRegistry {
|
|
|
|
|
|
|
|
s := strings.Split(*type_registry, "/")
|
|
|
|
|
|
|
|
return registry.NewGithubRegistry(s[0], s[1])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
flag.Parse()
|
|
|
|
name := getNameArgument()
|
|
|
|
name := getNameArgument()
|
|
|
|
switch *action {
|
|
|
|
switch *action {
|
|
|
|
case "types":
|
|
|
|
case "types":
|
|
|
|
s := strings.Split(*type_registry, "/")
|
|
|
|
git := getGitRegistry()
|
|
|
|
git := registry.NewGithubRegistry(s[0], s[1])
|
|
|
|
|
|
|
|
types, err := git.List()
|
|
|
|
types, err := git.List()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Cannot list %v err")
|
|
|
|
log.Fatalf("Cannot list %v err")
|
|
|
@ -71,7 +72,7 @@ func main() {
|
|
|
|
log.Printf("%s:%s", t.Name, t.Version)
|
|
|
|
log.Printf("%s:%s", t.Name, t.Version)
|
|
|
|
downloadURL, err := git.GetURL(t)
|
|
|
|
downloadURL, err := git.GetURL(t)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to get download URL for %s:%s", t.Name, t.Version)
|
|
|
|
log.Printf("Failed to get download URL for type %s:%s", t.Name, t.Version)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Printf("\tdownload URL: %s", downloadURL)
|
|
|
|
log.Printf("\tdownload URL: %s", downloadURL)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -149,8 +150,8 @@ func loadTemplate(name string) *expander.Template {
|
|
|
|
var template *expander.Template
|
|
|
|
var template *expander.Template
|
|
|
|
var err error
|
|
|
|
var err error
|
|
|
|
if len(args) == 1 {
|
|
|
|
if len(args) == 1 {
|
|
|
|
if strings.HasSuffix(args[0], ".py") || strings.HasSuffix(args[0], ".jinja") {
|
|
|
|
if t := getRegistryType(args[0]); t != nil {
|
|
|
|
template = buildTemplateFromType(name, args[0])
|
|
|
|
template = buildTemplateFromType(name, *t)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
template, err = expander.NewTemplateFromRootTemplate(args[0])
|
|
|
|
template, err = expander.NewTemplateFromRootTemplate(args[0])
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -168,9 +169,25 @@ func loadTemplate(name string) *expander.Template {
|
|
|
|
return template
|
|
|
|
return template
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func buildTemplateFromType(name string, typeName string) *expander.Template {
|
|
|
|
// TODO: needs better validation that this is actually a registry type.
|
|
|
|
// TODO: Fill this in with an actual URL fetched from github.
|
|
|
|
func getRegistryType(fullType string) *registry.Type {
|
|
|
|
fullType := *repository + "/" + typeName
|
|
|
|
tList := strings.Split(fullType, ":")
|
|
|
|
|
|
|
|
if len(tList) != 2 {
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ®istry.Type{
|
|
|
|
|
|
|
|
Name: tList[0],
|
|
|
|
|
|
|
|
Version: tList[1],
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func buildTemplateFromType(name string, t registry.Type) *expander.Template {
|
|
|
|
|
|
|
|
git := getGitRegistry()
|
|
|
|
|
|
|
|
downloadURL, err := git.GetURL(t)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Printf("Failed to get download URL for type %s:%s", t.Name, t.Version)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
props := make(map[string]interface{})
|
|
|
|
props := make(map[string]interface{})
|
|
|
|
if *properties != "" {
|
|
|
|
if *properties != "" {
|
|
|
@ -182,7 +199,7 @@ func buildTemplateFromType(name string, typeName string) *expander.Template {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// support ints
|
|
|
|
// support ints
|
|
|
|
// TODO: needs to done to support other types.
|
|
|
|
// TODO: needs to support other types.
|
|
|
|
i, err := strconv.Atoi(ppair[1])
|
|
|
|
i, err := strconv.Atoi(ppair[1])
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
props[ppair[0]] = ppair[1]
|
|
|
|
props[ppair[0]] = ppair[1]
|
|
|
@ -194,7 +211,7 @@ func buildTemplateFromType(name string, typeName string) *expander.Template {
|
|
|
|
|
|
|
|
|
|
|
|
config := manager.Configuration{Resources: []*manager.Resource{&manager.Resource{
|
|
|
|
config := manager.Configuration{Resources: []*manager.Resource{&manager.Resource{
|
|
|
|
Name: name,
|
|
|
|
Name: name,
|
|
|
|
Type: fullType,
|
|
|
|
Type: downloadURL,
|
|
|
|
Properties: props,
|
|
|
|
Properties: props,
|
|
|
|
}}}
|
|
|
|
}}}
|
|
|
|
|
|
|
|
|
|
|
|