|
|
|
@ -39,14 +39,11 @@ var (
|
|
|
|
|
action = flag.String("action", "deploy", "expand | deploy | list | get | delete | update | listtypes | listtypeinstances | types")
|
|
|
|
|
name = flag.String("name", "", "Name of template or deployment")
|
|
|
|
|
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",
|
|
|
|
|
"Path to template expansion binary")
|
|
|
|
|
|
|
|
|
|
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() {
|
|
|
|
@ -55,13 +52,17 @@ var usage = func() {
|
|
|
|
|
flag.PrintDefaults()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getGitRegistry() *registry.GithubRegistry {
|
|
|
|
|
s := strings.Split(*type_registry, "/")
|
|
|
|
|
return registry.NewGithubRegistry(s[0], s[1])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
flag.Parse()
|
|
|
|
|
name := getNameArgument()
|
|
|
|
|
switch *action {
|
|
|
|
|
case "types":
|
|
|
|
|
s := strings.Split(*type_registry, "/")
|
|
|
|
|
git := registry.NewGithubRegistry(s[0], s[1])
|
|
|
|
|
git := getGitRegistry()
|
|
|
|
|
types, err := git.List()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("Cannot list %v err")
|
|
|
|
@ -71,7 +72,7 @@ func main() {
|
|
|
|
|
log.Printf("%s:%s", t.Name, t.Version)
|
|
|
|
|
downloadURL, err := git.GetURL(t)
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
@ -149,8 +150,8 @@ func loadTemplate(name string) *expander.Template {
|
|
|
|
|
var template *expander.Template
|
|
|
|
|
var err error
|
|
|
|
|
if len(args) == 1 {
|
|
|
|
|
if strings.HasSuffix(args[0], ".py") || strings.HasSuffix(args[0], ".jinja") {
|
|
|
|
|
template = buildTemplateFromType(name, args[0])
|
|
|
|
|
if t := getRegistryType(args[0]); t != nil {
|
|
|
|
|
template = buildTemplateFromType(name, *t)
|
|
|
|
|
} else {
|
|
|
|
|
template, err = expander.NewTemplateFromRootTemplate(args[0])
|
|
|
|
|
}
|
|
|
|
@ -168,9 +169,25 @@ func loadTemplate(name string) *expander.Template {
|
|
|
|
|
return template
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func buildTemplateFromType(name string, typeName string) *expander.Template {
|
|
|
|
|
// TODO: Fill this in with an actual URL fetched from github.
|
|
|
|
|
fullType := *repository + "/" + typeName
|
|
|
|
|
// TODO: needs better validation that this is actually a registry type.
|
|
|
|
|
func getRegistryType(fullType string) *registry.Type {
|
|
|
|
|
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{})
|
|
|
|
|
if *properties != "" {
|
|
|
|
@ -182,7 +199,7 @@ func buildTemplateFromType(name string, typeName string) *expander.Template {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// support ints
|
|
|
|
|
// TODO: needs to done to support other types.
|
|
|
|
|
// TODO: needs to support other types.
|
|
|
|
|
i, err := strconv.Atoi(ppair[1])
|
|
|
|
|
if err != nil {
|
|
|
|
|
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{
|
|
|
|
|
Name: name,
|
|
|
|
|
Type: fullType,
|
|
|
|
|
Type: downloadURL,
|
|
|
|
|
Properties: props,
|
|
|
|
|
}}}
|
|
|
|
|
|
|
|
|
|