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
1e741afb
Commit
1e741afb
authored
Feb 08, 2016
by
Adam Reese
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(get): add get verb
parent
57008336
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
31 deletions
+92
-31
get.go
cmd/helm/get.go
+33
-0
helm.go
cmd/helm/helm.go
+1
-0
list.go
cmd/helm/list.go
+4
-10
client.go
dm/client.go
+32
-21
client_test.go
dm/client_test.go
+22
-0
No files found.
cmd/helm/get.go
0 → 100644
View file @
1e741afb
package
main
import
(
"errors"
"github.com/codegangsta/cli"
"github.com/deis/helm-dm/dm"
"github.com/deis/helm-dm/format"
)
func
getCmd
()
cli
.
Command
{
return
cli
.
Command
{
Name
:
"get"
,
Usage
:
"Retrieves the supplied deployment"
,
Action
:
func
(
c
*
cli
.
Context
)
{
run
(
c
,
get
)
},
}
}
func
get
(
c
*
cli
.
Context
)
error
{
args
:=
c
.
Args
()
if
len
(
args
)
<
1
{
return
errors
.
New
(
"First argument, deployment name, is required. Try 'helm get --help'"
)
}
name
:=
args
[
0
]
host
:=
c
.
GlobalString
(
"host"
)
client
:=
dm
.
NewClient
(
host
)
.
SetDebug
(
c
.
GlobalBool
(
"debug"
))
deployment
,
err
:=
client
.
GetDeployment
(
name
)
if
err
!=
nil
{
return
err
}
return
format
.
YAML
(
deployment
)
}
cmd/helm/helm.go
View file @
1e741afb
...
...
@@ -181,6 +181,7 @@ func commands() []cli.Command {
Name
:
"search"
,
},
listCmd
(),
getCmd
(),
}
}
...
...
cmd/helm/list.go
View file @
1e741afb
package
main
import
(
"os"
"github.com/codegangsta/cli"
"github.com/deis/helm-dm/dm"
"github.com/deis/helm-dm/format"
...
...
@@ -12,17 +10,13 @@ func listCmd() cli.Command {
return
cli
.
Command
{
Name
:
"list"
,
Usage
:
"Lists the deployments in the cluster"
,
Action
:
func
(
c
*
cli
.
Context
)
{
if
err
:=
list
(
c
.
GlobalString
(
"host"
));
err
!=
nil
{
format
.
Err
(
"%s (Is the cluster running?)"
,
err
)
os
.
Exit
(
1
)
}
},
Action
:
func
(
c
*
cli
.
Context
)
{
run
(
c
,
list
)
},
}
}
func
list
(
host
string
)
error
{
client
:=
dm
.
NewClient
(
host
)
.
SetDebug
(
isDebugging
)
func
list
(
c
*
cli
.
Context
)
error
{
host
:=
c
.
GlobalString
(
"host"
)
client
:=
dm
.
NewClient
(
host
)
.
SetDebug
(
c
.
GlobalBool
(
"debug"
))
list
,
err
:=
client
.
ListDeployments
()
if
err
!=
nil
{
return
err
...
...
dm/client.go
View file @
1e741afb
...
...
@@ -11,6 +11,8 @@ import (
"path/filepath"
"strings"
"time"
"github.com/kubernetes/deployment-manager/common"
)
// The default HTTP timeout
...
...
@@ -125,10 +127,34 @@ func (c *Client) callHTTP(path, method, action string, reader io.ReadCloser) (st
return
string
(
body
),
nil
}
// DefaultServerURL converts a host, host:port, or URL string to the default base server API path
// to use with a Client
func
DefaultServerURL
(
host
string
)
(
*
url
.
URL
,
error
)
{
if
host
==
""
{
return
nil
,
fmt
.
Errorf
(
"host must be a URL or a host:port pair"
)
}
base
:=
host
hostURL
,
err
:=
url
.
Parse
(
base
)
if
err
!=
nil
{
return
nil
,
err
}
if
hostURL
.
Scheme
==
""
{
hostURL
,
err
=
url
.
Parse
(
DefaultHTTPProtocol
+
"://"
+
base
)
if
err
!=
nil
{
return
nil
,
err
}
}
if
len
(
hostURL
.
Path
)
>
0
&&
!
strings
.
HasSuffix
(
hostURL
.
Path
,
"/"
)
{
hostURL
.
Path
=
hostURL
.
Path
+
"/"
}
return
hostURL
,
nil
}
// ListDeployments lists the deployments in DM.
func
(
c
*
Client
)
ListDeployments
()
([]
string
,
error
)
{
var
l
[]
string
if
err
:=
c
.
CallService
(
"deployments"
,
"GET"
,
"
foo
"
,
&
l
,
nil
);
err
!=
nil
{
if
err
:=
c
.
CallService
(
"deployments"
,
"GET"
,
"
list deployments
"
,
&
l
,
nil
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -181,26 +207,11 @@ func (c *Client) DeployChart(filename, deployname string) error {
return
nil
}
// DefaultServerURL converts a host, host:port, or URL string to the default base server API path
// to use with a Client
func
DefaultServerURL
(
host
string
)
(
*
url
.
URL
,
error
)
{
if
host
==
""
{
return
nil
,
fmt
.
Errorf
(
"host must be a URL or a host:port pair"
)
}
base
:=
host
hostURL
,
err
:=
url
.
Parse
(
base
)
if
err
!=
nil
{
// GetDeployment retrieves the supplied deployment
func
(
c
*
Client
)
GetDeployment
(
name
string
)
(
*
common
.
Deployment
,
error
)
{
var
deployment
*
common
.
Deployment
if
err
:=
c
.
CallService
(
filepath
.
Join
(
"deployments"
,
name
),
"GET"
,
"get deployment"
,
&
deployment
,
nil
);
err
!=
nil
{
return
nil
,
err
}
if
hostURL
.
Scheme
==
""
{
hostURL
,
err
=
url
.
Parse
(
DefaultHTTPProtocol
+
"://"
+
base
)
if
err
!=
nil
{
return
nil
,
err
}
}
if
len
(
hostURL
.
Path
)
>
0
&&
!
strings
.
HasSuffix
(
hostURL
.
Path
,
"/"
)
{
hostURL
.
Path
=
hostURL
.
Path
+
"/"
}
return
hostURL
,
nil
return
deployment
,
nil
}
dm/client_test.go
View file @
1e741afb
...
...
@@ -4,6 +4,8 @@ import (
"net/http"
"net/http/httptest"
"testing"
"github.com/kubernetes/deployment-manager/common"
)
func
TestDefaultServerURL
(
t
*
testing
.
T
)
{
...
...
@@ -96,3 +98,23 @@ func TestListDeployments(t *testing.T) {
t
.
Fatal
(
"expected a single deployment"
)
}
}
func
TestGetDeployment
(
t
*
testing
.
T
)
{
fc
:=
&
fakeClient
{
response
:
[]
byte
(
`{"name":"guestbook.yaml","id":0,"createdAt":"2016-02-08T12:17:49.251658308-08:00","deployedAt":"2016-02-08T12:17:49.251658589-08:00","modifiedAt":"2016-02-08T12:17:51.177518098-08:00","deletedAt":"0001-01-01T00:00:00Z","state":{"status":"Deployed"},"latestManifest":"manifest-1454962670728402229"}`
),
}
defer
fc
.
teardown
()
d
,
err
:=
fc
.
setup
()
.
GetDeployment
(
"guestbook.yaml"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
d
.
Name
!=
"guestbook.yaml"
{
t
.
Fatalf
(
"expected deployment name 'guestbook.yaml', got '%s'"
,
d
.
Name
)
}
if
d
.
State
.
Status
!=
common
.
DeployedStatus
{
t
.
Fatalf
(
"expected deployment status 'Deployed', got '%s'"
,
d
.
State
.
Status
)
}
}
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