Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
c14b92bd
Commit
c14b92bd
authored
Mar 23, 2016
by
jackgr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move expansion types out of pkg/common
parent
e65b6bee
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
144 deletions
+61
-144
expander.go
cmd/expandybird/expander/expander.go
+4
-4
expander_test.go
cmd/expandybird/expander/expander_test.go
+31
-30
service.go
cmd/expandybird/service/service.go
+5
-5
types.go
pkg/common/types.go
+18
-46
types.go
pkg/expansion/types.go
+3
-59
No files found.
cmd/expandybird/expander/expander.go
View file @
c14b92bd
...
...
@@ -24,7 +24,7 @@ import (
"log"
"os/exec"
"github.com/kubernetes/helm/pkg/
comm
on"
"github.com/kubernetes/helm/pkg/
expansi
on"
)
type
expander
struct
{
...
...
@@ -32,7 +32,7 @@ type expander struct {
}
// NewExpander returns an ExpandyBird expander.
func
NewExpander
(
binary
string
)
comm
on
.
Expander
{
func
NewExpander
(
binary
string
)
expansi
on
.
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
)
(
*
comm
on
.
ExpansionResponse
,
error
)
{
func
(
e
*
expander
)
ExpandChart
(
request
*
expansion
.
ExpansionRequest
)
(
*
expansi
on
.
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
&
comm
on
.
ExpansionResponse
{
Resources
:
output
.
Config
.
Resources
},
nil
return
&
expansi
on
.
ExpansionResponse
{
Resources
:
output
.
Config
.
Resources
},
nil
}
cmd/expandybird/expander/expander_test.go
View file @
c14b92bd
...
...
@@ -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
*
comm
on
.
ExpansionRequest
ExpectedResponse
*
comm
on
.
ExpansionResponse
Request
*
expansi
on
.
ExpansionRequest
ExpectedResponse
*
expansi
on
.
ExpansionResponse
ExpectedError
string
}
...
...
@@ -47,8 +48,8 @@ func funcName() string {
return
runtime
.
FuncForPC
(
pc
)
.
Name
()
}
func
testExpansion
(
t
*
testing
.
T
,
req
*
comm
on
.
ExpansionRequest
,
expResponse
*
comm
on
.
ExpansionResponse
,
expError
string
)
{
func
testExpansion
(
t
*
testing
.
T
,
req
*
expansi
on
.
ExpansionRequest
,
expResponse
*
expansi
on
.
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
,
&
comm
on
.
ExpansionRequest
{
&
expansi
on
.
ExpansionRequest
{
ChartInvocation
:
&
common
.
Resource
{
Name
:
"test_invocation"
,
Type
:
funcName
(),
...
...
@@ -99,7 +100,7 @@ func TestEmptyJinja(t *testing.T) {
},
},
},
&
comm
on
.
ExpansionResponse
{
&
expansi
on
.
ExpansionResponse
{
Resources
:
[]
interface
{}{},
},
""
,
// Error
...
...
@@ -109,7 +110,7 @@ func TestEmptyJinja(t *testing.T) {
func
TestEmptyPython
(
t
*
testing
.
T
)
{
testExpansion
(
t
,
&
comm
on
.
ExpansionRequest
{
&
expansi
on
.
ExpansionRequest
{
ChartInvocation
:
&
common
.
Resource
{
Name
:
"test_invocation"
,
Type
:
funcName
(),
...
...
@@ -130,7 +131,7 @@ func TestEmptyPython(t *testing.T) {
},
},
},
&
comm
on
.
ExpansionResponse
{
&
expansi
on
.
ExpansionResponse
{
Resources
:
[]
interface
{}{},
},
""
,
// Error
...
...
@@ -140,7 +141,7 @@ func TestEmptyPython(t *testing.T) {
func
TestSimpleJinja
(
t
*
testing
.
T
)
{
testExpansion
(
t
,
&
comm
on
.
ExpansionRequest
{
&
expansi
on
.
ExpansionRequest
{
ChartInvocation
:
&
common
.
Resource
{
Name
:
"test_invocation"
,
Type
:
funcName
(),
...
...
@@ -162,7 +163,7 @@ func TestSimpleJinja(t *testing.T) {
},
},
},
&
comm
on
.
ExpansionResponse
{
&
expansi
on
.
ExpansionResponse
{
Resources
:
[]
interface
{}{
map
[
string
]
interface
{}{
"name"
:
"foo"
,
...
...
@@ -177,7 +178,7 @@ func TestSimpleJinja(t *testing.T) {
func
TestSimplePython
(
t
*
testing
.
T
)
{
testExpansion
(
t
,
&
comm
on
.
ExpansionRequest
{
&
expansi
on
.
ExpansionRequest
{
ChartInvocation
:
&
common
.
Resource
{
Name
:
"test_invocation"
,
Type
:
funcName
(),
...
...
@@ -201,7 +202,7 @@ func TestSimplePython(t *testing.T) {
},
},
},
&
comm
on
.
ExpansionResponse
{
&
expansi
on
.
ExpansionResponse
{
Resources
:
[]
interface
{}{
map
[
string
]
interface
{}{
"name"
:
"foo"
,
...
...
@@ -216,7 +217,7 @@ func TestSimplePython(t *testing.T) {
func
TestPropertiesJinja
(
t
*
testing
.
T
)
{
testExpansion
(
t
,
&
comm
on
.
ExpansionRequest
{
&
expansi
on
.
ExpansionRequest
{
ChartInvocation
:
&
common
.
Resource
{
Name
:
"test_invocation"
,
Type
:
funcName
(),
...
...
@@ -244,7 +245,7 @@ func TestPropertiesJinja(t *testing.T) {
},
},
},
&
comm
on
.
ExpansionResponse
{
&
expansi
on
.
ExpansionResponse
{
Resources
:
[]
interface
{}{
map
[
string
]
interface
{}{
"name"
:
"foo"
,
...
...
@@ -262,7 +263,7 @@ func TestPropertiesJinja(t *testing.T) {
func
TestPropertiesPython
(
t
*
testing
.
T
)
{
testExpansion
(
t
,
&
comm
on
.
ExpansionRequest
{
&
expansi
on
.
ExpansionRequest
{
ChartInvocation
:
&
common
.
Resource
{
Name
:
"test_invocation"
,
Type
:
funcName
(),
...
...
@@ -292,7 +293,7 @@ func TestPropertiesPython(t *testing.T) {
},
},
},
&
comm
on
.
ExpansionResponse
{
&
expansi
on
.
ExpansionResponse
{
Resources
:
[]
interface
{}{
map
[
string
]
interface
{}{
"name"
:
"foo"
,
...
...
@@ -310,7 +311,7 @@ func TestPropertiesPython(t *testing.T) {
func
TestMultiFileJinja
(
t
*
testing
.
T
)
{
testExpansion
(
t
,
&
comm
on
.
ExpansionRequest
{
&
expansi
on
.
ExpansionRequest
{
ChartInvocation
:
&
common
.
Resource
{
Name
:
"test_invocation"
,
Type
:
funcName
(),
...
...
@@ -336,7 +337,7 @@ func TestMultiFileJinja(t *testing.T) {
},
},
},
&
comm
on
.
ExpansionResponse
{
&
expansi
on
.
ExpansionResponse
{
Resources
:
[]
interface
{}{
map
[
string
]
interface
{}{
"name"
:
"foo"
,
...
...
@@ -368,7 +369,7 @@ var schemaContent = content([]string{
func
TestSchema
(
t
*
testing
.
T
)
{
testExpansion
(
t
,
&
comm
on
.
ExpansionRequest
{
&
expansi
on
.
ExpansionRequest
{
ChartInvocation
:
&
common
.
Resource
{
Name
:
"test_invocation"
,
Type
:
funcName
(),
...
...
@@ -401,7 +402,7 @@ func TestSchema(t *testing.T) {
},
},
},
&
comm
on
.
ExpansionResponse
{
&
expansi
on
.
ExpansionResponse
{
Resources
:
[]
interface
{}{
map
[
string
]
interface
{}{
"name"
:
"foo"
,
...
...
@@ -419,7 +420,7 @@ func TestSchema(t *testing.T) {
func
TestSchemaFail
(
t
*
testing
.
T
)
{
testExpansion
(
t
,
&
comm
on
.
ExpansionRequest
{
&
expansi
on
.
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
,
&
comm
on
.
ExpansionRequest
{
&
expansi
on
.
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
,
&
comm
on
.
ExpansionRequest
{
&
expansi
on
.
ExpansionRequest
{
ChartInvocation
:
&
common
.
Resource
{
Name
:
"test_invocation"
,
Type
:
funcName
(),
...
...
@@ -531,7 +532,7 @@ func TestMultiFilePython(t *testing.T) {
},
},
},
&
comm
on
.
ExpansionResponse
{
&
expansi
on
.
ExpansionResponse
{
Resources
:
[]
interface
{}{
map
[
string
]
interface
{}{
"name"
:
"foo"
,
...
...
@@ -546,7 +547,7 @@ func TestMultiFilePython(t *testing.T) {
func
TestMultiFilePythonMissing
(
t
*
testing
.
T
)
{
testExpansion
(
t
,
&
comm
on
.
ExpansionRequest
{
&
expansi
on
.
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
,
&
comm
on
.
ExpansionRequest
{
&
expansi
on
.
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
,
&
comm
on
.
ExpansionRequest
{
&
expansi
on
.
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
,
&
comm
on
.
ExpansionRequest
{
&
expansi
on
.
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
,
&
comm
on
.
ExpansionRequest
{
&
expansi
on
.
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
,
&
comm
on
.
ExpansionRequest
{
&
expansi
on
.
ExpansionRequest
{
ChartInvocation
:
&
common
.
Resource
{
Name
:
"test_invocation"
,
Type
:
funcName
(),
...
...
cmd/expandybird/service/service.go
View file @
c14b92bd
...
...
@@ -17,7 +17,7 @@ limitations under the License.
package
service
import
(
"github.com/kubernetes/helm/pkg/
comm
on"
"github.com/kubernetes/helm/pkg/
expansi
on"
"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
(
&
comm
on
.
ExpansionRequest
{})
.
Writes
(
&
comm
on
.
ExpansionResponse
{}))
Reads
(
&
expansi
on
.
ExpansionRequest
{})
.
Writes
(
&
expansi
on
.
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
comm
on
.
Expander
)
restful
.
RouteFunction
{
func
NewExpansionHandler
(
backend
expansi
on
.
Expander
)
restful
.
RouteFunction
{
return
func
(
req
*
restful
.
Request
,
resp
*
restful
.
Response
)
{
util
.
LogHandlerEntry
(
"expandybird: expand"
,
req
.
Request
)
request
:=
&
comm
on
.
ExpansionRequest
{}
request
:=
&
expansi
on
.
ExpansionRequest
{}
if
err
:=
req
.
ReadEntity
(
&
request
);
err
!=
nil
{
logAndReturnErrorFromHandler
(
http
.
StatusBadRequest
,
err
.
Error
(),
resp
)
return
...
...
pkg/common/types.go
View file @
c14b92bd
...
...
@@ -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"`
}
pkg/expan
der
/types.go
→
pkg/expan
sion
/types.go
View file @
c14b92bd
...
...
@@ -14,37 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package
expan
der
package
expan
sion
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"`
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment