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

Cleanup natipmigration logic #406

Merged
merged 1 commit into from
Dec 1, 2021
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
13 changes: 0 additions & 13 deletions hack/api-reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -659,19 +659,6 @@ bool
<p>Zoned indicates whether the cluster uses zones</p>
</td>
</tr>
<tr>
<td>
<code>natGatewayPublicIpMigrated</code></br>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>NatGatewayPublicIPMigrated is an indicator if the Gardener managed public ip address is already migrated.
TODO(natipmigration) This can be removed in future versions when the ip migration has been completed.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="azure.provider.extensions.gardener.cloud/v1alpha1.MachineImage">MachineImage
Expand Down
3 changes: 0 additions & 3 deletions pkg/apis/azure/types_infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ type InfrastructureStatus struct {
Identity *IdentityStatus
// Zoned indicates whether the cluster uses zones
Zoned bool
// NatGatewayPublicIPMigrated is an indicator if the Gardener managed public ip address is already migrated.
// TODO(natipmigration) This can be removed in future versions when the ip migration has been completed.
NatGatewayPublicIPMigrated bool
}

// NetworkStatus is the current status of the infrastructure networks.
Expand Down
4 changes: 0 additions & 4 deletions pkg/apis/azure/v1alpha1/types_infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ type InfrastructureStatus struct {
// Zoned indicates whether the cluster uses zones
// +optional
Zoned bool `json:"zoned,omitempty"`
// NatGatewayPublicIPMigrated is an indicator if the Gardener managed public ip address is already migrated.
// TODO(natipmigration) This can be removed in future versions when the ip migration has been completed.
// +optional
NatGatewayPublicIPMigrated bool `json:"natGatewayPublicIpMigrated,omitempty"`
}

// NetworkStatus is the current status of the infrastructure networks.
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/azure/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions pkg/internal/infrastructure/templates/main.tpl.tf
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ resource "azurerm_nat_gateway" "nat" {
{{ if hasKey .natGateway "zone" -}}
zones = [{{ .natGateway.zone | quote }}]
{{- end }}
{{ if .natGateway.migrateNatGatewayToIPAssociation -}}
# TODO(natipmigration) This can be removed in future versions when the ip migration has been completed.
public_ip_address_ids = []
{{- end }}
{{- end }}
}
resource "azurerm_subnet_nat_gateway_association" "nat-worker-subnet-association" {
Expand Down
42 changes: 0 additions & 42 deletions pkg/internal/infrastructure/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,6 @@ func ComputeTerraformerTemplateValues(

natGatewayConfig, createNatGateway := generateNatGatewayValues(config)

// Checks if the Gardener managed NatGateway public ip needs to be migrated.
// TODO(natipmigration) This can be removed in future versions when the ip migration has been completed.
natGatewayIPMigrationRequired, err := isNatGatewayIPMigrationRequired(infra, config)
if err != nil {
return nil, err
}
natGatewayConfig["migrateNatGatewayToIPAssociation"] = natGatewayIPMigrationRequired

if config.Identity != nil && config.Identity.Name != "" && config.Identity.ResourceGroup != "" {
identityConfig = map[string]interface{}{
"name": config.Identity.Name,
Expand Down Expand Up @@ -274,9 +266,6 @@ type TerraformState struct {
IdentityClientID string
// Zoned is an indicator if zones should be used.
Zoned bool
// NatGatewayIPMigrated is the indicator if the nat gateway ip is migrated.
// TODO(natipmigration) This can be removed in future versions when the ip migration has been completed.
NatGatewayIPMigrated string
}

// ExtractTerraformState extracts the TerraformState from the given Terraformer.
Expand Down Expand Up @@ -350,10 +339,6 @@ func ExtractTerraformState(ctx context.Context, tf terraformer.Terraformer, infr
tfState.IdentityClientID = vars[TerraformerOutputKeyIdentityClientID]
}

if config.Networks.NatGateway != nil && config.Networks.NatGateway.Enabled {
tfState.NatGatewayIPMigrated = "true"
}

return &tfState, nil
}

Expand Down Expand Up @@ -412,11 +397,6 @@ func StatusFromTerraformState(tfState *TerraformState) *apiv1alpha1.Infrastructu
})
}

// TODO(natipmigration) This can be removed in future versions when the ip migration has been completed.
if tfState.NatGatewayIPMigrated == "true" {
infraState.NatGatewayPublicIPMigrated = true
}

return &infraState
}

Expand Down Expand Up @@ -528,25 +508,3 @@ func isPrimaryAvailabilitySetRequired(infra *extensionsv1alpha1.Infrastructure,

return false, nil
}

// isNatGatewayIPMigrationRequired checks if the Gardener managed NatGateway public ip needs to be migrated.
// TODO(natipmigration) This can be removed in future versions when the ip migration has been completed.
func isNatGatewayIPMigrationRequired(infra *extensionsv1alpha1.Infrastructure, config *api.InfrastructureConfig) (bool, error) {
if config.Networks.NatGateway == nil || !config.Networks.NatGateway.Enabled {
return false, nil
}

if infra.Status.ProviderStatus == nil {
return false, nil
}

infrastructureStatus, err := helper.InfrastructureStatusFromInfrastructure(infra)
if err != nil {
return false, err
}

if infrastructureStatus.NatGatewayPublicIPMigrated {
return false, nil
}
return true, nil
}
48 changes: 1 addition & 47 deletions pkg/internal/infrastructure/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@ var _ = Describe("Terraform", func() {
"securityGroupName": TerraformerOutputKeySecurityGroupName,
}

expectedNatGatewayValues = map[string]interface{}{
"migrateNatGatewayToIPAssociation": false,
}
expectedNatGatewayValues = map[string]interface{}{}

expectedValues = map[string]interface{}{
"azure": expectedAzureValues,
Expand Down Expand Up @@ -437,50 +435,6 @@ var _ = Describe("Terraform", func() {
Expect(err).NotTo(HaveOccurred())
Expect(values).To(BeEquivalentTo(expectedValues))
})

// TODO(natipmigration) This can be removed in future versions when the ip migration has been completed.
Context("NatGateway Gardener managed IP migration", func() {
BeforeEach(func() {
config.Networks.NatGateway = &api.NatGatewayConfig{
Enabled: true,
}
expectedCreateValues["natGateway"] = true
})

It("should migrate the NatGateway IP as it is not yet migrated", func() {
infrastructureStatus := api.InfrastructureStatus{
NatGatewayPublicIPMigrated: false,
}
infrastructureStatusMarshalled, err := json.Marshal(infrastructureStatus)
Expect(err).NotTo(HaveOccurred())

infra.Status.ProviderStatus = &runtime.RawExtension{
Raw: infrastructureStatusMarshalled,
}

expectedNatGatewayValues["migrateNatGatewayToIPAssociation"] = true
values, err := ComputeTerraformerTemplateValues(infra, config, cluster)
Expect(err).To(Not(HaveOccurred()))
Expect(values).To(BeEquivalentTo(expectedValues))
})

It("should not migrate the NatGateway IP as it is already migrated", func() {
infrastructureStatus := api.InfrastructureStatus{
NatGatewayPublicIPMigrated: true,
}
infrastructureStatusMarshalled, err := json.Marshal(infrastructureStatus)
Expect(err).NotTo(HaveOccurred())

infra.Status.ProviderStatus = &runtime.RawExtension{
Raw: infrastructureStatusMarshalled,
}

expectedNatGatewayValues["migrateNatGatewayToIPAssociation"] = false
values, err := ComputeTerraformerTemplateValues(infra, config, cluster)
Expect(err).To(Not(HaveOccurred()))
Expect(values).To(BeEquivalentTo(expectedValues))
})
})
})
})

Expand Down