Skip to content

Commit

Permalink
chore: release host-network ports at the component termination (#7493)
Browse files Browse the repository at this point in the history
  • Loading branch information
leon-inf authored Jun 5, 2024
1 parent fd2831b commit 29e0bf1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
11 changes: 0 additions & 11 deletions controllers/apps/transformer_cluster_deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
"github.com/apecloud/kubeblocks/pkg/constant"
"github.com/apecloud/kubeblocks/pkg/controller/graph"
"github.com/apecloud/kubeblocks/pkg/controller/model"
intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
)

// clusterDeletionTransformer handles cluster deletion
Expand Down Expand Up @@ -140,16 +139,6 @@ func (t *clusterDeletionTransformer) Transform(ctx graph.TransformContext, dag *
return newRequeueError(time.Second*1, "not all sub-resources deleted")
}

// release the allocated host ports
// TODO release ports if scale in the components
// TODO release ports one by one without using prefix
pm := intctrlutil.GetPortManager()
for _, comp := range transCtx.ComponentSpecs {
if err = pm.ReleaseByPrefix(fmt.Sprintf("%s-%s", transCtx.Cluster.Name, comp.Name)); err != nil {
return newRequeueError(time.Second*1, "release host ports failed")
}
}

// fast return, that is stopping the plan.Build() stage and jump to plan.Execute() directly
return graph.ErrPrematureStop
}
Expand Down
6 changes: 6 additions & 0 deletions controllers/apps/transformer_component_deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ func (t *componentDeletionTransformer) deleteCompResources(transCtx *componentTr
graphCli.Delete(dag, comp)
}

// release the allocated host-network ports for the component
pm := intctrlutil.GetPortManager()
if err = pm.ReleaseByPrefix(comp.Name); err != nil {
return newRequeueError(time.Second*1, fmt.Sprintf("release host ports for component %s error: %s", comp.Name, err.Error()))
}

// fast return, that is stopping the plan.Build() stage and jump to plan.Execute() directly
return graph.ErrPrematureStop
}
Expand Down

0 comments on commit 29e0bf1

Please sign in to comment.