Update manager for refactored expander

pull/462/head
jackgr 9 years ago
parent ba469fbf7f
commit 6c838585fa

@ -22,6 +22,7 @@ import (
"regexp"
"time"
"github.com/ghodss/yaml"
"github.com/kubernetes/helm/cmd/manager/repository"
"github.com/kubernetes/helm/pkg/chart"
"github.com/kubernetes/helm/pkg/common"
@ -136,7 +137,7 @@ func (m *manager) CreateDeployment(t *common.Template) (*common.Deployment, erro
return nil, err
}
manifest, err := m.createManifest(t)
manifest, err := m.Expand(t)
if err != nil {
log.Printf("Manifest creation failed: %v", err)
m.repository.SetDeploymentState(t.Name, failState(err))
@ -186,22 +187,6 @@ func (m *manager) CreateDeployment(t *common.Template) (*common.Deployment, erro
return m.repository.GetValidDeployment(t.Name)
}
func (m *manager) createManifest(t *common.Template) (*common.Manifest, error) {
et, err := m.expander.ExpandTemplate(t)
if err != nil {
log.Printf("Expansion failed %v", err)
return nil, err
}
return &common.Manifest{
Name: generateManifestName(),
Deployment: t.Name,
InputConfig: t,
ExpandedConfig: et.Config,
Layout: et.Layout,
}, nil
}
func (m *manager) setChartInstances(deploymentName string, manifestName string, layout *common.Layout) {
m.repository.ClearChartInstancesForDeployment(deploymentName)
@ -290,7 +275,7 @@ func (m *manager) PutDeployment(name string, t *common.Template) (*common.Deploy
return nil, err
}
manifest, err := m.createManifest(t)
manifest, err := m.Expand(t)
if err != nil {
log.Printf("Manifest creation failed: %v", err)
m.repository.SetDeploymentState(name, failState(err))
@ -316,15 +301,23 @@ func (m *manager) PutDeployment(name string, t *common.Template) (*common.Deploy
}
func (m *manager) Expand(t *common.Template) (*common.Manifest, error) {
et, err := m.expander.ExpandTemplate(t)
conf := &common.Configuration{}
if err := yaml.Unmarshal([]byte(t.Content), conf); err != nil {
return nil, fmt.Errorf("Unable to unmarshal configuration: %s\n%s\n", err, t.Content)
}
expConf, err := m.expander.ExpandConfiguration(conf)
if err != nil {
log.Printf("Expansion failed %v", err)
return nil, err
}
return &common.Manifest{
ExpandedConfig: et.Config,
Layout: et.Layout,
Name: generateManifestName(),
Deployment: t.Name,
InputConfig: t,
ExpandedConfig: expConf.Config,
Layout: expConf.Layout,
}, nil
}

@ -19,6 +19,7 @@ package manager
import (
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/repo"
"github.com/kubernetes/helm/pkg/util"
"errors"
"reflect"
@ -26,8 +27,6 @@ import (
"testing"
)
var template = common.Template{Name: "test", Content: "test"}
var layout = common.Layout{
Resources: []*common.LayoutResource{{Resource: common.Resource{Name: "test", Type: "test"}}},
}
@ -47,7 +46,9 @@ var resourcesWithFailureState = common.Configuration{
},
}},
}
var expandedConfig = ExpandedTemplate{
var template = common.Template{Name: "test", Content: util.ToYAMLOrError(&configuration)}
var expandedConfig = ExpandedConfiguration{
Config: &configuration,
Layout: &layout,
}
@ -70,8 +71,8 @@ var errTest = errors.New("test error")
type expanderStub struct{}
func (expander *expanderStub) ExpandTemplate(t *common.Template) (*ExpandedTemplate, error) {
if reflect.DeepEqual(*t, template) {
func (expander *expanderStub) ExpandConfiguration(conf *common.Configuration) (*ExpandedConfiguration, error) {
if reflect.DeepEqual(conf, &configuration) {
return &expandedConfig, nil
}
@ -422,14 +423,18 @@ func TestCreateDeploymentCreationResourceFailure(t *testing.T) {
t.Fatal("CreateDeployment failure did not mark deployment as failed")
}
if !strings.HasPrefix(testRepository.ManifestAdd[template.Name].Name, "manifest-") {
t.Fatalf("Repository AddManifest was called with %s but expected manifest name"+
"to begin with manifest-.", testRepository.ManifestAdd[template.Name].Name)
if manifest, ok := testRepository.ManifestAdd[template.Name]; ok {
if !strings.HasPrefix(manifest.Name, "manifest-") {
t.Fatalf("Repository AddManifest was called with %s but expected manifest name"+
"to begin with manifest-.", manifest.Name)
}
}
if !strings.HasPrefix(testRepository.ManifestSet[template.Name].Name, "manifest-") {
t.Fatalf("Repository SetManifest was called with %s but expected manifest name"+
"to begin with manifest-.", testRepository.ManifestSet[template.Name].Name)
if manifest, ok := testRepository.ManifestSet[template.Name]; ok {
if !strings.HasPrefix(manifest.Name, "manifest-") {
t.Fatalf("Repository AddManifest was called with %s but expected manifest name"+
"to begin with manifest-.", manifest.Name)
}
}
if err != nil || !reflect.DeepEqual(d, &deployment) {
@ -497,18 +502,6 @@ func TestExpand(t *testing.T) {
t.Fatal("Failed to expand template into manifest.")
}
if m.Name != "" {
t.Fatalf("Name was not empty: %v", *m)
}
if m.Deployment != "" {
t.Fatalf("Deployment was not empty: %v", *m)
}
if m.InputConfig != nil {
t.Fatalf("Input config not nil: %v", *m)
}
if !reflect.DeepEqual(*m.ExpandedConfig, configuration) {
t.Fatalf("Expanded config not correct in output manifest: %v", *m)
}

Loading…
Cancel
Save