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
d0dd3021
Commit
d0dd3021
authored
May 06, 2016
by
vaikas-google
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #655 from vaikas-google/master
Add ability to untar charts after downloading them
parents
9a0c4a69
92039222
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
21 deletions
+90
-21
fetch.go
cmd/helm/fetch.go
+7
-16
chart.go
pkg/chart/chart.go
+39
-1
chart_test.go
pkg/chart/chart_test.go
+44
-4
No files found.
cmd/helm/fetch.go
View file @
d0dd3021
...
...
@@ -13,8 +13,13 @@ import (
"github.com/spf13/cobra"
)
var
untarFile
bool
var
untarDir
string
func
init
()
{
RootCommand
.
AddCommand
(
fetchCmd
)
fetchCmd
.
Flags
()
.
BoolVar
(
&
untarFile
,
"untar"
,
false
,
"If set to true, will untar the chart after downloading it."
)
fetchCmd
.
Flags
()
.
StringVar
(
&
untarDir
,
"untardir"
,
"."
,
"If untar is specified, this flag specifies where to untar the chart."
)
}
var
fetchCmd
=
&
cobra
.
Command
{
...
...
@@ -49,10 +54,8 @@ func fetch(cmd *cobra.Command, args []string) error {
}
defer
resp
.
Body
.
Close
()
// TODO(vaikas): Implement untar / flag
untar
:=
false
if
untar
{
return
untarChart
(
resp
.
Body
)
if
untarFile
{
return
chart
.
Expand
(
untarDir
,
resp
.
Body
)
}
p
:=
strings
.
Split
(
u
.
String
(),
"/"
)
return
saveChartFile
(
p
[
len
(
p
)
-
1
],
resp
.
Body
)
...
...
@@ -84,18 +87,6 @@ func mapRepoArg(arg string, r map[string]string) (*url.URL, error) {
return
nil
,
fmt
.
Errorf
(
"Invalid chart url format: %s"
,
arg
)
}
func
untarChart
(
r
io
.
Reader
)
error
{
c
,
err
:=
chart
.
LoadDataFromReader
(
r
)
if
err
!=
nil
{
return
err
}
if
c
==
nil
{
return
fmt
.
Errorf
(
"Failed to untar the chart"
)
}
return
fmt
.
Errorf
(
"Not implemented yee"
)
}
func
saveChartFile
(
c
string
,
r
io
.
Reader
)
error
{
// Grab the chart name that we'll use for the name of the file to download to.
out
,
err
:=
os
.
Create
(
c
)
...
...
pkg/chart/chart.go
View file @
d0dd3021
...
...
@@ -88,7 +88,7 @@ func (c *Chart) TemplatesDir() string {
return
filepath
.
Join
(
c
.
loader
.
dir
(),
preTemplates
)
}
// ChartsDir returns t
eh
directory where dependency charts are stored.
// ChartsDir returns t
he
directory where dependency charts are stored.
func
(
c
*
Chart
)
ChartsDir
()
string
{
return
filepath
.
Join
(
c
.
loader
.
dir
(),
preCharts
)
}
...
...
@@ -214,6 +214,44 @@ func Create(chartfile *Chartfile, dir string) (*Chart, error) {
},
nil
}
// Expand uncompresses and extracts a chart into the specified directory.
func
Expand
(
dir
string
,
r
io
.
Reader
)
error
{
gr
,
err
:=
gzip
.
NewReader
(
r
)
if
err
!=
nil
{
return
err
}
defer
gr
.
Close
()
tr
:=
tar
.
NewReader
(
gr
)
for
{
header
,
err
:=
tr
.
Next
()
if
err
==
io
.
EOF
{
break
}
else
if
err
!=
nil
{
return
err
}
path
:=
filepath
.
Clean
(
filepath
.
Join
(
dir
,
header
.
Name
))
info
:=
header
.
FileInfo
()
if
info
.
IsDir
()
{
if
err
=
os
.
MkdirAll
(
path
,
info
.
Mode
());
err
!=
nil
{
return
err
}
continue
}
file
,
err
:=
os
.
OpenFile
(
path
,
os
.
O_CREATE
|
os
.
O_TRUNC
|
os
.
O_WRONLY
,
info
.
Mode
())
if
err
!=
nil
{
return
err
}
defer
file
.
Close
()
_
,
err
=
io
.
Copy
(
file
,
tr
)
if
err
!=
nil
{
return
err
}
}
return
nil
}
// fname prepares names for the filesystem
func
fname
(
name
string
)
string
{
// Right now, we don't do anything. Do we need to encode any particular
...
...
pkg/chart/chart_test.go
View file @
d0dd3021
...
...
@@ -26,10 +26,11 @@ import (
)
const
(
testfile
=
"testdata/frobnitz/Chart.yaml"
testdir
=
"testdata/frobnitz/"
testarchive
=
"testdata/frobnitz-0.0.1.tgz"
testmember
=
"templates/template.tpl"
testfile
=
"testdata/frobnitz/Chart.yaml"
testdir
=
"testdata/frobnitz/"
testarchive
=
"testdata/frobnitz-0.0.1.tgz"
testmember
=
"templates/template.tpl"
expectedTemplate
=
"Hello {{.Name | default
\"
world
\"
}}
\n
"
)
// Type canaries. If these fail, they will fail at compile time.
...
...
@@ -270,3 +271,42 @@ func compareContent(filename string, content []byte) error {
return
nil
}
func
TestExpand
(
t
*
testing
.
T
)
{
r
,
err
:=
os
.
Open
(
testarchive
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to read testarchive file: %s"
,
err
)
return
}
td
,
err
:=
ioutil
.
TempDir
(
""
,
"helm-unittest-chart-"
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to create tempdir: %s"
,
err
)
return
}
err
=
Expand
(
td
,
r
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to expand testarchive file: %s"
,
err
)
}
fi
,
err
:=
os
.
Lstat
(
td
+
"/frobnitz/Chart.yaml"
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to stat Chart.yaml from expanded archive: %s"
,
err
)
}
if
fi
.
Name
()
!=
"Chart.yaml"
{
t
.
Errorf
(
"Didn't get the right file name from stat, expected Chart.yaml, got: %s"
,
fi
.
Name
())
}
tr
,
err
:=
os
.
Open
(
td
+
"/frobnitz/templates/template.tpl"
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to open template.tpl from expanded archive: %s"
,
err
)
}
c
,
err
:=
ioutil
.
ReadAll
(
tr
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to read contents of template.tpl from expanded archive: %s"
,
err
)
}
if
string
(
c
)
!=
expectedTemplate
{
t
.
Errorf
(
"Contents of the expanded template differ, wanted '%s' got '%s'"
,
expectedTemplate
,
c
)
}
}
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