From 20a3de17d7e5c6af2e2a9cbe6f59a3a7397ce0ae Mon Sep 17 00:00:00 2001 From: MajidAbuRmila Date: Sat, 30 Nov 2024 05:28:28 +0200 Subject: [PATCH] Add load balancer to mk8s triton --- docs/resources/mk8s.md | 156 ++++++++++++- internal/provider/client/mk8s.go | 37 +++- internal/provider/resource_mk8s.go | 175 ++++++++++++++- internal/provider/resource_mk8s_test.go | 277 +++++++++++++++++++++++- 4 files changed, 626 insertions(+), 19 deletions(-) diff --git a/docs/resources/mk8s.md b/docs/resources/mk8s.md index 625cd2e..3a139d1 100644 --- a/docs/resources/mk8s.md +++ b/docs/resources/mk8s.md @@ -448,6 +448,7 @@ Required: - **connection** (Block List, Max: 1) ([see below](#nestedblock--triton_provider--connection)) - **networking** (Block List, Max: 1) ([see below](#nestedblock--generic_provider--networking)) - **location** (String) Control Plane location that will host the K8s components. Prefer one that is closest to the Triton datacenter. +- **load_balancer** (Block List, Max: 1) ([see below](#nestedblock--triton_provider--load_balancer)) - **private_network_id** (String) ID of the private Fabric/Network. - **image_id** (String) Default image for all nodes. @@ -473,6 +474,30 @@ Optional: - **user** (String) + + +### `triton_provider.load_balancer` + +Required: + +~> **Note** Only one of the attributes listed below can be included in load balancer. + +- **gateway** (Block List, Max: 1) Just an empty list. E.g. `gateway {}`. +- **manual** (Block List, Max: 1) ([see below](#nestedblock--triton_provider--load_balancer--manual)) + + + +### `triton_provider.load_balancer.manual` + +Required: + +- **package_id** (String) +- **image_id** (String) +- **public_network_id** (String) If set, machine will also get a public IP. +- **count** (Number) +- **cns_internal_domain** (String) +- **cns_public_domain** (String) + ### `triton_provider.node_pool` @@ -1678,6 +1703,10 @@ resource "cpln_mk8s" "triton" { user = "julian_controlplane.com" private_key_secret_link = "/org/terraform-test-org/secret/triton" } + + load_balancer { + gateway {} + } node_pool { name = "my-triton-node-pool" @@ -1757,11 +1786,136 @@ resource "cpln_mk8s" "triton" { } ``` -# Example Usage - Digital Ocean Provider +## Example Usage - Triton Provider - Load Balancer Manual ```terraform resource "cpln_mk8s" "triton" { + name = "demo-mk8s-triton-provider" + description = "demo-mk8s-triton-provider" + + tags = { + terraform_generated = "true" + acceptance_test = "true" + } + + version = "1.28.4" + + firewall { + source_cidr = "192.168.1.255" + description = "hello world" + } + + triton_provider { + pre_install_script = "#! echo hello world" + location = "aws-eu-central-1" + private_network_id = "6704dae9-00f4-48b5-8bbf-1be538f20587" + firewall_enabled = false + image_id = "6b98a11c-53a4-4a62-99e7-cf3dcf150ab2" + + networking {} + + connection { + url = "https://us-central-1.api.mnx.io" + account = "eric_controlplane.com" + user = "julian_controlplane.com" + private_key_secret_link = "/org/terraform-test-org/secret/triton" + } + + load_balancer { + manual { + package_id = "df26ba1d-1261-6fc1-b35c-f1b390bc06ff" + image_id = "8605a524-0655-43b9-adf1-7d572fe797eb" + public_network_id = "5ff1fe03-075b-4e4c-b85b-73de0c452f77" + count = 1 + cns_internal_domain = "example.com" + cns_public_domain = "example.com" + } + } + + node_pool { + name = "my-triton-node-pool" + package_id = "da311341-b42b-45a8-9386-78ede625d0a4" + override_image_id = "e2f3f2aa-a833-49e0-94af-7a7e092cdd9e" + public_network_id = "5ff1fe03-075b-4e4c-b85b-73de0c452f77" + min_size = 0 + max_size = 0 + + private_network_ids = ["6704dae9-00f4-48b5-8bbf-1be538f20587"] + + labels = { + hello = "world" + } + + taint { + key = "hello" + value = "world" + effect = "NoSchedule" + } + + triton_tags = { + drink = "water" + } + } + + autoscaler { + expander = ["most-pods"] + unneeded_time = "10m" + unready_time = "20m" + utilization_threshold = 0.7 + } + } + + add_ons { + dashboard = true + + azure_workload_identity { + tenant_id = "7f43458a-a34e-4bfa-9e56-e2289e49c4ec" + } + + aws_workload_identity = true + local_path_storage = true + + metrics { + kube_state = true + core_dns = true + kubelet = true + api_server = true + node_exporter = true + cadvisor = true + + scrape_annotated { + interval_seconds = 30 + include_namespaces = "^\\d+$" + exclude_namespaces = "^[a-z]$" + retain_labels = "^\\w+$" + } + } + + logs { + audit_enabled = true + include_namespaces = "^\\d+$" + exclude_namespaces = "^[a-z]$" + } + + nvidia { + taint_gpu_nodes = true + } + + azure_acr { + client_id = "4e25b134-160b-4a9d-b392-13b381ced5ef" + } + + sysbox = true + } +} +``` + +# Example Usage - Digital Ocean Provider + +```terraform +resource "cpln_mk8s" "digital-ocean-provider" { + name = "demo-mk8s-digital-ocean-provider" description = "demo-mk8s-digital-ocean-provider" diff --git a/internal/provider/client/mk8s.go b/internal/provider/client/mk8s.go index 0b0f20e..d0b4bce 100644 --- a/internal/provider/client/mk8s.go +++ b/internal/provider/client/mk8s.go @@ -153,16 +153,17 @@ type Mk8sEphemeralProvider struct { } type Mk8sTritonProvider struct { - Connection *Mk8sTritonConnection `json:"connection,omitempty"` - Networking *Mk8sNetworkingConfig `json:"networking,omitempty"` - PreInstallScript *string `json:"preInstallScript,omitempty"` - Location *string `json:"location,omitempty"` - PrivateNetworkId *string `json:"privateNetworkId,omitempty"` - FirewallEnabled *bool `json:"firewallEnabled,omitempty"` - NodePools *[]Mk8sTritonPool `json:"nodePools,omitempty"` - ImageId *string `json:"imageId,omitempty"` - SshKeys *[]string `json:"sshKeys,omitempty"` - Autoscaler *Mk8sAutoscalerConfig `json:"autoscaler,omitempty"` + Connection *Mk8sTritonConnection `json:"connection,omitempty"` + Networking *Mk8sNetworkingConfig `json:"networking,omitempty"` + PreInstallScript *string `json:"preInstallScript,omitempty"` + Location *string `json:"location,omitempty"` + LoadBalancer *Mk8sTritonLoadBalancer `json:"loadBalancer,omitempty"` + PrivateNetworkId *string `json:"privateNetworkId,omitempty"` + FirewallEnabled *bool `json:"firewallEnabled,omitempty"` + NodePools *[]Mk8sTritonPool `json:"nodePools,omitempty"` + ImageId *string `json:"imageId,omitempty"` + SshKeys *[]string `json:"sshKeys,omitempty"` + Autoscaler *Mk8sAutoscalerConfig `json:"autoscaler,omitempty"` } type Mk8sDigitalOceanProvider struct { @@ -314,6 +315,22 @@ type Mk8sTritonConnection struct { PrivateKeySecretLink *string `json:"privateKeySecretLink,omitempty"` } +type Mk8sTritonLoadBalancer struct { + Manual *Mk8sTritonManual `json:"manual,omitempty"` + Gateway *Mk8sTritonGateway `json:"gateway,omitempty"` +} + +type Mk8sTritonManual struct { + PackageId *string `json:"packageId,omitempty"` + ImageId *string `json:"imageId,omitempty"` + PublicNetworkId *string `json:"publicNetworkId,omitempty"` + Count *int `json:"count,omitempty"` + CnsInternalDomain *string `json:"cnsInternalDomain,omitempty"` + CnsPublicDomain *string `json:"cnsPublicDomain,omitempty"` +} + +type Mk8sTritonGateway struct{} + // Add Ons // type Mk8sAzureWorkloadIdentityAddOnConfig struct { diff --git a/internal/provider/resource_mk8s.go b/internal/provider/resource_mk8s.go index 40fdb3e..f182e34 100644 --- a/internal/provider/resource_mk8s.go +++ b/internal/provider/resource_mk8s.go @@ -3,7 +3,6 @@ package cpln import ( "context" "encoding/json" - client "github.com/controlplane-com/terraform-provider-cpln/internal/provider/client" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -468,6 +467,75 @@ func resourceMk8s() *schema.Resource { Description: "Control Plane location that will host the K8s components. Prefer one that is closest to the Triton datacenter.", Required: true, }, + "load_balancer": { + Type: schema.TypeList, + Description: "", + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "manual": { + Type: schema.TypeList, + Description: "", + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "package_id": { + Type: schema.TypeString, + Description: "", + Required: true, + }, + "image_id": { + Type: schema.TypeString, + Description: "", + Required: true, + }, + "public_network_id": { + Type: schema.TypeString, + Description: "If set, machine will also get a public IP.", + Required: true, + }, + "count": { + Type: schema.TypeInt, + Description: "", + Required: true, + ValidateFunc: RangeValidator(1, 3), + }, + "cns_internal_domain": { + Type: schema.TypeString, + Description: "", + Required: true, + }, + "cns_public_domain": { + Type: schema.TypeString, + Description: "", + Required: true, + }, + }, + }, + ExactlyOneOf: []string{"triton_provider.0.load_balancer.0.gateway", "triton_provider.0.load_balancer.0.manual"}, + }, + "gateway": { + Type: schema.TypeList, + Description: "", + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "_sentinel": { + Type: schema.TypeBool, + Description: "", + Optional: true, + Default: true, + }, + }, + }, + ExactlyOneOf: []string{"triton_provider.0.load_balancer.0.gateway", "triton_provider.0.load_balancer.0.manual"}, + }, + }, + }, + }, "private_network_id": { Type: schema.TypeString, Description: "ID of the private Fabric/Network.", @@ -1517,6 +1585,10 @@ func buildMk8sTritonProvider(specs []interface{}) *client.Mk8sTritonProvider { output.PreInstallScript = GetString(spec["pre_install_script"]) } + if spec["load_balancer"] != nil { + output.LoadBalancer = buildMk8sTritonLoadBalancer(spec["load_balancer"].([]interface{})) + } + if spec["firewall_enabled"] != nil { output.FirewallEnabled = GetBool(spec["firewall_enabled"]) } @@ -2041,6 +2113,50 @@ func buildMk8sTritonConnection(specs []interface{}) *client.Mk8sTritonConnection return &output } +func buildMk8sTritonLoadBalancer(specs []interface{}) *client.Mk8sTritonLoadBalancer { + if len(specs) == 0 || specs[0] == nil { + return nil + } + + output := client.Mk8sTritonLoadBalancer{} + spec := specs[0].(map[string]interface{}) + + if spec["manual"] != nil { + output.Manual = buildMk8sTritonManual(spec["manual"].([]interface{})) + } + + if spec["gateway"] != nil { + output.Gateway = buildMk8sTritonGateway(spec["gateway"].([]interface{})) + } + + return &output +} + +func buildMk8sTritonManual(specs []interface{}) *client.Mk8sTritonManual { + if len(specs) == 0 || specs[0] == nil { + return nil + } + + spec := specs[0].(map[string]interface{}) + + return &client.Mk8sTritonManual{ + PackageId: GetString(spec["package_id"]), + ImageId: GetString(spec["image_id"]), + PublicNetworkId: GetString(spec["public_network_id"]), + Count: GetInt(spec["count"]), + CnsInternalDomain: GetString(spec["cns_internal_domain"]), + CnsPublicDomain: GetString(spec["cns_public_domain"]), + } +} + +func buildMk8sTritonGateway(specs []interface{}) *client.Mk8sTritonGateway { + if len(specs) == 0 || specs[0] == nil { + return nil + } + + return &client.Mk8sTritonGateway{} +} + // Common func buildMk8sNetworking(specs []interface{}) *client.Mk8sNetworkingConfig { @@ -2726,6 +2842,10 @@ func flattenMk8sTritonProvider(triton *client.Mk8sTritonProvider) []interface{} spec["pre_install_script"] = *triton.PreInstallScript } + if triton.LoadBalancer != nil { + spec["load_balancer"] = flattenMk8sTritonLoadBalancer(triton.LoadBalancer) + } + if triton.FirewallEnabled != nil { spec["firewall_enabled"] = *triton.FirewallEnabled } @@ -3239,6 +3359,59 @@ func flattenMk8sTritonConnection(connection *client.Mk8sTritonConnection) []inte } } +func flattenMk8sTritonLoadBalancer(loadBalancer *client.Mk8sTritonLoadBalancer) []interface{} { + if loadBalancer == nil { + return nil + } + + spec := make(map[string]interface{}) + + if loadBalancer.Manual != nil { + spec["manual"] = flattenMk8sTritonManual(loadBalancer.Manual) + } + + if loadBalancer.Gateway != nil { + spec["gateway"] = flattenMk8sTritonGateway(loadBalancer.Gateway) + } + + return []interface{}{ + spec, + } +} + +func flattenMk8sTritonManual(manual *client.Mk8sTritonManual) []interface{} { + if manual == nil { + return nil + } + + spec := make(map[string]interface{}) + + spec["package_id"] = *manual.PackageId + spec["image_id"] = *manual.ImageId + spec["public_network_id"] = *manual.PublicNetworkId + spec["count"] = *manual.Count + spec["cns_internal_domain"] = *manual.CnsInternalDomain + spec["cns_public_domain"] = *manual.CnsPublicDomain + + return []interface{}{ + spec, + } +} + +func flattenMk8sTritonGateway(gateway *client.Mk8sTritonGateway) []interface{} { + if gateway == nil { + return nil + } + + spec := map[string]interface{}{ + "_sentinel": true, + } + + return []interface{}{ + spec, + } +} + // Common func flattenMk8sNetworking(networking *client.Mk8sNetworkingConfig) []interface{} { diff --git a/internal/provider/resource_mk8s_test.go b/internal/provider/resource_mk8s_test.go index fe31753..05595d5 100644 --- a/internal/provider/resource_mk8s_test.go +++ b/internal/provider/resource_mk8s_test.go @@ -101,7 +101,7 @@ func TestAccControlPlaneMk8s_basic(t *testing.T) { Config: testAccControlPlaneTritonProvider(name+"-triton", description), Check: resource.ComposeTestCheckFunc( testAccCheckControlPlaneMk8sExists("cpln_mk8s.triton", name+"-triton", &mk8s), - testAccCheckControlPlaneMk8sAttributes(&mk8s, "triton", ""), + testAccCheckControlPlaneMk8sAttributes(&mk8s, "triton", "gateway"), resource.TestCheckResourceAttr("cpln_mk8s.triton", "name", name+"-triton"), resource.TestCheckResourceAttr("cpln_mk8s.triton", "description", description), ), @@ -125,6 +125,15 @@ func TestAccControlPlaneMk8s_basic(t *testing.T) { resource.TestCheckResourceAttr("cpln_mk8s.lambdalabs", "description", description), ), }, + { + Config: testAccControlPlaneTritonProviderUpdate(name+"-triton", description), + Check: resource.ComposeTestCheckFunc( + testAccCheckControlPlaneMk8sExists("cpln_mk8s.triton", name+"-triton", &mk8s), + testAccCheckControlPlaneMk8sAttributes(&mk8s, "triton", "manual"), + resource.TestCheckResourceAttr("cpln_mk8s.triton", "name", name+"-triton"), + resource.TestCheckResourceAttr("cpln_mk8s.triton", "description", description), + ), + }, }, }) } @@ -1174,6 +1183,10 @@ func testAccControlPlaneTritonProvider(name string, description string) string { private_key_secret_link = "/org/terraform-test-org/secret/triton" } + load_balancer { + gateway {} + } + node_pool { name = "my-triton-node-pool" package_id = "da311341-b42b-45a8-9386-78ede625d0a4" @@ -1504,6 +1517,133 @@ func testAccControlPlaneMk8sLambdalabsProviderUpdate(name string, description st `, name, description) } +func testAccControlPlaneTritonProviderUpdate(name string, description string) string { + return fmt.Sprintf(` + + resource "cpln_mk8s" "triton" { + + name = "%s" + description = "%s" + + tags = { + terraform_generated = "true" + acceptance_test = "true" + "cpln/ignore" = "true" + } + + version = "1.28.4" + + firewall { + source_cidr = "192.168.1.255" + description = "hello world" + } + + triton_provider { + pre_install_script = "#! echo hello world" + location = "aws-eu-central-1" + private_network_id = "6704dae9-00f4-48b5-8bbf-1be538f20587" + firewall_enabled = false + image_id = "6b98a11c-53a4-4a62-99e7-cf3dcf150ab2" + + networking {} + + connection { + url = "https://us-central-1.api.mnx.io" + account = "eric_controlplane.com" + user = "julian_controlplane.com" + private_key_secret_link = "/org/terraform-test-org/secret/triton" + } + + load_balancer { + manual { + package_id = "df26ba1d-1261-6fc1-b35c-f1b390bc06ff" + image_id = "8605a524-0655-43b9-adf1-7d572fe797eb" + public_network_id = "5ff1fe03-075b-4e4c-b85b-73de0c452f77" + count = 1 + cns_internal_domain = "example.com" + cns_public_domain = "example.com" + } + } + + node_pool { + name = "my-triton-node-pool" + package_id = "da311341-b42b-45a8-9386-78ede625d0a4" + override_image_id = "e2f3f2aa-a833-49e0-94af-7a7e092cdd9e" + public_network_id = "5ff1fe03-075b-4e4c-b85b-73de0c452f77" + min_size = 0 + max_size = 0 + + private_network_ids = ["6704dae9-00f4-48b5-8bbf-1be538f20587"] + + labels = { + hello = "world" + } + + taint { + key = "hello" + value = "world" + effect = "NoSchedule" + } + + triton_tags = { + drink = "water" + } + } + + autoscaler { + expander = ["most-pods"] + unneeded_time = "10m" + unready_time = "20m" + utilization_threshold = 0.7 + } + } + + add_ons { + dashboard = true + + azure_workload_identity { + tenant_id = "7f43458a-a34e-4bfa-9e56-e2289e49c4ec" + } + + aws_workload_identity = true + local_path_storage = true + + metrics { + kube_state = true + core_dns = true + kubelet = true + api_server = true + node_exporter = true + cadvisor = true + + scrape_annotated { + interval_seconds = 30 + include_namespaces = "^\\d+$" + exclude_namespaces = "^[a-z]$" + retain_labels = "^\\w+$" + } + } + + logs { + audit_enabled = true + include_namespaces = "^\\d+$" + exclude_namespaces = "^[a-z]$" + } + + nvidia { + taint_gpu_nodes = true + } + + azure_acr { + client_id = "4e25b134-160b-4a9d-b392-13b381ced5ef" + } + + sysbox = true + } + } + `, name, description) +} + // !SECTION // !SECTION @@ -1605,7 +1745,7 @@ func TestControlPlane_BuildMk8sEphemeralProvider(t *testing.T) { func TestControlPlane_BuildMk8sTritonProvider(t *testing.T) { - triton, expectedTriton, _ := generateTestMk8sTritonProvider() + triton, expectedTriton, _ := generateTestMk8sTritonProvider("gateway") if diff := deep.Equal(triton, expectedTriton); diff != nil { t.Errorf("Mk8s Triton Provider was not built correctly, Diff: %s", diff) @@ -1759,6 +1899,24 @@ func TestControlPlane_BuildMk8sTritonConnection(t *testing.T) { } } +func TestControlPlane_BuildMk8sTritonLoadBalancerGateway(t *testing.T) { + + loadBalancer, expectedLoadBalancer, _ := generateTestMk8sTritonLoadBalancer("gateway") + + if diff := deep.Equal(loadBalancer, expectedLoadBalancer); diff != nil { + t.Errorf("Mk8s Triton Load Balancer Gateway was not built correctly, Diff: %s", diff) + } +} + +func TestControlPlane_BuildMk8sTritonLoadBalancerManual(t *testing.T) { + + loadBalancer, expectedLoadBalancer, _ := generateTestMk8sTritonLoadBalancer("manual") + + if diff := deep.Equal(loadBalancer, expectedLoadBalancer); diff != nil { + t.Errorf("Mk8s Triton Load Balancer Manual was not built correctly, Diff: %s", diff) + } +} + // !SECTION // SECTION Common @@ -2031,7 +2189,7 @@ func TestControlPlane_FlattenMk8sEphemeralProvider(t *testing.T) { func TestControlPlane_FlattenMk8sTritonProvider(t *testing.T) { - _, expectedTriton, expectedFlatten := generateTestMk8sTritonProvider() + _, expectedTriton, expectedFlatten := generateTestMk8sTritonProvider("gateway") flattenedTriton := flattenMk8sTritonProvider(expectedTriton) // Extract the interface slice from *schema.Set @@ -2249,6 +2407,26 @@ func TestControlPlane_FlattenMk8sTritonConnection(t *testing.T) { } } +func TestControlPlane_FlattenMk8sTritonLoadBalancerGateway(t *testing.T) { + + _, expectedLoadBalancer, expectedFlatten := generateTestMk8sTritonLoadBalancer("gateway") + flattenedLoadBalancer := flattenMk8sTritonLoadBalancer(expectedLoadBalancer) + + if diff := deep.Equal(expectedFlatten, flattenedLoadBalancer); diff != nil { + t.Errorf("Mk8s Triton LoadBalancer Gateway was not flattened correctly. Diff: %s", diff) + } +} + +func TestControlPlane_FlattenMk8sTritonLoadBalancerManual(t *testing.T) { + + _, expectedLoadBalancer, expectedFlatten := generateTestMk8sTritonLoadBalancer("manual") + flattenedLoadBalancer := flattenMk8sTritonLoadBalancer(expectedLoadBalancer) + + if diff := deep.Equal(expectedFlatten, flattenedLoadBalancer); diff != nil { + t.Errorf("Mk8s Triton LoadBalancer Manual was not flattened correctly. Diff: %s", diff) + } +} + // !SECTION // SECTION Common @@ -2416,7 +2594,7 @@ func generateTestMk8sProvider(provider string, update string) *client.Mk8sProvid generated, _, _ := generateTestMk8sEphemeralProvider() output.Ephemeral = generated case "triton": - generated, _, _ := generateTestMk8sTritonProvider() + generated, _, _ := generateTestMk8sTritonProvider(update) output.Triton = generated } @@ -2720,7 +2898,7 @@ func generateTestMk8sEphemeralProvider() (*client.Mk8sEphemeralProvider, *client return ephemeral, &expectedEphemeral, flattened } -func generateTestMk8sTritonProvider() (*client.Mk8sTritonProvider, *client.Mk8sTritonProvider, []interface{}) { +func generateTestMk8sTritonProvider(update string) (*client.Mk8sTritonProvider, *client.Mk8sTritonProvider, []interface{}) { preInstallScript := "#! echo hello world" location := "aws-eu-central-1" @@ -2731,16 +2909,18 @@ func generateTestMk8sTritonProvider() (*client.Mk8sTritonProvider, *client.Mk8sT connection, _, flattenedConnection := generateTestMk8sTritonConnection() networking, _, flattenedNetworking := generateTestMk8sNetworking() + loadBalancer, _, flattenedLoadBalancer := generateTestMk8sTritonLoadBalancer(update) nodePools, _, flattenedNodePools := generateTestMk8sTritonNodePools() autoscaler, _, flattenedAutoscaler := generateTestMk8sAutoscaler() - flattened := generateFlatTestMk8sTritonProvider(flattenedConnection, flattenedNetworking, preInstallScript, location, privateNetworkId, firewallEnabled, flattenedNodePools, imageId, sshKeys, flattenedAutoscaler) + flattened := generateFlatTestMk8sTritonProvider(flattenedConnection, flattenedNetworking, preInstallScript, location, flattenedLoadBalancer, privateNetworkId, firewallEnabled, flattenedNodePools, imageId, sshKeys, flattenedAutoscaler) triton := buildMk8sTritonProvider(flattened) expectedTriton := client.Mk8sTritonProvider{ Connection: connection, Networking: networking, PreInstallScript: &preInstallScript, Location: &location, + LoadBalancer: loadBalancer, PrivateNetworkId: &privateNetworkId, FirewallEnabled: &firewallEnabled, NodePools: nodePools, @@ -3202,6 +3382,47 @@ func generateTestMk8sTritonConnection() (*client.Mk8sTritonConnection, *client.M return connection, &expectedConnection, flattened } +func generateTestMk8sTritonLoadBalancer(option string) (*client.Mk8sTritonLoadBalancer, *client.Mk8sTritonLoadBalancer, []interface{}) { + var gateway *client.Mk8sTritonGateway + var manual *client.Mk8sTritonManual + var gatewayFlattened *[]interface{} + var manualFlattened *[]interface{} + + switch option { + case "gateway": + _flattened := generateFlatTestMk8sTritonGateway() + gatewayFlattened = &_flattened + gateway = &client.Mk8sTritonGateway{} + case "manual": + packageId := "df26ba1d-1261-6fc1-b35c-f1b390bc06ff" + imageId := "8605a524-0655-43b9-adf1-7d572fe797eb" + publicNetworkId := "5ff1fe03-075b-4e4c-b85b-73de0c452f77" + count := 1 + cnsInternalDomain := "example.com" + cnsPublicDomain := "example.com" + + _flattened := generateFlatTestMk8sTritonManual(packageId, imageId, publicNetworkId, count, cnsInternalDomain, cnsPublicDomain) + manualFlattened = &_flattened + manual = &client.Mk8sTritonManual{ + PackageId: &packageId, + ImageId: &imageId, + PublicNetworkId: &publicNetworkId, + Count: &count, + CnsInternalDomain: &cnsInternalDomain, + CnsPublicDomain: &cnsPublicDomain, + } + } + + flattened := generateFlatTestMk8sTritonLoadBalancer(gatewayFlattened, manualFlattened) + loadBalancer := buildMk8sTritonLoadBalancer(flattened) + expectedLoadBalancer := client.Mk8sTritonLoadBalancer{ + Gateway: gateway, + Manual: manual, + } + + return loadBalancer, &expectedLoadBalancer, flattened +} + // !SECTION // SECTION Common @@ -3545,13 +3766,14 @@ func generateFlatTestMk8sEphemeralProvider(location string, nodePools []interfac } } -func generateFlatTestMk8sTritonProvider(connection []interface{}, networking []interface{}, preInstallScript string, location string, privateNetworkId string, firewallEnabled bool, nodePools []interface{}, imageId string, sshKeys []string, autoscaler []interface{}) []interface{} { +func generateFlatTestMk8sTritonProvider(connection []interface{}, networking []interface{}, preInstallScript string, location string, loadBalancer []interface{}, privateNetworkId string, firewallEnabled bool, nodePools []interface{}, imageId string, sshKeys []string, autoscaler []interface{}) []interface{} { spec := map[string]interface{}{ "connection": connection, "networking": networking, "pre_install_script": preInstallScript, "location": location, + "load_balancer": loadBalancer, "private_network_id": privateNetworkId, "firewall_enabled": firewallEnabled, "node_pool": nodePools, @@ -3819,6 +4041,47 @@ func generateFlatTestMk8sTritonConnection(url string, account string, user strin } } +func generateFlatTestMk8sTritonLoadBalancer(gateway *[]interface{}, manual *[]interface{}) []interface{} { + spec := map[string]interface{}{} + + if gateway != nil { + spec["gateway"] = *gateway + } + + if manual != nil { + spec["manual"] = *manual + } + + return []interface{}{ + spec, + } +} + +func generateFlatTestMk8sTritonGateway() []interface{} { + spec := map[string]interface{}{ + "_sentinel": true, + } + + return []interface{}{ + spec, + } +} + +func generateFlatTestMk8sTritonManual(packageId string, imageId string, publicNetworkId string, count int, cnsInternalDomain string, cnsPublicDomain string) []interface{} { + spec := map[string]interface{}{ + "package_id": packageId, + "image_id": imageId, + "public_network_id": publicNetworkId, + "count": count, + "cns_internal_domain": cnsInternalDomain, + "cns_public_domain": cnsPublicDomain, + } + + return []interface{}{ + spec, + } +} + // !SECTION // SECTION Common