From 0e72dd600d5ed49d571225739b6b4ec6ca045541 Mon Sep 17 00:00:00 2001 From: Aleksandr Semenov Date: Thu, 5 Dec 2024 16:57:08 +0300 Subject: [PATCH] chore(CLOUDDEV-642): Raise error for K8s data sources and resources --- docs/data-sources/k8s.md | 3 + docs/data-sources/k8s_client_config.md | 5 +- docs/data-sources/k8s_pool.md | 3 + docs/resources/k8s.md | 5 +- docs/resources/k8s_pool.md | 5 +- edgecenter/data_source_edgecenter_k8s.go | 114 +------ ...ata_source_edgecenter_k8s_client_config.go | 45 +-- edgecenter/data_source_edgecenter_k8s_pool.go | 60 +--- edgecenter/resource_edgecenter_k8s.go | 304 +----------------- edgecenter/resource_edgecenter_k8s_pool.go | 204 +----------- 10 files changed, 37 insertions(+), 711 deletions(-) diff --git a/docs/data-sources/k8s.md b/docs/data-sources/k8s.md index 0e01f69c..b585ee8c 100644 --- a/docs/data-sources/k8s.md +++ b/docs/data-sources/k8s.md @@ -4,12 +4,15 @@ page_title: "edgecenter_k8s Data Source - edgecenter" subcategory: "" description: |- Represent k8s cluster with one default pool. + WARNING: Data source "edgecenter_k8s" is deprecated and unavailable. --- # edgecenter_k8s (Data Source) Represent k8s cluster with one default pool. + **WARNING:** Data source "edgecenter_k8s" is deprecated and unavailable. + ## Example Usage ```terraform diff --git a/docs/data-sources/k8s_client_config.md b/docs/data-sources/k8s_client_config.md index ed26b094..61f0db21 100644 --- a/docs/data-sources/k8s_client_config.md +++ b/docs/data-sources/k8s_client_config.md @@ -4,11 +4,14 @@ page_title: "edgecenter_k8s_client_config Data Source - edgecenter" subcategory: "" description: |- Represent k8s cluster with one default pool. + WARNING: Data source "edgecenter_k8s_client_config" is deprecated and unavailable. --- # edgecenter_k8s_client_config (Data Source) -Represent k8s cluster with one default pool. +Represent k8s cluster with one default pool. + + **WARNING:** Data source "edgecenter_k8s_client_config" is deprecated and unavailable. ## Example Usage diff --git a/docs/data-sources/k8s_pool.md b/docs/data-sources/k8s_pool.md index 0be95f9e..d1a806ad 100644 --- a/docs/data-sources/k8s_pool.md +++ b/docs/data-sources/k8s_pool.md @@ -4,12 +4,15 @@ page_title: "edgecenter_k8s_pool Data Source - edgecenter" subcategory: "" description: |- Represent k8s cluster's pool. + WARNING: Data source "edgecenter_k8s_pool" is deprecated and unavailable. --- # edgecenter_k8s_pool (Data Source) Represent k8s cluster's pool. + **WARNING:** Data source "edgecenter_k8s_pool" is deprecated and unavailable. + ## Example Usage ```terraform diff --git a/docs/resources/k8s.md b/docs/resources/k8s.md index 3e95be07..08b3f22e 100644 --- a/docs/resources/k8s.md +++ b/docs/resources/k8s.md @@ -4,11 +4,14 @@ page_title: "edgecenter_k8s Resource - edgecenter" subcategory: "" description: |- Represent k8s cluster with one default pool. + WARNING: Resource "edgecenter_k8s" is deprecated and unavailable. --- # edgecenter_k8s (Resource) -Represent k8s cluster with one default pool. +Represent k8s cluster with one default pool. + + **WARNING:** Resource "edgecenter_k8s" is deprecated and unavailable. ## Example Usage diff --git a/docs/resources/k8s_pool.md b/docs/resources/k8s_pool.md index 87d5b2df..fcc04bfe 100644 --- a/docs/resources/k8s_pool.md +++ b/docs/resources/k8s_pool.md @@ -4,11 +4,14 @@ page_title: "edgecenter_k8s_pool Resource - edgecenter" subcategory: "" description: |- Represent k8s cluster's pool. + WARNING: Resource "edgecenter_k8s_pool" is deprecated and unavailable. --- # edgecenter_k8s_pool (Resource) -Represent k8s cluster's pool. +Represent k8s cluster's pool. + + **WARNING:** Resource "edgecenter_k8s_pool" is deprecated and unavailable. ## Example Usage diff --git a/edgecenter/data_source_edgecenter_k8s.go b/edgecenter/data_source_edgecenter_k8s.go index 8830e1ad..8150a995 100644 --- a/edgecenter/data_source_edgecenter_k8s.go +++ b/edgecenter/data_source_edgecenter_k8s.go @@ -2,21 +2,16 @@ package edgecenter import ( "context" - "log" - "time" - + "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - "github.com/Edge-Center/edgecentercloud-go/edgecenter/k8s/v1/clusters" - "github.com/Edge-Center/edgecentercloud-go/edgecenter/k8s/v1/pools" ) func dataSourceK8s() *schema.Resource { return &schema.Resource{ DeprecationMessage: "!> **WARNING:** This data source is deprecated and will be removed in the next major version. Data source \"edgecenter_k8s\" unavailable.", ReadContext: dataSourceK8sRead, - Description: "Represent k8s cluster with one default pool.", + Description: "Represent k8s cluster with one default pool.\n\n **WARNING:** Data source \"edgecenter_k8s\" is deprecated and unavailable.", Schema: map[string]*schema.Schema{ "project_id": { Type: schema.TypeInt, @@ -224,108 +219,5 @@ func dataSourceK8s() *schema.Resource { } func dataSourceK8sRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Println("[DEBUG] Start K8s reading") - var diags diag.Diagnostics - config := m.(*Config) - provider := config.Provider - - client, err := CreateClient(provider, d, K8sPoint, VersionPointV1) - if err != nil { - return diag.FromErr(err) - } - - clusterID := d.Get("cluster_id").(string) - cluster, err := clusters.Get(client, clusterID).Extract() - if err != nil { - return diag.FromErr(err) - } - - d.SetId(cluster.UUID) - - d.Set("name", cluster.Name) - d.Set("fixed_network", cluster.FixedNetwork) - d.Set("fixed_subnet", cluster.FixedSubnet) - d.Set("master_lb_floating_ip_enabled", cluster.FloatingIPEnabled) - d.Set("keypair", cluster.KeyPair) - d.Set("node_count", cluster.NodeCount) - d.Set("status", cluster.Status) - d.Set("status_reason", cluster.StatusReason) - - masterAddresses := make([]string, len(cluster.MasterAddresses)) - for i, addr := range cluster.MasterAddresses { - masterAddresses[i] = addr.String() - } - if err := d.Set("master_addresses", masterAddresses); err != nil { - return diag.FromErr(err) - } - - nodeAddresses := make([]string, len(cluster.NodeAddresses)) - for i, addr := range cluster.NodeAddresses { - nodeAddresses[i] = addr.String() - } - if err := d.Set("node_addresses", nodeAddresses); err != nil { - return diag.FromErr(err) - } - - d.Set("container_version", cluster.ContainerVersion) - d.Set("api_address", cluster.APIAddress.String()) - d.Set("user_id", cluster.UserID) - d.Set("discovery_url", cluster.DiscoveryURL.String()) - - d.Set("health_status", cluster.HealthStatus) - if err := d.Set("health_status_reason", cluster.HealthStatusReason); err != nil { - return diag.FromErr(err) - } - - if err := d.Set("faults", cluster.Faults); err != nil { - return diag.FromErr(err) - } - - d.Set("master_flavor_id", cluster.MasterFlavorID) - d.Set("cluster_template_id", cluster.ClusterTemplateID) - d.Set("version", cluster.Version) - d.Set("updated_at", cluster.UpdatedAt.Format(time.RFC850)) - d.Set("created_at", cluster.CreatedAt.Format(time.RFC850)) - - var pool pools.ClusterPool - for _, p := range cluster.Pools { - if p.IsDefault { - pool = p - } - } - - p := make(map[string]interface{}) - p["uuid"] = pool.UUID - p["name"] = pool.Name - p["flavor_id"] = pool.FlavorID - p["min_node_count"] = pool.MinNodeCount - p["max_node_count"] = pool.MaxNodeCount - p["node_count"] = pool.NodeCount - p["docker_volume_type"] = pool.DockerVolumeType.String() - p["docker_volume_size"] = pool.DockerVolumeSize - p["stack_id"] = pool.StackID - p["created_at"] = pool.CreatedAt.Format(time.RFC850) - - if err := d.Set("pool", []interface{}{p}); err != nil { - return diag.FromErr(err) - } - - getConfigResult, err := clusters.GetConfig(client, clusterID).Extract() - if err != nil { - return diag.FromErr(err) - } - - clusterConfig, err := parseK8sConfig(getConfigResult.Config) - if err != nil { - return diag.Errorf("failed to parse k8s config: %s", err) - } - - certificateAuthorityData := clusterConfig.Clusters[0].Cluster.CertificateAuthorityData - if err := d.Set("certificate_authority_data", certificateAuthorityData); err != nil { - return diag.Errorf("couldn't get certificate_authority_data: %s", err) - } - - log.Println("[DEBUG] Finish K8s reading") - - return diags + return diag.FromErr(fmt.Errorf("resource \"edgecenter_k8s\" is deprecated and unavailable")) } diff --git a/edgecenter/data_source_edgecenter_k8s_client_config.go b/edgecenter/data_source_edgecenter_k8s_client_config.go index eb808f3a..dd228ff7 100644 --- a/edgecenter/data_source_edgecenter_k8s_client_config.go +++ b/edgecenter/data_source_edgecenter_k8s_client_config.go @@ -2,19 +2,16 @@ package edgecenter import ( "context" - "log" - + "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - "github.com/Edge-Center/edgecentercloud-go/edgecenter/k8s/v1/clusters" ) func dataSourceK8sClientConfig() *schema.Resource { return &schema.Resource{ DeprecationMessage: "!> **WARNING:** This data source is deprecated and will be removed in the next major version. Data source \"edgecenter_k8s_client_config\" unavailable.", ReadContext: dataSourceK8sReadClientConfig, - Description: "Represent k8s cluster with one default pool.", + Description: "Represent k8s cluster with one default pool. \n\n **WARNING:** Data source \"edgecenter_k8s_client_config\" is deprecated and unavailable.", Schema: map[string]*schema.Schema{ "project_id": { Type: schema.TypeInt, @@ -60,41 +57,5 @@ func dataSourceK8sClientConfig() *schema.Resource { } func dataSourceK8sReadClientConfig(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Println("[DEBUG] Start K8s client config reading") - var diags diag.Diagnostics - config := m.(*Config) - provider := config.Provider - - client, err := CreateClient(provider, d, K8sPoint, VersionPointV1) - if err != nil { - return diag.FromErr(err) - } - - clusterID := d.Get("cluster_id").(string) - - d.SetId(clusterID) - - getConfigResult, err := clusters.GetConfig(client, clusterID).Extract() - if err != nil { - return diag.FromErr(err) - } - - clusterConfig, err := parseK8sConfig(getConfigResult.Config) - if err != nil { - return diag.Errorf("failed to parse k8s config: %s", err) - } - - clientCertificateData := clusterConfig.Users[0].User.ClientCertificateData - if err := d.Set("client_certificate_data", clientCertificateData); err != nil { - return diag.Errorf("couldn't get client_certificate_data: %s", err) - } - - clientKeyData := clusterConfig.Users[0].User.ClientKeyData - if err := d.Set("client_key_data", clientKeyData); err != nil { - return diag.Errorf("couldn't get client_key_data: %s", err) - } - - log.Println("[DEBUG] Finish K8s client config reading") - - return diags + return diag.FromErr(fmt.Errorf("data source \"edgecenter_k8s_client_config\" is deprecated and unavailable")) } diff --git a/edgecenter/data_source_edgecenter_k8s_pool.go b/edgecenter/data_source_edgecenter_k8s_pool.go index 8859cefd..454d1dfb 100644 --- a/edgecenter/data_source_edgecenter_k8s_pool.go +++ b/edgecenter/data_source_edgecenter_k8s_pool.go @@ -2,20 +2,16 @@ package edgecenter import ( "context" - "log" - "time" - + "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - "github.com/Edge-Center/edgecentercloud-go/edgecenter/k8s/v1/pools" ) func dataSourceK8sPool() *schema.Resource { return &schema.Resource{ DeprecationMessage: "!> **WARNING:** This data source is deprecated and will be removed in the next major version. Data source \"edgecenter_k8s_pool\" unavailable.", ReadContext: dataSourceK8sPoolRead, - Description: "Represent k8s cluster's pool.", + Description: "Represent k8s cluster's pool.\n\n **WARNING:** Data source \"edgecenter_k8s_pool\" is deprecated and unavailable.", Schema: map[string]*schema.Schema{ "project_id": { Type: schema.TypeInt, @@ -122,55 +118,5 @@ func dataSourceK8sPool() *schema.Resource { } func dataSourceK8sPoolRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Println("[DEBUG] Start K8s pool reading") - var diags diag.Diagnostics - config := m.(*Config) - provider := config.Provider - - client, err := CreateClient(provider, d, K8sPoint, VersionPointV1) - if err != nil { - return diag.FromErr(err) - } - - clusterID := d.Get("cluster_id").(string) - poolID := d.Get("pool_id").(string) - - pool, err := pools.Get(client, clusterID, poolID).Extract() - if err != nil { - return diag.FromErr(err) - } - d.SetId(pool.UUID) - - d.Set("name", pool.Name) - d.Set("cluster_id", clusterID) - d.Set("is_default", pool.IsDefault) - d.Set("flavor_id", pool.FlavorID) - d.Set("min_node_count", pool.MinNodeCount) - d.Set("max_node_count", pool.MaxNodeCount) - d.Set("node_count", pool.NodeCount) - d.Set("docker_volume_type", pool.DockerVolumeType.String()) - d.Set("docker_volume_size", pool.DockerVolumeSize) - d.Set("stack_id", pool.StackID) - d.Set("created_at", pool.CreatedAt.Format(time.RFC850)) - - nodeAddresses := make([]string, len(pool.NodeAddresses)) - for i, na := range pool.NodeAddresses { - nodeAddresses[i] = na.String() - } - d.Set("node_addresses", nodeAddresses) - - poolInstances, err := pools.InstancesAll(client, clusterID, poolID) - if err != nil { - return diag.FromErr(err) - } - - nodeNames := make([]string, len(poolInstances)) - for j, instance := range poolInstances { - nodeNames[j] = instance.Name - } - d.Set("node_names", nodeNames) - - log.Println("[DEBUG] Finish K8s pool reading") - - return diags + return diag.FromErr(fmt.Errorf("data source \"edgecenter_k8s_pool\" is deprecated and unavailable")) } diff --git a/edgecenter/resource_edgecenter_k8s.go b/edgecenter/resource_edgecenter_k8s.go index 1e68acda..98447ae5 100644 --- a/edgecenter/resource_edgecenter_k8s.go +++ b/edgecenter/resource_edgecenter_k8s.go @@ -2,20 +2,11 @@ package edgecenter import ( "context" - "errors" "fmt" - "log" "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - edgecloud "github.com/Edge-Center/edgecentercloud-go" - "github.com/Edge-Center/edgecentercloud-go/edgecenter/k8s/v1/clusters" - "github.com/Edge-Center/edgecentercloud-go/edgecenter/k8s/v1/pools" - "github.com/Edge-Center/edgecentercloud-go/edgecenter/keypair/v2/keypairs" - "github.com/Edge-Center/edgecentercloud-go/edgecenter/task/v1/tasks" - "github.com/Edge-Center/edgecentercloud-go/edgecenter/volume/v1/volumes" ) const ( @@ -32,7 +23,7 @@ func resourceK8s() *schema.Resource { ReadContext: resourceK8sRead, UpdateContext: resourceK8sUpdate, DeleteContext: resourceK8sDelete, - Description: "Represent k8s cluster with one default pool.", + Description: "Represent k8s cluster with one default pool. \n\n **WARNING:** Resource \"edgecenter_k8s\" is deprecated and unavailable.", Timeouts: &schema.ResourceTimeout{ Create: &k8sCreateTimeout, Update: &k8sCreateTimeout, @@ -273,302 +264,17 @@ func resourceK8s() *schema.Resource { } func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Println("[DEBUG] Start K8s creating") - var diags diag.Diagnostics - config := m.(*Config) - provider := config.Provider - - client, err := CreateClient(provider, d, K8sPoint, VersionPointV1) - if err != nil { - return diag.FromErr(err) - } - - opts := clusters.CreateOpts{ - Name: d.Get("name").(string), - Version: d.Get("version").(string), - FixedNetwork: d.Get("fixed_network").(string), - FixedSubnet: d.Get("fixed_subnet").(string), - KeyPair: d.Get("keypair").(string), - AutoHealingEnabled: d.Get("auto_healing_enabled").(bool), - MasterLBFloatingIPEnabled: d.Get("master_lb_floating_ip_enabled").(bool), - } - - if podsIP, ok := d.GetOk("pods_ip_pool"); ok { - eccidr, err := parseCIDRFromString(podsIP.(string)) - if err != nil { - return diag.FromErr(err) - } - opts.PodsIPPool = &eccidr - } - - if svcIP, ok := d.GetOk("services_ip_pool"); ok { - eccidr, err := parseCIDRFromString(svcIP.(string)) - if err != nil { - return diag.FromErr(err) - } - opts.ServicesIPPool = &eccidr - } - - poolRaw := d.Get("pool").([]interface{}) - pool := poolRaw[0].(map[string]interface{}) - - poolNodeCount := pool["node_count"].(int) - maxNodeCount := pool["max_node_count"].(int) - optPool := pools.CreateOpts{ - Name: pool["name"].(string), - FlavorID: pool["flavor_id"].(string), - NodeCount: &poolNodeCount, - MinNodeCount: pool["min_node_count"].(int), - MaxNodeCount: &maxNodeCount, - } - - dockerVolumeSize := pool["docker_volume_size"].(int) - if dockerVolumeSize != 0 { - optPool.DockerVolumeSize = &dockerVolumeSize - } - - dockerVolumeType := pool["docker_volume_type"].(string) - if dockerVolumeType != "" { - optPool.DockerVolumeType = volumes.VolumeType(dockerVolumeType) - } - - opts.Pools = []pools.CreateOpts{optPool} - results, err := clusters.Create(client, opts).Extract() - if err != nil { - return diag.FromErr(err) - } - - taskID := results.Tasks[0] - log.Printf("[DEBUG] Task id (%s)", taskID) - k8sID, err := tasks.WaitTaskAndReturnResult(client, taskID, true, K8sCreateTimeout, func(task tasks.TaskID) (interface{}, error) { - taskInfo, err := tasks.Get(client, string(task)).Extract() - if err != nil { - return nil, fmt.Errorf("cannot get task with ID: %s. Error: %w", task, err) - } - k8sID, err := clusters.ExtractClusterIDFromTask(taskInfo) - if err != nil { - return nil, fmt.Errorf("cannot retrieve k8s ID from task info: %w", err) - } - return k8sID, nil - }, - ) - if err != nil { - return diag.FromErr(err) - } - - d.SetId(k8sID.(string)) - resourceK8sRead(ctx, d, m) - - log.Printf("[DEBUG] Finish K8s creating (%s)", k8sID) - - return diags + return diag.FromErr(fmt.Errorf("resource \"edgecenter_k8s\" is deprecated and unavailable")) } func resourceK8sRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Println("[DEBUG] Start K8s reading") - var diags diag.Diagnostics - config := m.(*Config) - provider := config.Provider - - clientK8S, err := CreateClient(provider, d, K8sPoint, VersionPointV1) - if err != nil { - return diag.FromErr(err) - } - - clusterID := d.Id() - cluster, err := clusters.Get(clientK8S, clusterID).Extract() - if err != nil { - return diag.FromErr(err) - } - - d.Set("name", cluster.Name) - d.Set("fixed_network", cluster.FixedNetwork) - d.Set("fixed_subnet", cluster.FixedSubnet) - d.Set("master_lb_floating_ip_enabled", cluster.FloatingIPEnabled) - d.Set("node_count", cluster.NodeCount) - d.Set("status", cluster.Status) - d.Set("status_reason", cluster.StatusReason) - - clientKeypairs, err := CreateClient(provider, d, KeypairsPoint, VersionPointV2) - if err != nil { - return diag.FromErr(err) - } - - keypairInfo, err := keypairs.Get(clientKeypairs, cluster.KeyPair).Extract() - if err != nil { - return diag.FromErr(err) - } - d.Set("keypair", keypairInfo.Name) - - masterAddresses := make([]string, len(cluster.MasterAddresses)) - for i, addr := range cluster.MasterAddresses { - masterAddresses[i] = addr.String() - } - if err := d.Set("master_addresses", masterAddresses); err != nil { - return diag.FromErr(err) - } - - nodeAddresses := make([]string, len(cluster.NodeAddresses)) - for i, addr := range cluster.NodeAddresses { - nodeAddresses[i] = addr.String() - } - if err := d.Set("node_addresses", nodeAddresses); err != nil { - return diag.FromErr(err) - } - - d.Set("container_version", cluster.ContainerVersion) - d.Set("api_address", cluster.APIAddress.String()) - d.Set("user_id", cluster.UserID) - d.Set("discovery_url", cluster.DiscoveryURL.String()) - - d.Set("health_status", cluster.HealthStatus) - if err := d.Set("health_status_reason", cluster.HealthStatusReason); err != nil { - return diag.FromErr(err) - } - - if err := d.Set("faults", cluster.Faults); err != nil { - return diag.FromErr(err) - } - - d.Set("master_flavor_id", cluster.MasterFlavorID) - d.Set("cluster_template_id", cluster.ClusterTemplateID) - d.Set("version", cluster.Version) - d.Set("updated_at", cluster.UpdatedAt.Format(time.RFC850)) - d.Set("created_at", cluster.CreatedAt.Format(time.RFC850)) - - var pool pools.ClusterPool - for _, p := range cluster.Pools { - if p.IsDefault { - pool = p - } - } - - p := make(map[string]interface{}) - p["uuid"] = pool.UUID - p["name"] = pool.Name - p["flavor_id"] = pool.FlavorID - p["min_node_count"] = pool.MinNodeCount - p["max_node_count"] = pool.MaxNodeCount - p["node_count"] = pool.NodeCount - p["docker_volume_type"] = pool.DockerVolumeType.String() - p["docker_volume_size"] = pool.DockerVolumeSize - p["stack_id"] = pool.StackID - p["created_at"] = pool.CreatedAt.Format(time.RFC850) - - if err := d.Set("pool", []interface{}{p}); err != nil { - return diag.FromErr(err) - } - - fields := []string{"region_id", "auto_healing_enabled", "pods_ip_pool", "services_ip_pool"} - revertState(d, &fields) - - log.Println("[DEBUG] Finish K8s reading") - - return diags + return diag.FromErr(fmt.Errorf("resource \"edgecenter_k8s\" is deprecated and unavailable")) } func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Println("[DEBUG] Start K8s updating") - config := m.(*Config) - provider := config.Provider - - client, err := CreateClient(provider, d, K8sPoint, VersionPointV1) - if err != nil { - return diag.FromErr(err) - } - - if d.HasChange("pool") { - poolRaw := d.Get("pool").([]interface{})[0] - pool := poolRaw.(map[string]interface{}) - - clusterID := d.Id() - poolID := pool["uuid"].(string) - - if d.HasChanges("pool.0.name", "pool.0.min_node_count", "pool.0.max_node_count") { - updateOpts := pools.UpdateOpts{ - Name: pool["name"].(string), - MinNodeCount: pool["min_node_count"].(int), - MaxNodeCount: pool["max_node_count"].(int), - } - results, err := pools.Update(client, clusterID, poolID, updateOpts).Extract() - if err != nil { - return diag.FromErr(err) - } - - taskID := results.Tasks[0] - _, err = tasks.WaitTaskAndReturnResult(client, taskID, true, K8sCreateTimeout, func(task tasks.TaskID) (interface{}, error) { - _, err := pools.Get(client, clusterID, poolID).Extract() - if err != nil { - return nil, fmt.Errorf("cannot get pool with ID: %s. Error: %w", poolID, err) - } - return nil, nil - }) - if err != nil { - return diag.FromErr(err) - } - } - - if d.HasChange("pool.0.node_count") { - resizeOpts := clusters.ResizeOpts{ - NodeCount: pool["node_count"].(*int), - } - results, err := clusters.Resize(client, clusterID, poolID, resizeOpts).Extract() - if err != nil { - return diag.FromErr(err) - } - - taskID := results.Tasks[0] - _, err = tasks.WaitTaskAndReturnResult(client, taskID, true, K8sCreateTimeout, func(task tasks.TaskID) (interface{}, error) { - _, err := pools.Get(client, clusterID, poolID).Extract() - if err != nil { - return nil, fmt.Errorf("cannot get pool with ID: %s. Error: %w", poolID, err) - } - return nil, nil - }) - if err != nil { - return diag.FromErr(err) - } - } - } - - return resourceK8sRead(ctx, d, m) + return diag.FromErr(fmt.Errorf("resource \"edgecenter_k8s\" is deprecated and unavailable")) } func resourceK8sDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Println("[DEBUG] Start K8s deleting") - var diags diag.Diagnostics - config := m.(*Config) - provider := config.Provider - - client, err := CreateClient(provider, d, K8sPoint, VersionPointV1) - if err != nil { - return diag.FromErr(err) - } - - id := d.Id() - results, err := clusters.Delete(client, id).Extract() - if err != nil { - return diag.FromErr(err) - } - - taskID := results.Tasks[0] - _, err = tasks.WaitTaskAndReturnResult(client, taskID, true, K8sCreateTimeout, func(task tasks.TaskID) (interface{}, error) { - _, err := clusters.Get(client, id).Extract() - if err == nil { - return nil, fmt.Errorf("cannot delete k8s cluster with ID: %s", id) - } - var errDefault404 edgecloud.Default404Error - if errors.As(err, &errDefault404) { - return nil, nil - } - return nil, fmt.Errorf("extracting Cluster resource error: %w", err) - }) - if err != nil { - return diag.FromErr(err) - } - - d.SetId("") - log.Printf("[DEBUG] Finish of K8s deleting") - - return diags + return diag.FromErr(fmt.Errorf("resource \"edgecenter_k8s\" is deprecated and unavailable")) } diff --git a/edgecenter/resource_edgecenter_k8s_pool.go b/edgecenter/resource_edgecenter_k8s_pool.go index 143f9dd1..26a4aadd 100644 --- a/edgecenter/resource_edgecenter_k8s_pool.go +++ b/edgecenter/resource_edgecenter_k8s_pool.go @@ -2,19 +2,9 @@ package edgecenter import ( "context" - "errors" "fmt" - "log" - "time" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - edgecloud "github.com/Edge-Center/edgecentercloud-go" - "github.com/Edge-Center/edgecentercloud-go/edgecenter/k8s/v1/clusters" - "github.com/Edge-Center/edgecentercloud-go/edgecenter/k8s/v1/pools" - "github.com/Edge-Center/edgecentercloud-go/edgecenter/task/v1/tasks" - "github.com/Edge-Center/edgecentercloud-go/edgecenter/volume/v1/volumes" ) func resourceK8sPool() *schema.Resource { @@ -24,7 +14,7 @@ func resourceK8sPool() *schema.Resource { ReadContext: resourceK8sPoolRead, UpdateContext: resourceK8sPoolUpdate, DeleteContext: resourceK8sPoolDelete, - Description: "Represent k8s cluster's pool.", + Description: "Represent k8s cluster's pool. \n\n **WARNING:** Resource \"edgecenter_k8s_pool\" is deprecated and unavailable.", Timeouts: &schema.ResourceTimeout{ Create: &k8sCreateTimeout, Update: &k8sCreateTimeout, @@ -131,201 +121,17 @@ func resourceK8sPool() *schema.Resource { } func resourceK8sPoolCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Println("[DEBUG] Start K8s pool creating") - var diags diag.Diagnostics - config := m.(*Config) - provider := config.Provider - - client, err := CreateClient(provider, d, K8sPoint, VersionPointV1) - if err != nil { - return diag.FromErr(err) - } - - poolNodeCount := d.Get("node_count").(int) - maxNodeCount := d.Get("max_node_count").(int) - opts := pools.CreateOpts{ - Name: d.Get("name").(string), - FlavorID: d.Get("flavor_id").(string), - NodeCount: &poolNodeCount, - MinNodeCount: d.Get("min_node_count").(int), - MaxNodeCount: &maxNodeCount, - } - - dockerVolumeSize := d.Get("docker_volume_size").(int) - if dockerVolumeSize != 0 { - opts.DockerVolumeSize = &dockerVolumeSize - } - - dockerVolumeType := d.Get("docker_volume_type").(string) - if dockerVolumeType != "" { - opts.DockerVolumeType = volumes.VolumeType(dockerVolumeType) - } - - clusterID := d.Get("cluster_id").(string) - results, err := pools.Create(client, clusterID, opts).Extract() - if err != nil { - return diag.FromErr(err) - } - - taskID := results.Tasks[0] - log.Printf("[DEBUG] Task id (%s)", taskID) - poolID, err := tasks.WaitTaskAndReturnResult(client, taskID, true, K8sCreateTimeout, func(task tasks.TaskID) (interface{}, error) { - taskInfo, err := tasks.Get(client, string(task)).Extract() - if err != nil { - return nil, fmt.Errorf("cannot get task with ID: %s. Error: %w", task, err) - } - poolID, err := pools.ExtractClusterPoolIDFromTask(taskInfo) - if err != nil { - return nil, fmt.Errorf("cannot retrieve k8s pool ID from task info: %w", err) - } - return poolID, nil - }, - ) - if err != nil { - return diag.FromErr(err) - } - - d.SetId(poolID.(string)) - resourceK8sPoolRead(ctx, d, m) - - log.Printf("[DEBUG] Finish K8s pool creating (%s)", poolID) - - return diags + return diag.FromErr(fmt.Errorf("resource \"edgecenter_k8s_pool\" is deprecated and unavailable")) } func resourceK8sPoolRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Println("[DEBUG] Start K8s pool reading") - var diags diag.Diagnostics - config := m.(*Config) - provider := config.Provider - - client, err := CreateClient(provider, d, K8sPoint, VersionPointV1) - if err != nil { - return diag.FromErr(err) - } - - clusterID := d.Get("cluster_id").(string) - poolID := d.Id() - - pool, err := pools.Get(client, clusterID, poolID).Extract() - if err != nil { - return diag.FromErr(err) - } - - d.Set("name", pool.Name) - d.Set("cluster_id", pool.ClusterID) - d.Set("flavor_id", pool.FlavorID) - d.Set("min_node_count", pool.MinNodeCount) - d.Set("max_node_count", pool.MaxNodeCount) - d.Set("node_count", pool.NodeCount) - d.Set("docker_volume_type", pool.DockerVolumeType.String()) - d.Set("docker_volume_size", pool.DockerVolumeSize) - d.Set("stack_id", pool.StackID) - d.Set("created_at", pool.CreatedAt.Format(time.RFC850)) - - log.Println("[DEBUG] Finish K8s pool reading") - - return diags + return diag.FromErr(fmt.Errorf("resource \"edgecenter_k8s_pool\" is deprecated and unavailable")) } func resourceK8sPoolUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Println("[DEBUG] Start K8s updating") - config := m.(*Config) - provider := config.Provider - - client, err := CreateClient(provider, d, K8sPoint, VersionPointV1) - if err != nil { - return diag.FromErr(err) - } - - poolID := d.Id() - clusterID := d.Get("cluster_id").(string) - - if d.HasChanges("name", "min_node_count", "max_node_count") { - updateOpts := pools.UpdateOpts{ - Name: d.Get("name").(string), - MinNodeCount: d.Get("min_node_count").(int), - MaxNodeCount: d.Get("max_node_count").(int), - } - results, err := pools.Update(client, clusterID, poolID, updateOpts).Extract() - if err != nil { - return diag.FromErr(err) - } - - taskID := results.Tasks[0] - _, err = tasks.WaitTaskAndReturnResult(client, taskID, true, K8sCreateTimeout, func(task tasks.TaskID) (interface{}, error) { - _, err := pools.Get(client, clusterID, poolID).Extract() - if err != nil { - return nil, fmt.Errorf("cannot get pool with ID: %s. Error: %w", poolID, err) - } - return nil, nil - }) - if err != nil { - return diag.FromErr(err) - } - } - - if d.HasChange("node_count") { - resizeOpts := clusters.ResizeOpts{ - NodeCount: d.Get("node_count").(*int), - } - results, err := clusters.Resize(client, clusterID, poolID, resizeOpts).Extract() - if err != nil { - return diag.FromErr(err) - } - - taskID := results.Tasks[0] - _, err = tasks.WaitTaskAndReturnResult(client, taskID, true, K8sCreateTimeout, func(task tasks.TaskID) (interface{}, error) { - _, err := pools.Get(client, clusterID, poolID).Extract() - if err != nil { - return nil, fmt.Errorf("cannot get pool with ID: %s. Error: %w", poolID, err) - } - return nil, nil - }) - if err != nil { - return diag.FromErr(err) - } - } - - return resourceK8sPoolRead(ctx, d, m) + return diag.FromErr(fmt.Errorf("resource \"edgecenter_k8s_pool\" is deprecated and unavailable")) } func resourceK8sPoolDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - log.Println("[DEBUG] Start K8s deleting") - var diags diag.Diagnostics - config := m.(*Config) - provider := config.Provider - - client, err := CreateClient(provider, d, K8sPoint, VersionPointV1) - if err != nil { - return diag.FromErr(err) - } - - id := d.Id() - clusterID := d.Get("cluster_id").(string) - results, err := pools.Delete(client, clusterID, id).Extract() - if err != nil { - return diag.FromErr(err) - } - - taskID := results.Tasks[0] - _, err = tasks.WaitTaskAndReturnResult(client, taskID, true, K8sCreateTimeout, func(task tasks.TaskID) (interface{}, error) { - _, err := pools.Get(client, clusterID, id).Extract() - if err == nil { - return nil, fmt.Errorf("cannot delete k8s cluster pool with ID: %s", id) - } - var errDefault404 edgecloud.Default404Error - if errors.As(err, &errDefault404) { - return nil, nil - } - return nil, fmt.Errorf("extracting Pool resource error: %w", err) - }) - if err != nil { - return diag.FromErr(err) - } - - d.SetId("") - log.Printf("[DEBUG] Finish of K8s pool deleting") - - return diags + return diag.FromErr(fmt.Errorf("resource \"edgecenter_k8s_pool\" is deprecated and unavailable")) }