kubepack/swift

can not create pvc

Closed this issue ยท 5 comments

@tamalsaha
hi
I'll create pvc with wheel 1.0

this is my helm charts
https://github.com/orangesys/charts/tree/master/influxdb
can create pvc with helm

cd influxdb
helm install --name my-release --set retentionPolicy=40d,persistence.size=50Gi .

can not create pvc with wheel

http POST http://127.0.0.1:9855/tiller/v2/releases/rel222-i/json < influxdb.json

influxdb.json

{
        "chart_url": "https://github.com/orangesys/charts/raw/master/docs/influxdb-0.1.13.tgz",
        "values": {
                "raw": "{\"retentionPolicy\":\"40d\",\"persistence.size\":\"50Gi\"}"
        }
}

I made the following change to make it work:

{
        "chart_url": "https://github.com/orangesys/charts/raw/master/docs/influxdb-0.1.13.tgz",
        "values": {
                "raw": "{ \"retentionPolicy\": \"40d\", \"persistence\": { \"size\": \"50Gi\" } }"
        }
}

The command line values your are passing to helm cli can be described as below in YAML:

retentionPolicy:40d
persistence:
  size: 50Gi

When converted to JSON this becomes:

{
  "retentionPolicy": "40d",
  "persistence": {
    "size": "50Gi"
  }
}

You were using \"persistence.size\" . This results in invalid json.

Let me know if you are still having trouble.

working it, thank you !

@tamalsaha

package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

type CreateInfluxDB struct {
	ChartURL string `json:"chart_url"`
	Values   Values `json:"values"`
}

type Values struct {
	Values Raw `json:"raw"`
}

type Raw struct {
	Persistence     Persistence `json:"persistence"`
	RetentionPolicy string      `json:"retentionPolicy"`
}

type Persistence struct {
	Size string `json:"size"`
}

func main() {
	p := Persistence{Size: "50Gi"}
	r := Raw{Persistence: p, RetentionPolicy: "40d"}
	v := Values{Values: r}
	c := CreateInfluxDB{ChartURL: "https://github.com/orangesys/charts/raw/master/docs/influxdb-0.1.13.tgz", Values: v}
	data, err := json.Marshal(c)
	if err != nil {
		fmt.Println("json err:", err)
	}
	fmt.Println(string(data))
	resp, err := http.Post("http://127.0.0.1:9855/tiller/v2/releases/re2222-i/json", "application/json", bytes.NewBuffer(data))
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Println(string(body))

}

can not post json to wheel 1.0
Give me some help

go run main.go                                                               
{"chart_url":"https://github.com/orangesys/charts/raw/master/docs/influxdb-0.1.13.tgz","values":{"raw":{"persistence":{"size":"50Gi"},"retentionPolicy":"40d"}}}
{"code":3,"message":"json: cannot unmarshal object into Go value of type string"}%

can send post json body with
http://httpbin.org/post
it working

@gavinzhou I modified the code like below and it is working now. The main change is that

type Values struct {
	Values string `json:"raw"`
}

Working sample:

package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"github.com/appscode/go/log"
	"github.com/tamalsaha/go-oneliners"
)

type CreateInfluxDB struct {
	ChartURL string `json:"chart_url"`
	Values   Values `json:"values"`
}

type Values struct {
	Values string `json:"raw"`
}

type Raw struct {
	Persistence     Persistence `json:"persistence"`
	RetentionPolicy string      `json:"retentionPolicy"`
}

type Persistence struct {
	Size string `json:"size"`
}

func main() {
	p := Persistence{Size: "50Gi"}
	r := Raw{Persistence: p, RetentionPolicy: "40d"}
	rb, _ := json.Marshal(r)
	v := Values{Values: string(rb)}
	c := CreateInfluxDB{ChartURL: "https://github.com/orangesys/charts/raw/master/docs/influxdb-0.1.13.tgz", Values: v}
	data, err := json.Marshal(c)
	if err != nil {
		fmt.Println("json err:", err)
	}
	fmt.Println(string(data))

	req, err := http.NewRequest("POST", "http://127.0.0.1:9855/tiller/v2/releases/re2222-i/json", bytes.NewBuffer(data))
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("Content-Type", "application/json")
	oneliners.DumpHttpRequest(req)

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Println(string(body))
}

Btw, have you considered using Tiller's GRPC client directly if you are writing GO code?

Thank you for your advice.
swift(wheel) is very easy create k8s.
my apigateway -> wheel -> tiller in my prduction

there are very complex, but easy to implement.
thank you!