Remove unneccessary download url retrieval.

pull/256/head
jackgr 9 years ago
parent edd4e9dcba
commit f14c53980f

@ -245,15 +245,7 @@ func execute() {
os.Exit(1)
}
tUrls := getDownloadURLs(args[1])
var tURL = ""
if len(tUrls) == 0 {
// Type is most likely a primitive.
tURL = args[1]
} else {
// TODO(vaikas): Support packages properly.
tURL = tUrls[0]
}
tURL := args[1]
path := fmt.Sprintf("types/%s/instances", url.QueryEscape(tURL))
action := fmt.Sprintf("list deployed instances of type %s", tURL)
callService(path, "GET", action, nil)
@ -431,24 +423,12 @@ func buildTemplateFromType(t string) *common.Template {
}
// Name the deployment after the type name.
name := t
config := common.Configuration{Resources: []*common.Resource{&common.Resource{
Name: name,
Type: getDownloadURLs(t)[0],
Properties: props,
}}}
y, err := yaml.Marshal(config)
template, err := expander.NewTemplateFromType(t, t, props)
if err != nil {
panic(fmt.Errorf("error: %s\ncannot create configuration for deployment: %v\n", err, config))
panic(fmt.Errorf("cannot create configuration from type (%s): %s\n", t, err))
}
return &common.Template{
Name: name,
Content: string(y),
// No imports, as this is a single type from repository.
}
return template
}
func marshalTemplate(template *common.Template) io.ReadCloser {

@ -46,6 +46,28 @@ func NewExpander(binary string) Expander {
return &expander{binary}
}
func NewTemplateFromType(name, typeName string, properties map[string]interface{}) (*common.Template, error) {
resource := &common.Resource{
Name: name,
Type: typeName,
Properties: properties,
}
config := common.Configuration{Resources: []*common.Resource{resource}}
content, err := yaml.Marshal(config)
if err != nil {
return nil, fmt.Errorf("error: %s\ncannot marshal configuration: %v\n", err, config)
}
template := &common.Template{
Name: name,
Content: string(content),
Imports: []*common.ImportFile{},
}
return template, nil
}
// NewTemplateFromArchive creates and returns a new template whose content
// and imported files are read from the supplied archive.
func NewTemplateFromArchive(name string, r io.Reader, importFileNames []string) (*common.Template, error) {

@ -28,6 +28,7 @@ import (
"strings"
"testing"
"github.com/ghodss/yaml"
"github.com/kubernetes/deployment-manager/common"
)
@ -107,6 +108,33 @@ func testExpandTemplateFromFile(t *testing.T, fileName, baseName string, importF
expandAndVerifyOutput(t, actualOutput, description)
}
var (
testTemplateName = "expandybird"
testTemplateType = "replicatedservice.py"
testTemplateProperties = `
service_port: 8080
target_port: 8080
container_port: 8080
external_service: true
replicas: 3
image: gcr.io/dm-k8s-testing/expandybird
labels:
app: expandybird
`
)
func TestNewTemplateFromType(t *testing.T) {
var properties map[string]interface{}
if err := yaml.Unmarshal([]byte(testTemplateProperties), &properties); err != nil {
t.Fatalf("cannot unmarshal test data: %s", err)
}
_, err := NewTemplateFromType(testTemplateName, testTemplateType, properties)
if err != nil {
t.Fatalf("cannot create template from type %s: %s", testTemplateType, err)
}
}
func TestNewTemplateFromReader(t *testing.T) {
r := bytes.NewReader([]byte{})
if _, err := NewTemplateFromReader("test", r, nil); err == nil {

Loading…
Cancel
Save