Skip to content

Commit

Permalink
Merge branch 'master' into WIRE-837-role-bindings-support
Browse files Browse the repository at this point in the history
# Conflicts:
#	castai/provider.go
  • Loading branch information
oskarwojciski committed Dec 9, 2024
2 parents b284bcf + 1cd3c96 commit 70d483c
Show file tree
Hide file tree
Showing 7 changed files with 1,197 additions and 45 deletions.
1 change: 1 addition & 0 deletions castai/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func Provider(version string) *schema.Provider {
"castai_organization_members": resourceOrganizationMembers(),
"castai_sso_connection": resourceSSOConnection(),
"castai_workload_scaling_policy": resourceWorkloadScalingPolicy(),
"castai_organization_group": resourceOrganizationGroup(),
"castai_role_bindings": resourceRoleBindings(),
},

Expand Down
140 changes: 100 additions & 40 deletions castai/resource_node_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,28 @@ import (
)

const (
FieldNodeConfigurationName = "name"
FieldNodeConfigurationDiskCpuRatio = "disk_cpu_ratio"
FieldNodeConfigurationMinDiskSize = "min_disk_size"
FieldNodeConfigurationDrainTimeoutSec = "drain_timeout_sec"
FieldNodeConfigurationSubnets = "subnets"
FieldNodeConfigurationSSHPublicKey = "ssh_public_key"
FieldNodeConfigurationImage = "image"
FieldNodeConfigurationTags = "tags"
FieldNodeConfigurationInitScript = "init_script"
FieldNodeConfigurationContainerRuntime = "container_runtime"
FieldNodeConfigurationDockerConfig = "docker_config"
FieldNodeConfigurationKubeletConfig = "kubelet_config"
FieldNodeConfigurationAKS = "aks"
FieldNodeConfigurationEKS = "eks"
FieldNodeConfigurationKOPS = "kops"
FieldNodeConfigurationGKE = "gke"
FieldNodeConfigurationEKSTargetGroup = "target_group"
FieldNodeConfigurationAKSImageFamily = "aks_image_family"
FieldNodeConfigurationEKSImageFamily = "eks_image_family"
FieldNodeConfigurationLoadbalancers = "loadbalancers"
FieldNodeConfigurationName = "name"
FieldNodeConfigurationDiskCpuRatio = "disk_cpu_ratio"
FieldNodeConfigurationMinDiskSize = "min_disk_size"
FieldNodeConfigurationDrainTimeoutSec = "drain_timeout_sec"
FieldNodeConfigurationSubnets = "subnets"
FieldNodeConfigurationSSHPublicKey = "ssh_public_key"
FieldNodeConfigurationImage = "image"
FieldNodeConfigurationTags = "tags"
FieldNodeConfigurationInitScript = "init_script"
FieldNodeConfigurationContainerRuntime = "container_runtime"
FieldNodeConfigurationDockerConfig = "docker_config"
FieldNodeConfigurationKubeletConfig = "kubelet_config"
FieldNodeConfigurationAKS = "aks"
FieldNodeConfigurationEKS = "eks"
FieldNodeConfigurationKOPS = "kops"
FieldNodeConfigurationGKE = "gke"
FieldNodeConfigurationEKSTargetGroup = "target_group"
FieldNodeConfigurationAKSImageFamily = "aks_image_family"
FieldNodeConfigurationEKSImageFamily = "eks_image_family"
FieldNodeConfigurationLoadbalancers = "loadbalancers"
FieldNodeConfigurationAKSLoadbalancerIPPools = "ip_based_backend_pools"
FieldNodeConfigurationAKSLoadbalancerNICPools = "nic_based_backend_pools"
)

const (
Expand Down Expand Up @@ -333,15 +335,21 @@ func resourceNodeConfiguration() *schema.Resource {
FieldNodeConfigurationLoadbalancers: {
Type: schema.TypeList,
Optional: true,
Description: "Loadboalancer configuration for CAST provisioned nodes",
Description: "Load balancer configuration for CAST provisioned nodes",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Description: "The full ID of the load balancer in azure.",
Optional: true, // Can't make it required as it was added after `name` so it'd be a breaking change.
},
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of loadbalancer",
Description: "Name of load balancer",
Optional: true,
Deprecated: "name field is deprecated, use ID instead. Will be removed in future versions.",
},
"ip_based_backend_pools": {
FieldNodeConfigurationAKSLoadbalancerIPPools: {
Type: schema.TypeList,
Optional: true,
Description: "IP based backend pools configuration for CAST provisioned nodes",
Expand All @@ -355,6 +363,20 @@ func resourceNodeConfiguration() *schema.Resource {
},
},
},
FieldNodeConfigurationAKSLoadbalancerNICPools: {
Type: schema.TypeList,
Optional: true,
Description: "NIC based backend pools configuration for CAST provisioned nodes.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of the NIC based backend pool",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -981,12 +1003,19 @@ func toAksLoadBalancers(obj []interface{}) *[]sdk.NodeconfigV1AKSConfigLoadBalan
for _, lbRaw := range obj {
if lb, ok := lbRaw.(map[string]interface{}); ok {
sdkLB := sdk.NodeconfigV1AKSConfigLoadBalancers{}
if id, ok := lb["id"].(string); ok && id != "" {
sdkLB.Id = lo.ToPtr(id)
}
if name, ok := lb["name"].(string); ok && name != "" {
//nolint:staticcheck //We have to do this until we drop the field in TF major provider version.
sdkLB.Name = lo.ToPtr(name)
}
if ipBasedBackendPools, ok := lb["ip_based_backend_pools"].([]interface{}); ok && len(ipBasedBackendPools) > 0 {
if ipBasedBackendPools, ok := lb[FieldNodeConfigurationAKSLoadbalancerIPPools].([]interface{}); ok && len(ipBasedBackendPools) > 0 {
sdkLB.IpBasedBackendPools = toAksIpBasedBackendPools(ipBasedBackendPools)
}
if nicBasedBackendPools, ok := lb[FieldNodeConfigurationAKSLoadbalancerNICPools].([]interface{}); ok && len(nicBasedBackendPools) > 0 {
sdkLB.NicBasedBackendPools = toAksNICBasedBackendPools(nicBasedBackendPools)
}
out = append(out, sdkLB)
}
}
Expand All @@ -999,18 +1028,33 @@ func toAksIpBasedBackendPools(obj []interface{}) *[]sdk.NodeconfigV1AKSConfigLoa
return nil
}

out := make([]sdk.NodeconfigV1AKSConfigLoadBalancersIPBasedBackendPool, 0, len(obj))
for _, poolRaw := range obj {
pools := lo.Map(extractAksBackendPoolNames(obj), func(name string, _ int) sdk.NodeconfigV1AKSConfigLoadBalancersIPBasedBackendPool {
return sdk.NodeconfigV1AKSConfigLoadBalancersIPBasedBackendPool{Name: lo.ToPtr(name)}
})
return &pools
}

func toAksNICBasedBackendPools(obj []any) *[]sdk.NodeconfigV1AKSConfigLoadBalancersNICBasedBackendPool {
if obj == nil {
return nil
}

pools := lo.Map(extractAksBackendPoolNames(obj), func(name string, _ int) sdk.NodeconfigV1AKSConfigLoadBalancersNICBasedBackendPool {
return sdk.NodeconfigV1AKSConfigLoadBalancersNICBasedBackendPool{Name: lo.ToPtr(name)}
})
return &pools
}

func extractAksBackendPoolNames(pools []any) []string {
return lo.Reduce(pools, func(names []string, poolRaw any, _ int) []string {
if pool, ok := poolRaw.(map[string]interface{}); ok {
sdkPool := sdk.NodeconfigV1AKSConfigLoadBalancersIPBasedBackendPool{}
if name, ok := pool["name"].(string); ok && name != "" {
sdkPool.Name = lo.ToPtr(name)
names = append(names, name)
}
out = append(out, sdkPool)
}
}

return &out
return names
}, make([]string, 0))
}

func toAKSOSDiskType(v string) *sdk.NodeconfigV1AKSConfigOsDiskType {
Expand Down Expand Up @@ -1077,29 +1121,45 @@ func fromAksLoadBalancers(lbs []sdk.NodeconfigV1AKSConfigLoadBalancers) []map[st
out := make([]map[string]interface{}, 0, len(lbs))
for _, lb := range lbs {
m := map[string]interface{}{}
if lb.Id != nil {
m["id"] = *lb.Id
}
//nolint:staticcheck //We have to do this until we drop the field in TF major provider version.
if lb.Name != nil {
//nolint:staticcheck //We have to do this until we drop the field in TF major provider version.
m["name"] = *lb.Name
}
if lb.IpBasedBackendPools != nil && len(*lb.IpBasedBackendPools) > 0 {
m["ip_based_backend_pools"] = fromAksIpBasedBackendPools(*lb.IpBasedBackendPools)
m[FieldNodeConfigurationAKSLoadbalancerIPPools] = fromAksIpBasedBackendPoolNames(lo.FilterMap(*lb.IpBasedBackendPools, func(pool sdk.NodeconfigV1AKSConfigLoadBalancersIPBasedBackendPool, _ int) (string, bool) {
if pool.Name != nil {
return *pool.Name, true
}
return "", false
}))
}
if lb.NicBasedBackendPools != nil && len(*lb.NicBasedBackendPools) > 0 {
m[FieldNodeConfigurationAKSLoadbalancerNICPools] = fromAksIpBasedBackendPoolNames(lo.FilterMap(*lb.NicBasedBackendPools, func(pool sdk.NodeconfigV1AKSConfigLoadBalancersNICBasedBackendPool, _ int) (string, bool) {
if pool.Name != nil {
return *pool.Name, true
}
return "", false
}))
}
out = append(out, m)
}

return out
}

func fromAksIpBasedBackendPools(pools []sdk.NodeconfigV1AKSConfigLoadBalancersIPBasedBackendPool) []map[string]interface{} {
if pools == nil {
func fromAksIpBasedBackendPoolNames(names []string) []map[string]interface{} {
if names == nil {
return nil
}

out := make([]map[string]interface{}, 0, len(pools))
for _, pool := range pools {
out := make([]map[string]interface{}, 0, len(names))
for _, name := range names {
m := map[string]interface{}{}
if pool.Name != nil {
m["name"] = *pool.Name
}
m["name"] = name
out = append(out, m)
}

Expand Down
Loading

0 comments on commit 70d483c

Please sign in to comment.