diff --git a/charts/internal/azure-infra/templates/main.tf b/charts/internal/azure-infra/templates/main.tf index ba2d99b1a..398a00cbc 100644 --- a/charts/internal/azure-infra/templates/main.tf +++ b/charts/internal/azure-infra/templates/main.tf @@ -16,9 +16,9 @@ data "azurerm_resource_group" "rg" { } {{- end}} -#===================================================================== -#= VNet, Subnets, Route Table, Security Groups, Identity -#===================================================================== +#=============================================== +#= VNet, Subnets, Route Table, Security Groups +#=============================================== {{ if .Values.create.vnet -}} resource "azurerm_virtual_network" "vnet" { @@ -73,7 +73,46 @@ resource "azurerm_network_security_group" "workers" { {{- end}} } +{{ if .Values.create.natGateway -}} +#=============================================== +#= NAT Gateway +#=============================================== + +resource "azurerm_public_ip" "natip" { + name = "{{ required "clusterName is required" .Values.clusterName }}-nat-ip" + location = "{{ required "azure.region is required" .Values.azure.region }}" + {{ if .Values.create.resourceGroup -}} + resource_group_name = "${azurerm_resource_group.rg.name}" + {{- else -}} + resource_group_name = "${data.azurerm_resource_group.rg.name}" + {{- end }} + allocation_method = "Static" + sku = "Standard" +} + +resource "azurerm_nat_gateway" "nat" { + name = "{{ required "clusterName is required" .Values.clusterName }}-nat-gateway" + location = "{{ required "azure.region is required" .Values.azure.region }}" + {{ if .Values.create.resourceGroup -}} + resource_group_name = "${azurerm_resource_group.rg.name}" + {{- else -}} + resource_group_name = "${data.azurerm_resource_group.rg.name}" + {{- end }} + sku_name = "Standard" + public_ip_address_ids = ["${azurerm_public_ip.natip.id}"] +} + +resource "azurerm_subnet_nat_gateway_association" "nat-worker-subnet-association" { + subnet_id = "${azurerm_subnet.workers.id}" + nat_gateway_id = "${azurerm_nat_gateway.nat.id}" +} +{{- end }} + {{ if .Values.identity -}} +#=============================================== +#= Identity +#=============================================== + data "azurerm_user_assigned_identity" "identity" { name = "{{ required "identity.name is required" .Values.identity.name }}" resource_group_name = "{{ required "identity.resourceGroup is required" .Values.identity.resourceGroup }}" @@ -81,9 +120,9 @@ data "azurerm_user_assigned_identity" "identity" { {{- end }} {{ if .Values.create.availabilitySet -}} -#===================================================================== +#=============================================== #= Availability Set -#===================================================================== +#=============================================== resource "azurerm_availability_set" "workers" { name = "{{ required "clusterName is required" .Values.clusterName }}-avset-workers" @@ -99,9 +138,9 @@ resource "azurerm_availability_set" "workers" { } {{- end}} -//===================================================================== +#=============================================== //= Output variables -//===================================================================== +#=============================================== output "{{ .Values.outputKeys.resourceGroupName }}" { {{ if .Values.create.resourceGroup -}} diff --git a/charts/internal/azure-infra/values.yaml b/charts/internal/azure-infra/values.yaml index 92a777c11..43e552153 100644 --- a/charts/internal/azure-infra/values.yaml +++ b/charts/internal/azure-infra/values.yaml @@ -9,6 +9,7 @@ create: resourceGroup: true vnet: true availabilitySet: false + natGateway: false # identity: # name: identity-name diff --git a/docs/usage-as-end-user.md b/docs/usage-as-end-user.md index 467ce6506..82ca06c27 100644 --- a/docs/usage-as-end-user.md +++ b/docs/usage-as-end-user.md @@ -40,6 +40,8 @@ networks: # resouceGroup: my-vnet-resource-group cidr: 10.250.0.0/16 workers: 10.250.0.0/19 + # natGateway: + # enabled: false # serviceEndpoints: # - Microsoft.Test zoned: false @@ -64,6 +66,8 @@ You can freely choose this CIDR and it is your responsibility to properly design In the `networks.serviceEndpoints[]` list you can specify the list of Azure service endpoints which shall be associated with the worker subnet. All available service endpoints and their technical names can be found in the (Azure Service Endpoint documentation](https://docs.microsoft.com/en-us/azure/virtual-network/virtual-network-service-endpoints-overview). +The `networks.natGateway` section contains configuration for the Azure NatGateway which can be attached to the worker subnet of the Shoot cluster. The NatGateway is currently optional and can be enabled/disabled via the field `networks.natGateway.enabled`. If the NatGateway is not deployed then the outgoing traffic initiated within the Shoot cluster will be routed via cluster LoadBalancer (default behaviour, see [here](https://docs.microsoft.com/en-us/azure/load-balancer/load-balancer-outbound-connections#scenarios)). **Restrictions:** The NatGateway is currently only available for zoned clusters (`.zoned=true`, see [#43](https://github.com/gardener/gardener-extension-provider-azure/issues/43) for more details) and it will not be deployed zone-redundant yet. Furthermore, the Azure NatGateway is not yet generally available (GA) from Azure side, hence, you need to register your subscription to participate in the preview for NatGateway. + Via the `.zoned` boolean you can tell whether you want to use Azure availability zones or not. If you don't use zones then an availability set will be created and only basic load balancers will be used. Zoned clusters use standard load balancers. diff --git a/example/30-infrastructure.yaml b/example/30-infrastructure.yaml index 3bb1f026f..d05ba42f5 100644 --- a/example/30-infrastructure.yaml +++ b/example/30-infrastructure.yaml @@ -68,6 +68,8 @@ spec: # resourceGroup: my-vnet-group cidr: 10.250.0.0/16 workers: 10.250.0.0/19 + # natGateway: + # enabled: false # serviceEndpoints: # - entry1 zoned: false diff --git a/hack/api-reference/api.md b/hack/api-reference/api.md index 9f8c930e8..5fca8d0bf 100644 --- a/hack/api-reference/api.md +++ b/hack/api-reference/api.md @@ -746,6 +746,36 @@ string +
+(Appears on: +NetworkConfig) +
++
NatGatewayConfig contains configuration for the nat gateway and the attached resources.
+ +Field | +Description | +
---|---|
+enabled
+
+bool
+
+ |
+
+ Enabled is an indicator if NAT gateway should be deployed. + |
+
@@ -789,6 +819,20 @@ string
natGateway
+
+
+NatGatewayConfig
+
+
+NatGateway contains the configuration for the NatGateway.
+serviceEndpoints
[]string
diff --git a/pkg/apis/azure/types_infrastructure.go b/pkg/apis/azure/types_infrastructure.go
index 65a4c764e..067d3c64e 100644
--- a/pkg/apis/azure/types_infrastructure.go
+++ b/pkg/apis/azure/types_infrastructure.go
@@ -45,6 +45,8 @@ type NetworkConfig struct {
VNet VNet
// Workers is the worker subnet range to create (used for the VMs).
Workers string
+ // NatGateway contains the configuration for the NatGateway.
+ NatGateway *NatGatewayConfig
// ServiceEndpoints is a list of Azure ServiceEndpoints which should be associated with the worker subnet.
ServiceEndpoints []string
}
@@ -140,6 +142,12 @@ type VNetStatus struct {
ResourceGroup *string
}
+// NatGatewayConfig contains configuration for the nat gateway and the attached resources.
+type NatGatewayConfig struct {
+ // Enabled is an indicator if NAT gateway should be deployed.
+ Enabled bool
+}
+
// IdentityConfig contains configuration for the managed identity.
type IdentityConfig struct {
// Name is the name of the identity.
diff --git a/pkg/apis/azure/v1alpha1/types_infrastructure.go b/pkg/apis/azure/v1alpha1/types_infrastructure.go
index b890e121f..4aae20dc3 100644
--- a/pkg/apis/azure/v1alpha1/types_infrastructure.go
+++ b/pkg/apis/azure/v1alpha1/types_infrastructure.go
@@ -49,6 +49,9 @@ type NetworkConfig struct {
VNet VNet `json:"vnet"`
// Workers is the worker subnet range to create (used for the VMs).
Workers string `json:"workers"`
+ // NatGateway contains the configuration for the NatGateway.
+ // +optional
+ NatGateway *NatGatewayConfig `json:"natGateway,omitempty"`
// ServiceEndpoints is a list of Azure ServiceEndpoints which should be associated with the worker subnet.
// +optional
ServiceEndpoints []string `json:"serviceEndpoints,omitempty"`
@@ -152,6 +155,12 @@ type VNetStatus struct {
ResourceGroup *string `json:"resourceGroup,omitempty"`
}
+// NatGatewayConfig contains configuration for the nat gateway and the attached resources.
+type NatGatewayConfig struct {
+ // Enabled is an indicator if NAT gateway should be deployed.
+ Enabled bool `json:"enabled"`
+}
+
// IdentityConfig contains configuration for the managed identity.
type IdentityConfig struct {
// Name is the name of the identity.
diff --git a/pkg/apis/azure/v1alpha1/zz_generated.conversion.go b/pkg/apis/azure/v1alpha1/zz_generated.conversion.go
index 1c020287e..5525460a1 100644
--- a/pkg/apis/azure/v1alpha1/zz_generated.conversion.go
+++ b/pkg/apis/azure/v1alpha1/zz_generated.conversion.go
@@ -155,6 +155,16 @@ func RegisterConversions(s *runtime.Scheme) error {
}); err != nil {
return err
}
+ if err := s.AddGeneratedConversionFunc((*NatGatewayConfig)(nil), (*azure.NatGatewayConfig)(nil), func(a, b interface{}, scope conversion.Scope) error {
+ return Convert_v1alpha1_NatGatewayConfig_To_azure_NatGatewayConfig(a.(*NatGatewayConfig), b.(*azure.NatGatewayConfig), scope)
+ }); err != nil {
+ return err
+ }
+ if err := s.AddGeneratedConversionFunc((*azure.NatGatewayConfig)(nil), (*NatGatewayConfig)(nil), func(a, b interface{}, scope conversion.Scope) error {
+ return Convert_azure_NatGatewayConfig_To_v1alpha1_NatGatewayConfig(a.(*azure.NatGatewayConfig), b.(*NatGatewayConfig), scope)
+ }); err != nil {
+ return err
+ }
if err := s.AddGeneratedConversionFunc((*NetworkConfig)(nil), (*azure.NetworkConfig)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1alpha1_NetworkConfig_To_azure_NetworkConfig(a.(*NetworkConfig), b.(*azure.NetworkConfig), scope)
}); err != nil {
@@ -544,11 +554,32 @@ func Convert_azure_MachineImages_To_v1alpha1_MachineImages(in *azure.MachineImag
return autoConvert_azure_MachineImages_To_v1alpha1_MachineImages(in, out, s)
}
+func autoConvert_v1alpha1_NatGatewayConfig_To_azure_NatGatewayConfig(in *NatGatewayConfig, out *azure.NatGatewayConfig, s conversion.Scope) error {
+ out.Enabled = in.Enabled
+ return nil
+}
+
+// Convert_v1alpha1_NatGatewayConfig_To_azure_NatGatewayConfig is an autogenerated conversion function.
+func Convert_v1alpha1_NatGatewayConfig_To_azure_NatGatewayConfig(in *NatGatewayConfig, out *azure.NatGatewayConfig, s conversion.Scope) error {
+ return autoConvert_v1alpha1_NatGatewayConfig_To_azure_NatGatewayConfig(in, out, s)
+}
+
+func autoConvert_azure_NatGatewayConfig_To_v1alpha1_NatGatewayConfig(in *azure.NatGatewayConfig, out *NatGatewayConfig, s conversion.Scope) error {
+ out.Enabled = in.Enabled
+ return nil
+}
+
+// Convert_azure_NatGatewayConfig_To_v1alpha1_NatGatewayConfig is an autogenerated conversion function.
+func Convert_azure_NatGatewayConfig_To_v1alpha1_NatGatewayConfig(in *azure.NatGatewayConfig, out *NatGatewayConfig, s conversion.Scope) error {
+ return autoConvert_azure_NatGatewayConfig_To_v1alpha1_NatGatewayConfig(in, out, s)
+}
+
func autoConvert_v1alpha1_NetworkConfig_To_azure_NetworkConfig(in *NetworkConfig, out *azure.NetworkConfig, s conversion.Scope) error {
if err := Convert_v1alpha1_VNet_To_azure_VNet(&in.VNet, &out.VNet, s); err != nil {
return err
}
out.Workers = in.Workers
+ out.NatGateway = (*azure.NatGatewayConfig)(unsafe.Pointer(in.NatGateway))
out.ServiceEndpoints = *(*[]string)(unsafe.Pointer(&in.ServiceEndpoints))
return nil
}
@@ -563,6 +594,7 @@ func autoConvert_azure_NetworkConfig_To_v1alpha1_NetworkConfig(in *azure.Network
return err
}
out.Workers = in.Workers
+ out.NatGateway = (*NatGatewayConfig)(unsafe.Pointer(in.NatGateway))
out.ServiceEndpoints = *(*[]string)(unsafe.Pointer(&in.ServiceEndpoints))
return nil
}
diff --git a/pkg/apis/azure/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/azure/v1alpha1/zz_generated.deepcopy.go
index 5405a266b..a6a94b859 100644
--- a/pkg/apis/azure/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/azure/v1alpha1/zz_generated.deepcopy.go
@@ -329,10 +329,31 @@ func (in *MachineImages) DeepCopy() *MachineImages {
return out
}
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *NatGatewayConfig) DeepCopyInto(out *NatGatewayConfig) {
+ *out = *in
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NatGatewayConfig.
+func (in *NatGatewayConfig) DeepCopy() *NatGatewayConfig {
+ if in == nil {
+ return nil
+ }
+ out := new(NatGatewayConfig)
+ in.DeepCopyInto(out)
+ return out
+}
+
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *NetworkConfig) DeepCopyInto(out *NetworkConfig) {
*out = *in
in.VNet.DeepCopyInto(&out.VNet)
+ if in.NatGateway != nil {
+ in, out := &in.NatGateway, &out.NatGateway
+ *out = new(NatGatewayConfig)
+ **out = **in
+ }
if in.ServiceEndpoints != nil {
in, out := &in.ServiceEndpoints, &out.ServiceEndpoints
*out = make([]string, len(*in))
diff --git a/pkg/apis/azure/validation/infrastructure.go b/pkg/apis/azure/validation/infrastructure.go
index a9ac84bbd..19bece2a7 100644
--- a/pkg/apis/azure/validation/infrastructure.go
+++ b/pkg/apis/azure/validation/infrastructure.go
@@ -83,6 +83,16 @@ func ValidateInfrastructureConfig(infra *apisazure.InfrastructureConfig, nodesCI
}
}
+ // TODO(dkistner) Remove once we proceed with multiple AvailabilitySet support.
+ // Currently we will not offer Nat Gateway for non zoned/AvailabilitySet based
+ // clusters as the NatGateway is not compatible with Basic LoadBalancer and
+ // we would need Standard LoadBalancers also in combination with AvailabilitySets.
+ // For the multiple AvailabilitySet approach we would always need
+ // a Standard LoadBalancer and a NatGateway.
+ if !infra.Zoned && infra.Networks.NatGateway != nil {
+ allErrs = append(allErrs, field.Invalid(fldPath.Child("networks", "natGateway"), infra.Networks.NatGateway, "NatGateway is currently only supported for zoned cluster"))
+ }
+
if infra.Identity != nil && (infra.Identity.Name == "" || infra.Identity.ResourceGroup == "") {
allErrs = append(allErrs, field.Invalid(fldPath.Child("identity"), infra.Identity, "specifying an identity requires the name of the identity and the resource group which hosts the identity"))
}
diff --git a/pkg/apis/azure/validation/infrastructure_test.go b/pkg/apis/azure/validation/infrastructure_test.go
index d4b718300..cde8efab8 100644
--- a/pkg/apis/azure/validation/infrastructure_test.go
+++ b/pkg/apis/azure/validation/infrastructure_test.go
@@ -270,6 +270,26 @@ var _ = Describe("InfrastructureConfig validation", func() {
}))
})
})
+
+ Context("NatGateway", func() {
+ It("should return no errors using a NatGateway for a zoned cluster", func() {
+ infrastructureConfig.Zoned = true
+ infrastructureConfig.Networks.NatGateway = &apisazure.NatGatewayConfig{Enabled: true}
+ Expect(ValidateInfrastructureConfig(infrastructureConfig, &nodes, &pods, &services, fldPath)).To(BeEmpty())
+ })
+
+ It("should return an error using a NatGateway for a non zoned cluster", func() {
+ infrastructureConfig.Zoned = false
+ infrastructureConfig.Networks.NatGateway = &apisazure.NatGatewayConfig{}
+ errorList := ValidateInfrastructureConfig(infrastructureConfig, &nodes, &pods, &services, fldPath)
+ Expect(errorList).To(HaveLen(1))
+ Expect(errorList).To(ConsistOfFields(Fields{
+ "Type": Equal(field.ErrorTypeInvalid),
+ "Field": Equal("networks.natGateway"),
+ "Detail": Equal("NatGateway is currently only supported for zoned cluster"),
+ }))
+ })
+ })
})
Describe("#ValidateInfrastructureConfigUpdate", func() {
diff --git a/pkg/apis/azure/zz_generated.deepcopy.go b/pkg/apis/azure/zz_generated.deepcopy.go
index 5da22f33a..fd22039ad 100644
--- a/pkg/apis/azure/zz_generated.deepcopy.go
+++ b/pkg/apis/azure/zz_generated.deepcopy.go
@@ -329,10 +329,31 @@ func (in *MachineImages) DeepCopy() *MachineImages {
return out
}
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *NatGatewayConfig) DeepCopyInto(out *NatGatewayConfig) {
+ *out = *in
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NatGatewayConfig.
+func (in *NatGatewayConfig) DeepCopy() *NatGatewayConfig {
+ if in == nil {
+ return nil
+ }
+ out := new(NatGatewayConfig)
+ in.DeepCopyInto(out)
+ return out
+}
+
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *NetworkConfig) DeepCopyInto(out *NetworkConfig) {
*out = *in
in.VNet.DeepCopyInto(&out.VNet)
+ if in.NatGateway != nil {
+ in, out := &in.NatGateway, &out.NatGateway
+ *out = new(NatGatewayConfig)
+ **out = **in
+ }
if in.ServiceEndpoints != nil {
in, out := &in.ServiceEndpoints, &out.ServiceEndpoints
*out = make([]string, len(*in))
diff --git a/pkg/internal/infrastructure/terraform.go b/pkg/internal/infrastructure/terraform.go
index 2caec11f9..678ac048e 100644
--- a/pkg/internal/infrastructure/terraform.go
+++ b/pkg/internal/infrastructure/terraform.go
@@ -69,6 +69,7 @@ func ComputeTerraformerChartValues(infra *extensionsv1alpha1.Infrastructure, cli
createResourceGroup = true
createVNet = true
createAvailabilitySet = false
+ createNatGateway = false
resourceGroupName = infra.Namespace
identityConfig map[string]interface{}
@@ -133,6 +134,10 @@ func ComputeTerraformerChartValues(infra *extensionsv1alpha1.Infrastructure, cli
azure["countFaultDomains"] = countFaultDomains
}
+ if config.Networks.NatGateway != nil && config.Networks.NatGateway.Enabled {
+ createNatGateway = true
+ }
+
if config.Identity != nil && config.Identity.Name != "" && config.Identity.ResourceGroup != "" {
identityConfig = map[string]interface{}{
"name": config.Identity.Name,
@@ -148,6 +153,7 @@ func ComputeTerraformerChartValues(infra *extensionsv1alpha1.Infrastructure, cli
"resourceGroup": createResourceGroup,
"vnet": createVNet,
"availabilitySet": createAvailabilitySet,
+ "natGateway": createNatGateway,
},
"resourceGroup": map[string]interface{}{
"name": resourceGroupName,
diff --git a/pkg/internal/infrastructure/terraform_test.go b/pkg/internal/infrastructure/terraform_test.go
index e40d6bb46..025bd6654 100644
--- a/pkg/internal/infrastructure/terraform_test.go
+++ b/pkg/internal/infrastructure/terraform_test.go
@@ -75,7 +75,6 @@ var _ = Describe("Terraform", func() {
var (
infra *extensionsv1alpha1.Infrastructure
config *api.InfrastructureConfig
- identity map[string]interface{}
cluster *controller.Cluster
clientAuth *internal.ClientAuth
@@ -86,18 +85,16 @@ var _ = Describe("Terraform", func() {
BeforeEach(func() {
var (
- VNetName = "vnet"
TestCIDR = "10.1.0.0/16"
VNetCIDR = TestCIDR
)
config = &api.InfrastructureConfig{
Networks: api.NetworkConfig{
VNet: api.VNet{
- Name: &VNetName,
CIDR: &VNetCIDR,
},
Workers: TestCIDR,
- ServiceEndpoints: []string{testServiceEndpoint},
+ ServiceEndpoints: []string{},
},
Zoned: true,
}
@@ -105,7 +102,6 @@ var _ = Describe("Terraform", func() {
rawconfig := &apiv1alpha1.InfrastructureConfig{
Networks: apiv1alpha1.NetworkConfig{
VNet: apiv1alpha1.VNet{
- Name: &VNetName,
CIDR: &VNetCIDR,
},
Workers: TestCIDR,
@@ -143,88 +139,74 @@ var _ = Describe("Terraform", func() {
})
Describe("#ComputeTerraformerChartValues", func() {
- It("should correctly compute the terraformer chart values for a zoned cluster", func() {
- values, err := ComputeTerraformerChartValues(infra, clientAuth, config, cluster)
- expectedValues := map[string]interface{}{
- "azure": map[string]interface{}{
- "subscriptionID": clientAuth.SubscriptionID,
- "tenantID": clientAuth.TenantID,
- "region": infra.Spec.Region,
- },
- "create": map[string]interface{}{
- "resourceGroup": true,
- "vnet": true,
- "availabilitySet": false,
- },
- "resourceGroup": map[string]interface{}{
+ var (
+ expectedValues map[string]interface{}
+ expectedAzureValues map[string]interface{}
+ expectedCreateValues map[string]interface{}
+ expectedOutputKeysValues map[string]interface{}
+ expectedResourceGroupValues map[string]interface{}
+ expectedIdentityValues map[string]interface{}
+ )
+
+ BeforeEach(func() {
+ expectedAzureValues = map[string]interface{}{
+ "subscriptionID": clientAuth.SubscriptionID,
+ "tenantID": clientAuth.TenantID,
+ "region": infra.Spec.Region,
+ }
+ expectedCreateValues = map[string]interface{}{
+ "resourceGroup": true,
+ "vnet": true,
+ "availabilitySet": false,
+ "natGateway": false,
+ }
+ expectedResourceGroupValues = map[string]interface{}{
+ "name": infra.Namespace,
+ "vnet": map[string]interface{}{
"name": infra.Namespace,
- "vnet": map[string]interface{}{
- "name": infra.Namespace,
- "cidr": config.Networks.Workers,
- },
- "subnet": map[string]interface{}{
- "serviceEndpoints": []string{testServiceEndpoint},
- },
+ "cidr": config.Networks.Workers,
},
- "identity": identity,
- "clusterName": infra.Namespace,
+ "subnet": map[string]interface{}{
+ "serviceEndpoints": []string{},
+ },
+ }
+ expectedOutputKeysValues = map[string]interface{}{
+ "resourceGroupName": TerraformerOutputKeyResourceGroupName,
+ "vnetName": TerraformerOutputKeyVNetName,
+ "subnetName": TerraformerOutputKeySubnetName,
+ "routeTableName": TerraformerOutputKeyRouteTableName,
+ "securityGroupName": TerraformerOutputKeySecurityGroupName,
+ }
+
+ expectedValues = map[string]interface{}{
+ "azure": expectedAzureValues,
+ "create": expectedCreateValues,
+ "resourceGroup": expectedResourceGroupValues,
+ "identity": expectedIdentityValues,
+ "clusterName": infra.Namespace,
"networks": map[string]interface{}{
"worker": config.Networks.Workers,
},
- "outputKeys": map[string]interface{}{
- "resourceGroupName": TerraformerOutputKeyResourceGroupName,
- "vnetName": TerraformerOutputKeyVNetName,
- "subnetName": TerraformerOutputKeySubnetName,
- "routeTableName": TerraformerOutputKeyRouteTableName,
- "securityGroupName": TerraformerOutputKeySecurityGroupName,
- },
+ "outputKeys": expectedOutputKeysValues,
}
+ })
+
+ It("should correctly compute the terraformer chart values for a zoned cluster", func() {
+ values, err := ComputeTerraformerChartValues(infra, clientAuth, config, cluster)
Expect(err).To(Not(HaveOccurred()))
Expect(values).To(BeEquivalentTo(expectedValues))
})
It("should correctly compute the terraformer chart values for a non zoned cluster", func() {
config.Zoned = false
+ expectedCreateValues["availabilitySet"] = true
+ expectedAzureValues["countUpdateDomains"] = countUpdateDomain
+ expectedAzureValues["countFaultDomains"] = countFaultDomain
+ expectedOutputKeysValues["availabilitySetID"] = TerraformerOutputKeyAvailabilitySetID
+ expectedOutputKeysValues["availabilitySetName"] = TerraformerOutputKeyAvailabilitySetName
+
values, err := ComputeTerraformerChartValues(infra, clientAuth, config, cluster)
Expect(err).To(Not(HaveOccurred()))
- expectedValues := map[string]interface{}{
- "azure": map[string]interface{}{
- "subscriptionID": clientAuth.SubscriptionID,
- "tenantID": clientAuth.TenantID,
- "region": infra.Spec.Region,
- "countUpdateDomains": countUpdateDomain,
- "countFaultDomains": countFaultDomain,
- },
- "create": map[string]interface{}{
- "resourceGroup": true,
- "vnet": true,
- "availabilitySet": true,
- },
- "resourceGroup": map[string]interface{}{
- "name": infra.Namespace,
- "vnet": map[string]interface{}{
- "name": infra.Namespace,
- "cidr": config.Networks.Workers,
- },
- "subnet": map[string]interface{}{
- "serviceEndpoints": []string{testServiceEndpoint},
- },
- },
- "identity": identity,
- "clusterName": infra.Namespace,
- "networks": map[string]interface{}{
- "worker": config.Networks.Workers,
- },
- "outputKeys": map[string]interface{}{
- "resourceGroupName": TerraformerOutputKeyResourceGroupName,
- "vnetName": TerraformerOutputKeyVNetName,
- "subnetName": TerraformerOutputKeySubnetName,
- "routeTableName": TerraformerOutputKeyRouteTableName,
- "securityGroupName": TerraformerOutputKeySecurityGroupName,
- "availabilitySetID": TerraformerOutputKeyAvailabilitySetID,
- "availabilitySetName": TerraformerOutputKeyAvailabilitySetName,
- },
- }
Expect(values).To(BeEquivalentTo(expectedValues))
})
@@ -233,50 +215,69 @@ var _ = Describe("Terraform", func() {
existingVnetName = "test"
existingVnetResourceGroup = "test-rg"
)
-
config.Networks.VNet = api.VNet{
Name: &existingVnetName,
ResourceGroup: &existingVnetResourceGroup,
}
+
+ expectedCreateValues["vnet"] = false
+ expectedResourceGroupValues["vnet"] = map[string]interface{}{
+ "name": existingVnetName,
+ "resourceGroup": existingVnetResourceGroup,
+ }
+ expectedOutputKeysValues["vnetName"] = TerraformerOutputKeyVNetName
+ expectedOutputKeysValues["vnetResourceGroup"] = TerraformerOutputKeyVNetResourceGroup
+
values, err := ComputeTerraformerChartValues(infra, clientAuth, config, cluster)
- expectedValues := map[string]interface{}{
- "azure": map[string]interface{}{
- "subscriptionID": clientAuth.SubscriptionID,
- "tenantID": clientAuth.TenantID,
- "region": infra.Spec.Region,
- },
- "create": map[string]interface{}{
- "resourceGroup": true,
- "vnet": false,
- "availabilitySet": false,
- },
- "resourceGroup": map[string]interface{}{
- "name": infra.Namespace,
- "vnet": map[string]interface{}{
- "name": existingVnetName,
- "resourceGroup": existingVnetResourceGroup,
- },
- "subnet": map[string]interface{}{
- "serviceEndpoints": []string{testServiceEndpoint},
- },
- },
- "identity": identity,
- "clusterName": infra.Namespace,
- "networks": map[string]interface{}{
- "worker": config.Networks.Workers,
- },
- "outputKeys": map[string]interface{}{
- "resourceGroupName": TerraformerOutputKeyResourceGroupName,
- "vnetName": TerraformerOutputKeyVNetName,
- "vnetResourceGroup": TerraformerOutputKeyVNetResourceGroup,
- "subnetName": TerraformerOutputKeySubnetName,
- "routeTableName": TerraformerOutputKeyRouteTableName,
- "securityGroupName": TerraformerOutputKeySecurityGroupName,
- },
+ Expect(err).To(Not(HaveOccurred()))
+ Expect(values).To(BeEquivalentTo(expectedValues))
+ })
+
+ It("should correctly compute the terraformer chart values for a cluster with Azure Service Endpoints", func() {
+ var serviceEndpointList = []string{testServiceEndpoint}
+ config.Networks.ServiceEndpoints = serviceEndpointList
+ expectedResourceGroupValues["subnet"] = map[string]interface{}{
+ "serviceEndpoints": serviceEndpointList,
+ }
+ values, err := ComputeTerraformerChartValues(infra, clientAuth, config, cluster)
+ Expect(err).To(Not(HaveOccurred()))
+ Expect(values).To(BeEquivalentTo(expectedValues))
+ })
+
+ It("should correctly compute terraform chart values with identity", func() {
+ var (
+ identityName = "identity-name"
+ identityResourceGroup = "identity-rg"
+ )
+ config.Identity = &api.IdentityConfig{
+ Name: identityName,
+ ResourceGroup: identityResourceGroup,
+ }
+
+ identityValues := map[string]interface{}{
+ "name": identityName,
+ "resourceGroup": identityResourceGroup,
}
+ expectedValues["identity"] = identityValues
+ expectedOutputKeysValues["identityID"] = TerraformerOutputKeyIdentityID
+ expectedOutputKeysValues["identityClientID"] = TerraformerOutputKeyIdentityClientID
+
+ values, err := ComputeTerraformerChartValues(infra, clientAuth, config, cluster)
Expect(err).To(Not(HaveOccurred()))
Expect(values).To(BeEquivalentTo(expectedValues))
})
+
+ Context("NatGateway", func() {
+ It("should correctly compute terraform chart values with NatGateway", func() {
+ config.Networks.NatGateway = &api.NatGatewayConfig{
+ Enabled: true,
+ }
+ expectedCreateValues["natGateway"] = true
+ values, err := ComputeTerraformerChartValues(infra, clientAuth, config, cluster)
+ Expect(err).To(Not(HaveOccurred()))
+ Expect(values).To(BeEquivalentTo(expectedValues))
+ })
+ })
})
Describe("#StatusFromTerraformState", func() {