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

r/service: Make spec.port.target_port optional #69

Merged
merged 1 commit into from
Oct 3, 2017
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
3 changes: 2 additions & 1 deletion kubernetes/resource_kubernetes_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ func resourceKubernetesService() *schema.Resource {
"target_port": {
Type: schema.TypeInt,
Description: "Number or name of the port to access on the pods targeted by the service. Number must be in the range 1 to 65535. This field is ignored for services with `cluster_ip = \"None\"`. More info: http://kubernetes.io/docs/user-guide/services#defining-a-service",
Required: true,
Optional: true,
Computed: true,
},
},
},
Expand Down
77 changes: 77 additions & 0 deletions kubernetes/resource_kubernetes_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,59 @@ func TestAccKubernetesService_nodePort(t *testing.T) {
})
}

func TestAccKubernetesService_noTargetPort(t *testing.T) {
var conf api.Service
name := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); skipIfNoLoadBalancersAvailable(t) },
IDRefreshName: "kubernetes_service.test",
Providers: testAccProviders,
CheckDestroy: testAccCheckKubernetesServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccKubernetesServiceConfig_noTargetPort(name),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesServiceExists("kubernetes_service.test", &conf),
resource.TestCheckResourceAttr("kubernetes_service.test", "metadata.0.name", name),
resource.TestCheckResourceAttr("kubernetes_service.test", "spec.#", "1"),
resource.TestCheckResourceAttrSet("kubernetes_service.test", "spec.0.cluster_ip"),
resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.external_ips.#", "0"),
resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.port.#", "2"),
resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.port.0.name", "http"),
resource.TestCheckResourceAttrSet("kubernetes_service.test", "spec.0.port.0.node_port"),
resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.port.0.port", "80"),
resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.port.0.protocol", "TCP"),
resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.port.0.target_port", "80"),
resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.port.1.name", "https"),
resource.TestCheckResourceAttrSet("kubernetes_service.test", "spec.0.port.1.node_port"),
resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.port.1.port", "443"),
resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.port.1.protocol", "TCP"),
resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.port.1.target_port", "443"),
resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.selector.%", "1"),
resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.selector.App", "MyOtherApp"),
resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.session_affinity", "None"),
resource.TestCheckResourceAttr("kubernetes_service.test", "spec.0.type", "LoadBalancer"),
testAccCheckServicePorts(&conf, []api.ServicePort{
{
Name: "http",
Port: int32(80),
Protocol: api.ProtocolTCP,
TargetPort: intstr.FromInt(80),
},
{
Name: "https",
Port: int32(443),
Protocol: api.ProtocolTCP,
TargetPort: intstr.FromInt(443),
},
}),
),
},
},
})
}

func TestAccKubernetesService_externalName(t *testing.T) {
var conf api.Service
name := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
Expand Down Expand Up @@ -522,6 +575,30 @@ resource "kubernetes_service" "test" {
}`, name, name)
}

func testAccKubernetesServiceConfig_noTargetPort(name string) string {
return fmt.Sprintf(`
resource "kubernetes_service" "test" {
metadata {
name = "%s"
}
spec {
selector {
App = "MyOtherApp"
}
port {
name = "http"
port = 80
}
port {
name = "https"
port = 443
}
type = "LoadBalancer"
}
}
`, name)
}

func testAccKubernetesServiceConfig_externalName(name string) string {
return fmt.Sprintf(`
resource "kubernetes_service" "test" {
Expand Down