From dd68f9f13d09ced0732d18909b60867fc5dea227 Mon Sep 17 00:00:00 2001 From: "Kistner, Dominic" Date: Tue, 30 Nov 2021 12:19:37 +0100 Subject: [PATCH] Cleanup natipmigration logic --- hack/api-reference/api.md | 13 ----- pkg/apis/azure/types_infrastructure.go | 3 -- .../azure/v1alpha1/types_infrastructure.go | 4 -- .../azure/v1alpha1/zz_generated.conversion.go | 2 - .../infrastructure/templates/main.tpl.tf | 4 -- pkg/internal/infrastructure/terraform.go | 42 ---------------- pkg/internal/infrastructure/terraform_test.go | 48 +------------------ 7 files changed, 1 insertion(+), 115 deletions(-) diff --git a/hack/api-reference/api.md b/hack/api-reference/api.md index 41a9dc1ad..8fcc95ef6 100644 --- a/hack/api-reference/api.md +++ b/hack/api-reference/api.md @@ -659,19 +659,6 @@ bool

Zoned indicates whether the cluster uses zones

- - -natGatewayPublicIpMigrated
- -bool - - - -(Optional) -

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.

- -

MachineImage diff --git a/pkg/apis/azure/types_infrastructure.go b/pkg/apis/azure/types_infrastructure.go index cedf0c277..7ac6536ae 100644 --- a/pkg/apis/azure/types_infrastructure.go +++ b/pkg/apis/azure/types_infrastructure.go @@ -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. diff --git a/pkg/apis/azure/v1alpha1/types_infrastructure.go b/pkg/apis/azure/v1alpha1/types_infrastructure.go index 151fcc1dc..0d1277303 100644 --- a/pkg/apis/azure/v1alpha1/types_infrastructure.go +++ b/pkg/apis/azure/v1alpha1/types_infrastructure.go @@ -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. diff --git a/pkg/apis/azure/v1alpha1/zz_generated.conversion.go b/pkg/apis/azure/v1alpha1/zz_generated.conversion.go index c26c39a9c..e00a71578 100644 --- a/pkg/apis/azure/v1alpha1/zz_generated.conversion.go +++ b/pkg/apis/azure/v1alpha1/zz_generated.conversion.go @@ -494,7 +494,6 @@ func autoConvert_v1alpha1_InfrastructureStatus_To_azure_InfrastructureStatus(in out.SecurityGroups = *(*[]azure.SecurityGroup)(unsafe.Pointer(&in.SecurityGroups)) out.Identity = (*azure.IdentityStatus)(unsafe.Pointer(in.Identity)) out.Zoned = in.Zoned - out.NatGatewayPublicIPMigrated = in.NatGatewayPublicIPMigrated return nil } @@ -515,7 +514,6 @@ func autoConvert_azure_InfrastructureStatus_To_v1alpha1_InfrastructureStatus(in out.SecurityGroups = *(*[]SecurityGroup)(unsafe.Pointer(&in.SecurityGroups)) out.Identity = (*IdentityStatus)(unsafe.Pointer(in.Identity)) out.Zoned = in.Zoned - out.NatGatewayPublicIPMigrated = in.NatGatewayPublicIPMigrated return nil } diff --git a/pkg/internal/infrastructure/templates/main.tpl.tf b/pkg/internal/infrastructure/templates/main.tpl.tf index a582a241f..7a12457a2 100644 --- a/pkg/internal/infrastructure/templates/main.tpl.tf +++ b/pkg/internal/infrastructure/templates/main.tpl.tf @@ -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" { diff --git a/pkg/internal/infrastructure/terraform.go b/pkg/internal/infrastructure/terraform.go index f82f5e35c..564313eb8 100644 --- a/pkg/internal/infrastructure/terraform.go +++ b/pkg/internal/infrastructure/terraform.go @@ -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, @@ -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. @@ -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 } @@ -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 } @@ -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 -} diff --git a/pkg/internal/infrastructure/terraform_test.go b/pkg/internal/infrastructure/terraform_test.go index 9eb98f383..4ec37df99 100644 --- a/pkg/internal/infrastructure/terraform_test.go +++ b/pkg/internal/infrastructure/terraform_test.go @@ -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, @@ -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)) - }) - }) }) })