Skip to content

Commit

Permalink
add ReleaseHostPort for api server and service
Browse files Browse the repository at this point in the history
Signed-off-by: qiuwei <[email protected]>
  • Loading branch information
qiuwei68 committed Apr 25, 2024
1 parent 08051b0 commit 564a2e4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pkg/kubenest/controlplane/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
kuberuntime "k8s.io/apimachinery/pkg/runtime"
clientset "k8s.io/client-go/kubernetes"
clientsetscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/klog/v2"

"github.com/kosmos.io/kosmos/pkg/kubenest/constants"
vcnodecontroller "github.com/kosmos.io/kosmos/pkg/kubenest/controller/virtualcluster.node.controller"
Expand All @@ -27,11 +28,15 @@ func EnsureVirtualClusterAPIServer(client clientset.Interface, name, namespace s
return nil
}

func DeleteVirtualClusterAPIServer(client clientset.Interface, name, namespace string) error {
func DeleteVirtualClusterAPIServer(client clientset.Interface, name, namespace string, manager *vcnodecontroller.HostPortManager) error {
deployName := fmt.Sprintf("%s-%s", name, "apiserver")
if err := util.DeleteDeployment(client, deployName, namespace); err != nil {
return errors.Wrapf(err, "Failed to delete deployment %s/%s", deployName, namespace)
}
err := manager.ReleaseHostPort(name)
if err != nil {
klog.Errorf("Error releasing host port for cluster %s: %v", name, err)
}
return nil
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/kubenest/controlplane/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func EnsureVirtualClusterService(client clientset.Interface, name, namespace str
return nil
}

func DeleteVirtualClusterService(client clientset.Interface, name, namespace string) error {
func DeleteVirtualClusterService(client clientset.Interface, name, namespace string, manager *vcnodecontroller.HostPortManager) error {
services := []string{
fmt.Sprintf("%s-%s", name, "apiserver"),
fmt.Sprintf("%s-%s", name, "etcd"),
Expand All @@ -49,6 +49,11 @@ func DeleteVirtualClusterService(client clientset.Interface, name, namespace str
}
}

err := manager.ReleaseHostPort(name)
if err != nil {
klog.Errorf("Error releasing host port for cluster %s: %v", name, err)
}

klog.V(2).Infof("Successfully uninstalled service for virtualcluster %s", name)
return nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/kubenest/tasks/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func uninstallVirtualClusterAPIServer(r workflow.RunData) error {
data.RemoteClient(),
data.GetName(),
data.GetNamespace(),
data.GetHostPortManager(),
)
if err != nil {
return fmt.Errorf("failed to install virtual cluster apiserver component, err: %w", err)
Expand Down
1 change: 1 addition & 0 deletions pkg/kubenest/tasks/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func uninstallVirtualClusterService(r workflow.RunData) error {
data.RemoteClient(),
data.GetName(),
data.GetNamespace(),
data.GetHostPortManager(),
)
if err != nil {
return fmt.Errorf("failed to uninstall virtual cluster service , err: %w", err)
Expand Down

0 comments on commit 564a2e4

Please sign in to comment.