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

feat: Support CPU manufacturer node template constraint #367

Merged
merged 4 commits into from
Aug 22, 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
12 changes: 6 additions & 6 deletions castai/resource_node_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,11 +717,11 @@ func toEKSImageFamily(v string) *sdk.NodeconfigV1EKSConfigImageFamily {

switch strings.ToLower(v) {
case eksImageFamilyAL2:
return lo.ToPtr(sdk.FAMILYAL2)
return lo.ToPtr(sdk.NodeconfigV1EKSConfigImageFamilyFamilyAl2)
case eksImageFamilyAL2023:
return lo.ToPtr(sdk.FAMILYAL2023)
return lo.ToPtr(sdk.NodeconfigV1EKSConfigImageFamilyFAMILYAL2023)
case eksImageFamilyBottlerocket:
return lo.ToPtr(sdk.FAMILYBOTTLEROCKET)
return lo.ToPtr(sdk.NodeconfigV1EKSConfigImageFamilyFAMILYBOTTLEROCKET)
default:
return nil
}
Expand Down Expand Up @@ -801,11 +801,11 @@ func flattenEKSConfig(config *sdk.NodeconfigV1EKSConfig) []map[string]interface{

func fromEKSImageFamily(family sdk.NodeconfigV1EKSConfigImageFamily) string {
switch family {
case sdk.FAMILYBOTTLEROCKET, sdk.FamilyBottlerocket:
case sdk.NodeconfigV1EKSConfigImageFamilyFAMILYBOTTLEROCKET, sdk.NodeconfigV1EKSConfigImageFamilyFamilyBottlerocket:
return eksImageFamilyBottlerocket
case sdk.FAMILYAL2, sdk.FamilyAl2:
case sdk.NodeconfigV1EKSConfigImageFamilyFAMILYAL2, sdk.NodeconfigV1EKSConfigImageFamilyFamilyAl2:
return eksImageFamilyAL2
case sdk.FAMILYAL2023, sdk.FamilyAl2023:
case sdk.NodeconfigV1EKSConfigImageFamilyFAMILYAL2023, sdk.NodeconfigV1EKSConfigImageFamilyFamilyAl2023:
return eksImageFamilyAL2023
default:
return ""
Expand Down
21 changes: 21 additions & 0 deletions castai/resource_node_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const (
FieldNodeTemplateAffinityValuesName = "values"
FieldNodeTemplateBurstableInstances = "burstable_instances"
FieldNodeTemplateCustomerSpecific = "customer_specific"
FieldNodeTemplateCPUManufacturers = "cpu_manufacturers"
)

const (
Expand Down Expand Up @@ -116,6 +117,7 @@ func resourceNodeTemplate() *schema.Resource {
supportedArchitectures := []string{ArchAMD64, ArchARM64}
supportedOs := []string{OsLinux, OsWindows}
supportedSelectorOperations := nodeSelectorOperators
supportedCPUManufacturers := []string{string(sdk.AMD), string(sdk.AMPERE), string(sdk.APPLE), string(sdk.AWS), string(sdk.INTEL)}

return &schema.Resource{
CreateContext: resourceNodeTemplateCreate,
Expand Down Expand Up @@ -498,6 +500,16 @@ func resourceNodeTemplate() *schema.Resource {
Description: "Will include customer specific (preview) instances when enabled otherwise they will be excluded. Supported values: `enabled`, `disabled` or ``.",
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"", Enabled, Disabled}, false)),
},
FieldNodeTemplateCPUManufacturers: {
Type: schema.TypeList,
MinItems: 1,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice(supportedCPUManufacturers, false)),
},
Description: fmt.Sprintf("List of acceptable CPU manufacturers. Allowed values: %s.", strings.Join(supportedCPUManufacturers, ", ")),
},
},
},
},
Expand Down Expand Up @@ -714,6 +726,9 @@ func flattenConstraints(c *sdk.NodetemplatesV1TemplateConstraints) ([]map[string
if c.Azs != nil {
out[FieldNodeTemplateAZs] = lo.FromPtr(c.Azs)
}
if c.CpuManufacturers != nil {
out[FieldNodeTemplateCPUManufacturers] = lo.FromPtr(c.CpuManufacturers)
}
setStateConstraintValue(c.Burstable, FieldNodeTemplateBurstableInstances, out)
setStateConstraintValue(c.CustomerSpecific, FieldNodeTemplateCustomerSpecific, out)
return []map[string]any{out}, nil
Expand Down Expand Up @@ -1289,6 +1304,12 @@ func toTemplateConstraints(obj map[string]any) *sdk.NodetemplatesV1TemplateConst
}
}

if v, ok := obj[FieldNodeTemplateCPUManufacturers].([]any); ok {
out.CpuManufacturers = toPtr(lo.Map(v, func(item any, _ int) sdk.NodetemplatesV1TemplateConstraintsCPUManufacturer {
return sdk.NodetemplatesV1TemplateConstraintsCPUManufacturer(item.(string))
}))
}

return out
}

Expand Down
16 changes: 15 additions & 1 deletion castai/resource_node_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func TestNodeTemplateResourceReadContext(t *testing.T) {
}
]
}
]
],
"cpuManufacturers": ["INTEL", "AMD"]
},
"version": "3",
"shouldTaint": true,
Expand Down Expand Up @@ -161,6 +162,9 @@ constraints.0.azs.1 = us-west-2b
constraints.0.azs.2 = us-west-2c
constraints.0.compute_optimized = false
constraints.0.compute_optimized_state = disabled
constraints.0.cpu_manufacturers.# = 2
constraints.0.cpu_manufacturers.0 = INTEL
constraints.0.cpu_manufacturers.1 = AMD
constraints.0.custom_priority.# = 1
constraints.0.custom_priority.0.instance_families.# = 2
constraints.0.custom_priority.0.instance_families.0 = a
Expand Down Expand Up @@ -556,6 +560,9 @@ func TestAccResourceNodeTemplate_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "constraints.0.dedicated_node_affinity.#", "0"),
resource.TestCheckResourceAttr(resourceName, "constraints.0.storage_optimized_state", "disabled"),
resource.TestCheckResourceAttr(resourceName, "constraints.0.compute_optimized_state", ""),
resource.TestCheckResourceAttr(resourceName, "constraints.0.cpu_manufacturers.#", "2"),
resource.TestCheckResourceAttr(resourceName, "constraints.0.cpu_manufacturers.0", "INTEL"),
resource.TestCheckResourceAttr(resourceName, "constraints.0.cpu_manufacturers.1", "AMD"),
),
},
{
Expand Down Expand Up @@ -622,6 +629,9 @@ func TestAccResourceNodeTemplate_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "constraints.0.compute_optimized_state", "disabled"),
resource.TestCheckResourceAttr(resourceName, "constraints.0.burstable_instances", "enabled"),
resource.TestCheckResourceAttr(resourceName, "constraints.0.customer_specific", "enabled"),
resource.TestCheckResourceAttr(resourceName, "constraints.0.cpu_manufacturers.#", "2"),
resource.TestCheckResourceAttr(resourceName, "constraints.0.cpu_manufacturers.0", "INTEL"),
resource.TestCheckResourceAttr(resourceName, "constraints.0.cpu_manufacturers.1", "AMD"),
),
},
},
Expand Down Expand Up @@ -696,6 +706,8 @@ func testAccNodeTemplateConfig(rName, clusterName string) string {
spot = true
on_demand = true
}

cpu_manufacturers = ["INTEL", "AMD"]
}
}
`, rName))
Expand Down Expand Up @@ -750,6 +762,8 @@ func testNodeTemplateUpdated(rName, clusterName string) string {
spot = true
on_demand = true
}

cpu_manufacturers = ["INTEL", "AMD"]
}
}
`, rName))
Expand Down
9 changes: 5 additions & 4 deletions castai/resource_organization_members.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"fmt"
"time"

"github.com/castai/terraform-provider-castai/castai/sdk"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/samber/lo"

"github.com/castai/terraform-provider-castai/castai/sdk"
)

const (
Expand Down Expand Up @@ -142,7 +143,7 @@ func resourceOrganizationMembersRead(ctx context.Context, data *schema.ResourceD
client := meta.(*ProviderConfig).api

organizationID := data.Id()
usersResp, err := client.UsersAPIListOrganizationUsersWithResponse(ctx, organizationID)
usersResp, err := client.UsersAPIListOrganizationUsersWithResponse(ctx, organizationID, &sdk.UsersAPIListOrganizationUsersParams{})
Copy link
Contributor

@vladklokun vladklokun Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question(non-blocking): just to confirm, these are changes required by the newly generated SDK, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

if err := sdk.CheckOKResponse(usersResp, err); err != nil {
return diag.FromErr(fmt.Errorf("retrieving users: %w", err))
}
Expand Down Expand Up @@ -208,7 +209,7 @@ func resourceOrganizationMembersUpdate(ctx context.Context, data *schema.Resourc
client := meta.(*ProviderConfig).api
organizationID := data.Id()

usersResp, err := client.UsersAPIListOrganizationUsersWithResponse(ctx, organizationID)
usersResp, err := client.UsersAPIListOrganizationUsersWithResponse(ctx, organizationID, &sdk.UsersAPIListOrganizationUsersParams{})
if err := sdk.CheckOKResponse(usersResp, err); err != nil {
return diag.FromErr(fmt.Errorf("retrieving users: %w", err))
}
Expand Down Expand Up @@ -308,7 +309,7 @@ func resourceOrganizationMembersDelete(ctx context.Context, data *schema.Resourc
return diag.FromErr(fmt.Errorf("retrieving current user profile: %w", err))
}

usersResp, err := client.UsersAPIListOrganizationUsersWithResponse(ctx, organizationID)
usersResp, err := client.UsersAPIListOrganizationUsersWithResponse(ctx, organizationID, &sdk.UsersAPIListOrganizationUsersParams{})
if err := sdk.CheckOKResponse(usersResp, err); err != nil {
return diag.FromErr(fmt.Errorf("retrieving users: %w", err))
}
Expand Down
2 changes: 1 addition & 1 deletion castai/resource_organization_members_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestOrganizationResourceReadContext(t *testing.T) {
"invitations": []
}`)))
mockClient.EXPECT().
UsersAPIListOrganizationUsers(gomock.Any(), organizationID).
UsersAPIListOrganizationUsers(gomock.Any(), organizationID, &sdk.UsersAPIListOrganizationUsersParams{}).
Return(&http.Response{StatusCode: 200, Body: body, Header: map[string][]string{"Content-Type": {"json"}}}, nil)

mockClient.EXPECT().
Expand Down
88 changes: 66 additions & 22 deletions castai/sdk/api.gen.go

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

Loading
Loading