Skip to content

Commit

Permalink
Merge pull request kosmos-io#349 from wangyizhi1/mcs
Browse files Browse the repository at this point in the history
fix: serviceimport may not be deleted cleanly
  • Loading branch information
wuyingjun-lucky authored Dec 27, 2023
2 parents 47e012b + 677e078 commit ed1b248
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
11 changes: 5 additions & 6 deletions pkg/clustertree/cluster-manager/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,11 @@ func (c *ClusterController) setupControllers(

if c.Options.MultiClusterService {
serviceImportController := &mcs.ServiceImportController{
LeafClient: mgr.GetClient(),
LeafKosmosClient: leafKosmosClient,
EventRecorder: mgr.GetEventRecorderFor(mcs.LeafServiceImportControllerName),
Logger: mgr.GetLogger(),
LeafNodeName: cluster.Name,
// todo @wyz
LeafClient: mgr.GetClient(),
LeafKosmosClient: leafKosmosClient,
EventRecorder: mgr.GetEventRecorderFor(mcs.LeafServiceImportControllerName),
Logger: mgr.GetLogger(),
LeafNodeName: cluster.Name,
IPFamilyType: cluster.Spec.ClusterLinkOptions.IPFamily,
RootResourceManager: c.RootResourceManager,
ReservedNamespaces: c.Options.ReservedNamespaces,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
kosmosv1alpha1 "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1"
kosmosversioned "github.com/kosmos.io/kosmos/pkg/generated/clientset/versioned"
"github.com/kosmos.io/kosmos/pkg/generated/informers/externalversions"
"github.com/kosmos.io/kosmos/pkg/generated/listers/apis/v1alpha1"
"github.com/kosmos.io/kosmos/pkg/utils"
"github.com/kosmos.io/kosmos/pkg/utils/flags"
"github.com/kosmos.io/kosmos/pkg/utils/helper"
Expand All @@ -46,9 +47,10 @@ type ServiceImportController struct {
processor utils.AsyncWorker
RootResourceManager *utils.ResourceManager
// ReservedNamespaces are the protected namespaces to prevent Kosmos for deleting system resources
ReservedNamespaces []string
BackoffOptions flags.BackoffOptions
SyncPeriod time.Duration
ReservedNamespaces []string
BackoffOptions flags.BackoffOptions
SyncPeriod time.Duration
serviceImportLister v1alpha1.ServiceImportLister
}

func (c *ServiceImportController) AddController(mgr manager.Manager) error {
Expand All @@ -74,6 +76,7 @@ func (c *ServiceImportController) Start(ctx context.Context) error {

serviceImportInformerFactory := externalversions.NewSharedInformerFactory(c.LeafKosmosClient, c.SyncPeriod)
serviceImportInformer := serviceImportInformerFactory.Multicluster().V1alpha1().ServiceImports()
serviceImportLister := serviceImportInformer.Lister()
_, err := serviceImportInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: c.OnAdd,
UpdateFunc: c.OnUpdate,
Expand All @@ -82,6 +85,7 @@ func (c *ServiceImportController) Start(ctx context.Context) error {
if err != nil {
return err
}
c.serviceImportLister = serviceImportLister

_, err = c.RootResourceManager.EndpointSliceInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: c.OnEpsAdd,
Expand Down Expand Up @@ -112,8 +116,8 @@ func (c *ServiceImportController) Reconcile(key utils.QueueKey) error {
klog.V(4).Infof("============ %s has been reconciled in cluster %s =============", clusterWideKey.NamespaceKey(), c.LeafNodeName)
}()

serviceImport := &mcsv1alpha1.ServiceImport{}
if err := c.LeafClient.Get(context.TODO(), types.NamespacedName{Namespace: clusterWideKey.Namespace, Name: clusterWideKey.Name}, serviceImport); err != nil {
serviceImport, err := c.serviceImportLister.ServiceImports(clusterWideKey.Namespace).Get(clusterWideKey.Name)
if err != nil {
if !apierrors.IsNotFound(err) {
klog.Errorf("Get %s in cluster %s failed, Error: %v", clusterWideKey.NamespaceKey(), c.LeafNodeName, err)
return err
Expand All @@ -130,7 +134,7 @@ func (c *ServiceImportController) Reconcile(key utils.QueueKey) error {
return c.removeFinalizer(serviceImport)
}

err := c.syncServiceImport(serviceImport)
err = c.syncServiceImport(serviceImport)
if err != nil {
klog.Errorf("Sync serviceImport %s/%s's finalizer in cluster %s failed, Error: %v", serviceImport.Namespace, serviceImport.Name, c.LeafNodeName, err)
return err
Expand Down
4 changes: 1 addition & 3 deletions pkg/utils/constants.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package utils

import (
"time"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)
Expand Down Expand Up @@ -131,7 +129,7 @@ const (
DefaultK8sOS = "linux"
DefaultK8sArch = "amd64"

DefaultInformerResyncPeriod = 1 * time.Minute
DefaultInformerResyncPeriod = 0
DefaultListenPort = 10250
DefaultPodSyncWorkers = 10
DefaultWorkers = 5
Expand Down

0 comments on commit ed1b248

Please sign in to comment.