Skip to content

Commit

Permalink
adding comments
Browse files Browse the repository at this point in the history
Signed-off-by: jooho <[email protected]>
  • Loading branch information
Jooho committed Sep 11, 2023
1 parent 471a6f2 commit 4a014c8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions controllers/service_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,18 @@ func (r *ServiceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
namespace = req.Name
n := &corev1.Namespace{}
if err := r.Client.Get(ctx, req.NamespacedName, n); err != nil {
// Previously, the controller kept checking namespaces even though the namespaces do not exist anymore.
// As a result, a lot of misleading error messages showed up in the log
if k8serr.IsNotFound(err) {
err = nil
}
return ctrl.Result{}, err
}
if !modelMeshEnabled(n, r.ControllerDeployment.Namespace) {
sl := &corev1.ServiceList{}
//The logic is
// - If the namespace is not for modelmesh anymore, it will delete modelmesh Service when it exists.
// - If the namespace is being terminated, it does not need to delete the modelmesh Service because it will be gone with the namespace
if err := r.List(ctx, sl, client.HasLabels{"modelmesh-service"}, client.InNamespace(namespace)); err != nil {
return ctrl.Result{}, err
} else {
Expand All @@ -141,6 +146,7 @@ func (r *ServiceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
mms.Disconnect()
r.MMServices.Delete(namespace)
//requeue is never expected here
//If the namespace is not for modelmesh anymore, it should trigger reconcileService for MMService list that manages the goroutines.
if _, err, _ := r.reconcileService(ctx, mms, namespace, owner); err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -237,6 +243,9 @@ func (r *ServiceReconciler) reconcileService(ctx context.Context, mms *mmesh.MMS
return nil, err, false
}

//This will remove the goroutine when modelmesh is not enabled for a namespace.
// - when the namespace does not have the annotation modelmesh-enabled
// - when the namespace is under a Terminating state.
n := &corev1.Namespace{}
if err := r.Client.Get(ctx, types.NamespacedName{Name: namespace}, n); err != nil {
return nil, err, false
Expand Down

0 comments on commit 4a014c8

Please sign in to comment.