Saramanda9988 commented on code in PR #1440:
URL: https://github.com/apache/dubbo-admin/pull/1440#discussion_r3005663602
##########
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:
使用了label主要是因为
1. 这里拿到的是 podIP,不是 稳定的 serviceIP或者clusterIP,存在旧 rpc instance 残留和 podIP
复用窗口的时候,ip-only 容易把新 pod 的 runtime 信息合并到旧实例上,出现误关联。
2. starting 状态依赖 runtime 侧先创建/融合实例;如果不使用 label/annotation identifier 提供的
mesh/appName/rpcPort,rpc runtime
侧无法可靠识别实例(因为有attributeCheck,或许我们假定rpc一定会去注册?),只能等注册中心返回 rpc instance
后再展示,starting 状态会无法显示。
我建议保留现在这样的逻辑,ip可以作为fallback,但是能否在文档中推荐用户标注相关label以获取更准确的生命周期显示?或者有其他更好的方案,比如这里的podIP使用clusterIP?
--
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]