Commit 8fbb567c authored by Matt Butcher's avatar Matt Butcher

fix(cli): revert to older deploy formatting

Prior to merging the projects, the version of `helm deploy` used a
different REST API (one without YAML in JSON). Post-merge, we need to
revert back to the older common.Template version.

As part of this, I switched an io.ReadCloser back to an io.Reader
because there is nowhere where the Closer part is used. The http lib
does not close a reader passed to it.
parent 187f6e05
......@@ -102,7 +102,7 @@ func deploy(c *cli.Context) error {
}
}
return NewClient(c).PostDeployment(cfg)
return NewClient(c).PostDeployment(cfg.Resources[0].Name, cfg)
}
// isLocalChart returns true if the given path can be statted.
......
......@@ -17,6 +17,7 @@ limitations under the License.
package client
import (
"bytes"
"encoding/json"
"fmt"
"io"
......@@ -29,6 +30,7 @@ import (
"strings"
"time"
"github.com/ghodss/yaml"
"github.com/kubernetes/deployment-manager/pkg/common"
)
......@@ -108,7 +110,7 @@ func (c *Client) agent() string {
// CallService is a low-level function for making an API call.
//
// This calls the service and then unmarshals the returned data into dest.
func (c *Client) CallService(path, method, action string, dest interface{}, reader io.ReadCloser) error {
func (c *Client) CallService(path, method, action string, dest interface{}, reader io.Reader) error {
u, err := c.url(path)
if err != nil {
return err
......@@ -125,7 +127,7 @@ func (c *Client) CallService(path, method, action string, dest interface{}, read
}
// callHTTP is a low-level primitive for executing HTTP operations.
func (c *Client) callHTTP(path, method, action string, reader io.ReadCloser) (string, error) {
func (c *Client) callHTTP(path, method, action string, reader io.Reader) (string, error) {
request, err := http.NewRequest(method, path, reader)
// TODO: dynamically set version
......@@ -280,7 +282,25 @@ func (c *Client) DeleteDeployment(name string) (*common.Deployment, error) {
return deployment, nil
}
// PostDeployment posts a deployment objec to the manager service.
func (c *Client) PostDeployment(cfg *common.Configuration) error {
return c.CallService("/deployments", "POST", "post deployment", cfg, nil)
// PostDeployment posts a deployment object to the manager service.
func (c *Client) PostDeployment(name string, cfg *common.Configuration) error {
d, err := yaml.Marshal(cfg)
if err != nil {
return err
}
// This is a stop-gap until we get this API cleaned up.
t := common.Template{
Name: name,
Content: string(d),
}
data, err := json.Marshal(t)
if err != nil {
return err
}
var out interface{}
b := bytes.NewBuffer(data)
return c.CallService("/deployments", "POST", "post deployment", &out, b)
}
......@@ -169,7 +169,7 @@ func TestPostDeployment(t *testing.T) {
}
defer fc.teardown()
if err := fc.setup().PostDeployment(cfg); err != nil {
if err := fc.setup().PostDeployment("foo", cfg); err != nil {
t.Fatalf("failed to post deployment: %s", err)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment