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
1660c27f
Commit
1660c27f
authored
Nov 30, 2015
by
Brendan Melville
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Type resolver now stores resolved imports in the manifest.
parent
d4bf89c5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
21 deletions
+19
-21
expander.go
manager/manager/expander.go
+10
-16
expander_test.go
manager/manager/expander_test.go
+1
-1
manager.go
manager/manager/manager.go
+2
-2
manager_test.go
manager/manager/manager_test.go
+2
-2
typeresolver.go
manager/manager/typeresolver.go
+4
-0
No files found.
manager/manager/expander.go
View file @
1660c27f
...
...
@@ -37,7 +37,7 @@ type ExpandedTemplate struct {
// Expander abstracts interactions with the expander and deployer services.
type
Expander
interface
{
ExpandTemplate
(
t
Template
)
(
*
ExpandedTemplate
,
error
)
ExpandTemplate
(
t
*
Template
)
(
*
ExpandedTemplate
,
error
)
}
// NewExpander returns a new initialized Expander.
...
...
@@ -110,7 +110,9 @@ func walkLayout(l *Layout, toReplace map[string]*LayoutResource) map[string]*Lay
}
// ExpandTemplate expands the supplied template, and returns a configuration.
func
(
e
*
expander
)
ExpandTemplate
(
t
Template
)
(
*
ExpandedTemplate
,
error
)
{
// It will also update the imports in the provided template if any were added
// during type resolution.
func
(
e
*
expander
)
ExpandTemplate
(
t
*
Template
)
(
*
ExpandedTemplate
,
error
)
{
// We have a fencepost problem here.
// 1. Start by trying to resolve any missing templates
// 2. Expand the configuration using all the of the imports available to us at this point
...
...
@@ -129,17 +131,17 @@ func (e *expander) ExpandTemplate(t Template) (*ExpandedTemplate, error) {
newImp
,
err
:=
e
.
typeResolver
.
ResolveTypes
(
config
,
t
.
Imports
)
if
err
!=
nil
{
e
:=
fmt
.
Errorf
(
"type resolution failed: %s"
,
err
)
return
nil
,
expanderError
(
&
t
,
e
)
return
nil
,
expanderError
(
t
,
e
)
}
t
.
Imports
=
append
(
t
.
Imports
,
newImp
...
)
for
{
// Now expand with everything imported.
result
,
err
:=
e
.
expandTemplate
(
&
t
)
result
,
err
:=
e
.
expandTemplate
(
t
)
if
err
!=
nil
{
e
:=
fmt
.
Errorf
(
"template expansion: %s"
,
err
)
return
nil
,
expanderError
(
&
t
,
e
)
return
nil
,
expanderError
(
t
,
e
)
}
// Once we set this layout, we're operating on the "needResolve" *LayoutResources,
...
...
@@ -151,10 +153,10 @@ func (e *expander) ExpandTemplate(t Template) (*ExpandedTemplate, error) {
}
needResolve
=
walkLayout
(
result
.
Layout
,
needResolve
)
newImp
,
err
=
e
.
typeResolver
.
ResolveTypes
(
result
.
Config
,
nil
)
newImp
,
err
=
e
.
typeResolver
.
ResolveTypes
(
result
.
Config
,
t
.
Imports
)
if
err
!=
nil
{
e
:=
fmt
.
Errorf
(
"type resolution failed: %s"
,
err
)
return
nil
,
expanderError
(
&
t
,
e
)
return
nil
,
expanderError
(
t
,
e
)
}
// If the new imports contain nothing, we are done. Everything is fully expanded.
...
...
@@ -163,16 +165,8 @@ func (e *expander) ExpandTemplate(t Template) (*ExpandedTemplate, error) {
return
result
,
nil
}
// Update imports with any new imports from type resolution.
t
.
Imports
=
append
(
t
.
Imports
,
newImp
...
)
var
content
[]
byte
content
,
err
=
yaml
.
Marshal
(
result
.
Config
)
t
.
Content
=
string
(
content
)
if
err
!=
nil
{
e
:=
fmt
.
Errorf
(
"Unable to unmarshal response from expander (%s): %s"
,
err
,
result
.
Config
)
return
nil
,
expanderError
(
&
t
,
e
)
}
}
}
...
...
manager/manager/expander_test.go
View file @
1660c27f
...
...
@@ -262,7 +262,7 @@ func TestExpandTemplate(t *testing.T) {
defer
ts
.
Close
()
expander
:=
NewExpander
(
ts
.
URL
,
etc
.
Resolver
)
actualResponse
,
err
:=
expander
.
ExpandTemplate
(
validTemplateTestCaseData
)
actualResponse
,
err
:=
expander
.
ExpandTemplate
(
&
validTemplateTestCaseData
)
if
err
!=
nil
{
message
:=
err
.
Error
()
if
etc
.
Error
==
""
{
...
...
manager/manager/manager.go
View file @
1660c27f
...
...
@@ -142,7 +142,7 @@ func (m *manager) CreateDeployment(t *Template) (*Deployment, error) {
}
func
(
m
*
manager
)
createManifest
(
t
*
Template
)
(
*
Manifest
,
error
)
{
et
,
err
:=
m
.
expander
.
ExpandTemplate
(
*
t
)
et
,
err
:=
m
.
expander
.
ExpandTemplate
(
t
)
if
err
!=
nil
{
log
.
Printf
(
"Expansion failed %v"
,
err
)
return
nil
,
err
...
...
@@ -263,7 +263,7 @@ func (m *manager) PutDeployment(name string, t *Template) (*Deployment, error) {
}
func
(
m
*
manager
)
Expand
(
t
*
Template
)
(
*
Manifest
,
error
)
{
et
,
err
:=
m
.
expander
.
ExpandTemplate
(
*
t
)
et
,
err
:=
m
.
expander
.
ExpandTemplate
(
t
)
if
err
!=
nil
{
log
.
Printf
(
"Expansion failed %v"
,
err
)
return
nil
,
err
...
...
manager/manager/manager_test.go
View file @
1660c27f
...
...
@@ -64,8 +64,8 @@ var errTest = errors.New("test")
type
expanderStub
struct
{}
func
(
expander
*
expanderStub
)
ExpandTemplate
(
t
Template
)
(
*
ExpandedTemplate
,
error
)
{
if
reflect
.
DeepEqual
(
t
,
template
)
{
func
(
expander
*
expanderStub
)
ExpandTemplate
(
t
*
Template
)
(
*
ExpandedTemplate
,
error
)
{
if
reflect
.
DeepEqual
(
*
t
,
template
)
{
return
&
expandedConfig
,
nil
}
...
...
manager/manager/typeresolver.go
View file @
1660c27f
...
...
@@ -90,7 +90,11 @@ func (tr *typeResolver) ResolveTypes(config *Configuration, imports []*ImportFil
// Only fetch HTTP URLs that we haven't already imported.
if
util
.
IsHttpUrl
(
r
.
Type
)
&&
!
existing
[
r
.
Type
]
{
toFetch
=
append
(
toFetch
,
r
.
Type
)
fetched
[
r
.
Type
]
=
append
(
fetched
[
r
.
Type
],
&
ImportFile
{
Name
:
r
.
Type
})
// Add to existing map so it is not fetched multiple times.
existing
[
r
.
Type
]
=
true
}
}
...
...
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