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
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
100 additions
and
22 deletions
+100
-22
helm.go
cmd/helm/helm.go
+13
-0
init.go
cmd/helm/init.go
+5
-4
repo.go
cmd/helm/repo.go
+48
-16
repo_test.go
cmd/helm/repo_test.go
+34
-2
No files found.
cmd/helm/helm.go
View file @
45932547
package
main
package
main
import
(
import
(
"fmt"
"os"
"os"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
)
)
...
@@ -44,3 +46,14 @@ func init() {
...
@@ -44,3 +46,14 @@ func init() {
func
main
()
{
func
main
()
{
RootCommand
.
Execute
()
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
...
@@ -3,7 +3,6 @@ package main
import
(
import
(
"errors"
"errors"
"fmt"
"fmt"
"io/ioutil"
"os"
"os"
"github.com/kubernetes/helm/pkg/client"
"github.com/kubernetes/helm/pkg/client"
...
@@ -16,8 +15,7 @@ Kubernetes Cluster and sets up local configuration in $HELM_HOME (default: ~/.he
...
@@ -16,8 +15,7 @@ Kubernetes Cluster and sets up local configuration in $HELM_HOME (default: ~/.he
`
`
var
(
var
(
tillerImg
string
tillerImg
string
defaultRepo
=
map
[
string
]
string
{
"default-name"
:
"default-url"
}
)
)
func
init
()
{
func
init
()
{
...
@@ -83,7 +81,10 @@ func ensureHome() error {
...
@@ -83,7 +81,10 @@ func ensureHome() error {
repoFile
:=
repositoriesFile
()
repoFile
:=
repositoriesFile
()
if
fi
,
err
:=
os
.
Stat
(
repoFile
);
err
!=
nil
{
if
fi
,
err
:=
os
.
Stat
(
repoFile
);
err
!=
nil
{
fmt
.
Printf
(
"Creating %s
\n
"
,
repoFile
)
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
return
err
}
}
}
else
if
fi
.
IsDir
()
{
}
else
if
fi
.
IsDir
()
{
...
...
cmd/helm/repo.go
View file @
45932547
...
@@ -2,7 +2,7 @@ package main
...
@@ -2,7 +2,7 @@ package main
import
(
import
(
"fmt"
"fmt"
"
os
"
"
io/ioutil
"
"github.com/gosuri/uitable"
"github.com/gosuri/uitable"
"github.com/kubernetes/helm/pkg/repo"
"github.com/kubernetes/helm/pkg/repo"
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
func
init
()
{
func
init
()
{
repoCmd
.
AddCommand
(
repoAddCmd
)
repoCmd
.
AddCommand
(
repoAddCmd
)
repoCmd
.
AddCommand
(
repoListCmd
)
repoCmd
.
AddCommand
(
repoListCmd
)
repoCmd
.
AddCommand
(
repoRemoveCmd
)
RootCommand
.
AddCommand
(
repoCmd
)
RootCommand
.
AddCommand
(
repoCmd
)
}
}
...
@@ -33,9 +34,15 @@ var repoListCmd = &cobra.Command{
...
@@ -33,9 +34,15 @@ var repoListCmd = &cobra.Command{
RunE
:
runRepoList
,
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
{
func
runRepoAdd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
if
len
(
args
)
!=
2
{
if
err
:=
checkArgsLength
(
2
,
len
(
args
),
"name for the chart repository"
,
"the url of the chart repository"
);
err
!=
nil
{
return
fmt
.
Errorf
(
"This command needs two argument, a name for the chart repository and the url of the chart repository"
)
return
err
}
}
err
:=
insertRepoLine
(
args
[
0
],
args
[
1
])
err
:=
insertRepoLine
(
args
[
0
],
args
[
1
])
...
@@ -65,35 +72,60 @@ func runRepoList(cmd *cobra.Command, args []string) error {
...
@@ -65,35 +72,60 @@ func runRepoList(cmd *cobra.Command, args []string) error {
return
nil
return
nil
}
}
func
insertRepoLine
(
name
,
url
string
)
error
{
func
runRepoRemove
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
err
:=
checkUniqueName
(
name
)
if
err
:=
checkArgsLength
(
1
,
len
(
args
),
"name of chart repository"
);
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
removeRepoLine
(
args
[
0
]);
err
!=
nil
{
b
,
_
:=
yaml
.
Marshal
(
map
[
string
]
string
{
name
:
url
})
f
,
err
:=
os
.
OpenFile
(
repositoriesFile
(),
os
.
O_APPEND
|
os
.
O_WRONLY
,
0666
)
if
err
!=
nil
{
return
err
return
err
}
}
defer
f
.
Close
()
return
nil
_
,
err
=
f
.
Write
(
b
)
}
func
removeRepoLine
(
name
string
)
error
{
r
,
err
:=
repo
.
LoadRepositoriesFile
(
repositoriesFile
())
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
_
,
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
return
nil
}
}
func
checkUniqueName
(
name
string
)
error
{
func
insertRepoLine
(
name
,
url
string
)
error
{
f
ile
,
err
:=
repo
.
LoadRepositoriesFile
(
repositoriesFile
())
f
,
err
:=
repo
.
LoadRepositoriesFile
(
repositoriesFile
())
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
_
,
ok
:=
f
.
Repositories
[
name
]
_
,
ok
:=
file
.
Repositories
[
name
]
if
ok
{
if
ok
{
return
fmt
.
Errorf
(
"The repository name you provided (%s) already exists. Please specifiy a different name."
,
name
)
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
return
nil
}
}
cmd/helm/repo_test.go
View file @
45932547
...
@@ -6,6 +6,11 @@ import (
...
@@ -6,6 +6,11 @@ import (
"github.com/kubernetes/helm/pkg/repo"
"github.com/kubernetes/helm/pkg/repo"
)
)
var
(
testName
=
"test-name"
testURL
=
"test-url"
)
func
TestRepoAdd
(
t
*
testing
.
T
)
{
func
TestRepoAdd
(
t
*
testing
.
T
)
{
home
:=
createTmpHome
()
home
:=
createTmpHome
()
helmHome
=
home
helmHome
=
home
...
@@ -13,8 +18,6 @@ func TestRepoAdd(t *testing.T) {
...
@@ -13,8 +18,6 @@ func TestRepoAdd(t *testing.T) {
t
.
Errorf
(
"%s"
,
err
)
t
.
Errorf
(
"%s"
,
err
)
}
}
testName
:=
"test-name"
testURL
:=
"test-url"
if
err
:=
insertRepoLine
(
testName
,
testURL
);
err
!=
nil
{
if
err
:=
insertRepoLine
(
testName
,
testURL
);
err
!=
nil
{
t
.
Errorf
(
"%s"
,
err
)
t
.
Errorf
(
"%s"
,
err
)
}
}
...
@@ -33,3 +36,32 @@ func TestRepoAdd(t *testing.T) {
...
@@ -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