Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

Commit

Permalink
networking fix (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Roth authored Oct 6, 2020
1 parent a884202 commit d421190
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
28 changes: 28 additions & 0 deletions kind/resource_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ func TestAccClusterConfigBase(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "kind_config.0.api_version", "kind.x-k8s.io/v1alpha4"),
),
},
{
Config: testAccClusterConfigAndExtraWithEmptyNetwork(clusterName),
Check: resource.ComposeTestCheckFunc(
testAccCheckClusterCreate(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", clusterName),
resource.TestCheckNoResourceAttr(resourceName, "node_image"),
resource.TestCheckResourceAttr(resourceName, "wait_for_ready", "false"),
resource.TestCheckResourceAttr(resourceName, "kind_config.#", "1"),
resource.TestCheckResourceAttr(resourceName, "kind_config.0.kind", "Cluster"),
resource.TestCheckResourceAttr(resourceName, "kind_config.0.api_version", "kind.x-k8s.io/v1alpha4"),
resource.TestCheckResourceAttr(resourceName, "kind_config.0.networking.#", "1"),
),
},
},
})
}
Expand Down Expand Up @@ -639,3 +652,18 @@ resource "kind_cluster" "test" {
}
`, name)
}

func testAccClusterConfigAndExtraWithEmptyNetwork(name string) string {
return fmt.Sprintf(`
resource "kind_cluster" "test" {
name = "%s"
wait_for_ready = false
kind_config {
kind = "Cluster"
api_version = "kind.x-k8s.io/v1alpha4"
networking {}
}
}
`, name)
}
1 change: 0 additions & 1 deletion kind/schema_kind_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ func kindConfigNetworkingFields() map[string]*schema.Schema {
},
"disable_default_cni": {
Type: schema.TypeBool,
Default: false,
Optional: true,
},
"kube_proxy_mode": {
Expand Down
12 changes: 7 additions & 5 deletions kind/structure_kind_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ func flattenKindConfig(d map[string]interface{}) *v1alpha4.Cluster {
networking := mapKeyIfExists(d, "networking")
if networking != nil {
if n := networking.([]interface{}); len(n) == 1 { // MaxItems: 1, no more than one allowed so we don't have to loop here
data := n[0].(map[string]interface{})
obj.Networking = flattenKindConfigNetworking(data)
if n[0] != nil {
data := n[0].(map[string]interface{})
obj.Networking = flattenKindConfigNetworking(data)
}
}
}

Expand Down Expand Up @@ -93,7 +95,7 @@ func flattenKindConfigNetworking(d map[string]interface{}) v1alpha4.Networking {

apiServerPort := mapKeyIfExists(d, "api_server_port")
if apiServerPort != nil {
obj.APIServerPort = apiServerPort.(int32)
obj.APIServerPort = int32(apiServerPort.(int))
}

disableDefaultCNI := mapKeyIfExists(d, "disable_default_cni")
Expand Down Expand Up @@ -174,11 +176,11 @@ func flattenKindConfigExtraPortMappings(d map[string]interface{}) v1alpha4.PortM

containerPort := mapKeyIfExists(d, "container_port")
if containerPort != nil {
obj.ContainerPort = containerPort.(int32)
obj.ContainerPort = int32(containerPort.(int))
}
hostPort := mapKeyIfExists(d, "host_port")
if hostPort != nil {
obj.HostPort = hostPort.(int32)
obj.HostPort = int32(hostPort.(int))
}
listenAddress := mapKeyIfExists(d, "listen_address")
if listenAddress != nil && listenAddress.(string) != "" {
Expand Down

0 comments on commit d421190

Please sign in to comment.