pull/445/merge
Dave Cunningham 11 years ago
commit e15da9d263

@ -24,16 +24,16 @@ import (
"log"
"os/exec"
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/expander"
)
type expander struct {
type expandyBirdExpander struct {
ExpansionBinary string
}
// NewExpander returns an ExpandyBird expander.
func NewExpander(binary string) common.Expander {
return &expander{binary}
func NewExpander(binary string) expander.Expander {
return &expandyBirdExpander{binary}
}
type expandyBirdConfigOutput struct {
@ -47,7 +47,7 @@ type expandyBirdOutput struct {
// ExpandChart passes the given configuration to the expander and returns the
// expanded configuration as a string on success.
func (e *expander) ExpandChart(request *common.ExpansionRequest) (*common.ExpansionResponse, error) {
func (e *expandyBirdExpander) ExpandChart(request *expander.ExpansionRequest) (*expander.ExpansionResponse, error) {
if request.ChartInvocation == nil {
return nil, fmt.Errorf("Request does not have invocation field")
}
@ -155,5 +155,5 @@ func (e *expander) ExpandChart(request *common.ExpansionRequest) (*common.Expans
return nil, fmt.Errorf("cannot unmarshal expansion result (%s):\n%s", err, output)
}
return &common.ExpansionResponse{Resources: output.Config.Resources}, nil
return &expander.ExpansionResponse{Resources: output.Config.Resources}, nil
}

@ -24,15 +24,15 @@ import (
"testing"
"github.com/kubernetes/helm/pkg/chart"
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/expander"
)
var expanderName = "../../../expansion/expansion.py"
type testCase struct {
Description string
Request *common.ExpansionRequest
ExpectedResponse *common.ExpansionResponse
Request *expander.ExpansionRequest
ExpectedResponse *expander.ExpansionResponse
ExpectedError string
}
@ -47,8 +47,8 @@ func funcName() string {
return runtime.FuncForPC(pc).Name()
}
func testExpansion(t *testing.T, req *common.ExpansionRequest,
expResponse *common.ExpansionResponse, expError string) {
func testExpansion(t *testing.T, req *expander.ExpansionRequest,
expResponse *expander.ExpansionResponse, expError string) {
backend := NewExpander(expanderName)
response, err := backend.ExpandChart(req)
if err != nil {
@ -81,8 +81,8 @@ var jinjaExpander = &chart.Expander{
func TestEmptyJinja(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
ChartInvocation: &common.Resource{
&expander.ExpansionRequest{
ChartInvocation: &expander.Resource{
Name: "test_invocation",
Type: funcName(),
},
@ -99,7 +99,7 @@ func TestEmptyJinja(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expander.ExpansionResponse{
Resources: []interface{}{},
},
"", // Error
@ -109,8 +109,8 @@ func TestEmptyJinja(t *testing.T) {
func TestEmptyPython(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
ChartInvocation: &common.Resource{
&expander.ExpansionRequest{
ChartInvocation: &expander.Resource{
Name: "test_invocation",
Type: funcName(),
},
@ -130,7 +130,7 @@ func TestEmptyPython(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expander.ExpansionResponse{
Resources: []interface{}{},
},
"", // Error
@ -140,8 +140,8 @@ func TestEmptyPython(t *testing.T) {
func TestSimpleJinja(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
ChartInvocation: &common.Resource{
&expander.ExpansionRequest{
ChartInvocation: &expander.Resource{
Name: "test_invocation",
Type: funcName(),
},
@ -162,7 +162,7 @@ func TestSimpleJinja(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expander.ExpansionResponse{
Resources: []interface{}{
map[string]interface{}{
"name": "foo",
@ -177,8 +177,8 @@ func TestSimpleJinja(t *testing.T) {
func TestSimplePython(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
ChartInvocation: &common.Resource{
&expander.ExpansionRequest{
ChartInvocation: &expander.Resource{
Name: "test_invocation",
Type: funcName(),
},
@ -201,7 +201,7 @@ func TestSimplePython(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expander.ExpansionResponse{
Resources: []interface{}{
map[string]interface{}{
"name": "foo",
@ -216,8 +216,8 @@ func TestSimplePython(t *testing.T) {
func TestPropertiesJinja(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
ChartInvocation: &common.Resource{
&expander.ExpansionRequest{
ChartInvocation: &expander.Resource{
Name: "test_invocation",
Type: funcName(),
Properties: map[string]interface{}{
@ -244,7 +244,7 @@ func TestPropertiesJinja(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expander.ExpansionResponse{
Resources: []interface{}{
map[string]interface{}{
"name": "foo",
@ -262,8 +262,8 @@ func TestPropertiesJinja(t *testing.T) {
func TestPropertiesPython(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
ChartInvocation: &common.Resource{
&expander.ExpansionRequest{
ChartInvocation: &expander.Resource{
Name: "test_invocation",
Type: funcName(),
Properties: map[string]interface{}{
@ -292,7 +292,7 @@ func TestPropertiesPython(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expander.ExpansionResponse{
Resources: []interface{}{
map[string]interface{}{
"name": "foo",
@ -310,8 +310,8 @@ func TestPropertiesPython(t *testing.T) {
func TestMultiFileJinja(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
ChartInvocation: &common.Resource{
&expander.ExpansionRequest{
ChartInvocation: &expander.Resource{
Name: "test_invocation",
Type: funcName(),
},
@ -336,7 +336,7 @@ func TestMultiFileJinja(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expander.ExpansionResponse{
Resources: []interface{}{
map[string]interface{}{
"name": "foo",
@ -368,8 +368,8 @@ var schemaContent = content([]string{
func TestSchema(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
ChartInvocation: &common.Resource{
&expander.ExpansionRequest{
ChartInvocation: &expander.Resource{
Name: "test_invocation",
Type: funcName(),
Properties: map[string]interface{}{
@ -401,7 +401,7 @@ func TestSchema(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expander.ExpansionResponse{
Resources: []interface{}{
map[string]interface{}{
"name": "foo",
@ -419,8 +419,8 @@ func TestSchema(t *testing.T) {
func TestSchemaFail(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
ChartInvocation: &common.Resource{
&expander.ExpansionRequest{
ChartInvocation: &expander.Resource{
Name: "test_invocation",
Type: funcName(),
Properties: map[string]interface{}{
@ -460,8 +460,8 @@ func TestSchemaFail(t *testing.T) {
func TestMultiFileJinjaMissing(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
ChartInvocation: &common.Resource{
&expander.ExpansionRequest{
ChartInvocation: &expander.Resource{
Name: "test_invocation",
Type: funcName(),
},
@ -486,8 +486,8 @@ func TestMultiFileJinjaMissing(t *testing.T) {
func TestMultiFilePython(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
ChartInvocation: &common.Resource{
&expander.ExpansionRequest{
ChartInvocation: &expander.Resource{
Name: "test_invocation",
Type: funcName(),
},
@ -531,7 +531,7 @@ func TestMultiFilePython(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expander.ExpansionResponse{
Resources: []interface{}{
map[string]interface{}{
"name": "foo",
@ -546,8 +546,8 @@ func TestMultiFilePython(t *testing.T) {
func TestMultiFilePythonMissing(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
ChartInvocation: &common.Resource{
&expander.ExpansionRequest{
ChartInvocation: &expander.Resource{
Name: "test_invocation",
Type: funcName(),
},
@ -574,8 +574,8 @@ func TestMultiFilePythonMissing(t *testing.T) {
func TestWrongChartName(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
ChartInvocation: &common.Resource{
&expander.ExpansionRequest{
ChartInvocation: &expander.Resource{
Name: "test_invocation",
Type: funcName(),
},
@ -600,8 +600,8 @@ func TestWrongChartName(t *testing.T) {
func TestEntrypointNotFound(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
ChartInvocation: &common.Resource{
&expander.ExpansionRequest{
ChartInvocation: &expander.Resource{
Name: "test_invocation",
Type: funcName(),
},
@ -621,8 +621,8 @@ func TestEntrypointNotFound(t *testing.T) {
func TestMalformedResource(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
ChartInvocation: &common.Resource{
&expander.ExpansionRequest{
ChartInvocation: &expander.Resource{
Name: "test_invocation",
Type: funcName(),
},
@ -650,8 +650,8 @@ func TestMalformedResource(t *testing.T) {
func TestResourceNoName(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
ChartInvocation: &common.Resource{
&expander.ExpansionRequest{
ChartInvocation: &expander.Resource{
Name: "test_invocation",
Type: funcName(),
},
@ -679,8 +679,8 @@ func TestResourceNoName(t *testing.T) {
func TestResourceNoType(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
ChartInvocation: &common.Resource{
&expander.ExpansionRequest{
ChartInvocation: &expander.Resource{
Name: "test_invocation",
Type: funcName(),
},

@ -17,7 +17,7 @@ limitations under the License.
package service
import (
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/expander"
"github.com/kubernetes/helm/pkg/util"
"errors"
@ -43,8 +43,8 @@ func NewService(handler restful.RouteFunction) *Service {
webService.Produces(restful.MIME_JSON, restful.MIME_XML)
webService.Route(webService.POST("/expand").To(handler).
Doc("Expand a template.").
Reads(&common.ExpansionRequest{}).
Writes(&common.ExpansionResponse{}))
Reads(&expander.ExpansionRequest{}).
Writes(&expander.ExpansionResponse{}))
return &Service{webService}
}
@ -61,10 +61,10 @@ func (s *Service) Register(container *restful.Container) {
// NewExpansionHandler returns a route function that handles an incoming
// template expansion request, bound to the supplied expander.
func NewExpansionHandler(backend common.Expander) restful.RouteFunction {
func NewExpansionHandler(backend expander.Expander) restful.RouteFunction {
return func(req *restful.Request, resp *restful.Response) {
util.LogHandlerEntry("expandybird: expand", req.Request)
request := &common.ExpansionRequest{}
request := &expander.ExpansionRequest{}
if err := req.ReadEntity(&request); err != nil {
logAndReturnErrorFromHandler(http.StatusBadRequest, err.Error(), resp)
return

@ -28,7 +28,7 @@ import (
"testing"
"github.com/kubernetes/helm/cmd/expandybird/expander"
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/expander"
"github.com/kubernetes/helm/pkg/util"
restful "github.com/emicklei/go-restful"
@ -185,7 +185,7 @@ type mockExpander struct {
// ExpandTemplate passes the given configuration to the expander and returns the
// expanded configuration as a string on success.
func (e *mockExpander) ExpandTemplate(template *common.Template) (string, error) {
func (e *mockExpander) ExpandTemplate(template *expander.Template) (string, error) {
switch template.Name {
case "InvalidFileName.yaml":
return "", fmt.Errorf("expansion error")

@ -17,7 +17,6 @@ limitations under the License.
package common
import (
"github.com/kubernetes/helm/pkg/chart"
"time"
)
@ -130,22 +129,6 @@ type Layout struct {
Resources []*LayoutResource `json:"resources,omitempty"`
}
// ExpansionRequest defines the API to expander.
type ExpansionRequest struct {
ChartInvocation *Resource `json:"chart_invocation"`
Chart *chart.Content `json:"chart"`
}
// ExpansionResponse defines the API to expander.
type ExpansionResponse struct {
Resources []interface{} `json:"resources"`
}
// Expander abstracts interactions with the expander and deployer services.
type Expander interface {
ExpandChart(request *ExpansionRequest) (*ExpansionResponse, error)
}
// Configuration describes a set of resources in a form
// that can be instantiated.
type Configuration struct {

Loading…
Cancel
Save