Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ReleaseHostPort for api server and service #489

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pkg/kubenest/controller/virtualcluster_init_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ func (c *VirtualClusterInitController) assignNodesByPolicy(virtualCluster *v1alp
return nil, errors.Wrapf(err, "Failed to update globalNode %s to InUse", updated.Name)
}
}

} else { // nodes needs to decrease
klog.V(2).Infof("Try decrease nodes %d for policy %s", -requestNodesChanged, policy.LabelSelector.String())
decrease := int(-requestNodesChanged)
Expand Down
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
Loading