Skip to content

Commit

Permalink
fix: add cluster to channel context
Browse files Browse the repository at this point in the history
  • Loading branch information
tvirgl-wish authored and tvi committed Apr 28, 2019
1 parent 62c7f7d commit 9f268f5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions cmd/wk/cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var editCmd = &cobra.Command{
}
defer os.Remove(tmpfile) // clean up

out2, err := kops.Edit(context.Background(), args[0], tmpfile, "")
out2, _, err := kops.Edit(context.Background(), args[0], tmpfile, "")
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -66,7 +66,7 @@ var editIGCmd = &cobra.Command{
}
defer os.Remove(tmpfile) // clean up

out2, err := kops.Edit(context.Background(), args[0], "", tmpfile)
out2, _, err := kops.Edit(context.Background(), args[0], "", tmpfile)
if err != nil {
panic(err)
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/kops/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
`

func Apply(ctx context.Context, file string) (err error) {
out, err := Edit(ctx, file, "", "")
out, raw, err := Edit(ctx, file, "", "")
if err != nil {
return fmt.Errorf("could not render jsonnet: %v", err)
}
Expand All @@ -35,7 +35,7 @@ func Apply(ctx context.Context, file string) (err error) {
}

for _, c := range out.Kops.Channels {
err := generateChannel(ctx, c, file)
err := generateChannel(ctx, c, raw, file)
if err != nil {
return fmt.Errorf("could not generate channel: %v", err)
}
Expand Down Expand Up @@ -108,7 +108,7 @@ const extCode = `kops={
},
}`

func Edit(ctx context.Context, file, clusterFile, igFile string) (*Cluster, error) {
func Edit(ctx context.Context, file, clusterFile, igFile string) (*Cluster, []byte, error) {
clusterData := ""

args := []string{}
Expand All @@ -117,7 +117,7 @@ func Edit(ctx context.Context, file, clusterFile, igFile string) (*Cluster, erro
} else {
b, err := ioutil.ReadFile(clusterFile)
if err != nil {
return nil, err
return nil, nil, err
}
clusterData = string(b)
}
Expand All @@ -128,7 +128,7 @@ func Edit(ctx context.Context, file, clusterFile, igFile string) (*Cluster, erro
} else {
b, err := ioutil.ReadFile(igFile)
if err != nil {
return nil, err
return nil, nil, err
}
igData = string(b)
}
Expand All @@ -141,11 +141,11 @@ func Edit(ctx context.Context, file, clusterFile, igFile string) (*Cluster, erro
c.Stderr = os.Stderr
err := c.Run()
if err != nil {
return nil, err
return nil, nil, err
}

// out2 := make(map[string]interface{})
out2 := &Cluster{}
json.Unmarshal(out.Bytes(), out2)
return out2, nil
return out2, out.Bytes(), nil
}
4 changes: 2 additions & 2 deletions pkg/kops/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"k8s.io/kops/util/pkg/vfs"
)

func generateChannel(ctx context.Context, c Channel, file string) error {
func generateChannel(ctx context.Context, c Channel, rawCluster []byte, file string) error {
bb := bytes.NewBufferString("std.flattenArrays([\n")
for _, a := range c.Apps {
switch a.Type {
Expand All @@ -29,7 +29,7 @@ func generateChannel(ctx context.Context, c Channel, file string) error {
}
fmt.Fprintf(bb, "])\n")

cmd := exec.CommandContext(ctx, "jsonnet", "-y", "--ext-code", "cluster={data:1}", "-")
cmd := exec.CommandContext(ctx, "jsonnet", "-y", "--ext-code", "cluster="+string(rawCluster), "-")
hashB := bytes.NewBufferString("")
cmd.Stdin = bb
cmd.Stdout = hashB
Expand Down
4 changes: 2 additions & 2 deletions pkg/kops/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func Update(ctx context.Context, file string) (err error) {
out, err := Edit(ctx, file, "", "")
out, _, err := Edit(ctx, file, "", "")
if err != nil {
return fmt.Errorf("could not render jsonnet: %v", err)
}
Expand All @@ -33,7 +33,7 @@ func Update(ctx context.Context, file string) (err error) {
}

func Delete(ctx context.Context, file string) (err error) {
out, err := Edit(ctx, file, "", "")
out, _, err := Edit(ctx, file, "", "")
if err != nil {
return fmt.Errorf("could not render jsonnet: %v", err)
}
Expand Down

0 comments on commit 9f268f5

Please sign in to comment.