Move expansion types out of pkg/common

pull/446/head
jackgr 9 years ago
parent e65b6beed3
commit c14b92bd29

@ -24,7 +24,7 @@ import (
"log" "log"
"os/exec" "os/exec"
"github.com/kubernetes/helm/pkg/common" "github.com/kubernetes/helm/pkg/expansion"
) )
type expander struct { type expander struct {
@ -32,7 +32,7 @@ type expander struct {
} }
// NewExpander returns an ExpandyBird expander. // NewExpander returns an ExpandyBird expander.
func NewExpander(binary string) common.Expander { func NewExpander(binary string) expansion.Expander {
return &expander{binary} return &expander{binary}
} }
@ -47,7 +47,7 @@ type expandyBirdOutput struct {
// ExpandChart passes the given configuration to the expander and returns the // ExpandChart passes the given configuration to the expander and returns the
// expanded configuration as a string on success. // 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 { if request.ChartInvocation == nil {
return nil, fmt.Errorf("Request does not have invocation field") 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 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/chart"
"github.com/kubernetes/helm/pkg/common" "github.com/kubernetes/helm/pkg/common"
"github.com/kubernetes/helm/pkg/expansion"
) )
var expanderName = "../../../expansion/expansion.py" var expanderName = "../../../expansion/expansion.py"
type testCase struct { type testCase struct {
Description string Description string
Request *common.ExpansionRequest Request *expansion.ExpansionRequest
ExpectedResponse *common.ExpansionResponse ExpectedResponse *expansion.ExpansionResponse
ExpectedError string ExpectedError string
} }
@ -47,8 +48,8 @@ func funcName() string {
return runtime.FuncForPC(pc).Name() return runtime.FuncForPC(pc).Name()
} }
func testExpansion(t *testing.T, req *common.ExpansionRequest, func testExpansion(t *testing.T, req *expansion.ExpansionRequest,
expResponse *common.ExpansionResponse, expError string) { expResponse *expansion.ExpansionResponse, expError string) {
backend := NewExpander(expanderName) backend := NewExpander(expanderName)
response, err := backend.ExpandChart(req) response, err := backend.ExpandChart(req)
if err != nil { if err != nil {
@ -81,7 +82,7 @@ var jinjaExpander = &chart.Expander{
func TestEmptyJinja(t *testing.T) { func TestEmptyJinja(t *testing.T) {
testExpansion( testExpansion(
t, t,
&common.ExpansionRequest{ &expansion.ExpansionRequest{
ChartInvocation: &common.Resource{ ChartInvocation: &common.Resource{
Name: "test_invocation", Name: "test_invocation",
Type: funcName(), Type: funcName(),
@ -99,7 +100,7 @@ func TestEmptyJinja(t *testing.T) {
}, },
}, },
}, },
&common.ExpansionResponse{ &expansion.ExpansionResponse{
Resources: []interface{}{}, Resources: []interface{}{},
}, },
"", // Error "", // Error
@ -109,7 +110,7 @@ func TestEmptyJinja(t *testing.T) {
func TestEmptyPython(t *testing.T) { func TestEmptyPython(t *testing.T) {
testExpansion( testExpansion(
t, t,
&common.ExpansionRequest{ &expansion.ExpansionRequest{
ChartInvocation: &common.Resource{ ChartInvocation: &common.Resource{
Name: "test_invocation", Name: "test_invocation",
Type: funcName(), Type: funcName(),
@ -130,7 +131,7 @@ func TestEmptyPython(t *testing.T) {
}, },
}, },
}, },
&common.ExpansionResponse{ &expansion.ExpansionResponse{
Resources: []interface{}{}, Resources: []interface{}{},
}, },
"", // Error "", // Error
@ -140,7 +141,7 @@ func TestEmptyPython(t *testing.T) {
func TestSimpleJinja(t *testing.T) { func TestSimpleJinja(t *testing.T) {
testExpansion( testExpansion(
t, t,
&common.ExpansionRequest{ &expansion.ExpansionRequest{
ChartInvocation: &common.Resource{ ChartInvocation: &common.Resource{
Name: "test_invocation", Name: "test_invocation",
Type: funcName(), Type: funcName(),
@ -162,7 +163,7 @@ func TestSimpleJinja(t *testing.T) {
}, },
}, },
}, },
&common.ExpansionResponse{ &expansion.ExpansionResponse{
Resources: []interface{}{ Resources: []interface{}{
map[string]interface{}{ map[string]interface{}{
"name": "foo", "name": "foo",
@ -177,7 +178,7 @@ func TestSimpleJinja(t *testing.T) {
func TestSimplePython(t *testing.T) { func TestSimplePython(t *testing.T) {
testExpansion( testExpansion(
t, t,
&common.ExpansionRequest{ &expansion.ExpansionRequest{
ChartInvocation: &common.Resource{ ChartInvocation: &common.Resource{
Name: "test_invocation", Name: "test_invocation",
Type: funcName(), Type: funcName(),
@ -201,7 +202,7 @@ func TestSimplePython(t *testing.T) {
}, },
}, },
}, },
&common.ExpansionResponse{ &expansion.ExpansionResponse{
Resources: []interface{}{ Resources: []interface{}{
map[string]interface{}{ map[string]interface{}{
"name": "foo", "name": "foo",
@ -216,7 +217,7 @@ func TestSimplePython(t *testing.T) {
func TestPropertiesJinja(t *testing.T) { func TestPropertiesJinja(t *testing.T) {
testExpansion( testExpansion(
t, t,
&common.ExpansionRequest{ &expansion.ExpansionRequest{
ChartInvocation: &common.Resource{ ChartInvocation: &common.Resource{
Name: "test_invocation", Name: "test_invocation",
Type: funcName(), Type: funcName(),
@ -244,7 +245,7 @@ func TestPropertiesJinja(t *testing.T) {
}, },
}, },
}, },
&common.ExpansionResponse{ &expansion.ExpansionResponse{
Resources: []interface{}{ Resources: []interface{}{
map[string]interface{}{ map[string]interface{}{
"name": "foo", "name": "foo",
@ -262,7 +263,7 @@ func TestPropertiesJinja(t *testing.T) {
func TestPropertiesPython(t *testing.T) { func TestPropertiesPython(t *testing.T) {
testExpansion( testExpansion(
t, t,
&common.ExpansionRequest{ &expansion.ExpansionRequest{
ChartInvocation: &common.Resource{ ChartInvocation: &common.Resource{
Name: "test_invocation", Name: "test_invocation",
Type: funcName(), Type: funcName(),
@ -292,7 +293,7 @@ func TestPropertiesPython(t *testing.T) {
}, },
}, },
}, },
&common.ExpansionResponse{ &expansion.ExpansionResponse{
Resources: []interface{}{ Resources: []interface{}{
map[string]interface{}{ map[string]interface{}{
"name": "foo", "name": "foo",
@ -310,7 +311,7 @@ func TestPropertiesPython(t *testing.T) {
func TestMultiFileJinja(t *testing.T) { func TestMultiFileJinja(t *testing.T) {
testExpansion( testExpansion(
t, t,
&common.ExpansionRequest{ &expansion.ExpansionRequest{
ChartInvocation: &common.Resource{ ChartInvocation: &common.Resource{
Name: "test_invocation", Name: "test_invocation",
Type: funcName(), Type: funcName(),
@ -336,7 +337,7 @@ func TestMultiFileJinja(t *testing.T) {
}, },
}, },
}, },
&common.ExpansionResponse{ &expansion.ExpansionResponse{
Resources: []interface{}{ Resources: []interface{}{
map[string]interface{}{ map[string]interface{}{
"name": "foo", "name": "foo",
@ -368,7 +369,7 @@ var schemaContent = content([]string{
func TestSchema(t *testing.T) { func TestSchema(t *testing.T) {
testExpansion( testExpansion(
t, t,
&common.ExpansionRequest{ &expansion.ExpansionRequest{
ChartInvocation: &common.Resource{ ChartInvocation: &common.Resource{
Name: "test_invocation", Name: "test_invocation",
Type: funcName(), Type: funcName(),
@ -401,7 +402,7 @@ func TestSchema(t *testing.T) {
}, },
}, },
}, },
&common.ExpansionResponse{ &expansion.ExpansionResponse{
Resources: []interface{}{ Resources: []interface{}{
map[string]interface{}{ map[string]interface{}{
"name": "foo", "name": "foo",
@ -419,7 +420,7 @@ func TestSchema(t *testing.T) {
func TestSchemaFail(t *testing.T) { func TestSchemaFail(t *testing.T) {
testExpansion( testExpansion(
t, t,
&common.ExpansionRequest{ &expansion.ExpansionRequest{
ChartInvocation: &common.Resource{ ChartInvocation: &common.Resource{
Name: "test_invocation", Name: "test_invocation",
Type: funcName(), Type: funcName(),
@ -460,7 +461,7 @@ func TestSchemaFail(t *testing.T) {
func TestMultiFileJinjaMissing(t *testing.T) { func TestMultiFileJinjaMissing(t *testing.T) {
testExpansion( testExpansion(
t, t,
&common.ExpansionRequest{ &expansion.ExpansionRequest{
ChartInvocation: &common.Resource{ ChartInvocation: &common.Resource{
Name: "test_invocation", Name: "test_invocation",
Type: funcName(), Type: funcName(),
@ -486,7 +487,7 @@ func TestMultiFileJinjaMissing(t *testing.T) {
func TestMultiFilePython(t *testing.T) { func TestMultiFilePython(t *testing.T) {
testExpansion( testExpansion(
t, t,
&common.ExpansionRequest{ &expansion.ExpansionRequest{
ChartInvocation: &common.Resource{ ChartInvocation: &common.Resource{
Name: "test_invocation", Name: "test_invocation",
Type: funcName(), Type: funcName(),
@ -531,7 +532,7 @@ func TestMultiFilePython(t *testing.T) {
}, },
}, },
}, },
&common.ExpansionResponse{ &expansion.ExpansionResponse{
Resources: []interface{}{ Resources: []interface{}{
map[string]interface{}{ map[string]interface{}{
"name": "foo", "name": "foo",
@ -546,7 +547,7 @@ func TestMultiFilePython(t *testing.T) {
func TestMultiFilePythonMissing(t *testing.T) { func TestMultiFilePythonMissing(t *testing.T) {
testExpansion( testExpansion(
t, t,
&common.ExpansionRequest{ &expansion.ExpansionRequest{
ChartInvocation: &common.Resource{ ChartInvocation: &common.Resource{
Name: "test_invocation", Name: "test_invocation",
Type: funcName(), Type: funcName(),
@ -574,7 +575,7 @@ func TestMultiFilePythonMissing(t *testing.T) {
func TestWrongChartName(t *testing.T) { func TestWrongChartName(t *testing.T) {
testExpansion( testExpansion(
t, t,
&common.ExpansionRequest{ &expansion.ExpansionRequest{
ChartInvocation: &common.Resource{ ChartInvocation: &common.Resource{
Name: "test_invocation", Name: "test_invocation",
Type: funcName(), Type: funcName(),
@ -600,7 +601,7 @@ func TestWrongChartName(t *testing.T) {
func TestEntrypointNotFound(t *testing.T) { func TestEntrypointNotFound(t *testing.T) {
testExpansion( testExpansion(
t, t,
&common.ExpansionRequest{ &expansion.ExpansionRequest{
ChartInvocation: &common.Resource{ ChartInvocation: &common.Resource{
Name: "test_invocation", Name: "test_invocation",
Type: funcName(), Type: funcName(),
@ -621,7 +622,7 @@ func TestEntrypointNotFound(t *testing.T) {
func TestMalformedResource(t *testing.T) { func TestMalformedResource(t *testing.T) {
testExpansion( testExpansion(
t, t,
&common.ExpansionRequest{ &expansion.ExpansionRequest{
ChartInvocation: &common.Resource{ ChartInvocation: &common.Resource{
Name: "test_invocation", Name: "test_invocation",
Type: funcName(), Type: funcName(),
@ -650,7 +651,7 @@ func TestMalformedResource(t *testing.T) {
func TestResourceNoName(t *testing.T) { func TestResourceNoName(t *testing.T) {
testExpansion( testExpansion(
t, t,
&common.ExpansionRequest{ &expansion.ExpansionRequest{
ChartInvocation: &common.Resource{ ChartInvocation: &common.Resource{
Name: "test_invocation", Name: "test_invocation",
Type: funcName(), Type: funcName(),
@ -679,7 +680,7 @@ func TestResourceNoName(t *testing.T) {
func TestResourceNoType(t *testing.T) { func TestResourceNoType(t *testing.T) {
testExpansion( testExpansion(
t, t,
&common.ExpansionRequest{ &expansion.ExpansionRequest{
ChartInvocation: &common.Resource{ ChartInvocation: &common.Resource{
Name: "test_invocation", Name: "test_invocation",
Type: funcName(), Type: funcName(),

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

@ -17,7 +17,6 @@ limitations under the License.
package common package common
import ( import (
"github.com/kubernetes/helm/pkg/chart"
"time" "time"
) )
@ -90,35 +89,6 @@ type ChartInstance struct {
Path string `json:"path"` // JSON path within manifest 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. // LayoutResource defines the structure of resources in the manifest layout.
type LayoutResource struct { type LayoutResource struct {
Resource Resource
@ -130,22 +100,6 @@ type Layout struct {
Resources []*LayoutResource `json:"resources,omitempty"` 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 // Configuration describes a set of resources in a form
// that can be instantiated. // that can be instantiated.
type Configuration struct { type Configuration struct {
@ -180,3 +134,21 @@ type Resource struct {
Properties map[string]interface{} `json:"properties,omitempty"` Properties map[string]interface{} `json:"properties,omitempty"`
State *ResourceState `json:"state,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"`
}

@ -1,94 +0,0 @@
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package expander
import (
"github.com/kubernetes/helm/pkg/chart"
)
// 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"`
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 {
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"`
}

@ -0,0 +1,38 @@
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package expansion
import (
"github.com/kubernetes/helm/pkg/chart"
"github.com/kubernetes/helm/pkg/common"
)
// ExpansionRequest defines the API to expander.
type ExpansionRequest struct {
ChartInvocation *common.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)
}
Loading…
Cancel
Save