From 93c23347edab79321879a481a8261f80d993f3fb Mon Sep 17 00:00:00 2001 From: qiuwei Date: Wed, 15 May 2024 09:31:21 +0800 Subject: [PATCH] feat: Record the assigned port in the virtualcluster Signed-off-by: qiuwei --- cmd/kubenest/operator/app/operator.go | 16 +- deploy/crds/kosmos.io_virtualclusters.yaml | 3 + .../kosmos/v1alpha1/virtualcluster_types.go | 2 + pkg/generated/openapi/zz_generated.openapi.go | 6 + .../hostport_manager.go | 151 ------------------ .../virtualcluster_execute_controller.go | 7 +- .../virtualcluster_init_controller.go | 81 ++++++++-- pkg/kubenest/controlplane/apiserver.go | 22 +-- pkg/kubenest/controlplane/service.go | 16 +- pkg/kubenest/init.go | 23 ++- pkg/kubenest/tasks/apiserver.go | 3 +- pkg/kubenest/tasks/data.go | 3 +- pkg/kubenest/tasks/service.go | 3 +- 13 files changed, 112 insertions(+), 224 deletions(-) delete mode 100644 pkg/kubenest/controller/virtualcluster.node.controller/hostport_manager.go diff --git a/cmd/kubenest/operator/app/operator.go b/cmd/kubenest/operator/app/operator.go index 717505d16..529565b5d 100644 --- a/cmd/kubenest/operator/app/operator.go +++ b/cmd/kubenest/operator/app/operator.go @@ -88,18 +88,12 @@ func run(ctx context.Context, opts *options.Options) error { return fmt.Errorf("could not create clientset: %v", err) } - hostPortManager, err := vcnodecontroller.NewHostPortManager(hostKubeClient) - if err != nil { - return fmt.Errorf("failed to create host port manager: %v", err) - } - VirtualClusterInitController := controller.VirtualClusterInitController{ - Client: mgr.GetClient(), - Config: mgr.GetConfig(), - EventRecorder: mgr.GetEventRecorderFor(constants.InitControllerName), - HostPortManager: hostPortManager, - RootClientSet: hostKubeClient, - KosmosClient: kosmosClient, + Client: mgr.GetClient(), + Config: mgr.GetConfig(), + EventRecorder: mgr.GetEventRecorderFor(constants.InitControllerName), + RootClientSet: hostKubeClient, + KosmosClient: kosmosClient, } if err = VirtualClusterInitController.SetupWithManager(mgr); err != nil { return fmt.Errorf("error starting %s: %v", constants.InitControllerName, err) diff --git a/deploy/crds/kosmos.io_virtualclusters.yaml b/deploy/crds/kosmos.io_virtualclusters.yaml index c290a6f1e..4439823b1 100644 --- a/deploy/crds/kosmos.io_virtualclusters.yaml +++ b/deploy/crds/kosmos.io_virtualclusters.yaml @@ -144,6 +144,9 @@ spec: phase: description: Phase is the phase of kosmos-operator handling the VirtualCluster type: string + port: + format: int32 + type: integer reason: type: string updateTime: diff --git a/pkg/apis/kosmos/v1alpha1/virtualcluster_types.go b/pkg/apis/kosmos/v1alpha1/virtualcluster_types.go index 048d743fd..1a016843f 100644 --- a/pkg/apis/kosmos/v1alpha1/virtualcluster_types.go +++ b/pkg/apis/kosmos/v1alpha1/virtualcluster_types.go @@ -97,6 +97,8 @@ type VirtualClusterStatus struct { Reason string `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"` // +optional UpdateTime *metav1.Time `json:"updateTime,omitempty" protobuf:"bytes,7,opt,name=updateTime"` + // +optional + Port int32 `json:"port,omitempty"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index b84111ba2..33dc8be22 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -3094,6 +3094,12 @@ func schema_pkg_apis_kosmos_v1alpha1_VirtualClusterStatus(ref common.ReferenceCa Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.Time"), }, }, + "port": { + SchemaProps: spec.SchemaProps{ + Type: []string{"integer"}, + Format: "int32", + }, + }, }, }, }, diff --git a/pkg/kubenest/controller/virtualcluster.node.controller/hostport_manager.go b/pkg/kubenest/controller/virtualcluster.node.controller/hostport_manager.go deleted file mode 100644 index 4641f9a74..000000000 --- a/pkg/kubenest/controller/virtualcluster.node.controller/hostport_manager.go +++ /dev/null @@ -1,151 +0,0 @@ -package vcnodecontroller - -import ( - "context" - "fmt" - "sync" - - "gopkg.in/yaml.v3" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/kubernetes" - - "github.com/kosmos.io/kosmos/pkg/kubenest/constants" -) - -/** -apiVersion: v1 -kind: ConfigMap -metadata: - name: kosmos-hostports - namespace: kosmos-system -data: - config.yaml: | - PortsPool: - - 5443 - - 6443 - - 7443 - ClusterPorts: - - Port: 5443 - Cluster: "cluster1" - - Port: 6443 - Cluster: "cluster2" -*/ - -type HostPortManager struct { - HostPortPool *HostPortPool - kubeClient kubernetes.Interface - lock sync.Mutex -} - -type HostPortPool struct { - PortsPool []int32 `yaml:"portsPool"` - ClusterPorts []ClusterPort `yaml:"clusterPorts"` -} - -type ClusterPort struct { - Port int32 `yaml:"port"` - Cluster string `yaml:"cluster"` -} - -func NewHostPortManager(client kubernetes.Interface) (*HostPortManager, error) { - hostPorts, err := client.CoreV1().ConfigMaps(constants.KosmosNs).Get(context.TODO(), constants.HostPortsCMName, metav1.GetOptions{}) - if err != nil { - return nil, err - } - yamlData, exist := hostPorts.Data[constants.HostPortsCMDataName] - if !exist { - return nil, fmt.Errorf("hostports not found in configmap") - } - - var hostPool HostPortPool - if err := yaml.Unmarshal([]byte(yamlData), &hostPool); err != nil { - return nil, err - } - manager := &HostPortManager{ - HostPortPool: &hostPool, - kubeClient: client, - } - return manager, nil -} - -func (m *HostPortManager) AllocateHostPort(clusterName string) (int32, error) { - m.lock.Lock() - defer m.lock.Unlock() - - //使用临时变量存储原来的cm - oldHostPool := m.HostPortPool - - //查询该clusterName是否已经被分配了端口,如果分配了,返回之前分配的端口 - for _, cluster := range m.HostPortPool.ClusterPorts { - if cluster.Cluster == clusterName { - return cluster.Port, nil - } - } - - for _, port := range m.HostPortPool.PortsPool { - if !m.isPortAllocated(port) { - m.HostPortPool.ClusterPorts = append(m.HostPortPool.ClusterPorts, ClusterPort{Port: port, Cluster: clusterName}) - err := updateConfigMapAndRollback(m, oldHostPool) - if err != nil { - return 0, err - } - return port, err - } - } - return 0, fmt.Errorf("no available ports to allocate") -} - -func (m *HostPortManager) ReleaseHostPort(clusterName string) error { - m.lock.Lock() - defer m.lock.Unlock() - - oldHostPool := m.HostPortPool - - for i, cp := range m.HostPortPool.ClusterPorts { - if cp.Cluster == clusterName { - // Remove the entry from the slice - m.HostPortPool.ClusterPorts = append(m.HostPortPool.ClusterPorts[:i], m.HostPortPool.ClusterPorts[i+1:]...) - err := updateConfigMapAndRollback(m, oldHostPool) - if err != nil { - return err - } - return nil - } - } - return fmt.Errorf("no port found for cluster %s", clusterName) -} - -func updateConfigMapAndRollback(m *HostPortManager, oldHostPool *HostPortPool) error { - data, err := yaml.Marshal(m.HostPortPool) - if err != nil { - m.HostPortPool = oldHostPool - return err - } - - configMap, err := m.kubeClient.CoreV1().ConfigMaps(constants.KosmosNs).Get(context.TODO(), constants.HostPortsCMName, metav1.GetOptions{}) - if err != nil { - m.HostPortPool = oldHostPool - return err - } - - configMap.Data[constants.HostPortsCMDataName] = string(data) - - _, updateErr := m.kubeClient.CoreV1().ConfigMaps(constants.KosmosNs).Update(context.TODO(), configMap, metav1.UpdateOptions{}) - - if updateErr != nil { - // 回滚 HostPortPool - m.HostPortPool = oldHostPool - return updateErr - } - - return nil -} - -func (m *HostPortManager) isPortAllocated(port int32) bool { - for _, cp := range m.HostPortPool.ClusterPorts { - if cp.Port == port { - return true - } - } - return false -} diff --git a/pkg/kubenest/controller/virtualcluster_execute_controller.go b/pkg/kubenest/controller/virtualcluster_execute_controller.go index 0177354c7..9a07bdc1a 100644 --- a/pkg/kubenest/controller/virtualcluster_execute_controller.go +++ b/pkg/kubenest/controller/virtualcluster_execute_controller.go @@ -11,7 +11,6 @@ import ( "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1" "github.com/kosmos.io/kosmos/pkg/kubenest" "github.com/kosmos.io/kosmos/pkg/kubenest/constants" - vcnodecontroller "github.com/kosmos.io/kosmos/pkg/kubenest/controller/virtualcluster.node.controller" "github.com/kosmos.io/kosmos/pkg/kubenest/workflow" ) @@ -22,7 +21,7 @@ type Executor struct { config *rest.Config } -func NewExecutor(virtualCluster *v1alpha1.VirtualCluster, c client.Client, config *rest.Config, hostPortManager *vcnodecontroller.HostPortManager) (*Executor, error) { +func NewExecutor(virtualCluster *v1alpha1.VirtualCluster, c client.Client, config *rest.Config) (*Executor, error) { var phase *workflow.Phase opts := []kubenest.InitOpt{ @@ -33,9 +32,9 @@ func NewExecutor(virtualCluster *v1alpha1.VirtualCluster, c client.Client, confi action := recognizeActionFor(virtualCluster) switch action { case constants.InitAction: - phase = kubenest.NewInitPhase(options, hostPortManager) + phase = kubenest.NewInitPhase(options) case constants.DeInitAction: - phase = kubenest.UninstallPhase(options, hostPortManager) + phase = kubenest.UninstallPhase(options) default: return nil, fmt.Errorf("failed to recognize action for virtual cluster %s", virtualCluster.Name) } diff --git a/pkg/kubenest/controller/virtualcluster_init_controller.go b/pkg/kubenest/controller/virtualcluster_init_controller.go index 713383974..1a2fabd40 100644 --- a/pkg/kubenest/controller/virtualcluster_init_controller.go +++ b/pkg/kubenest/controller/virtualcluster_init_controller.go @@ -8,6 +8,7 @@ import ( "time" "github.com/pkg/errors" + "gopkg.in/yaml.v3" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" @@ -29,18 +30,16 @@ import ( "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1" "github.com/kosmos.io/kosmos/pkg/generated/clientset/versioned" "github.com/kosmos.io/kosmos/pkg/kubenest/constants" - vcnodecontroller "github.com/kosmos.io/kosmos/pkg/kubenest/controller/virtualcluster.node.controller" "github.com/kosmos.io/kosmos/pkg/kubenest/util" ) type VirtualClusterInitController struct { client.Client - Config *rest.Config - EventRecorder record.EventRecorder - HostPortManager *vcnodecontroller.HostPortManager - RootClientSet kubernetes.Interface - KosmosClient versioned.Interface - lock sync.Mutex + Config *rest.Config + EventRecorder record.EventRecorder + RootClientSet kubernetes.Interface + KosmosClient versioned.Interface + lock sync.Mutex } type NodePool struct { @@ -50,6 +49,10 @@ type NodePool struct { State string `json:"state" yaml:"state"` } +type HostPortPool struct { + PortsPool []int32 `yaml:"portsPool"` +} + const ( VirtualClusterControllerFinalizer = "kosmos.io/virtualcluster-controller" RequeueTime = 10 * time.Second @@ -230,7 +233,13 @@ func (c *VirtualClusterInitController) removeFinalizer(virtualCluster *v1alpha1. func (c *VirtualClusterInitController) createVirtualCluster(virtualCluster *v1alpha1.VirtualCluster) error { klog.V(2).Infof("Reconciling virtual cluster", "name", virtualCluster.Name) - executer, err := NewExecutor(virtualCluster, c.Client, c.Config, c.HostPortManager) + //Assign host port + _, err := c.AllocateHostPort(virtualCluster) + if err != nil { + return errors.Wrap(err, "Error in assign host port!") + } + + executer, err := NewExecutor(virtualCluster, c.Client, c.Config) if err != nil { return err } @@ -258,7 +267,7 @@ func (c *VirtualClusterInitController) createVirtualCluster(virtualCluster *v1al func (c *VirtualClusterInitController) destroyVirtualCluster(virtualCluster *v1alpha1.VirtualCluster) error { klog.V(2).Infof("Destroying virtual cluster %s", virtualCluster.Name) - execute, err := NewExecutor(virtualCluster, c.Client, c.Config, c.HostPortManager) + execute, err := NewExecutor(virtualCluster, c.Client, c.Config) if err != nil { return err } @@ -453,3 +462,57 @@ func mapContains(big map[string]string, small map[string]string) bool { } return true } + +func GetHostPortPoolFromConfigMap(client kubernetes.Interface, ns, cmName, dataKey string) (*HostPortPool, error) { + hostPorts, err := client.CoreV1().ConfigMaps(ns).Get(context.TODO(), cmName, metav1.GetOptions{}) + if err != nil { + return nil, err + } + + yamlData, exist := hostPorts.Data[dataKey] + if !exist { + return nil, fmt.Errorf("key '%s' not found in ConfigMap '%s'", dataKey, cmName) + } + + var hostPool HostPortPool + if err := yaml.Unmarshal([]byte(yamlData), &hostPool); err != nil { + return nil, err + } + + return &hostPool, nil +} + +func (c *VirtualClusterInitController) isPortAllocated(port int32) bool { + vcList := &v1alpha1.VirtualClusterList{} + err := c.List(context.Background(), vcList) + if err != nil { + klog.Errorf("list virtual cluster error: %v", err) + return false + } + + for _, vc := range vcList.Items { + if vc.Status.Port == port { + return true + } + } + + return false +} + +func (c *VirtualClusterInitController) AllocateHostPort(virtualCluster *v1alpha1.VirtualCluster) (int32, error) { + c.lock.Lock() + defer c.lock.Unlock() + + hostPool, err := GetHostPortPoolFromConfigMap(c.RootClientSet, constants.KosmosNs, constants.HostPortsCMName, constants.HostPortsCMDataName) + if err != nil { + return 0, err + } + + for _, port := range hostPool.PortsPool { + if !c.isPortAllocated(port) { + virtualCluster.Status.Port = port + return port, nil + } + } + return 0, fmt.Errorf("no available ports to allocate") +} diff --git a/pkg/kubenest/controlplane/apiserver.go b/pkg/kubenest/controlplane/apiserver.go index 72a75aadd..67488f032 100644 --- a/pkg/kubenest/controlplane/apiserver.go +++ b/pkg/kubenest/controlplane/apiserver.go @@ -3,39 +3,27 @@ package controlplane import ( "fmt" + "github.com/kosmos.io/kosmos/pkg/kubenest/constants" + "github.com/kosmos.io/kosmos/pkg/kubenest/manifest/controlplane/apiserver" + "github.com/kosmos.io/kosmos/pkg/kubenest/util" "github.com/pkg/errors" appsv1 "k8s.io/api/apps/v1" "k8s.io/apimachinery/pkg/util/yaml" clientset "k8s.io/client-go/kubernetes" - "k8s.io/klog/v2" - - "github.com/kosmos.io/kosmos/pkg/kubenest/constants" - vcnodecontroller "github.com/kosmos.io/kosmos/pkg/kubenest/controller/virtualcluster.node.controller" - "github.com/kosmos.io/kosmos/pkg/kubenest/manifest/controlplane/apiserver" - "github.com/kosmos.io/kosmos/pkg/kubenest/util" ) -func EnsureVirtualClusterAPIServer(client clientset.Interface, name, namespace string, manager *vcnodecontroller.HostPortManager) error { - port, err := manager.AllocateHostPort(name) - if err != nil { - return fmt.Errorf("failed to allocate host ip for virtual cluster apiserver, err: %w", err) - } - +func EnsureVirtualClusterAPIServer(client clientset.Interface, name, namespace string, port int32) error { if err := installAPIServer(client, name, namespace, port); err != nil { return fmt.Errorf("failed to install virtual cluster apiserver, err: %w", err) } return nil } -func DeleteVirtualClusterAPIServer(client clientset.Interface, name, namespace string, manager *vcnodecontroller.HostPortManager) error { +func DeleteVirtualClusterAPIServer(client clientset.Interface, name, namespace string) 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.Warningf("Error releasing host port for cluster %s: %v", name, err) - } return nil } diff --git a/pkg/kubenest/controlplane/service.go b/pkg/kubenest/controlplane/service.go index ca95e3655..b043fe54c 100644 --- a/pkg/kubenest/controlplane/service.go +++ b/pkg/kubenest/controlplane/service.go @@ -3,7 +3,6 @@ package controlplane import ( "context" "fmt" - "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -13,25 +12,19 @@ import ( "k8s.io/klog/v2" "github.com/kosmos.io/kosmos/pkg/kubenest/constants" - vcnodecontroller "github.com/kosmos.io/kosmos/pkg/kubenest/controller/virtualcluster.node.controller" "github.com/kosmos.io/kosmos/pkg/kubenest/manifest/controlplane/apiserver" "github.com/kosmos.io/kosmos/pkg/kubenest/manifest/controlplane/etcd" "github.com/kosmos.io/kosmos/pkg/kubenest/util" ) -func EnsureVirtualClusterService(client clientset.Interface, name, namespace string, manager *vcnodecontroller.HostPortManager) error { - port, err := manager.AllocateHostPort(name) - if err != nil { - return fmt.Errorf("failed to allocate host ip for virtual cluster apiserver, err: %w", err) - } - +func EnsureVirtualClusterService(client clientset.Interface, name, namespace string, port int32) error { if err := createServerService(client, name, namespace, port); err != nil { return fmt.Errorf("failed to create virtual cluster apiserver-service, err: %w", err) } return nil } -func DeleteVirtualClusterService(client clientset.Interface, name, namespace string, manager *vcnodecontroller.HostPortManager) error { +func DeleteVirtualClusterService(client clientset.Interface, name, namespace string) error { services := []string{ fmt.Sprintf("%s-%s", name, "apiserver"), fmt.Sprintf("%s-%s", name, "etcd"), @@ -48,11 +41,6 @@ func DeleteVirtualClusterService(client clientset.Interface, name, namespace str } } - err := manager.ReleaseHostPort(name) - if err != nil { - klog.Warningf("Error releasing host port for cluster %s: %v", name, err) - } - klog.V(2).Infof("Successfully uninstalled service for virtualcluster %s", name) return nil } diff --git a/pkg/kubenest/init.go b/pkg/kubenest/init.go index afcc64f00..b139da42a 100644 --- a/pkg/kubenest/init.go +++ b/pkg/kubenest/init.go @@ -12,7 +12,6 @@ import ( "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1" "github.com/kosmos.io/kosmos/pkg/generated/clientset/versioned" - vcnodecontroller "github.com/kosmos.io/kosmos/pkg/kubenest/controller/virtualcluster.node.controller" "github.com/kosmos.io/kosmos/pkg/kubenest/tasks" "github.com/kosmos.io/kosmos/pkg/kubenest/util" "github.com/kosmos.io/kosmos/pkg/kubenest/util/cert" @@ -35,7 +34,7 @@ type initData struct { virtualClusterDataDir string privateRegistry string externalIP string - hostPortManager *vcnodecontroller.HostPortManager + hostPort int32 } type InitOptions struct { @@ -47,7 +46,7 @@ type InitOptions struct { virtualCluster *v1alpha1.VirtualCluster } -func NewInitPhase(opts *InitOptions, hostPortManager *vcnodecontroller.HostPortManager) *workflow.Phase { +func NewInitPhase(opts *InitOptions) *workflow.Phase { initPhase := workflow.NewPhase() initPhase.AppendTask(tasks.NewVirtualClusterServiceTask()) @@ -65,12 +64,12 @@ func NewInitPhase(opts *InitOptions, hostPortManager *vcnodecontroller.HostPortM initPhase.AppendTask(tasks.NewComponentsFromManifestsTask()) initPhase.SetDataInitializer(func() (workflow.RunData, error) { - return newRunData(opts, hostPortManager) + return newRunData(opts) }) return initPhase } -func UninstallPhase(opts *InitOptions, hostPortManager *vcnodecontroller.HostPortManager) *workflow.Phase { +func UninstallPhase(opts *InitOptions) *workflow.Phase { destroyPhase := workflow.NewPhase() destroyPhase.AppendTask(tasks.UninstallCoreDNSTask()) destroyPhase.AppendTask(tasks.UninstallComponentTask()) @@ -81,7 +80,7 @@ func UninstallPhase(opts *InitOptions, hostPortManager *vcnodecontroller.HostPor destroyPhase.AppendTask(tasks.DeleteEtcdPvcTask()) destroyPhase.SetDataInitializer(func() (workflow.RunData, error) { - return newRunData(opts, hostPortManager) + return newRunData(opts) }) return destroyPhase } @@ -120,7 +119,7 @@ func NewInitOptWithKubeconfig(config *rest.Config) InitOpt { } } -func newRunData(opt *InitOptions, hostPortManager *vcnodecontroller.HostPortManager) (*initData, error) { +func newRunData(opt *InitOptions) (*initData, error) { if err := opt.Validate(); err != nil { return nil, err } @@ -170,7 +169,7 @@ func newRunData(opt *InitOptions, hostPortManager *vcnodecontroller.HostPortMana privateRegistry: utils.DefaultImageRepository, CertStore: cert.NewCertStore(), externalIP: opt.virtualCluster.Spec.ExternalIP, - hostPortManager: hostPortManager, + hostPort: opt.virtualCluster.Status.Port, }, nil } @@ -198,10 +197,6 @@ func (i initData) GetNamespace() string { return i.namespace } -func (i initData) GetHostPortManager() *vcnodecontroller.HostPortManager { - return i.hostPortManager -} - func (i initData) ControlplaneAddress() string { return i.controlplaneAddr } @@ -234,6 +229,10 @@ func (i initData) ExternalIP() string { return i.externalIP } +func (i initData) HostPort() int32 { + return i.hostPort +} + func (i initData) DynamicClient() *dynamic.DynamicClient { return i.dynamicClient } diff --git a/pkg/kubenest/tasks/apiserver.go b/pkg/kubenest/tasks/apiserver.go index 6efa79024..7d7370189 100644 --- a/pkg/kubenest/tasks/apiserver.go +++ b/pkg/kubenest/tasks/apiserver.go @@ -50,7 +50,7 @@ func runVirtualClusterAPIServer(r workflow.RunData) error { data.RemoteClient(), data.GetName(), data.GetNamespace(), - data.GetHostPortManager(), + data.HostPort(), ) if err != nil { return fmt.Errorf("failed to install virtual cluster apiserver component, err: %w", err) @@ -101,7 +101,6 @@ 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) diff --git a/pkg/kubenest/tasks/data.go b/pkg/kubenest/tasks/data.go index 9b737e0db..4cf65a336 100644 --- a/pkg/kubenest/tasks/data.go +++ b/pkg/kubenest/tasks/data.go @@ -5,7 +5,6 @@ import ( clientset "k8s.io/client-go/kubernetes" "github.com/kosmos.io/kosmos/pkg/generated/clientset/versioned" - vcnodecontroller "github.com/kosmos.io/kosmos/pkg/kubenest/controller/virtualcluster.node.controller" "github.com/kosmos.io/kosmos/pkg/kubenest/util/cert" ) @@ -13,7 +12,6 @@ type InitData interface { cert.CertStore GetName() string GetNamespace() string - GetHostPortManager() *vcnodecontroller.HostPortManager ControlplaneAddress() string ServiceClusterIp() []string RemoteClient() clientset.Interface @@ -21,5 +19,6 @@ type InitData interface { DataDir() string VirtualClusterVersion() string ExternalIP() string + HostPort() int32 DynamicClient() *dynamic.DynamicClient } diff --git a/pkg/kubenest/tasks/service.go b/pkg/kubenest/tasks/service.go index b38018b57..f91eb8a06 100644 --- a/pkg/kubenest/tasks/service.go +++ b/pkg/kubenest/tasks/service.go @@ -44,7 +44,7 @@ func runVirtualClusterService(r workflow.RunData) error { data.RemoteClient(), data.GetName(), data.GetNamespace(), - data.GetHostPortManager(), + data.HostPort(), ) if err != nil { return fmt.Errorf("failed to install virtual cluster service , err: %w", err) @@ -78,7 +78,6 @@ 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)