@@ -344,35 +344,37 @@ func reconcileBastion(scope *scope.Scope, cluster *clusterv1.Cluster, openStackC
344344 if err != nil {
345345 return errors .Errorf ("failed to reconcile bastion: %v" , err )
346346 }
347+ if ! openStackCluster .Spec .DisableFloatingIP {
348+ networkingService , err := networking .NewService (scope )
349+ if err != nil {
350+ return err
351+ }
352+ clusterName := fmt .Sprintf ("%s-%s" , cluster .Namespace , cluster .Name )
353+ fp , err := networkingService .GetOrCreateFloatingIP (openStackCluster , openStackCluster , clusterName , openStackCluster .Spec .Bastion .Instance .FloatingIP )
354+ if err != nil {
355+ handleUpdateOSCError (openStackCluster , errors .Errorf ("failed to get or create floating IP for bastion: %v" , err ))
356+ return errors .Errorf ("failed to get or create floating IP for bastion: %v" , err )
357+ }
358+ port , err := computeService .GetManagementPort (openStackCluster , instanceStatus )
359+ if err != nil {
360+ err = errors .Errorf ("getting management port for bastion: %v" , err )
361+ handleUpdateOSCError (openStackCluster , err )
362+ return err
363+ }
364+ err = networkingService .AssociateFloatingIP (openStackCluster , fp , port .ID )
365+ if err != nil {
366+ handleUpdateOSCError (openStackCluster , errors .Errorf ("failed to associate floating IP with bastion: %v" , err ))
367+ return errors .Errorf ("failed to associate floating IP with bastion: %v" , err )
368+ }
347369
348- networkingService , err := networking .NewService (scope )
349- if err != nil {
350- return err
351- }
352- clusterName := fmt .Sprintf ("%s-%s" , cluster .Namespace , cluster .Name )
353- fp , err := networkingService .GetOrCreateFloatingIP (openStackCluster , openStackCluster , clusterName , openStackCluster .Spec .Bastion .Instance .FloatingIP )
354- if err != nil {
355- handleUpdateOSCError (openStackCluster , errors .Errorf ("failed to get or create floating IP for bastion: %v" , err ))
356- return errors .Errorf ("failed to get or create floating IP for bastion: %v" , err )
357- }
358- port , err := computeService .GetManagementPort (openStackCluster , instanceStatus )
359- if err != nil {
360- err = errors .Errorf ("getting management port for bastion: %v" , err )
361- handleUpdateOSCError (openStackCluster , err )
362- return err
363- }
364- err = networkingService .AssociateFloatingIP (openStackCluster , fp , port .ID )
365- if err != nil {
366- handleUpdateOSCError (openStackCluster , errors .Errorf ("failed to associate floating IP with bastion: %v" , err ))
367- return errors .Errorf ("failed to associate floating IP with bastion: %v" , err )
370+ bastion , err := instanceStatus .APIInstance (openStackCluster )
371+ if err != nil {
372+ return err
373+ }
374+ bastion .FloatingIP = fp .FloatingIP
375+ openStackCluster .Status .Bastion = bastion
368376 }
369377
370- bastion , err := instanceStatus .APIInstance (openStackCluster )
371- if err != nil {
372- return err
373- }
374- bastion .FloatingIP = fp .FloatingIP
375- openStackCluster .Status .Bastion = bastion
376378 annotations .AddAnnotations (openStackCluster , map [string ]string {BastionInstanceHashAnnotation : bastionHash })
377379 return nil
378380}
0 commit comments