@@ -11,7 +11,6 @@ import (
1111 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
1212 extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
1313 "github.com/go-logr/logr"
14- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1514 "k8s.io/apimachinery/pkg/runtime"
1615 "k8s.io/apimachinery/pkg/util/sets"
1716 "k8s.io/client-go/rest"
@@ -20,7 +19,6 @@ import (
2019
2120 awsapi "github.com/gardener/gardener-extension-provider-aws/pkg/apis/aws"
2221 "github.com/gardener/gardener-extension-provider-aws/pkg/apis/aws/helper"
23- awsv1alpha1 "github.com/gardener/gardener-extension-provider-aws/pkg/apis/aws/v1alpha1"
2422 "github.com/gardener/gardener-extension-provider-aws/pkg/aws"
2523 "github.com/gardener/gardener-extension-provider-aws/pkg/controller/infrastructure/infraflow"
2624 "github.com/gardener/gardener-extension-provider-aws/pkg/controller/infrastructure/infraflow/shared"
@@ -185,8 +183,11 @@ func (f *FlowReconciler) migrateFromTerraform(ctx context.Context, infra *extens
185183 return nil , fmt .Errorf ("migration from terraform state failed: %w" , err )
186184 }
187185
188- // TODO duplication of computeProviderStatusFromFlowState and fctx.computeInfrastructureStatus
189- infrastructureStatus := computeProviderStatusFromFlowState (infrastructureConfig , state )
186+ whiteboard := shared .NewWhiteboard ()
187+ if state != nil {
188+ whiteboard .ImportFromFlatMap (state .Data )
189+ }
190+ infrastructureStatus := infraflow .BuildInfrastructureStatus (whiteboard , infrastructureConfig )
190191
191192 if err := infraflow .PatchProviderStatusAndState (ctx , f .client , infra , networking , infrastructureStatus , & runtime.RawExtension {Object : state }, nil , nil , nil ); err != nil {
192193 return nil , fmt .Errorf ("updating status state failed: %w" , err )
@@ -195,94 +196,6 @@ func (f *FlowReconciler) migrateFromTerraform(ctx context.Context, infra *extens
195196 return state , nil
196197}
197198
198- func computeProviderStatusFromFlowState (config * awsapi.InfrastructureConfig , state * awsapi.InfrastructureState ) * awsv1alpha1.InfrastructureStatus {
199- if len (state .Data ) == 0 {
200- return nil
201- }
202- status := & awsv1alpha1.InfrastructureStatus {
203- TypeMeta : metav1.TypeMeta {
204- APIVersion : awsv1alpha1 .SchemeGroupVersion .String (),
205- Kind : "InfrastructureStatus" ,
206- },
207- }
208-
209- vpcID := ""
210- if config .Networks .VPC .ID != nil {
211- vpcID = * config .Networks .VPC .ID
212- } else {
213- vpcID = state .Data [infraflow .IdentifierVPC ]
214- if ! shared .IsValidValue (vpcID ) {
215- vpcID = ""
216- }
217- }
218-
219- if vpcID != "" {
220- var subnets []awsv1alpha1.Subnet
221- prefix := infraflow .ChildIdZones + shared .Separator
222- for k , v := range state .Data {
223- if ! shared .IsValidValue (v ) {
224- continue
225- }
226- if strings .HasPrefix (k , prefix ) {
227- parts := strings .Split (k , shared .Separator )
228- if len (parts ) != 3 {
229- continue
230- }
231- var purpose string
232- switch parts [2 ] {
233- case infraflow .IdentifierZoneSubnetPublic :
234- purpose = awsapi .PurposePublic
235- case infraflow .IdentifierZoneSubnetWorkers :
236- purpose = awsapi .PurposeNodes
237- default :
238- continue
239- }
240- subnets = append (subnets , awsv1alpha1.Subnet {
241- ID : v ,
242- Purpose : purpose ,
243- Zone : parts [1 ],
244- })
245- }
246- }
247-
248- status .VPC = awsv1alpha1.VPCStatus {
249- ID : vpcID ,
250- Subnets : subnets ,
251- }
252- if groupID := state .Data [infraflow .IdentifierNodesSecurityGroup ]; shared .IsValidValue (groupID ) {
253- status .VPC .SecurityGroups = []awsv1alpha1.SecurityGroup {
254- {
255- Purpose : awsapi .PurposeNodes ,
256- ID : groupID ,
257- },
258- }
259- }
260- }
261-
262- if keyName := state .Data [infraflow .NameKeyPair ]; shared .IsValidValue (keyName ) {
263- status .EC2 .KeyName = keyName
264- }
265-
266- if name := state .Data [infraflow .NameIAMInstanceProfile ]; shared .IsValidValue (name ) {
267- status .IAM .InstanceProfiles = []awsv1alpha1.InstanceProfile {
268- {
269- Purpose : awsapi .PurposeNodes ,
270- Name : name ,
271- },
272- }
273- }
274- if arn := state .Data [infraflow .ARNIAMRole ]; shared .IsValidValue (arn ) {
275- status .IAM .Roles = []awsv1alpha1.Role {
276- {
277- Purpose : awsapi .PurposeNodes ,
278- ARN : arn ,
279- },
280- }
281- }
282-
283- return status
284- }
285-
286199func migrateTerraformStateToFlowState (rawExtension * runtime.RawExtension , zones []awsapi.Zone ) (* awsapi.InfrastructureState , error ) {
287200 var (
288201 flowState = & awsapi.InfrastructureState {
0 commit comments