added extnet_id parameter to k8s; added read-only parameter lb_ip to k8s

2.1
kjubybot 3 years ago
parent 94f222fe19
commit 92d96b13c6

@ -605,11 +605,27 @@ type K8sRecord struct {
Masters K8sNodeRecord `json:"masters"`
Workers []K8sNodeRecord `json:"workers"`
} `json:"k8sGroups"`
LbID int `json:"lbId"`
Name string `json:"name"`
RgID int `json:"rgId"`
RgName string `json:"rgName"`
}
//LbRecord represents load balancer instance
type LbRecord struct {
ID int `json:"id"`
Name string `json:"name"`
RgID int `json:"rgId"`
VinsID int `json:"vinsId"`
ExtNetID int `json:"extnetId"`
PrimaryNode struct {
BackendIP string `json:"backendIp"`
ComputeID int `json:"computeId"`
FrontendIP string `json:"frontendIp"`
NetworkID int `json:"networkId"`
} `json:"primaryNode"`
}
const K8sCreateAPI = "/restmachine/cloudapi/k8s/create"
const K8sGetAPI = "/restmachine/cloudapi/k8s/get"
const K8sUpdateAPI = "/restmachine/cloudapi/k8s/update"
@ -623,6 +639,8 @@ const K8sWorkerDeleteAPI = "/restmachine/cloudapi/k8s/deleteWorkerFromGroup"
const K8sGetConfigAPI = "/restmachine/cloudapi/k8s/getConfig"
const LbGetAPI = "/restmachine/cloudapi/lb/get"
//Blasphemous workaround for parsing Result value
type TaskResult int

@ -73,10 +73,11 @@ func resourceK8sCreate(d *schema.ResourceData, m interface{}) error {
//}
urlValues.Add("withLB", strconv.FormatBool(true))
//if extNet, ok := d.GetOk("extnet_id"); ok {
//urlValues.Add("extnetId", strconv.Itoa(extNet.(int)))
//}
urlValues.Add("extnetId", strconv.Itoa(0))
if extNet, ok := d.GetOk("extnet_id"); ok {
urlValues.Add("extnetId", strconv.Itoa(extNet.(int)))
} else {
urlValues.Add("extnetId", "0")
}
//if desc, ok := d.GetOk("desc"); ok {
//urlValues.Add("desc", desc.(string))
@ -121,6 +122,21 @@ func resourceK8sCreate(d *schema.ResourceData, m interface{}) error {
d.Set("default_wg_id", k8s.Groups.Workers[0].ID)
urlValues = &url.Values{}
urlValues.Add("lbId", strconv.Itoa(k8s.LbID))
resp, err = controller.decortAPICall("POST", LbGetAPI, urlValues)
if err != nil {
return err
}
var lb LbRecord
if err := json.Unmarshal([]byte(resp), &lb); err != nil {
return err
}
d.Set("extnet_id", lb.ExtNetID)
d.Set("lb_ip", lb.PrimaryNode.FrontendIP)
urlValues = &url.Values{}
urlValues.Add("k8sId", d.Id())
kubeconfig, err := controller.decortAPICall("POST", K8sGetConfigAPI, urlValues)
@ -151,6 +167,21 @@ func resourceK8sRead(d *schema.ResourceData, m interface{}) error {
controller := m.(*ControllerCfg)
urlValues := &url.Values{}
urlValues.Add("lbId", strconv.Itoa(k8s.LbID))
resp, err := controller.decortAPICall("POST", LbGetAPI, urlValues)
if err != nil {
return err
}
var lb LbRecord
if err := json.Unmarshal([]byte(resp), &lb); err != nil {
return err
}
d.Set("extnet_id", lb.ExtNetID)
d.Set("lb_ip", lb.PrimaryNode.FrontendIP)
urlValues = &url.Values{}
urlValues.Add("k8sId", d.Id())
kubeconfig, err := controller.decortAPICall("POST", K8sGetConfigAPI, urlValues)
if err != nil {
@ -303,13 +334,13 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
//Description: "Create k8s with load balancer if true.",
//},
//"extnet_id": {
//Type: schema.TypeInt,
//Optional: true,
//ForceNew: true,
//Default: 0,
//Description: "ID of the external network to connect workers to.",
//},
"extnet_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.",
},
//"desc": {
//Type: schema.TypeString,
@ -317,6 +348,12 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
//Description: "Text description of this instance.",
//},
"lb_ip": {
Type: schema.TypeString,
Computed: true,
Description: "IP address of default load balancer.",
},
"default_wg_id": {
Type: schema.TypeInt,
Computed: true,

@ -24,6 +24,7 @@ description: |-
### Optional
- **extnet_id** (Number) ID of the external network to connect workers to. If omitted network will be chosen by the platfom.
- **id** (String) The ID of this resource.
- **masters** (Block List, Max: 1) Master node(s) configuration. (see [below for nested schema](#nestedblock--masters))
- **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
@ -33,6 +34,7 @@ description: |-
- **default_wg_id** (Number) ID of default workers group for this instace.
- **kubeconfig** (String) Kubeconfig for cluster access.
- **lb_ip** (String) IP address of default load balancer.
<a id="nestedblock--masters"></a>
### Nested Schema for `masters`

Loading…
Cancel
Save