4.5.3
This commit is contained in:
@@ -35,6 +35,8 @@ package k8s
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/validators"
|
||||
)
|
||||
|
||||
func nodeMasterDefault() K8sNodeRecord {
|
||||
@@ -94,6 +96,10 @@ func mastersSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
//ForceNew: true,
|
||||
ValidateFunc: validation.All(
|
||||
validation.IntAtLeast(constants.MinRamPerCompute),
|
||||
validators.DivisibleBy(constants.RAMDivisibility),
|
||||
),
|
||||
Description: "Node RAM in MB.",
|
||||
}
|
||||
masters["disk"] = &schema.Schema{
|
||||
@@ -117,7 +123,11 @@ func workersSchemaMake() map[string]*schema.Schema {
|
||||
Required: true,
|
||||
},
|
||||
"ram": {
|
||||
Type: schema.TypeInt,
|
||||
Type: schema.TypeInt,
|
||||
ValidateFunc: validation.All(
|
||||
validation.IntAtLeast(constants.MinRamPerCompute),
|
||||
validators.DivisibleBy(constants.RAMDivisibility),
|
||||
),
|
||||
Required: true,
|
||||
},
|
||||
"cpu": {
|
||||
|
||||
@@ -189,7 +189,6 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
if oidcCertificate, ok := d.GetOk("oidc_cert"); ok {
|
||||
createReq.OidcCertificate = oidcCertificate.(string)
|
||||
}
|
||||
///
|
||||
|
||||
createReq.ExtNetOnly = d.Get("extnet_only").(bool)
|
||||
|
||||
@@ -520,6 +519,7 @@ func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
}
|
||||
|
||||
func resourceK8sDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
|
||||
log.Debugf("resourceK8sDelete: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int))
|
||||
|
||||
cluster, err := utilityK8sCheckPresence(ctx, d, m)
|
||||
@@ -527,12 +527,14 @@ func resourceK8sDelete(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := k8s.DeleteRequest{
|
||||
K8SID: cluster.ID,
|
||||
Permanently: true,
|
||||
req := k8s.DeleteRequest{K8SID: cluster.ID}
|
||||
|
||||
if val, ok := d.GetOk("permanently"); ok {
|
||||
req.Permanently = val.(bool)
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
_, err = c.CloudAPI().K8S().Delete(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
@@ -631,6 +633,12 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
|
||||
//ForceNew: true,
|
||||
Description: "ID of the external network to connect workers to. If omitted network will be chosen by the platfom.",
|
||||
},
|
||||
"permanently": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "Determines if cluster should be destroyed",
|
||||
},
|
||||
|
||||
///4.4.0
|
||||
"cloud_init": {
|
||||
@@ -686,8 +694,6 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
|
||||
Optional: true,
|
||||
Description: "insert ssl certificate in x509 pem format",
|
||||
},
|
||||
////
|
||||
|
||||
"desc": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
@@ -699,7 +705,6 @@ func resourceK8sSchemaMake() map[string]*schema.Schema {
|
||||
Default: true,
|
||||
Description: "Start k8s cluster",
|
||||
},
|
||||
|
||||
"acl": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
|
||||
@@ -52,6 +52,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/status"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/validators"
|
||||
)
|
||||
|
||||
func resourceK8sCPCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
@@ -175,8 +176,6 @@ func resourceK8sCPCreate(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
log.Debug(createReq.OidcCertificate)
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
createReq.ExtNetOnly = d.Get("extnet_only").(bool)
|
||||
|
||||
if extNet, ok := d.GetOk("extnet_id"); ok {
|
||||
@@ -537,6 +536,7 @@ func resourceK8sCPUpdate(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
}
|
||||
|
||||
func resourceK8sCPDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
|
||||
log.Debugf("resourceK8sControlPlaneDelete: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int))
|
||||
|
||||
cluster, err := utilityK8sCheckPresence(ctx, d, m)
|
||||
@@ -545,12 +545,14 @@ func resourceK8sCPDelete(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := k8s.DeleteRequest{
|
||||
K8SID: cluster.ID,
|
||||
Permanently: true,
|
||||
req := k8s.DeleteRequest{K8SID: cluster.ID}
|
||||
|
||||
if val, ok := d.GetOk("permanently"); ok {
|
||||
req.Permanently = val.(bool)
|
||||
}
|
||||
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
_, err = c.CloudAPI().K8S().Delete(ctx, req)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
@@ -600,9 +602,13 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
|
||||
Description: "Node CPU count.",
|
||||
},
|
||||
"ram": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ValidateFunc: validation.All(
|
||||
validation.IntAtLeast(constants.MinRamPerCompute),
|
||||
validators.DivisibleBy(constants.RAMDivisibility),
|
||||
),
|
||||
Description: "Node RAM in MB.",
|
||||
},
|
||||
"disk": {
|
||||
@@ -683,7 +689,6 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
|
||||
Optional: true,
|
||||
Description: "insert ssl certificate in x509 pem format",
|
||||
},
|
||||
////
|
||||
"extnet_id": {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
@@ -771,6 +776,12 @@ func resourceK8sCPSchemaMake() map[string]*schema.Schema {
|
||||
Computed: true,
|
||||
Description: "IP address of default load balancer.",
|
||||
},
|
||||
"permanently": {
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
Description: "Determines if cluster should be destroyed",
|
||||
},
|
||||
"rg_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
|
||||
@@ -34,16 +34,19 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/compute"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/validators"
|
||||
)
|
||||
|
||||
func resourceK8sWgCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
@@ -101,7 +104,7 @@ func resourceK8sWgCreate(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
d.SetId(strconv.FormatUint(resp, 10))
|
||||
d.SetId(fmt.Sprintf("%d#%d", d.Get("k8s_id").(int), resp))
|
||||
|
||||
return resourceK8sWgRead(ctx, d, m)
|
||||
}
|
||||
@@ -125,7 +128,7 @@ func resourceK8sWgRead(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
|
||||
d.Set("wg_id", wg.ID)
|
||||
if strings.Contains(d.Id(), "#") {
|
||||
k8sId, err := strconv.Atoi(strings.Split(d.Id(), "#")[1])
|
||||
k8sId, err := strconv.Atoi(strings.Split(d.Id(), "#")[0])
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
@@ -134,8 +137,7 @@ func resourceK8sWgRead(ctx context.Context, d *schema.ResourceData, m interface{
|
||||
} else {
|
||||
d.Set("k8s_id", d.Get("k8s_id"))
|
||||
}
|
||||
|
||||
d.SetId(strings.Split(d.Id(), "#")[0])
|
||||
d.SetId(fmt.Sprintf("%d#%d", d.Get("k8s_id").(int), wg.ID))
|
||||
|
||||
flattenWg(d, *wg, workersComputeList)
|
||||
|
||||
@@ -161,11 +163,10 @@ func resourceK8sWgUpdate(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
wgId, _ := strconv.ParseUint(d.Id(), 10, 64)
|
||||
if newNum := d.Get("num").(int); uint64(newNum) > wg.Num {
|
||||
req := k8s.WorkerAddRequest{
|
||||
K8SID: uint64(d.Get("k8s_id").(int)),
|
||||
WorkersGroupID: wgId,
|
||||
WorkersGroupID: wg.ID,
|
||||
Num: uint64(newNum) - wg.Num,
|
||||
}
|
||||
|
||||
@@ -177,7 +178,7 @@ func resourceK8sWgUpdate(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
for i := int(wg.Num) - 1; i >= newNum; i-- {
|
||||
req := k8s.DeleteWorkerFromGroupRequest{
|
||||
K8SID: uint64(d.Get("k8s_id").(int)),
|
||||
WorkersGroupID: wgId,
|
||||
WorkersGroupID: wg.ID,
|
||||
WorkerID: wg.DetailedInfo[i].ID,
|
||||
}
|
||||
|
||||
@@ -191,7 +192,7 @@ func resourceK8sWgUpdate(ctx context.Context, d *schema.ResourceData, m interfac
|
||||
if d.HasChange("cloud_init") {
|
||||
req := k8s.UpdateWorkerNodesMetaDataRequest{
|
||||
K8SID: uint64(d.Get("k8s_id").(int)),
|
||||
WorkersGroupID: wgId,
|
||||
WorkersGroupID: wg.ID,
|
||||
UserData: d.Get("cloud_init").(string),
|
||||
}
|
||||
|
||||
@@ -264,7 +265,11 @@ func resourceK8sWgSchemaMake() map[string]*schema.Schema {
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
//ForceNew: true,
|
||||
Default: 1024,
|
||||
Default: 1024,
|
||||
ValidateFunc: validation.All(
|
||||
validation.IntAtLeast(constants.MinRamPerCompute),
|
||||
validators.DivisibleBy(constants.RAMDivisibility),
|
||||
),
|
||||
Description: "Worker node RAM in MB.",
|
||||
},
|
||||
|
||||
|
||||
@@ -91,11 +91,11 @@ func utilityK8sWgCheckPresence(ctx context.Context, d *schema.ResourceData, m in
|
||||
var err error
|
||||
|
||||
if strings.Contains(d.Id(), "#") {
|
||||
wgId, err = strconv.Atoi(strings.Split(d.Id(), "#")[0])
|
||||
wgId, err = strconv.Atoi(strings.Split(d.Id(), "#")[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
k8sId, err = strconv.Atoi(strings.Split(d.Id(), "#")[1])
|
||||
k8sId, err = strconv.Atoi(strings.Split(d.Id(), "#")[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -125,7 +125,7 @@ func utilityK8sWgCheckPresence(ctx context.Context, d *schema.ResourceData, m in
|
||||
return nil, fmt.Errorf("not found wg with id: %v in k8s cluster: %v", wgId, cluster.ID)
|
||||
}
|
||||
|
||||
func utilityK8sWgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (k8s.ListK8SGroups, error) {
|
||||
func utilityK8sWgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (k8s.ListK8SGroups, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := k8s.GetRequest{
|
||||
K8SID: uint64(d.Get("k8s_id").(int)),
|
||||
@@ -142,7 +142,7 @@ func utilityK8sWgListCheckPresence(ctx context.Context, d *schema.ResourceData,
|
||||
func utilityK8sWgCloudInitCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := k8s.GetWorkerNodesMetaDataRequest{
|
||||
K8SID: uint64(d.Get("k8s_id").(int)),
|
||||
K8SID: uint64(d.Get("k8s_id").(int)),
|
||||
WorkersGroupID: uint64(d.Get("wg_id").(int)),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user