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
7842d245
Commit
7842d245
authored
Apr 19, 2016
by
Michelle Noorali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(helm): reindex cache file
parent
f9c06b1d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
6 deletions
+94
-6
init.go
cmd/helm/init.go
+1
-1
package.go
cmd/helm/package.go
+2
-5
local.go
pkg/repo/local.go
+91
-0
No files found.
cmd/helm/init.go
View file @
7842d245
...
...
@@ -20,7 +20,7 @@ Kubernetes Cluster and sets up local configuration in $HELM_HOME (default: ~/.he
const
repositoriesPath
=
".repositories"
const
cachePath
=
"cache"
const
localPath
=
"local"
const
localCacheFilePath
=
localPath
+
"/cache.
txt
"
const
localCacheFilePath
=
localPath
+
"/cache.
yaml
"
var
defaultRepo
=
map
[
string
]
string
{
"default-name"
:
"default-url"
}
var
tillerImg
string
...
...
cmd/helm/package.go
View file @
7842d245
...
...
@@ -6,6 +6,7 @@ import (
"path/filepath"
"github.com/deis/tiller/pkg/chart"
"github.com/deis/tiller/pkg/repo"
"github.com/spf13/cobra"
)
...
...
@@ -55,11 +56,7 @@ func runPackage(cmd *cobra.Command, args []string) error {
// Save to $HELM_HOME/local directory.
if
save
{
dir
:=
LocalDirectory
(
os
.
ExpandEnv
(
helmHome
))
name
,
err
:=
chart
.
Save
(
ch
,
dir
)
if
err
==
nil
{
cmd
.
Printf
(
"Saved %s to $HELM_HOME/local/
\n
"
,
name
)
}
else
{
if
err
:=
repo
.
AddChartToLocalRepo
(
ch
,
LocalDirectory
(
os
.
ExpandEnv
(
helmHome
)));
err
!=
nil
{
return
err
}
}
...
...
pkg/repo/local
Repo
.go
→
pkg/repo/local.go
View file @
7842d245
...
...
@@ -2,13 +2,26 @@ package repo
import
(
"fmt"
"io/ioutil"
"net/http"
"path/filepath"
"strings"
"github.com/deis/tiller/pkg/chart"
"gopkg.in/yaml.v2"
)
var
localRepoPath
string
type
CacheFile
struct
{
Entries
map
[
string
]
*
ChartRef
}
type
ChartRef
struct
{
Name
string
`yaml:name`
Url
string
`yaml:url`
}
func
StartLocalRepo
(
path
string
)
{
fmt
.
Println
(
"Now serving you on localhost:8879..."
)
localRepoPath
=
path
...
...
@@ -35,3 +48,81 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
func
serveFile
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
file
string
)
{
http
.
ServeFile
(
w
,
r
,
filepath
.
Join
(
localRepoPath
,
file
))
}
func
AddChartToLocalRepo
(
ch
*
chart
.
Chart
,
path
string
)
error
{
name
,
err
:=
chart
.
Save
(
ch
,
path
)
if
err
!=
nil
{
return
err
}
err
=
ReindexCacheFile
(
ch
,
path
+
"/cache.yaml"
)
if
err
!=
nil
{
return
nil
}
fmt
.
Printf
(
"Saved %s to $HELM_HOME/local"
,
name
)
return
nil
}
func
ReindexCacheFile
(
ch
*
chart
.
Chart
,
path
string
)
error
{
name
:=
ch
.
Chartfile
()
.
Name
+
"-"
+
ch
.
Chartfile
()
.
Version
fmt
.
Println
(
"
\n
name: "
+
name
)
b
,
err
:=
ioutil
.
ReadFile
(
path
)
if
err
!=
nil
{
fmt
.
Println
(
"read file err"
)
fmt
.
Printf
(
"err, %s"
,
err
)
return
err
}
var
y
CacheFile
err
=
yaml
.
Unmarshal
(
b
,
&
y
)
if
err
!=
nil
{
fmt
.
Println
(
"error unmarshaling"
)
fmt
.
Println
(
"err, %s"
,
err
)
return
err
}
fmt
.
Println
(
"%v
\n
"
,
y
)
found
:=
false
for
k
,
v
:=
range
y
.
Entries
{
fmt
.
Printf
(
"in here: %v"
,
v
)
fmt
.
Printf
(
"in here: %v"
,
k
)
if
k
==
name
{
found
=
true
break
}
}
if
!
found
{
url
:=
"localhost:8879/charts/"
+
name
+
".tgz"
out
,
err
:=
y
.
InsertChartEntry
(
name
,
url
)
if
err
!=
nil
{
return
err
}
ioutil
.
WriteFile
(
path
,
out
,
0644
)
}
return
nil
}
func
(
c
*
CacheFile
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
var
refs
map
[
string
]
*
ChartRef
if
err
:=
unmarshal
(
&
refs
);
err
!=
nil
{
if
_
,
ok
:=
err
.
(
*
yaml
.
TypeError
);
!
ok
{
return
err
}
}
c
.
Entries
=
refs
return
nil
}
func
(
cache
*
CacheFile
)
InsertChartEntry
(
name
string
,
url
string
)
([]
byte
,
error
)
{
if
cache
.
Entries
==
nil
{
cache
.
Entries
=
make
(
map
[
string
]
*
ChartRef
)
}
entry
:=
ChartRef
{
Name
:
name
,
Url
:
url
}
cache
.
Entries
[
name
]
=
&
entry
out
,
err
:=
yaml
.
Marshal
(
&
cache
.
Entries
)
if
err
!=
nil
{
return
nil
,
err
}
return
out
,
nil
}
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