-
Notifications
You must be signed in to change notification settings - Fork 979
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
Adding traffic_distribution field #2625
base: v3-major-release
Are you sure you want to change the base?
Changes from 3 commits
6af37ff
72d6cad
7ec763b
d6a2d50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:enhancement | ||
Added the `traffic_distribution` field to the `kubernetes_service_v1` resource | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -268,6 +268,14 @@ func resourceKubernetesServiceSchemaV1() map[string]*schema.Schema { | |
}, | ||
}, | ||
}, | ||
"traffic_distribution": { | ||
Type: schema.TypeString, | ||
Description: "Specifies the preferred strategy for distributing traffic to Service endpoints. When set to PreferClose, the Kubernetes will prioritize routing traffic to endpoints that are topologically closer", | ||
Optional: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
"PreferClose", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest importing such predefined words from Kubernetes code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @arybolovlev Wow, that's a clever approach! Would this be considered best practice for the future? Due to the k8s api were to update / expand on the |
||
}, false), | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Description: "Determines how the service is exposed. Defaults to `ClusterIP`. Valid options are `ExternalName`, `ClusterIP`, `NodePort`, and `LoadBalancer`. `ExternalName` maps to the specified `external_name`. More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -819,6 +819,36 @@ func TestAccKubernetesServiceV1_ipFamilies(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccKubernetesServiceV1_trafficDistribution(t *testing.T) { | ||
var conf corev1.Service | ||
name := acctest.RandomWithPrefix("tf-acc-test") | ||
resourceName := "kubernetes_service_v1.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add here |
||
IDRefreshIgnore: []string{"metadata.0.resource_version"}, | ||
ProviderFactories: testAccProviderFactories, | ||
CheckDestroy: testAccCheckKubernetesServiceV1Destroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccKubernetesServiceV1Config_trafficDistribution(name, "PreferClose"), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
testAccCheckKubernetesServiceV1Exists(resourceName, &conf), | ||
resource.TestCheckResourceAttr(resourceName, "metadata.0.name", name), | ||
resource.TestCheckResourceAttr(resourceName, "spec.#", "1"), | ||
resource.TestCheckResourceAttr(resourceName, "spec.0.traffic_distribution", "PreferClose"), | ||
), | ||
}, | ||
{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"metadata.0.resource_version", "wait_for_load_balancer"}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckServiceV1Ports(svc *corev1.Service, expected []corev1.ServicePort) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
if len(expected) == 0 && len(svc.Spec.Ports) == 0 { | ||
|
@@ -1417,3 +1447,26 @@ func testAccKubernetesServiceV1ConfigV1_ipFamilies(prefix string) string { | |
} | ||
`, prefix) | ||
} | ||
|
||
func testAccKubernetesServiceV1Config_trafficDistribution(name, trafficDistribution string) string { | ||
return fmt.Sprintf(` | ||
resource "kubernetes_service_v1" "test" { | ||
metadata { | ||
name = "%s" | ||
} | ||
|
||
spec { | ||
traffic_distribution = "%s" | ||
|
||
port { | ||
port = 8080 | ||
target_port = 80 | ||
} | ||
|
||
selector = { | ||
app = "MyApp" | ||
} | ||
} | ||
} | ||
`, name, trafficDistribution) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to use imperative voice here and add
kubernetes_service
too, since both resources refer to the same code: