Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(CLOUDDEV-642): Mark k8s as deprecated #179

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
118 changes: 6 additions & 112 deletions edgecenter/data_source_edgecenter_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"))
}
49 changes: 6 additions & 43 deletions edgecenter/data_source_edgecenter_k8s_client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"))
}
64 changes: 6 additions & 58 deletions edgecenter/data_source_edgecenter_k8s_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"))
}
Loading
Loading