This commit is contained in:
2023-12-19 16:37:50 +03:00
parent 20050bc169
commit f49d9f8860
150 changed files with 12582 additions and 11709 deletions

View File

@@ -50,6 +50,7 @@ import (
func dataSourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
cluster, err := utilityDataK8sCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
d.SetId(strconv.FormatUint(cluster.ID, 10))
@@ -399,6 +400,10 @@ func dataSourceK8sSchemaMake() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"network_plugin": {
Type: schema.TypeString,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,

View File

@@ -271,6 +271,10 @@ func createK8sListSchema() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"network_plugin": {
Type: schema.TypeString,
Computed: true,
},
"rg_id": {
Type: schema.TypeInt,
Computed: true,

View File

@@ -47,6 +47,7 @@ func dataSourceK8sWgRead(ctx context.Context, d *schema.ResourceData, m interfac
wg, workersComputeList, err := utilityDataK8sWgCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}

View File

@@ -47,6 +47,7 @@ func dataSourceK8sWgCloudInitRead(ctx context.Context, d *schema.ResourceData, m
metaData, err := utilityK8sWgCloudInitCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}

View File

@@ -45,6 +45,7 @@ import (
func dataSourceK8sWgListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
wgList, err := utilityK8sWgListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}

View File

@@ -106,7 +106,7 @@ func flattenWorkerComputes(cluster *k8s.RecordK8S) []map[string]interface{} {
}
func flattenAclList(aclList k8s.ListACL) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len (aclList))
res := make([]map[string]interface{}, 0, len(aclList))
for _, acl := range aclList {
temp := map[string]interface{}{
"explicit": acl.Explicit,
@@ -134,7 +134,7 @@ func flattenAcl(acl k8s.RecordACL) []map[string]interface{} {
}
func flattenInterfaces(interfaces compute.ListInterfaces) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len (interfaces))
res := make([]map[string]interface{}, 0, len(interfaces))
for _, interfaceCompute := range interfaces {
temp := map[string]interface{}{
"def_gw": interfaceCompute.DefGW,
@@ -147,7 +147,7 @@ func flattenInterfaces(interfaces compute.ListInterfaces) []map[string]interface
}
func flattenDetailedInfo(detailedInfoList k8s.ListDetailedInfo, computes []compute.RecordCompute) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len (detailedInfoList))
res := make([]map[string]interface{}, 0, len(detailedInfoList))
if computes != nil {
for i, detailedInfo := range detailedInfoList {
temp := map[string]interface{}{
@@ -247,6 +247,7 @@ func flattenK8sData(d *schema.ResourceData, cluster k8s.RecordK8S, masters []com
d.Set("workers", flattenK8sGroup(cluster.K8SGroups.Workers, workers))
d.Set("lb_id", cluster.LBID)
d.Set("name", cluster.Name)
d.Set("network_plugin", cluster.NetworkPlugin)
d.Set("rg_id", cluster.RGID)
d.Set("rg_name", cluster.RGName)
d.Set("status", cluster.Status)
@@ -267,7 +268,7 @@ func flattenServiceAccount(serviceAccount k8s.RecordServiceAccount) []map[string
}
func flattenWorkersGroup(workersGroups k8s.ListK8SGroups) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len (workersGroups))
res := make([]map[string]interface{}, 0, len(workersGroups))
for _, worker := range workersGroups {
temp := map[string]interface{}{
"annotations": worker.Annotations,
@@ -288,11 +289,11 @@ func flattenWorkersGroup(workersGroups k8s.ListK8SGroups) []map[string]interface
}
func flattenK8sItems(k8sItems *k8s.ListK8SClusters) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len (k8sItems.Data))
res := make([]map[string]interface{}, 0, len(k8sItems.Data))
for _, item := range k8sItems.Data {
temp := map[string]interface{}{
"account_id": item.AccountID,
"account_name": item.Name,
"account_name": item.AccountName,
"acl": item.ACL,
"bservice_id": item.BServiceID,
"ci_id": item.CIID,
@@ -308,6 +309,7 @@ func flattenK8sItems(k8sItems *k8s.ListK8SClusters) []map[string]interface{} {
"lb_id": item.LBID,
"milestones": item.Milestones,
"k8s_name": item.Name,
"network_plugin": item.NetworkPlugin,
"rg_id": item.RGID,
"rg_name": item.RGName,
"service_account": flattenServiceAccount(item.ServiceAccount),

View File

@@ -85,21 +85,21 @@ func mastersSchemaMake() map[string]*schema.Schema {
Optional: true,
}
masters["cpu"] = &schema.Schema{
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Type: schema.TypeInt,
Required: true,
//ForceNew: true,
Description: "Node CPU count.",
}
masters["ram"] = &schema.Schema{
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Type: schema.TypeInt,
Required: true,
//ForceNew: true,
Description: "Node RAM in MB.",
}
masters["disk"] = &schema.Schema{
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Type: schema.TypeInt,
Required: true,
//ForceNew: true,
Description: "Node boot disk size in GB.",
}

View File

@@ -14,15 +14,15 @@ func resourceK8sCPSchemaV1() *schema.Resource {
Description: "Name of the cluster.",
},
"rg_id": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Type: schema.TypeInt,
Required: true,
//ForceNew: true,
Description: "Resource group ID that this instance belongs to.",
},
"k8sci_id": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Type: schema.TypeInt,
Required: true,
//ForceNew: true,
Description: "ID of the k8s catalog item to base this instance on.",
},
"network_plugin": {
@@ -136,10 +136,10 @@ func resourceK8sCPSchemaV1() *schema.Resource {
},
////
"extnet_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
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": {

View File

@@ -211,6 +211,7 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
resp, err := c.CloudAPI().K8S().Create(ctx, createReq)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
@@ -316,7 +317,7 @@ func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{})
}
}
k8sList, err := utilityK8sListCheckPresence(ctx, d, m)
k8sList, err := utilityK8sListForResourceCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
@@ -515,7 +516,7 @@ func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{
}
}
return nil
return resourceK8sRead(ctx, d, m)
}
func resourceK8sDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
@@ -548,15 +549,15 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
Description: "Name of the cluster.",
},
"rg_id": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Type: schema.TypeInt,
Required: true,
//ForceNew: true,
Description: "Resource group ID that this instance belongs to.",
},
"k8sci_id": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Type: schema.TypeInt,
Required: true,
//ForceNew: true,
Description: "ID of the k8s catalog item to base this instance on.",
},
"wg_name": {
@@ -595,7 +596,7 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
Type: schema.TypeList,
Optional: true,
Computed: true,
ForceNew: true,
//ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: mastersSchemaMake(),
@@ -624,10 +625,10 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
Description: "Use only selected ExtNet for infrastructure connections",
},
"extnet_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
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.",
},

View File

@@ -197,6 +197,7 @@ func resourceK8sCPCreate(ctx context.Context, d *schema.ResourceData, m interfac
resp, err := c.CloudAPI().K8S().Create(ctx, createReq)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
@@ -317,7 +318,7 @@ func resourceK8sCPRead(ctx context.Context, d *schema.ResourceData, m interface{
}
}
k8sList, err := utilityK8sListCheckPresence(ctx, d, m)
k8sList, err := utilityK8sListForResourceCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
@@ -532,7 +533,7 @@ func resourceK8sCPUpdate(ctx context.Context, d *schema.ResourceData, m interfac
}
}
return nil
return resourceK8sCPRead(ctx, d, m)
}
func resourceK8sCPDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
@@ -540,6 +541,7 @@ func resourceK8sCPDelete(ctx context.Context, d *schema.ResourceData, m interfac
cluster, err := utilityK8sCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
@@ -554,6 +556,8 @@ func resourceK8sCPDelete(ctx context.Context, d *schema.ResourceData, m interfac
return diag.FromErr(err)
}
d.SetId("")
return nil
}
@@ -565,15 +569,15 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
Description: "Name of the cluster.",
},
"rg_id": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Type: schema.TypeInt,
Required: true,
//ForceNew: true,
Description: "Resource group ID that this instance belongs to.",
},
"k8sci_id": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Type: schema.TypeInt,
Required: true,
//ForceNew: true,
Description: "ID of the k8s catalog item to base this instance on.",
},
"network_plugin": {
@@ -681,10 +685,10 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
},
////
"extnet_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
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": {

View File

@@ -201,7 +201,7 @@ func resourceK8sWgUpdate(ctx context.Context, d *schema.ResourceData, m interfac
}
}
return nil
return resourceK8sWgRead(ctx, d, m)
}
func resourceK8sWgDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
@@ -209,6 +209,7 @@ func resourceK8sWgDelete(ctx context.Context, d *schema.ResourceData, m interfac
wg, err := utilityK8sWgCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
@@ -223,22 +224,24 @@ func resourceK8sWgDelete(ctx context.Context, d *schema.ResourceData, m interfac
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func resourceK8sWgSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"k8s_id": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Type: schema.TypeInt,
Required: true,
//ForceNew: true,
Description: "ID of k8s instance.",
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
//ForceNew: true,
Description: "Name of the worker group.",
},
@@ -250,17 +253,17 @@ func resourceK8sWgSchemaMake() map[string]*schema.Schema {
},
"cpu": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Type: schema.TypeInt,
Optional: true,
//ForceNew: true,
Default: 1,
Description: "Worker node CPU count.",
},
"ram": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Type: schema.TypeInt,
Optional: true,
//ForceNew: true,
Default: 1024,
Description: "Worker node RAM in MB.",
},

View File

@@ -273,7 +273,22 @@ func utilityK8sListCheckPresence(ctx context.Context, d *schema.ResourceData, m
req.Size = uint64(size.(int))
}
k8sList, err := c.CloudAPI().K8S().List(ctx, req)
if err != nil {
return nil, err
}
return k8sList, nil
}
func utilityK8sListForResourceCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*k8s.ListK8SClusters, error) {
c := m.(*controller.ControllerCfg)
req := k8s.ListRequest{
IncludeDeleted: false,
}
if name, ok := d.GetOk("name"); ok {
req.Name = name.(string)
}
k8sList, err := c.CloudAPI().K8S().List(ctx, req)
if err != nil {
return nil, err