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
45932547
Commit
45932547
authored
May 03, 2016
by
Michelle Noorali
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #631 from michelleN/helm-repo
feat(helm): add helm repo remove cmd
parents
2c71fb9f
6dd87645
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
19 deletions
+97
-19
helm.go
cmd/helm/helm.go
+13
-0
init.go
cmd/helm/init.go
+4
-3
repo.go
cmd/helm/repo.go
+46
-14
repo_test.go
cmd/helm/repo_test.go
+34
-2
No files found.
cmd/helm/helm.go
View file @
45932547
package
main
import
(
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
)
...
...
@@ -44,3 +46,14 @@ func init() {
func
main
()
{
RootCommand
.
Execute
()
}
func
checkArgsLength
(
expectedNum
,
actualNum
int
,
requiredArgs
...
string
)
error
{
if
actualNum
!=
expectedNum
{
arg
:=
"arguments"
if
expectedNum
==
1
{
arg
=
"argument"
}
return
fmt
.
Errorf
(
"This command needs %v %s: %s"
,
expectedNum
,
arg
,
strings
.
Join
(
requiredArgs
,
", "
))
}
return
nil
}
cmd/helm/init.go
View file @
45932547
...
...
@@ -3,7 +3,6 @@ package main
import
(
"errors"
"fmt"
"io/ioutil"
"os"
"github.com/kubernetes/helm/pkg/client"
...
...
@@ -17,7 +16,6 @@ Kubernetes Cluster and sets up local configuration in $HELM_HOME (default: ~/.he
var
(
tillerImg
string
defaultRepo
=
map
[
string
]
string
{
"default-name"
:
"default-url"
}
)
func
init
()
{
...
...
@@ -83,7 +81,10 @@ func ensureHome() error {
repoFile
:=
repositoriesFile
()
if
fi
,
err
:=
os
.
Stat
(
repoFile
);
err
!=
nil
{
fmt
.
Printf
(
"Creating %s
\n
"
,
repoFile
)
if
err
:=
ioutil
.
WriteFile
(
repoFile
,
[]
byte
(
"local: localhost:8879/charts
\n
"
),
0644
);
err
!=
nil
{
if
_
,
err
:=
os
.
Create
(
repoFile
);
err
!=
nil
{
return
err
}
if
err
:=
insertRepoLine
(
"local"
,
"localhost:8879/charts"
);
err
!=
nil
{
return
err
}
}
else
if
fi
.
IsDir
()
{
...
...
cmd/helm/repo.go
View file @
45932547
...
...
@@ -2,7 +2,7 @@ package main
import
(
"fmt"
"
os
"
"
io/ioutil
"
"github.com/gosuri/uitable"
"github.com/kubernetes/helm/pkg/repo"
...
...
@@ -13,6 +13,7 @@ import (
func
init
()
{
repoCmd
.
AddCommand
(
repoAddCmd
)
repoCmd
.
AddCommand
(
repoListCmd
)
repoCmd
.
AddCommand
(
repoRemoveCmd
)
RootCommand
.
AddCommand
(
repoCmd
)
}
...
...
@@ -33,9 +34,15 @@ var repoListCmd = &cobra.Command{
RunE
:
runRepoList
,
}
var
repoRemoveCmd
=
&
cobra
.
Command
{
Use
:
"remove [flags] [NAME]"
,
Short
:
"remove a chart repository"
,
RunE
:
runRepoRemove
,
}
func
runRepoAdd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
if
len
(
args
)
!=
2
{
return
fmt
.
Errorf
(
"This command needs two argument, a name for the chart repository and the url of the chart repository"
)
if
err
:=
checkArgsLength
(
2
,
len
(
args
),
"name for the chart repository"
,
"the url of the chart repository"
);
err
!=
nil
{
return
err
}
err
:=
insertRepoLine
(
args
[
0
],
args
[
1
])
...
...
@@ -65,35 +72,60 @@ func runRepoList(cmd *cobra.Command, args []string) error {
return
nil
}
func
insertRepoLine
(
name
,
url
string
)
error
{
err
:=
checkUniqueName
(
name
)
if
err
!=
nil
{
func
runRepoRemove
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
if
err
:=
checkArgsLength
(
1
,
len
(
args
),
"name of chart repository"
);
err
!=
nil
{
return
err
}
if
err
:=
removeRepoLine
(
args
[
0
]);
err
!=
nil
{
return
err
}
return
nil
}
b
,
_
:=
yaml
.
Marshal
(
map
[
string
]
string
{
name
:
url
})
f
,
err
:=
os
.
OpenFile
(
repositoriesFile
(),
os
.
O_APPEND
|
os
.
O_WRONLY
,
0666
)
func
removeRepoLine
(
name
string
)
error
{
r
,
err
:=
repo
.
LoadRepositoriesFile
(
repositoriesFile
()
)
if
err
!=
nil
{
return
err
}
defer
f
.
Close
()
_
,
err
=
f
.
Write
(
b
)
_
,
ok
:=
r
.
Repositories
[
name
]
if
ok
{
delete
(
r
.
Repositories
,
name
)
b
,
err
:=
yaml
.
Marshal
(
&
r
.
Repositories
)
if
err
!=
nil
{
return
err
}
if
err
:=
ioutil
.
WriteFile
(
repositoriesFile
(),
b
,
0666
);
err
!=
nil
{
return
err
}
}
else
{
return
fmt
.
Errorf
(
"The repository, %s, does not exist in your repositories list"
,
name
)
}
return
nil
}
func
checkUniqueName
(
name
string
)
error
{
f
ile
,
err
:=
repo
.
LoadRepositoriesFile
(
repositoriesFile
())
func
insertRepoLine
(
name
,
url
string
)
error
{
f
,
err
:=
repo
.
LoadRepositoriesFile
(
repositoriesFile
())
if
err
!=
nil
{
return
err
}
_
,
ok
:=
file
.
Repositories
[
name
]
_
,
ok
:=
f
.
Repositories
[
name
]
if
ok
{
return
fmt
.
Errorf
(
"The repository name you provided (%s) already exists. Please specifiy a different name."
,
name
)
}
if
f
.
Repositories
==
nil
{
f
.
Repositories
=
make
(
map
[
string
]
string
)
}
f
.
Repositories
[
name
]
=
url
b
,
_
:=
yaml
.
Marshal
(
&
f
.
Repositories
)
if
err
:=
ioutil
.
WriteFile
(
repositoriesFile
(),
b
,
0666
);
err
!=
nil
{
return
err
}
return
nil
}
cmd/helm/repo_test.go
View file @
45932547
...
...
@@ -6,6 +6,11 @@ import (
"github.com/kubernetes/helm/pkg/repo"
)
var
(
testName
=
"test-name"
testURL
=
"test-url"
)
func
TestRepoAdd
(
t
*
testing
.
T
)
{
home
:=
createTmpHome
()
helmHome
=
home
...
...
@@ -13,8 +18,6 @@ func TestRepoAdd(t *testing.T) {
t
.
Errorf
(
"%s"
,
err
)
}
testName
:=
"test-name"
testURL
:=
"test-url"
if
err
:=
insertRepoLine
(
testName
,
testURL
);
err
!=
nil
{
t
.
Errorf
(
"%s"
,
err
)
}
...
...
@@ -33,3 +36,32 @@ func TestRepoAdd(t *testing.T) {
}
}
func
TestRepoRemove
(
t
*
testing
.
T
)
{
home
:=
createTmpHome
()
helmHome
=
home
if
err
:=
ensureHome
();
err
!=
nil
{
t
.
Errorf
(
"%s"
,
err
)
}
if
err
:=
removeRepoLine
(
testName
);
err
==
nil
{
t
.
Errorf
(
"Expected error removing %s, but did not get one."
,
testName
)
}
if
err
:=
insertRepoLine
(
testName
,
testURL
);
err
!=
nil
{
t
.
Errorf
(
"%s"
,
err
)
}
if
err
:=
removeRepoLine
(
testName
);
err
!=
nil
{
t
.
Errorf
(
"Error removing %s from repositories"
,
testName
)
}
f
,
err
:=
repo
.
LoadRepositoriesFile
(
repositoriesFile
())
if
err
!=
nil
{
t
.
Errorf
(
"%s"
,
err
)
}
if
_
,
ok
:=
f
.
Repositories
[
testName
];
ok
{
t
.
Errorf
(
"%s was not successfully removed from repositories list"
,
testName
)
}
}
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