Skip to content

Commit

Permalink
KUBE-304: node configuration eks max pods formula (#324)
Browse files Browse the repository at this point in the history
* KUBE-304: node configuration eks max pods formula

* fix test

* regenerate doc

* fix test

* fix test

* fix test
  • Loading branch information
aldor007 authored Jun 10, 2024
1 parent 97fb27b commit 6521822
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ generate-all: generate-sdk generate-docs
.PHONY: build
build: init-examples
build: generate-sdk
build: generate-docs
build:
@echo "==> Building terraform-provider-castai"
go build
Expand Down
28 changes: 28 additions & 0 deletions castai/resource_node_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ func resourceNodeConfiguration() *schema.Resource {
Description: "AWS KMS key ARN for encrypting EBS volume attached to the node",
ValidateDiagFunc: validation.ToDiagFunc(validation.StringMatch(regexp.MustCompile(`arn:aws:kms:.*`), "Must be a valid KMS key ARN")),
},
"max_pods_per_node_formula": {
Type: schema.TypeString,
Optional: true,
Description: "Formula to calculate the maximum number of pods that can be run on a node.",
},
"ips_per_prefix": {
Type: schema.TypeInt,
Optional: true,
Default: nil,
Description: "Number of IPs per prefix to be used for calculating max pods.",
ValidateDiagFunc: validation.ToDiagFunc(validation.IntBetween(0, 256)),
},
FieldNodeConfigurationEKSTargetGroup: {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -646,6 +658,14 @@ func toEKSConfig(obj map[string]interface{}) *sdk.NodeconfigV1EKSConfig {
out.VolumeKmsKeyArn = toPtr(v)
}

if v, ok := obj["max_pods_per_node_formula"].(string); ok && v != "" {
out.MaxPodsPerNodeFormula = toPtr(v)
}

if v, ok := obj["ips_per_prefix"].(int); ok && v != 0 {
out.IpsPerPrefix = toPtr(int32(v))
}

if v, ok := obj[FieldNodeConfigurationEKSTargetGroup].([]interface{}); ok && len(v) > 0 && v[0] != nil {
if e, ok := v[0].(map[string]interface{}); ok {
out.TargetGroup = &sdk.NodeconfigV1TargetGroup{}
Expand Down Expand Up @@ -698,6 +718,14 @@ func flattenEKSConfig(config *sdk.NodeconfigV1EKSConfig) []map[string]interface{
m["volume_kms_key_arn"] = toString(config.VolumeKmsKeyArn)
}

if v := config.MaxPodsPerNodeFormula; v != nil {
m["max_pods_per_node_formula"] = toString(config.MaxPodsPerNodeFormula)
}

if v := config.IpsPerPrefix; v != nil {
m["ips_per_prefix"] = *config.IpsPerPrefix
}

if v := config.TargetGroup; v != nil {
if v.Arn != nil {
if v.Port != nil {
Expand Down
8 changes: 8 additions & 0 deletions castai/resource_node_configuration_eks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func TestAccResourceNodeConfiguration_eks(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "eks.0.imds_hop_limit", "3"),
resource.TestCheckResourceAttr(resourceName, "eks.0.volume_kms_key_arn", "arn:aws:kms:eu-central-1:012345:key/1d989ee1-59cd-4238-8018-79bae29d1109"),
resource.TestCheckResourceAttr(resourceName, "eks.0.target_group.#", "1"),
resource.TestCheckResourceAttr(resourceName, "eks.0.max_pods_per_node_formula", "NUM_IP_PER_PREFIX-NUM_MAX_NET_INTERFACES"),
resource.TestCheckResourceAttr(resourceName, "eks.0.ips_per_prefix", "4"),
resource.TestCheckResourceAttr(resourceName, "eks.0.target_group.0.arn", "arn:aws:test"),
resource.TestCheckResourceAttr(resourceName, "aks.#", "0"),
resource.TestCheckResourceAttr(resourceName, "kops.#", "0"),
Expand Down Expand Up @@ -78,6 +80,8 @@ func TestAccResourceNodeConfiguration_eks(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "eks.0.dns_cluster_ip", ""),
resource.TestCheckResourceAttr(resourceName, "eks.0.security_groups.#", "1"),
resource.TestCheckResourceAttr(resourceName, "eks.0.volume_throughput", "130"),
resource.TestCheckResourceAttr(resourceName, "eks.0.max_pods_per_node_formula", "NUM_IP_PER_PREFIX+NUM_MAX_NET_INTERFACES"),
resource.TestCheckResourceAttr(resourceName, "eks.0.ips_per_prefix", "3"),
resource.TestCheckResourceAttr(resourceName, "eks.0.target_group.#", "1"),
resource.TestCheckResourceAttr(resourceName, "eks.0.target_group.0.arn", "arn:aws:test2"),
resource.TestCheckResourceAttr(resourceName, "eks.0.target_group.0.port", "80"),
Expand Down Expand Up @@ -132,6 +136,8 @@ resource "castai_node_configuration" "test" {
volume_kms_key_arn = "arn:aws:kms:eu-central-1:012345:key/1d989ee1-59cd-4238-8018-79bae29d1109"
imds_v1 = true
imds_hop_limit = 3
max_pods_per_node_formula = "NUM_IP_PER_PREFIX-NUM_MAX_NET_INTERFACES"
ips_per_prefix = 4
target_group {
arn = "arn:aws:test"
}
Expand Down Expand Up @@ -161,6 +167,8 @@ resource "castai_node_configuration" "test" {
instance_profile_arn = aws_iam_instance_profile.test.arn
security_groups = [aws_security_group.test.id]
volume_throughput = 130
max_pods_per_node_formula = "NUM_IP_PER_PREFIX+NUM_MAX_NET_INTERFACES"
ips_per_prefix = 3
target_group {
arn = "arn:aws:test2"
port = 80
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/node_configuration.md

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

0 comments on commit 6521822

Please sign in to comment.