From 9f268f553c746f9e8523380b50a4dc836a543275 Mon Sep 17 00:00:00 2001 From: Tomas Virgl Date: Sun, 28 Apr 2019 00:09:10 +0200 Subject: [PATCH] fix: add cluster to channel context --- cmd/wk/cmd/edit.go | 4 ++-- pkg/kops/apply.go | 14 +++++++------- pkg/kops/channel.go | 4 ++-- pkg/kops/update.go | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cmd/wk/cmd/edit.go b/cmd/wk/cmd/edit.go index 8cd88c3..a122208 100644 --- a/cmd/wk/cmd/edit.go +++ b/cmd/wk/cmd/edit.go @@ -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) } @@ -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) } diff --git a/pkg/kops/apply.go b/pkg/kops/apply.go index 1e3f32f..8249eae 100644 --- a/pkg/kops/apply.go +++ b/pkg/kops/apply.go @@ -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) } @@ -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) } @@ -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{} @@ -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) } @@ -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) } @@ -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 } diff --git a/pkg/kops/channel.go b/pkg/kops/channel.go index ae6e34a..3f3c78f 100644 --- a/pkg/kops/channel.go +++ b/pkg/kops/channel.go @@ -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 { @@ -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 diff --git a/pkg/kops/update.go b/pkg/kops/update.go index fa11d73..2ba7144 100644 --- a/pkg/kops/update.go +++ b/pkg/kops/update.go @@ -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) } @@ -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) }