Commit c14b92bd authored by jackgr's avatar jackgr

Move expansion types out of pkg/common

parent e65b6bee
......@@ -24,7 +24,7 @@ import (
"log"
"os/exec"
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/expansion"
)
type expander struct {
......@@ -32,7 +32,7 @@ type expander struct {
}
// NewExpander returns an ExpandyBird expander.
func NewExpander(binary string) common.Expander {
func NewExpander(binary string) expansion.Expander {
return &expander{binary}
}
......@@ -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 *expander) ExpandChart(request *expansion.ExpansionRequest) (*expansion.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 &expansion.ExpansionResponse{Resources: output.Config.Resources}, nil
}
......@@ -25,14 +25,15 @@ import (
"github.com/kubernetes/helm/pkg/chart"
"github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/expansion"
)
var expanderName = "../../../expansion/expansion.py"
type testCase struct {
Description string
Request *common.ExpansionRequest
ExpectedResponse *common.ExpansionResponse
Request *expansion.ExpansionRequest
ExpectedResponse *expansion.ExpansionResponse
ExpectedError string
}
......@@ -47,8 +48,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 *expansion.ExpansionRequest,
expResponse *expansion.ExpansionResponse, expError string) {
backend := NewExpander(expanderName)
response, err := backend.ExpandChart(req)
if err != nil {
......@@ -81,7 +82,7 @@ var jinjaExpander = &chart.Expander{
func TestEmptyJinja(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
&expansion.ExpansionRequest{
ChartInvocation: &common.Resource{
Name: "test_invocation",
Type: funcName(),
......@@ -99,7 +100,7 @@ func TestEmptyJinja(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expansion.ExpansionResponse{
Resources: []interface{}{},
},
"", // Error
......@@ -109,7 +110,7 @@ func TestEmptyJinja(t *testing.T) {
func TestEmptyPython(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
&expansion.ExpansionRequest{
ChartInvocation: &common.Resource{
Name: "test_invocation",
Type: funcName(),
......@@ -130,7 +131,7 @@ func TestEmptyPython(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expansion.ExpansionResponse{
Resources: []interface{}{},
},
"", // Error
......@@ -140,7 +141,7 @@ func TestEmptyPython(t *testing.T) {
func TestSimpleJinja(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
&expansion.ExpansionRequest{
ChartInvocation: &common.Resource{
Name: "test_invocation",
Type: funcName(),
......@@ -162,7 +163,7 @@ func TestSimpleJinja(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expansion.ExpansionResponse{
Resources: []interface{}{
map[string]interface{}{
"name": "foo",
......@@ -177,7 +178,7 @@ func TestSimpleJinja(t *testing.T) {
func TestSimplePython(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
&expansion.ExpansionRequest{
ChartInvocation: &common.Resource{
Name: "test_invocation",
Type: funcName(),
......@@ -201,7 +202,7 @@ func TestSimplePython(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expansion.ExpansionResponse{
Resources: []interface{}{
map[string]interface{}{
"name": "foo",
......@@ -216,7 +217,7 @@ func TestSimplePython(t *testing.T) {
func TestPropertiesJinja(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
&expansion.ExpansionRequest{
ChartInvocation: &common.Resource{
Name: "test_invocation",
Type: funcName(),
......@@ -244,7 +245,7 @@ func TestPropertiesJinja(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expansion.ExpansionResponse{
Resources: []interface{}{
map[string]interface{}{
"name": "foo",
......@@ -262,7 +263,7 @@ func TestPropertiesJinja(t *testing.T) {
func TestPropertiesPython(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
&expansion.ExpansionRequest{
ChartInvocation: &common.Resource{
Name: "test_invocation",
Type: funcName(),
......@@ -292,7 +293,7 @@ func TestPropertiesPython(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expansion.ExpansionResponse{
Resources: []interface{}{
map[string]interface{}{
"name": "foo",
......@@ -310,7 +311,7 @@ func TestPropertiesPython(t *testing.T) {
func TestMultiFileJinja(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
&expansion.ExpansionRequest{
ChartInvocation: &common.Resource{
Name: "test_invocation",
Type: funcName(),
......@@ -336,7 +337,7 @@ func TestMultiFileJinja(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expansion.ExpansionResponse{
Resources: []interface{}{
map[string]interface{}{
"name": "foo",
......@@ -368,7 +369,7 @@ var schemaContent = content([]string{
func TestSchema(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
&expansion.ExpansionRequest{
ChartInvocation: &common.Resource{
Name: "test_invocation",
Type: funcName(),
......@@ -401,7 +402,7 @@ func TestSchema(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expansion.ExpansionResponse{
Resources: []interface{}{
map[string]interface{}{
"name": "foo",
......@@ -419,7 +420,7 @@ func TestSchema(t *testing.T) {
func TestSchemaFail(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
&expansion.ExpansionRequest{
ChartInvocation: &common.Resource{
Name: "test_invocation",
Type: funcName(),
......@@ -460,7 +461,7 @@ func TestSchemaFail(t *testing.T) {
func TestMultiFileJinjaMissing(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
&expansion.ExpansionRequest{
ChartInvocation: &common.Resource{
Name: "test_invocation",
Type: funcName(),
......@@ -486,7 +487,7 @@ func TestMultiFileJinjaMissing(t *testing.T) {
func TestMultiFilePython(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
&expansion.ExpansionRequest{
ChartInvocation: &common.Resource{
Name: "test_invocation",
Type: funcName(),
......@@ -531,7 +532,7 @@ func TestMultiFilePython(t *testing.T) {
},
},
},
&common.ExpansionResponse{
&expansion.ExpansionResponse{
Resources: []interface{}{
map[string]interface{}{
"name": "foo",
......@@ -546,7 +547,7 @@ func TestMultiFilePython(t *testing.T) {
func TestMultiFilePythonMissing(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
&expansion.ExpansionRequest{
ChartInvocation: &common.Resource{
Name: "test_invocation",
Type: funcName(),
......@@ -574,7 +575,7 @@ func TestMultiFilePythonMissing(t *testing.T) {
func TestWrongChartName(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
&expansion.ExpansionRequest{
ChartInvocation: &common.Resource{
Name: "test_invocation",
Type: funcName(),
......@@ -600,7 +601,7 @@ func TestWrongChartName(t *testing.T) {
func TestEntrypointNotFound(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
&expansion.ExpansionRequest{
ChartInvocation: &common.Resource{
Name: "test_invocation",
Type: funcName(),
......@@ -621,7 +622,7 @@ func TestEntrypointNotFound(t *testing.T) {
func TestMalformedResource(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
&expansion.ExpansionRequest{
ChartInvocation: &common.Resource{
Name: "test_invocation",
Type: funcName(),
......@@ -650,7 +651,7 @@ func TestMalformedResource(t *testing.T) {
func TestResourceNoName(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
&expansion.ExpansionRequest{
ChartInvocation: &common.Resource{
Name: "test_invocation",
Type: funcName(),
......@@ -679,7 +680,7 @@ func TestResourceNoName(t *testing.T) {
func TestResourceNoType(t *testing.T) {
testExpansion(
t,
&common.ExpansionRequest{
&expansion.ExpansionRequest{
ChartInvocation: &common.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/expansion"
"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(&expansion.ExpansionRequest{}).
Writes(&expansion.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 expansion.Expander) restful.RouteFunction {
return func(req *restful.Request, resp *restful.Response) {
util.LogHandlerEntry("expandybird: expand", req.Request)
request := &common.ExpansionRequest{}
request := &expansion.ExpansionRequest{}
if err := req.ReadEntity(&request); err != nil {
logAndReturnErrorFromHandler(http.StatusBadRequest, err.Error(), resp)
return
......
......@@ -17,7 +17,6 @@ limitations under the License.
package common
import (
"github.com/kubernetes/helm/pkg/chart"
"time"
)
......@@ -90,35 +89,6 @@ type ChartInstance struct {
Path string `json:"path"` // JSON path within manifest
}
// TODO: Remove the following section when the refactoring of templates is complete.
// Template describes a set of resources to be deployed.
// Manager expands a Template into a Configuration, which
// describes the set in a form that can be instantiated.
type Template struct {
Name string `json:"name"`
Content string `json:"content"`
Imports []*ImportFile `json:"imports"`
}
// ImportFile describes a base64 encoded file imported by a Template.
type ImportFile struct {
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"` // Actual URL for the file
Content string `json:"content"`
}
// SchemaImport represents an import as declared in a schema file.
type SchemaImport struct {
Path string `json:"path"`
Name string `json:"name"`
}
// Schema is a partial DM schema. We only need access to the imports object at this level.
type Schema struct {
Imports []SchemaImport `json:"imports"`
}
// LayoutResource defines the structure of resources in the manifest layout.
type LayoutResource struct {
Resource
......@@ -130,22 +100,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 {
......@@ -180,3 +134,21 @@ type Resource struct {
Properties map[string]interface{} `json:"properties,omitempty"`
State *ResourceState `json:"state,omitempty"`
}
// TODO: Remove the following section when the refactoring of templates is complete.
// Template describes a set of resources to be deployed.
// Manager expands a Template into a Configuration, which
// describes the set in a form that can be instantiated.
type Template struct {
Name string `json:"name"`
Content string `json:"content"`
Imports []*ImportFile `json:"imports"`
}
// ImportFile describes a base64 encoded file imported by a Template.
type ImportFile struct {
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"` // Actual URL for the file
Content string `json:"content"`
}
......@@ -14,37 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package expander
package expansion
import (
"github.com/kubernetes/helm/pkg/chart"
"github.com/kubernetes/helm/pkg/common"
)
// SchemaImport represents an import as declared in a schema file.
type SchemaImport struct {
Path string `json:"path"`
Name string `json:"name"`
}
// Schema is a partial DM schema. We only need access to the imports object at this level.
type Schema struct {
Imports []SchemaImport `json:"imports"`
}
// LayoutResource defines the structure of resources in the manifest layout.
type LayoutResource struct {
Resource
Layout
}
// Layout defines the structure of a layout as returned from expansion.
type Layout struct {
Resources []*LayoutResource `json:"resources,omitempty"`
}
// ExpansionRequest defines the API to expander.
type ExpansionRequest struct {
ChartInvocation *Resource `json:"chart_invocation"`
ChartInvocation *common.Resource `json:"chart_invocation"`
Chart *chart.Content `json:"chart"`
}
......@@ -57,38 +36,3 @@ type ExpansionResponse struct {
type Expander interface {
ExpandChart(request *ExpansionRequest) (*ExpansionResponse, error)
}
// Configuration describes a set of resources in a form
// that can be instantiated.
type Configuration struct {
Resources []*Resource `json:"resources"`
}
// ResourceStatus is an enumeration type for the status of a resource.
type ResourceStatus string
// These constants implement the resourceStatus enumeration type.
const (
Created ResourceStatus = "Created"
Failed ResourceStatus = "Failed"
Aborted ResourceStatus = "Aborted"
)
// ResourceState describes the state of a resource.
// Status is set during resource creation and is a terminal state.
type ResourceState struct {
Status ResourceStatus `json:"status,omitempty"`
SelfLink string `json:"selflink,omitempty"`
Errors []string `json:"errors,omitempty"`
}
// Resource describes a resource in a configuration. A resource has
// a name, a type and a set of properties. The name and type are used
// to identify the resource in Kubernetes. The properties are passed
// to Kubernetes as the resource configuration.
type Resource struct {
Name string `json:"name"`
Type string `json:"type"`
Properties map[string]interface{} `json:"properties,omitempty"`
State *ResourceState `json:"state,omitempty"`
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment