From 1cb306efec7ec66e9db83f9ba6227462021efc2e Mon Sep 17 00:00:00 2001 From: Aleksandr Semenov Date: Thu, 5 Dec 2024 13:10:21 +0300 Subject: [PATCH] chore(CLOUDDEV-642): Mark k8s as deprecated --- 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 | 118 +------ ...ata_source_edgecenter_k8s_client_config.go | 49 +-- edgecenter/data_source_edgecenter_k8s_pool.go | 64 +--- edgecenter/resource_edgecenter_k8s.go | 321 +----------------- edgecenter/resource_edgecenter_k8s_pool.go | 220 +----------- edgecenter/utils_k8s.go | 48 ++- 11 files changed, 85 insertions(+), 756 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 11b392d2..265fb5e3 100644 --- a/edgecenter/data_source_edgecenter_k8s.go +++ b/edgecenter/data_source_edgecenter_k8s.go @@ -2,20 +2,17 @@ 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{ - ReadContext: dataSourceK8sRead, - Description: "Represent k8s cluster with one default pool.", + 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.\n\n **WARNING:** Data source \"edgecenter_k8s\" is deprecated and unavailable.", Schema: map[string]*schema.Schema{ "project_id": { Type: schema.TypeInt, @@ -222,109 +219,6 @@ 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 +func dataSourceK8sRead(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { + 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 83aa7dcb..b7ce5fd3 100644 --- a/edgecenter/data_source_edgecenter_k8s_client_config.go +++ b/edgecenter/data_source_edgecenter_k8s_client_config.go @@ -2,18 +2,17 @@ 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{ - ReadContext: dataSourceK8sReadClientConfig, - Description: "Represent k8s cluster with one default pool.", + 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. \n\n **WARNING:** Data source \"edgecenter_k8s_client_config\" is deprecated and unavailable.", Schema: map[string]*schema.Schema{ "project_id": { Type: schema.TypeInt, @@ -58,42 +57,6 @@ 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 +func dataSourceK8sReadClientConfig(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { + 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 9ac6255b..ea16429a 100644 --- a/edgecenter/data_source_edgecenter_k8s_pool.go +++ b/edgecenter/data_source_edgecenter_k8s_pool.go @@ -2,19 +2,17 @@ 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{ - ReadContext: dataSourceK8sPoolRead, - Description: "Represent k8s cluster's pool.", + 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.\n\n **WARNING:** Data source \"edgecenter_k8s_pool\" is deprecated and unavailable.", Schema: map[string]*schema.Schema{ "project_id": { Type: schema.TypeInt, @@ -120,56 +118,6 @@ 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 +func dataSourceK8sPoolRead(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { + 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 84705c1f..3f656654 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 ( @@ -27,11 +18,12 @@ var k8sCreateTimeout = time.Second * time.Duration(K8sCreateTimeout) func resourceK8s() *schema.Resource { return &schema.Resource{ - CreateContext: resourceK8sCreate, - ReadContext: resourceK8sRead, - UpdateContext: resourceK8sUpdate, - DeleteContext: resourceK8sDelete, - Description: "Represent k8s cluster with one default pool.", + DeprecationMessage: "!> **WARNING:** This resource is deprecated and will be removed in the next major version. Resource \"edgecenter_k8s\" unavailable.", + CreateContext: resourceK8sCreate, + ReadContext: resourceK8sRead, + UpdateContext: resourceK8sUpdate, + DeleteContext: resourceK8sDelete, + 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, @@ -271,303 +263,18 @@ 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 +func resourceK8sCreate(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { + 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 +func resourceK8sRead(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { + 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) +func resourceK8sUpdate(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { + 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 +func resourceK8sDelete(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { + 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 ed7c0654..909e3d2b 100644 --- a/edgecenter/resource_edgecenter_k8s_pool.go +++ b/edgecenter/resource_edgecenter_k8s_pool.go @@ -2,28 +2,20 @@ 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 { return &schema.Resource{ - CreateContext: resourceK8sPoolCreate, - ReadContext: resourceK8sPoolRead, - UpdateContext: resourceK8sPoolUpdate, - DeleteContext: resourceK8sPoolDelete, - Description: "Represent k8s cluster's pool.", + DeprecationMessage: "!> **WARNING:** This resource is deprecated and will be removed in the next major version. Resource \"edgecenter_k8s_pool\" unavailable.", + CreateContext: resourceK8sPoolCreate, + ReadContext: resourceK8sPoolRead, + UpdateContext: resourceK8sPoolUpdate, + DeleteContext: resourceK8sPoolDelete, + Description: "Represent k8s cluster's pool. \n\n **WARNING:** Resource \"edgecenter_k8s_pool\" is deprecated and unavailable.", Timeouts: &schema.ResourceTimeout{ Create: &k8sCreateTimeout, Update: &k8sCreateTimeout, @@ -129,202 +121,18 @@ 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 +func resourceK8sPoolCreate(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { + 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 +func resourceK8sPoolRead(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { + 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) +func resourceK8sPoolUpdate(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { + 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 +func resourceK8sPoolDelete(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { + return diag.FromErr(fmt.Errorf("resource \"edgecenter_k8s_pool\" is deprecated and unavailable")) } diff --git a/edgecenter/utils_k8s.go b/edgecenter/utils_k8s.go index f53d77bd..7cdfa80a 100644 --- a/edgecenter/utils_k8s.go +++ b/edgecenter/utils_k8s.go @@ -1,24 +1,17 @@ package edgecenter -import ( - "net" - - "gopkg.in/yaml.v3" - - edgecloud "github.com/Edge-Center/edgecentercloud-go" -) - -func parseCIDRFromString(cidr string) (edgecloud.CIDR, error) { - var ecCIDR edgecloud.CIDR - _, netIPNet, err := net.ParseCIDR(cidr) - if err != nil { - return ecCIDR, err - } - ecCIDR.IP = netIPNet.IP - ecCIDR.Mask = netIPNet.Mask - - return ecCIDR, nil -} +// Temporary comment by CLOUDDEV-642 +// func parseCIDRFromString(cidr string) (edgecloud.CIDR, error) { +// var ecCIDR edgecloud.CIDR +// _, netIPNet, err := net.ParseCIDR(cidr) +// if err != nil { +// return ecCIDR, err +// } +// ecCIDR.IP = netIPNet.IP +// ecCIDR.Mask = netIPNet.Mask +// +// return ecCIDR, nil +// } type K8sConfig struct { APIVersion string `yaml:"apiVersion"` @@ -51,11 +44,12 @@ type K8sConfig struct { } `yaml:"users"` } -func parseK8sConfig(data string) (*K8sConfig, error) { - var config K8sConfig - err := yaml.Unmarshal([]byte(data), &config) - if err != nil { - return nil, err - } - return &config, nil -} +// Temporary comment by CLOUDDEV-642 +// func parseK8sConfig(data string) (*K8sConfig, error) { +// var config K8sConfig +// err := yaml.Unmarshal([]byte(data), &config) +// if err != nil { +// return nil, err +// } +// return &config, nil +// }