robocanic commented on code in PR #1440:
URL: https://github.com/apache/dubbo-admin/pull/1440#discussion_r3010098217
##########
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:
1. 这种情况是不是不太可能?rpc instance的生命周期长度是比runtime instance 短的。podIP存在的时候rpc
instance 的ip不一定存在;但反过来,rpc instance的ip存在,一定能找到一个唯一的runtime instance。
<img width="1504" height="414" alt="PixPin_2026-03-30_22-09-46"
src="https://github.com/user-attachments/assets/634bdd07-2c8a-416f-a613-f272c4ad0f8f"
/>
2. 用户如果不改造确实会有这个问题,但这个改造是需要用户去改造他们的CI/CD的,会有一定成本,这里确实需要在文档中说明并推荐用户进行标记
ip可以作为一个fallback,就通过resKey,resName都找不着再用ip。
--
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]