Saramanda9988 commented on code in PR #1440:
URL: https://github.com/apache/dubbo-admin/pull/1440#discussion_r3022557483
##########
pkg/core/engine/subscriber/runtime_instance.go:
##########
@@ -129,31 +131,110 @@ func (s *RuntimeInstanceEventSubscriber)
processUpsert(rtInstanceRes *meshresour
// processDelete when runtime instance deleted, we should delete the
corresponding instance resource
func (s *RuntimeInstanceEventSubscriber) processDelete(rtInstanceRes
*meshresource.RuntimeInstanceResource) error {
- var instanceResource *meshresource.InstanceResource
- var err error
- switch rtInstanceRes.Spec.SourceEngineType {
- case string(enginecfg.Kubernetes):
- instanceResource, err = s.getRelatedInstanceByIP(rtInstanceRes)
- default:
- instanceResource, err =
s.getRelatedInstanceByName(rtInstanceRes)
- }
+ instanceResource, err := s.getRelatedInstance(rtInstanceRes)
if err != nil {
return err
}
if instanceResource == nil {
logger.Warnf("cannot find instance resource by runtime instance
%s, skipped deleting instance", rtInstanceRes.ResourceKey())
return nil
}
+ meshresource.ClearRuntimeInstanceFromInstance(instanceResource)
+ if meshresource.HasRPCInstanceSource(instanceResource) {
+ if err = s.instanceStore.Update(instanceResource); err != nil {
+ logger.Errorf("update instance resource failed after
runtime delete, instance: %s, err: %s",
+ instanceResource.ResourceKey(), err.Error())
+ return err
+ }
+ logger.Infof("instance lifecycle runtime source removed, keep
instance by rpc source, instance: %s, runtime: %s, registerState: registered",
+ instanceResource.ResourceKey(),
rtInstanceRes.ResourceKey())
+ instanceUpdateEvent :=
events.NewResourceChangedEvent(cache.Updated, instanceResource,
instanceResource)
+ s.eventEmitter.Send(instanceUpdateEvent)
+ logger.Debugf("runtime instance delete trigger instance update
event, event: %s", instanceUpdateEvent.String())
+ return nil
+ }
if err = s.instanceStore.Delete(instanceResource); err != nil {
logger.Errorf("delete instance resource failed, instance: %s,
err: %s", instanceResource.ResourceKey(), err.Error())
return err
}
+ logger.Infof("instance lifecycle runtime source removed and no rpc
source remains, deleted instance: %s, runtime: %s",
+ instanceResource.ResourceKey(), rtInstanceRes.ResourceKey())
instanceDeleteEvent := events.NewResourceChangedEvent(cache.Deleted,
instanceResource, nil)
s.eventEmitter.Send(instanceDeleteEvent)
logger.Debugf("runtime instance delete trigger instance delete event,
event: %s", instanceDeleteEvent.String())
return nil
}
+func (s *RuntimeInstanceEventSubscriber) getRelatedInstance(
+ rtInstanceRes *meshresource.RuntimeInstanceResource)
(*meshresource.InstanceResource, error) {
+ if rtInstanceRes == nil || rtInstanceRes.Spec == nil {
+ return nil, nil
+ }
+ switch rtInstanceRes.Spec.SourceEngineType {
+ case string(enginecfg.Kubernetes):
+ return s.getRelatedKubernetesInstance(rtInstanceRes)
+ default:
+ return s.getRelatedInstanceByName(rtInstanceRes)
+ }
+}
+
+func (s *RuntimeInstanceEventSubscriber) getRelatedKubernetesInstance(
Review Comment:
我理解的是CNI会先释放ip,pod再完全销毁,这个时间窗口里面可能会出现ip重叠?
不过我又思考了一下,这个问题应该不会在我们这里出现,
因为如果用户不打label,无法提前融合出instance,我们这里不会有这个窗口,打了label就能唯一确定,不会有这个窗口,是可行的
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]