Commit 2c351c06 authored by Jack Greenfield's avatar Jack Greenfield

Merge pull request #498 from jackgr/deployment

More tweaks to enable end-to-end deployment
parents 91b1b0b3 b20a7c53
name: replicatedservice name: replicatedservice
description: Port of the replicatedservice template from kubernetes/charts description: Port of the replicatedservice template from kubernetes/charts
version: 3 version: "3"
home: ""
expander: expander:
name: Expandybird name: Expandybird
entrypoint: templates/replicatedservice.py entrypoint: templates/replicatedservice.py
schema: templates/replicatedservice.py.schema
...@@ -20,7 +20,6 @@ import ( ...@@ -20,7 +20,6 @@ import (
"archive/tar" "archive/tar"
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"encoding/base64"
"errors" "errors"
"fmt" "fmt"
"io" "io"
...@@ -412,16 +411,16 @@ func (c *Chart) loadMember(filename string) (*Member, error) { ...@@ -412,16 +411,16 @@ func (c *Chart) loadMember(filename string) (*Member, error) {
return nil, err return nil, err
} }
b, err := ioutil.ReadFile(filename) content, err := ioutil.ReadFile(filename)
if err != nil { if err != nil {
return nil, err return nil, err
} }
path := strings.TrimPrefix(filename, dir) path := strings.TrimPrefix(filename, dir)
content := base64.StdEncoding.EncodeToString(b) path = strings.TrimLeft(path, "/")
result := &Member{ result := &Member{
Path: path, Path: path,
Content: []byte(content), Content: content,
} }
return result, nil return result, nil
......
...@@ -17,13 +17,14 @@ limitations under the License. ...@@ -17,13 +17,14 @@ limitations under the License.
package chart package chart
import ( import (
"encoding/base64"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"path/filepath" "path/filepath"
"reflect"
"testing" "testing"
"github.com/kubernetes/helm/pkg/log" "github.com/kubernetes/helm/pkg/log"
"github.com/kubernetes/helm/pkg/util"
) )
const ( const (
...@@ -202,7 +203,7 @@ func findMember(root, path string, members []*Member) error { ...@@ -202,7 +203,7 @@ func findMember(root, path string, members []*Member) error {
for _, member := range members { for _, member := range members {
if member.Path == path { if member.Path == path {
filename := filepath.Join(root, path) filename := filepath.Join(root, path)
if err := compareContent(filename, string(member.Content)); err != nil { if err := compareContent(filename, member.Content); err != nil {
return err return err
} }
...@@ -233,20 +234,52 @@ func TestLoadMember(t *testing.T) { ...@@ -233,20 +234,52 @@ func TestLoadMember(t *testing.T) {
} }
filename := filepath.Join(c.loader.dir(), testmember) filename := filepath.Join(c.loader.dir(), testmember)
if err := compareContent(filename, string(member.Content)); err != nil { if err := compareContent(filename, member.Content); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
func compareContent(filename, content string) error { func TestLoadContent(t *testing.T) {
b, err := ioutil.ReadFile(filename) c, err := LoadDir(testdir)
if err != nil {
t.Errorf("Failed to load chart: %s", err)
}
content, err := c.LoadContent()
if err != nil {
t.Errorf("Failed to load chart content: %s", err)
}
want := c.Chartfile()
have := content.Chartfile
if !reflect.DeepEqual(want, have) {
t.Errorf("Unexpected chart file\nwant:\n%s\nhave:\n%s\n",
util.ToYAMLOrError(want), util.ToYAMLOrError(have))
}
for _, member := range content.Members {
have := member.Content
wantMember, err := c.LoadMember(member.Path)
if err != nil {
t.Errorf("Failed to load chart member: %s", err)
}
t.Logf("%s:\n%s\n\n", member.Path, member.Content)
want := wantMember.Content
if !reflect.DeepEqual(want, have) {
t.Errorf("Unexpected chart member %s\nwant:\n%v\nhave:\n%v\n", member.Path, want, have)
}
}
}
func compareContent(filename string, content []byte) error {
compare, err := ioutil.ReadFile(filename)
if err != nil { if err != nil {
return fmt.Errorf("Cannot read test file %s: %s", filename, err) return fmt.Errorf("Cannot read test file %s: %s", filename, err)
} }
compare := base64.StdEncoding.EncodeToString(b) if !reflect.DeepEqual(compare, content) {
if content != compare { return fmt.Errorf("Expected member content\n%v\ngot\n%v", compare, content)
return fmt.Errorf("Expected member content\n%v\ngot\n%v", []byte(compare), []byte(content))
} }
return nil return nil
......
...@@ -49,14 +49,18 @@ func NewService(address string, port int, backend Expander) *Service { ...@@ -49,14 +49,18 @@ func NewService(address string, port int, backend Expander) *Service {
badRequest(resp, err.Error()) badRequest(resp, err.Error())
return return
} }
reqMsg := fmt.Sprintf("\nhandling request:\n%s\n", util.ToYAMLOrError(request))
util.LogHandlerText("expansion service", reqMsg)
response, err := backend.ExpandChart(request) response, err := backend.ExpandChart(request)
if err != nil { if err != nil {
badRequest(resp, fmt.Sprintf("error expanding chart: %s", err)) badRequest(resp, fmt.Sprintf("error expanding chart: %s", err))
return return
} }
util.LogHandlerExit("expansion service", http.StatusOK, "OK", resp.ResponseWriter) util.LogHandlerExit("expansion service", http.StatusOK, "OK", resp.ResponseWriter)
message := fmt.Sprintf("\nResources:\n%s\n", response.Resources) respMsg := fmt.Sprintf("\nreturning response:\n%s\n", util.ToYAMLOrError(response.Resources))
util.LogHandlerText("expansion service", message) util.LogHandlerText("expansion service", respMsg)
resp.WriteEntity(response) resp.WriteEntity(response)
} }
webService.Route( webService.Route(
......
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