Skip to content

Commit

Permalink
chore(CLOUDDEV-642): Raise error for K8s data sources and resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandr Semenov committed Dec 5, 2024
1 parent 5b1f206 commit 0e72dd6
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 711 deletions.
3 changes: 3 additions & 0 deletions docs/data-sources/k8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion docs/data-sources/k8s_client_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions docs/data-sources/k8s_pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion docs/resources/k8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion docs/resources/k8s_pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
114 changes: 3 additions & 111 deletions edgecenter/data_source_edgecenter_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -224,108 +219,5 @@ func dataSourceK8s() *schema.Resource {
}

func dataSourceK8sRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {

Check failure on line 221 in edgecenter/data_source_edgecenter_k8s.go

View workflow job for this annotation

GitHub Actions / build

unused-parameter: parameter 'd' seems to be unused, consider removing or renaming it as _ (revive)
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"))
}
45 changes: 3 additions & 42 deletions edgecenter/data_source_edgecenter_k8s_client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -60,41 +57,5 @@ func dataSourceK8sClientConfig() *schema.Resource {
}

func dataSourceK8sReadClientConfig(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {

Check failure on line 59 in edgecenter/data_source_edgecenter_k8s_client_config.go

View workflow job for this annotation

GitHub Actions / build

unused-parameter: parameter 'd' seems to be unused, consider removing or renaming it as _ (revive)
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"))
}
60 changes: 3 additions & 57 deletions edgecenter/data_source_edgecenter_k8s_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -122,55 +118,5 @@ func dataSourceK8sPool() *schema.Resource {
}

func dataSourceK8sPoolRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {

Check failure on line 120 in edgecenter/data_source_edgecenter_k8s_pool.go

View workflow job for this annotation

GitHub Actions / build

unused-parameter: parameter 'd' seems to be unused, consider removing or renaming it as _ (revive)
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"))
}
Loading

0 comments on commit 0e72dd6

Please sign in to comment.