Skip to content

Commit

Permalink
Merge pull request #316 from Poor12/fix-mcs
Browse files Browse the repository at this point in the history
fix: repeatedly creating and deleting mcs, the creation of derived svc occasionally fails
  • Loading branch information
mrlihanbo authored Mar 22, 2024
2 parents eba0d26 + bc557fe commit e25f506
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/controllers/mcs/service_import_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,33 @@ func (c *ServiceImportController) reconcile(ctx context.Context, fedObjKey fedOb
keyedLogger.Error(err, "Failed to sync placements to endpointSlice")
return worker.StatusError
}

// Usually derivedSvcFedObj relies on the cascade deletion mechanism of K8s for cleaning,
// but the GC time of K8s is not certain, so when it has not been recycled,
// the controller needs to perform the deletion action.
derivedSvcFedObj, err := fedobjectadapters.GetFromLister(
c.fedObjectInformer.Lister(),
nil,
fedObjKey.qualifiedName.Namespace,
naming.GenerateDerivedSvcFedObjName(fedObjKey.sourceObjName),
)
if err != nil && !apierrors.IsNotFound(err) {
keyedLogger.Error(err, "Failed to get derived service federated object from store")
return worker.StatusError
}

if derivedSvcFedObj != nil && derivedSvcFedObj.GetDeletionTimestamp() == nil {
if err = fedobjectadapters.Delete(
ctx,
c.fedClient.CoreV1alpha1(),
derivedSvcFedObj.GetNamespace(),
derivedSvcFedObj.GetName(),
metav1.DeleteOptions{},
); err != nil {
return worker.StatusError
}
}

return worker.StatusAllOK
}

Expand Down Expand Up @@ -334,6 +361,8 @@ func (c *ServiceImportController) reconcileSvcImportFedObj(
logger.Error(err, "Failed to create derived service federated object")
return worker.StatusError
}
} else if derivedSvcFedObj.GetDeletionTimestamp() != nil {
return worker.StatusError
} else {
derivedSvcFedObj = derivedSvcFedObj.DeepCopyGenericFederatedObject()
if err := c.handleExistingFederatedObject(ctx, serviceImportObj, newDerivedSvc,
Expand Down

0 comments on commit e25f506

Please sign in to comment.