Skip to content

nodepools: public ip assignments #379

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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/sks_nodepool.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ description: |-
- `labels` (Map of String) A map of key/value labels.
- `name` (String)
- `private_network_ids` (Set of String) A list of [exoscale_private_network](./private_network.md) (IDs) to be attached to the managed instances.
- `public_ip_assignment` (String) Configures public IP assignment of the Instances with:
* IPv4 ('inet4') addressing only (default);
* both IPv4 and IPv6 ('dual') addressing.
- `security_group_ids` (Set of String) A list of [exoscale_security_group](./security_group.md) (IDs) to be attached to the managed instances.
- `size` (Number)
- `state` (String) The current pool state.
Expand Down
2 changes: 2 additions & 0 deletions docs/data-sources/sks_nodepool_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ description: |-
- `instance_type` (String) Match against this string. If you supply a string that begins and ends with a "/" it will be matched as a regex.
- `labels` (Map of String) Match against key/values. Keys are matched exactly, while values may be matched as a regex if you supply a string that begins and ends with "/"
- `name` (String) Match against this string. If you supply a string that begins and ends with a "/" it will be matched as a regex.
- `public_ip_assignment` (String) Match against this string. If you supply a string that begins and ends with a "/" it will be matched as a regex.
- `size` (Number) Match against this int
- `state` (String) Match against this string. If you supply a string that begins and ends with a "/" it will be matched as a regex.
- `storage_lvm` (Boolean) Match against this bool
Expand Down Expand Up @@ -62,6 +63,7 @@ Read-Only:
- `labels` (Map of String)
- `name` (String)
- `private_network_ids` (Set of String)
- `public_ip_assignment` (String)
- `security_group_ids` (Set of String)
- `size` (Number)
- `state` (String)
Expand Down
3 changes: 3 additions & 0 deletions docs/resources/sks_nodepool.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ directory for complete configuration examples.
- `kubelet_image_gc` (Block Set) Configuration for this nodepool's kubelet image garbage collector (see [below for nested schema](#nestedblock--kubelet_image_gc))
- `labels` (Map of String) A map of key/value labels.
- `private_network_ids` (Set of String) A list of [exoscale_private_network](./private_network.md) (IDs) to be attached to the managed instances.
- `public_ip_assignment` (String) Configures public IP assignment of the Instances with:
* IPv4 ('inet4') addressing only (default);
* both IPv4 and IPv6 ('dual') addressing.
- `security_group_ids` (Set of String) A list of [exoscale_security_group](./security_group.md) (IDs) to be attached to the managed instances.
- `storage_lvm` (Boolean) Create nodes with non-standard partitioning for persistent storage (requires min 100G of disk space) (may only be set at creation time).
- `taints` (Map of String) A map of key/value Kubernetes [taints](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/) ('taints = { <key> = "<value>:<effect>" }').
Expand Down
57 changes: 30 additions & 27 deletions exoscale/datasource_exoscale_sks_nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

v2 "github.com/exoscale/egoscale/v2"
exoapi "github.com/exoscale/egoscale/v2/api"
v3 "github.com/exoscale/egoscale/v3"
"github.com/exoscale/terraform-provider-exoscale/pkg/config"
"github.com/exoscale/terraform-provider-exoscale/pkg/filter"
"github.com/exoscale/terraform-provider-exoscale/pkg/general"
)
Expand Down Expand Up @@ -50,27 +50,28 @@ func dataSourceSKSNodepool() *schema.Resource {
return ret
}

func nodepoolToDataMap(nodepool *v2.SKSNodepool) general.TerraformObject {
func nodepoolToDataMap(nodepool *v3.SKSNodepool) general.TerraformObject {
ret := make(general.TerraformObject)

general.Assign(ret, resSKSNodepoolAttrAntiAffinityGroupIDs, nodepool.AntiAffinityGroupIDs)
general.AssignTime(ret, resSKSNodepoolAttrCreatedAt, nodepool.CreatedAt)
general.Assign(ret, resSKSNodepoolAttrDeployTargetID, nodepool.DeployTargetID)
general.Assign(ret, resSKSNodepoolAttrDescription, nodepool.Description)
general.Assign(ret, resSKSNodepoolAttrDiskSize, nodepool.DiskSize)
general.Assign(ret, resSKSNodepoolAttrInstancePoolID, nodepool.InstancePoolID)
general.Assign(ret, resSKSNodepoolAttrInstancePrefix, nodepool.InstancePrefix)
general.Assign(ret, resSKSNodepoolAttrInstanceType, nodepool.InstanceTypeID)
general.Assign(ret, resSKSNodepoolAttrLabels, nodepool.Labels)
general.Assign(ret, resSKSNodepoolAttrName, nodepool.Name)
general.Assign(ret, resSKSNodepoolAttrPrivateNetworkIDs, nodepool.PrivateNetworkIDs)
general.Assign(ret, resSKSNodepoolAttrSecurityGroupIDs, nodepool.SecurityGroupIDs)
general.Assign(ret, resSKSNodepoolAttrSize, nodepool.Size)
general.Assign(ret, resSKSNodepoolAttrState, nodepool.State)
general.Assign(ret, resSKSNodepoolAttrTaints, nodepool.Taints)
general.Assign(ret, resSKSNodepoolAttrTemplateID, nodepool.TemplateID)
general.Assign(ret, resSKSNodepoolAttrVersion, nodepool.Version)
general.Assign(ret, dsSKSNodepoolID, nodepool.ID)
general.Assign(ret, resSKSNodepoolAttrAntiAffinityGroupIDs, &nodepool.AntiAffinityGroups)
general.AssignTime(ret, resSKSNodepoolAttrCreatedAt, &nodepool.CreatedAT)
general.Assign(ret, resSKSNodepoolAttrDeployTargetID, &nodepool.DeployTarget.ID)
general.Assign(ret, resSKSNodepoolAttrDescription, &nodepool.Description)
general.Assign(ret, resSKSNodepoolAttrDiskSize, &nodepool.DiskSize)
general.Assign(ret, resSKSNodepoolAttrInstancePoolID, &nodepool.InstancePool.ID)
general.Assign(ret, resSKSNodepoolAttrInstancePrefix, &nodepool.InstancePrefix)
general.Assign(ret, resSKSNodepoolAttrInstanceType, &nodepool.InstanceType.ID)
general.Assign(ret, resSKSNodepoolAttrLabels, &nodepool.Labels)
general.Assign(ret, resSKSNodepoolAttrName, &nodepool.Name)
general.Assign(ret, resSKSNodepoolAttrPrivateNetworkIDs, &nodepool.PrivateNetworks)
general.Assign(ret, resSKSNodepoolAttrPublicIPAssignment, &nodepool.PublicIPAssignment)
general.Assign(ret, resSKSNodepoolAttrSecurityGroupIDs, &nodepool.SecurityGroups)
general.Assign(ret, resSKSNodepoolAttrSize, &nodepool.Size)
general.Assign(ret, resSKSNodepoolAttrState, &nodepool.State)
general.Assign(ret, resSKSNodepoolAttrTaints, &nodepool.Taints)
general.Assign(ret, resSKSNodepoolAttrTemplateID, &nodepool.Template.ID)
general.Assign(ret, resSKSNodepoolAttrVersion, &nodepool.Version)
general.Assign(ret, dsSKSNodepoolID, &nodepool.ID)

return ret
}
Expand All @@ -83,13 +84,15 @@ func dataSourceSKSNodepoolRead(ctx context.Context, d *schema.ResourceData, meta
zone := d.Get(resSKSClusterAttrZone).(string)

ctx, cancel := context.WithTimeout(ctx, d.Timeout(schema.TimeoutRead))
ctx = exoapi.WithEndpoint(ctx, exoapi.NewReqEndpoint(getEnvironment(meta), zone))
defer cancel()

client := getClient(meta)
client, err := config.GetClientV3WithZone(ctx, meta, zone)
if err != nil {
return diag.FromErr(err)
}

clusterID := d.Get(resSKSNodepoolAttrClusterID).(string)
cluster, err := client.GetSKSCluster(ctx, zone, clusterID)
clusterID := v3.UUID(d.Get(resSKSNodepoolAttrClusterID).(string))
cluster, err := client.GetSKSCluster(ctx, clusterID)
if err != nil {
return diag.Errorf("error getting cluster %q: %s", clusterID, err)
}
Expand All @@ -103,12 +106,12 @@ func dataSourceSKSNodepoolRead(ctx context.Context, d *schema.ResourceData, meta
nMatches := 0

for _, nodepool := range cluster.Nodepools {
nodepoolData := nodepoolToDataMap(nodepool)
nodepoolData := nodepoolToDataMap(&nodepool)
nodepoolData[resSKSNodepoolAttrClusterID] = clusterID
nodepoolData[resSKSNodepoolAttrZone] = zone
if filter.CheckForMatch(nodepoolData, filters) {
if nMatches < 1 {
d.SetId(*nodepool.ID)
d.SetId(nodepool.ID.String())

matchingNodePool = nodepoolData

Expand Down
29 changes: 21 additions & 8 deletions exoscale/datasource_exoscale_sks_nodepool_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

v2 "github.com/exoscale/egoscale/v2"
v3 "github.com/exoscale/egoscale/v3"
"github.com/exoscale/terraform-provider-exoscale/pkg/config"
"github.com/exoscale/terraform-provider-exoscale/pkg/general"
"github.com/exoscale/terraform-provider-exoscale/pkg/list"
)
Expand All @@ -27,28 +28,40 @@ func dataSourceSKSNodepoolList() *schema.Resource {
return list.FilterableListDataSource(dsSKSNodepoolsListIdentifier, dsSKSNodepoolsListAttributeIdentifier, resSKSNodepoolAttrZone, getNodepoolList, nodepoolToDataMap, generateSKSNodepoolListID, dataSourceSKSNodepoolListGetElementScheme)
}

func generateSKSNodepoolListID(nodepools []*v2.SKSNodepool) string {
func generateSKSNodepoolListID(nodepools []*v3.SKSNodepool) string {
ids := make([]string, 0, len(nodepools))

for _, cluster := range nodepools {
ids = append(ids, *cluster.ID)
ids = append(ids, cluster.ID.String())
}

sort.Strings(ids)

return fmt.Sprintf("%x", md5.Sum([]byte(strings.Join(ids, ""))))
}

func getNodepoolList(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*v2.SKSNodepool, error) {
clusters, err := getClusterList(ctx, d, meta)
func getNodepoolList(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*v3.SKSNodepool, error) {
zone := d.Get(resSKSClusterAttrZone).(string)

ctx, cancel := context.WithTimeout(ctx, d.Timeout(schema.TimeoutRead))
defer cancel()

client, err := config.GetClientV3WithZone(ctx, meta, zone)
if err != nil {
return nil, err
}

var nodepools []*v2.SKSNodepool
clusters, err := client.ListSKSClusters(ctx)
if err != nil {
return nil, fmt.Errorf("error getting cluster list from zone %q: %s", zone, err)
}

var nodepools []*v3.SKSNodepool

for _, cluster := range clusters {
nodepools = append(nodepools, cluster.Nodepools...)
for _, cluster := range clusters.SKSClusters {
for _, np := range cluster.Nodepools {
nodepools = append(nodepools, &np)
}
}

return nodepools, nil
Expand Down
Loading
Loading