Skip to content

Commit

Permalink
feat: AKS OS disk ephemeral (#446)
Browse files Browse the repository at this point in the history
* tests

* feat: support for AKS os disk ephemeral

* merge master

* tests

* tests - typo

* fix test

* tests

* tests

* tests

* fix sso tests

* tests

* make
  • Loading branch information
aldor007 authored Jan 27, 2025
1 parent e571e14 commit 6059929
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 3 deletions.
100 changes: 98 additions & 2 deletions castai/resource_node_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
FieldNodeConfigurationGKE = "gke"
FieldNodeConfigurationEKSTargetGroup = "target_group"
FieldNodeConfigurationAKSImageFamily = "aks_image_family"
FieldNodeConfigurationAKSEphemeralOSDisk = "ephemeral_os_disk"
FieldNodeConfigurationEKSImageFamily = "eks_image_family"
FieldNodeConfigurationLoadbalancers = "loadbalancers"
FieldNodeConfigurationAKSLoadbalancerIPPools = "ip_based_backend_pools"
Expand All @@ -52,8 +53,12 @@ const (
)

const (
aksImageFamilyUbuntu = "ubuntu"
aksImageFamilyAzureLinux = "azure-linux"
aksImageFamilyUbuntu = "ubuntu"
aksImageFamilyAzureLinux = "azure-linux"
aksEphemeralDiskPlacementCacheDisk = "cacheDisk"
aksEphemeralDiskPlacementResourceDisk = "resourceDisk"
aksDiskCacheReadOnly = "ReadOnly"
aksDiskCacheReadWrite = "ReadWrite"
)

func resourceNodeConfiguration() *schema.Resource {
Expand Down Expand Up @@ -332,6 +337,34 @@ func resourceNodeConfiguration() *schema.Resource {
return strings.EqualFold(oldValue, newValue)
},
},
FieldNodeConfigurationAKSEphemeralOSDisk: {
Type: schema.TypeList,
Optional: true,
Description: "Ephemeral OS disk configuration for CAST provisioned nodes",
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"placement": {
Type: schema.TypeString,
Required: true,
Description: "Placement of the ephemeral OS disk. One of: cacheDisk, resourceDisk",
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{aksEphemeralDiskPlacementCacheDisk, aksEphemeralDiskPlacementResourceDisk}, true)),
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
return strings.EqualFold(oldValue, newValue)
},
},
"cache": {
Type: schema.TypeString,
Optional: true,
Description: "Cache type for the ephemeral OS disk. One of: ReadOnly, ReadWrite",
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{aksDiskCacheReadOnly, aksDiskCacheReadWrite}, true)),
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
return strings.EqualFold(oldValue, newValue)
},
},
},
},
},
FieldNodeConfigurationLoadbalancers: {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -983,6 +1016,10 @@ func toAKSSConfig(obj map[string]interface{}) *sdk.NodeconfigV1AKSConfig {
out.OsDiskType = toAKSOSDiskType(v)
}

if v, ok := obj[FieldNodeConfigurationAKSEphemeralOSDisk].([]any); ok && len(v) > 0 {
out.OsDiskEphemeral = toAKSEphemeralOSDisk(v[0])
}

if v, ok := obj[FieldNodeConfigurationAKSImageFamily].(string); ok {
out.ImageFamily = toAKSImageFamily(v)
}
Expand All @@ -994,6 +1031,34 @@ func toAKSSConfig(obj map[string]interface{}) *sdk.NodeconfigV1AKSConfig {
return out
}

func toAKSEphemeralOSDisk(obj any) *sdk.NodeconfigV1AKSConfigOsDiskEphemeral {
if obj == nil {
return nil
}

osDisk := &sdk.NodeconfigV1AKSConfigOsDiskEphemeral{}

if v, ok := obj.(map[string]any)["placement"].(string); ok && v != "" {
switch v {
case aksEphemeralDiskPlacementResourceDisk:
osDisk.Placement = lo.ToPtr(sdk.PLACEMENTRESOURCEDISK)
case aksEphemeralDiskPlacementCacheDisk:
osDisk.Placement = lo.ToPtr(sdk.PLACEMENTCACHEDISK)
}
}

if v, ok := obj.(map[string]any)["cache"].(string); ok && v != "" {
switch v {
case aksDiskCacheReadWrite:
osDisk.CacheType = lo.ToPtr(sdk.NodeconfigV1AKSConfigOsDiskEphemeralCacheTypeREADWRITE)
case aksDiskCacheReadOnly:
osDisk.CacheType = lo.ToPtr(sdk.NodeconfigV1AKSConfigOsDiskEphemeralCacheTypeREADONLY)
}
}

return osDisk
}

func toAksLoadBalancers(obj []interface{}) *[]sdk.NodeconfigV1AKSConfigLoadBalancers {
if obj == nil {
return nil
Expand Down Expand Up @@ -1110,6 +1175,37 @@ func flattenAKSConfig(config *sdk.NodeconfigV1AKSConfig) []map[string]interface{
m[FieldNodeConfigurationLoadbalancers] = fromAksLoadBalancers(*v)
}

if v := config.OsDiskEphemeral; v != nil {
m[FieldNodeConfigurationAKSEphemeralOSDisk] = fromAKSEphemeralOSDisk(v)
}

return []map[string]interface{}{m}
}

func fromAKSEphemeralOSDisk(sdkEph *sdk.NodeconfigV1AKSConfigOsDiskEphemeral) []map[string]interface{} {
if sdkEph == nil {
return nil
}

m := map[string]interface{}{}
if sdkEph.Placement != nil {
switch *sdkEph.Placement {
case sdk.PLACEMENTRESOURCEDISK:
m["placement"] = aksEphemeralDiskPlacementResourceDisk
case sdk.PLACEMENTCACHEDISK:
m["placement"] = aksEphemeralDiskPlacementCacheDisk
}
}

if sdkEph.CacheType != nil {
switch *sdkEph.CacheType {
case sdk.NodeconfigV1AKSConfigOsDiskEphemeralCacheTypeREADWRITE:
m["cache"] = aksDiskCacheReadWrite
case sdk.NodeconfigV1AKSConfigOsDiskEphemeralCacheTypeREADONLY:
m["cache"] = aksDiskCacheReadOnly
}
}

return []map[string]interface{}{m}
}

Expand Down
6 changes: 6 additions & 0 deletions castai/resource_node_configuration_aks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func TestAccResourceNodeConfiguration_aks(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "min_disk_size", "121"),
resource.TestCheckResourceAttr(resourceName, "aks.0.max_pods_per_node", "32"),
resource.TestCheckResourceAttr(resourceName, "aks.0.aks_image_family", "azure-linux"),
resource.TestCheckResourceAttr(resourceName, "aks.0.ephemeral_os_disk.0.placement", "cacheDisk"),
resource.TestCheckResourceAttr(resourceName, "aks.0.ephemeral_os_disk.0.cache", "ReadOnly"),
resource.TestCheckResourceAttr(resourceName, "aks.0.loadbalancers.0.name", "test-lb"),
resource.TestCheckResourceAttr(resourceName, "aks.0.loadbalancers.0.ip_based_backend_pools.0.name", "test"),
resource.TestCheckResourceAttr(resourceName, "eks.#", "0"),
Expand Down Expand Up @@ -102,6 +104,10 @@ resource "castai_node_configuration" "test" {
aks {
max_pods_per_node = 32
aks_image_family = "azure-linux"
ephemeral_os_disk {
placement = "cacheDisk"
cache = "ReadOnly"
}
loadbalancers {
name = "test-lb"
ip_based_backend_pools {
Expand Down
7 changes: 6 additions & 1 deletion castai/resource_sso_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func TestSSOConnection_CreateADDConnector(t *testing.T) {
"clientSecret": "test_secret"
},
"emailDomain": "test_email",
"defaultRoleId": null,
"name": "test_sso"
}
`)
Expand Down Expand Up @@ -213,6 +214,7 @@ func TestSSOConnection_CreateADDConnector(t *testing.T) {
"clientSecret": "test_secret"
},
"emailDomain": "test_email",
"defaultRoleId": null,
"additionalEmailDomains": ["test_domain1.com", "test_domain2.com"],
"name": "test_sso"
}
Expand Down Expand Up @@ -294,6 +296,7 @@ func TestSSOConnection_CreateOktaConnector(t *testing.T) {
"clientSecret": "test_secret"
},
"emailDomain": "test_email",
"defaultRoleId": null,
"name": "test_sso"
}`)

Expand Down Expand Up @@ -391,6 +394,7 @@ func TestSSOConnection_UpdateADDConnector(t *testing.T) {
"clientId": "updated_client_id",
"clientSecret": "updated_client_secret"
},
"defaultRoleId": null,
"name": "updated_name"
}`)

Expand Down Expand Up @@ -452,7 +456,6 @@ func TestSSOConnection_UpdateADDConnector(t *testing.T) {
}
connectionID := "b6bfc074-a267-400f-b8f1-db0850c369b1"


raw := make(map[string]interface{})
raw[FieldSSOConnectionName] = "updated_name"

Expand Down Expand Up @@ -480,6 +483,7 @@ func TestSSOConnection_UpdateADDConnector(t *testing.T) {
"clientSecret": "updated_client_secret"
},
"name": "updated_name",
"defaultRoleId": null,
"additionalEmailDomains": ["updated_domain_one", "updated_domain_two"]
}`)

Expand Down Expand Up @@ -570,6 +574,7 @@ func TestSSOConnection_UpdateOktaConnector(t *testing.T) {
"clientId": "updated_client_id",
"clientSecret": "updated_client_secret"
},
"defaultRoleId": null,
"name": "updated_name"
}`)

Expand Down
18 changes: 18 additions & 0 deletions castai/sdk/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6059929

Please sign in to comment.