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

AKS: NetworkProfile / Advanced Networking #1479

Merged
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5865322
Added kubernetes_cluster advanced network creation
lfshr Jul 2, 2018
305c1d0
Changed network_profile from TypeSet to TypeList
lfshr Jul 2, 2018
df237b2
Added kubernetes_cluster advanced network creation
lfshr Jul 2, 2018
e3ec37e
Changed network_profile from TypeSet to TypeList
lfshr Jul 2, 2018
a3ff5b0
Merge branch 'containerservices-advancednetworking' of https://github…
lfshr Jul 2, 2018
b7d274b
Updated ForceNew attributes on kubernetes_cluster.network_profile params
lfshr Jul 2, 2018
11bed67
Added advanced network read functionality
lfshr Jul 2, 2018
30f39ff
Added tests for kubernetes_cluster.network_profile
lfshr Jul 2, 2018
195e7d6
Fixed indentations
lfshr Jul 2, 2018
f8f5626
Fixed function name in tests
lfshr Jul 2, 2018
25c6e6e
Fixed property name in test
lfshr Jul 2, 2018
48cff90
Fixed variable name
lfshr Jul 3, 2018
2dd887c
working on data source for kubernetes cluster
lfshr Jul 3, 2018
1bdf8b6
Merge branch 'containerservices-advancednetworking' of https://github…
lfshr Jul 3, 2018
33c84c6
Fixed issue with datasource not working
lfshr Jul 3, 2018
f9786e1
Added network_policy and fixed read
lfshr Jul 3, 2018
02b22e5
Removed network_policy as unsupported
lfshr Jul 3, 2018
b62a643
Added example of advanced networking
lfshr Jul 4, 2018
377c52f
Added test for data_source
lfshr Jul 4, 2018
7453f41
Made address space more sensible
lfshr Jul 4, 2018
c90ea55
Removing kubenet test.
lfshr Jul 6, 2018
16e7d3e
Made network_plugin a mandatory field.
lfshr Jul 6, 2018
675d0b9
Updated documentation to include network_profile
lfshr Jul 6, 2018
7c21183
Fixing the build
tombuildsstuff Jul 6, 2018
1959c2f
Added ForceNew to network_profile
lfshr Jul 6, 2018
518cacc
Made the docs a little clearer
lfshr Jul 6, 2018
9faeb69
Documenting a required field
tombuildsstuff Jul 11, 2018
1ef6ccf
Rephrasing the data sources
tombuildsstuff Jul 11, 2018
dac7913
Making the `network_profile` block computed
tombuildsstuff Jul 11, 2018
48d5ed7
Fixing the field we're asserting on
tombuildsstuff Jul 11, 2018
a54aa89
Conditionally expanding the network_profile block.
tombuildsstuff Jul 25, 2018
9e862eb
Validation to ensure that a Subnet ID is assigned to the cluster when…
tombuildsstuff Jul 25, 2018
f2219c5
Updating the documentation to mention the new behaviour
tombuildsstuff Jul 25, 2018
8a23d24
Adding independent tests for Kubenet and Azure networking profiles
tombuildsstuff Jul 25, 2018
8d08c53
Conditional validation of the `docker_bridge_cidr`, `dns_service_ip` …
tombuildsstuff Jul 25, 2018
a72f105
Updating the docs
tombuildsstuff Jul 25, 2018
ff3e206
Fixing the tests
tombuildsstuff Jul 25, 2018
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
63 changes: 63 additions & 0 deletions azurerm/data_source_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,39 @@ func dataSourceArmKubernetesCluster() *schema.Resource {
},
},

"network_profile": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we document this block/these new fields here? (I've had to link to the Blame since you can't link to a regular line in a Markdown file in Github ¯_(ツ)_/¯)

Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"network_plugin": {
Type: schema.TypeString,
Computed: true,
},

"service_cidr": {
Type: schema.TypeString,
Computed: true,
},

"dns_service_ip": {
Type: schema.TypeString,
Computed: true,
},

"docker_bridge_cidr": {
Type: schema.TypeString,
Computed: true,
},

"pod_cidr": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

"tags": tagsForDataSourceSchema(),
},
}
Expand Down Expand Up @@ -217,6 +250,12 @@ func dataSourceArmKubernetesClusterRead(d *schema.ResourceData, meta interface{}
}
}

networkProfile := flattenKubernetesClusterDataSourceNetworkProfile(resp.NetworkProfile)

if err := d.Set("network_profile", networkProfile); err != nil {
return fmt.Errorf("Error setting `network_profile`: %+v", err)
}

kubeConfigRaw, kubeConfig := flattenKubernetesClusterDataSourceAccessProfile(&profile)
d.Set("kube_config_raw", kubeConfigRaw)

Expand Down Expand Up @@ -350,3 +389,27 @@ func flattenKubernetesClusterDataSourceKubeConfig(config kubernetes.KubeConfig)

return []interface{}{values}
}

func flattenKubernetesClusterDataSourceNetworkProfile(profile *containerservice.NetworkProfile) []interface{} {
values := make(map[string]interface{})

values["network_plugin"] = profile.NetworkPlugin

if profile.ServiceCidr != nil {
values["service_cidr"] = *profile.ServiceCidr
}

if profile.DNSServiceIP != nil {
values["dns_service_ip"] = *profile.DNSServiceIP
}

if profile.DockerBridgeCidr != nil {
values["docker_bridge_cidr"] = *profile.DockerBridgeCidr
}

if profile.PodCidr != nil {
values["pod_cidr"] = *profile.PodCidr
}

return []interface{}{values}
}
40 changes: 40 additions & 0 deletions azurerm/data_source_kubernetes_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,34 @@ func TestAccDataSourceAzureRMKubernetesCluster_internalNetwork(t *testing.T) {
})
}

func TestAccDataSourceAzureRMKubernetesCluster_advancedNetworking(t *testing.T) {
dataSourceName := "data.azurerm_kubernetes_cluster.test"
ri := acctest.RandInt()
clientId := os.Getenv("ARM_CLIENT_ID")
clientSecret := os.Getenv("ARM_CLIENT_SECRET")
location := testLocation()
config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworking(ri, clientId, clientSecret, location)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMKubernetesClusterDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKubernetesClusterExists(dataSourceName),
resource.TestCheckResourceAttrSet(dataSourceName, "agent_pool_profile.0.vnet_subnet_id"),
resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.network_plugin"),
resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.dns_service_ip"),
resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.docker_bridge_cidr"),
resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.service_cidr"),
),
},
},
})
}

func testAccDataSourceAzureRMKubernetesCluster_basic(rInt int, clientId string, clientSecret string, location string) string {
resource := testAccAzureRMKubernetesCluster_basic(rInt, clientId, clientSecret, location)
return fmt.Sprintf(`
Expand All @@ -85,3 +113,15 @@ data "azurerm_kubernetes_cluster" "test" {
}
`, resource)
}

func testAccDataSourceAzureRMKubernetesCluster_advancedNetworking(rInt int, clientId string, clientSecret string, location string) string {
resource := testAccAzureRMKubernetesCluster_advancedNetworking(rInt, clientId, clientSecret, location)
return fmt.Sprintf(`
%s

data "azurerm_kubernetes_cluster" "test" {
name = "${azurerm_kubernetes_cluster.test.name}"
resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}"
}
`, resource)
}
99 changes: 99 additions & 0 deletions azurerm/resource_arm_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,48 @@ func resourceArmKubernetesCluster() *schema.Resource {
Set: resourceAzureRMKubernetesClusterServicePrincipalProfileHash,
},

"network_profile": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we document this block/these new fields here? (I've had to link to the Blame since you can't link to a regular line in a Markdown file in Github ¯_(ツ)_/¯)

Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{

"network_plugin": {
Type: schema.TypeString,
Default: "azure",
Optional: true,
ForceNew: true,
},

"service_cidr": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"dns_service_ip": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"docker_bridge_cidr": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"pod_cidr": {
Type: schema.TypeString,
Default: "10.244.0.0/24",
Optional: true,
ForceNew: true,
},
},
},
},

"tags": tagsSchema(),
},
}
Expand All @@ -229,6 +271,7 @@ func resourceArmKubernetesClusterCreate(d *schema.ResourceData, meta interface{}
linuxProfile := expandAzureRmKubernetesClusterLinuxProfile(d)
agentProfiles := expandAzureRmKubernetesClusterAgentProfiles(d)
servicePrincipalProfile := expandAzureRmKubernetesClusterServicePrincipal(d)
networkProfile := expandAzureRmKubernetesClusterNetworkProfile(d)

tags := d.Get("tags").(map[string]interface{})

Expand All @@ -241,6 +284,7 @@ func resourceArmKubernetesClusterCreate(d *schema.ResourceData, meta interface{}
KubernetesVersion: &kubernetesVersion,
LinuxProfile: &linuxProfile,
ServicePrincipalProfile: servicePrincipalProfile,
NetworkProfile: networkProfile,
},
Tags: expandTags(tags),
}
Expand Down Expand Up @@ -324,6 +368,12 @@ func resourceArmKubernetesClusterRead(d *schema.ResourceData, meta interface{})
}
}

networkProfile := flattenKubernetesClusterDataSourceNetworkProfile(resp.NetworkProfile)

if err := d.Set("network_profile", networkProfile); err != nil {
return fmt.Errorf("Error setting `network_profile`: %+v", err)
}

kubeConfigRaw, kubeConfig := flattenAzureRmKubernetesClusterAccessProfile(&profile)
d.Set("kube_config_raw", kubeConfigRaw)

Expand Down Expand Up @@ -469,6 +519,30 @@ func flattenAzureRmKubernetesClusterAccessProfile(profile *containerservice.Mana
return nil, []interface{}{}
}

func flattenAzureRmKubernetesClusterNetworkProfile(profile *containerservice.NetworkProfile) []interface{} {
values := make(map[string]interface{})

values["network_plugin"] = profile.NetworkPlugin

if profile.ServiceCidr != nil {
values["service_cidr"] = *profile.ServiceCidr
}

if profile.DNSServiceIP != nil {
values["dns_service_ip"] = *profile.DNSServiceIP
}

if profile.DockerBridgeCidr != nil {
values["docker_bridge_cidr"] = *profile.DockerBridgeCidr
}

if profile.PodCidr != nil {
values["pod_cidr"] = *profile.PodCidr
}

return []interface{}{values}
}

func flattenKubernetesClusterKubeConfig(config kubernetes.KubeConfig) []interface{} {
values := make(map[string]interface{})

Expand Down Expand Up @@ -566,6 +640,31 @@ func expandAzureRmKubernetesClusterAgentProfiles(d *schema.ResourceData) []conta
return profiles
}

func expandAzureRmKubernetesClusterNetworkProfile(d *schema.ResourceData) *containerservice.NetworkProfile {
configs := d.Get("network_profile").([]interface{})
if len(configs) == 0 {
return nil
}

config := configs[0].(map[string]interface{})

dnsServiceIP := config["dns_service_ip"].(string)
dockerBridgeCidr := config["docker_bridge_cidr"].(string)
networkPlugin := config["network_plugin"].(string)
podCidr := config["pod_cidr"].(string)
serviceCidr := config["service_cidr"].(string)

networkProfile := containerservice.NetworkProfile{
DNSServiceIP: utils.String(dnsServiceIP),
DockerBridgeCidr: utils.String(dockerBridgeCidr),
NetworkPlugin: containerservice.NetworkPlugin(networkPlugin),
PodCidr: utils.String(podCidr),
ServiceCidr: utils.String(serviceCidr),
}

return &networkProfile
}

func resourceAzureRMKubernetesClusterServicePrincipalProfileHash(v interface{}) int {
var buf bytes.Buffer

Expand Down
Loading