Skip to content

Commit

Permalink
fix: support change kosmos.io/auto-create-mcs value
Browse files Browse the repository at this point in the history
Signed-off-by: wangyizhi1 <[email protected]>
  • Loading branch information
wangyizhi1 committed Nov 3, 2023
1 parent 7f7e82a commit accafe0
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ func (c *AutoCreateMCSController) Reconcile(ctx context.Context, request reconci
shouldDelete = true
}

annotations := service.GetAnnotations()
if annotations == nil {
shouldDelete = true
}
if _, exists := annotations[utils.AutoCreateMCSAnnotation]; !exists {
shouldDelete = true
}

clusterList := &kosmosv1alpha1.ClusterList{}
if err := c.RootClient.List(ctx, clusterList); err != nil {
klog.Errorf("Cloud not get cluster in root cluster,Error: %v", err)
Expand Down Expand Up @@ -105,10 +113,10 @@ func (c *AutoCreateMCSController) SetupWithManager(mgr manager.Manager) error {
return true
},
DeleteFunc: func(deleteEvent event.DeleteEvent) bool {
return false
return true
},
UpdateFunc: func(updateEvent event.UpdateEvent) bool {
return false
return true
},
GenericFunc: func(genericEvent event.GenericEvent) bool {
return false
Expand Down Expand Up @@ -136,7 +144,7 @@ func (c *AutoCreateMCSController) SetupWithManager(mgr manager.Manager) error {
return shouldEnqueue(deleteEvent.Object)
},
UpdateFunc: func(updateEvent event.UpdateEvent) bool {
return shouldEnqueue(updateEvent.ObjectNew)
return true
},
GenericFunc: func(genericEvent event.GenericEvent) bool {
return false
Expand Down Expand Up @@ -168,6 +176,9 @@ func (c *AutoCreateMCSController) cleanUpMcsResources(ctx context.Context, names
continue
}
leafNodeName := fmt.Sprintf("%s%s", utils.KosmosNodePrefix, cluster.Name)
if !c.GlobalLeafManager.Has(leafNodeName) {
return fmt.Errorf("leaf client is not initialized, will requeue")
}
leafManager, err := c.GlobalLeafManager.GetLeafResource(leafNodeName)
if err != nil {
klog.Errorf("get leafManager for cluster %s failed,Error: %v", cluster.Name, err)
Expand Down Expand Up @@ -205,6 +216,9 @@ func (c *AutoCreateMCSController) autoCreateMcsResources(ctx context.Context, se
continue
}
leafNodeName := fmt.Sprintf("%s%s", utils.KosmosNodePrefix, cluster.Name)
if !c.GlobalLeafManager.Has(leafNodeName) {
return fmt.Errorf("leaf client is not initialized")
}
leafManager, err := c.GlobalLeafManager.GetLeafResource(leafNodeName)
if err != nil {
klog.Errorf("get leafManager for cluster %s failed,Error: %v", cluster.Name, err)
Expand Down

0 comments on commit accafe0

Please sign in to comment.