Skip to content

Commit

Permalink
fix(bastion): public ip unlink
Browse files Browse the repository at this point in the history
  • Loading branch information
sebglon authored and outscale-hmi committed Aug 21, 2024
1 parent bee800c commit 20beff9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
9 changes: 6 additions & 3 deletions controllers/osccluster_bastion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,12 @@ func reconcileDeleteBastion(ctx context.Context, clusterScope *scope.ClusterScop
if bastionSpec.PublicIpName != "" {
linkPublicIpRef := clusterScope.GetLinkPublicIpRef()
publicIpName := bastionSpec.PublicIpName + "-" + clusterScope.GetUID()
err = publicIpSvc.UnlinkPublicIp(linkPublicIpRef.ResourceMap[publicIpName])
if err != nil {
return reconcile.Result{}, fmt.Errorf("%w Can not unlink publicIp for OscCluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName())
publicIpRef := linkPublicIpRef.ResourceMap[publicIpName]
if publicIpRef != "" {
err = publicIpSvc.UnlinkPublicIp(publicIpRef)
if err != nil {
return reconcile.Result{}, fmt.Errorf("%w Can not unlink publicIp for OscCluster %s/%s", err, clusterScope.GetNamespace(), clusterScope.GetName())
}
}
}
err = vmSvc.DeleteVm(vmId)
Expand Down
9 changes: 6 additions & 3 deletions controllers/oscmachine_vm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,12 @@ func reconcileDeleteVm(ctx context.Context, clusterScope *scope.ClusterScope, ma
if vmSpec.PublicIpName != "" {
linkPublicIpRef := machineScope.GetLinkPublicIpRef()
publicIpName := vmSpec.PublicIpName + "-" + clusterScope.GetUID()
err = publicIpSvc.UnlinkPublicIp(linkPublicIpRef.ResourceMap[publicIpName])
if err != nil {
return reconcile.Result{}, fmt.Errorf("%w Can not unlink publicIp for OscCluster %s/%s", err, machineScope.GetNamespace(), machineScope.GetName())
linkPublicIiId := linkPublicIpRef.ResourceMap[publicIpName]
if linkPublicIiId != "" {
err = publicIpSvc.UnlinkPublicIp(linkPublicIiId)
if err != nil {
return reconcile.Result{}, fmt.Errorf("%w Can not unlink publicIp for OscCluster %s/%s", err, machineScope.GetNamespace(), machineScope.GetName())
}
}
}
if vmSpec.PublicIp {
Expand Down
2 changes: 1 addition & 1 deletion controllers/oscmachine_volume_controller_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func TestReconcileVolumeResourceId(t *testing.T) {
expVolumeFound: true,
expSubnetFound: true,
expPublicIpFound: false,
expLinkPublicIpFound: true,
expLinkPublicIpFound: false,
expSecurityGroupFound: true,
expLoadBalancerSecurityGroupFound: true,
expTagFound: false,
Expand Down

0 comments on commit 20beff9

Please sign in to comment.