云端事件:修复实例通知并移出 LaunchInstance 回传
This commit is contained in:
@@ -234,8 +234,12 @@ func (c *RealClient) EnsureRelayConnector(ctx context.Context, cred Credentials,
|
||||
if err != nil {
|
||||
return RelayResource{}, err
|
||||
}
|
||||
if res, ok, err := findRelayConnector(ctx, sc, cred.TenancyOCID); err != nil || ok {
|
||||
return res, err
|
||||
res, ok, err := findRelayConnector(ctx, sc, cred.TenancyOCID)
|
||||
if err != nil {
|
||||
return RelayResource{}, err
|
||||
}
|
||||
if ok {
|
||||
return res, reconcileRelayCondition(ctx, sc, res.ID, condition)
|
||||
}
|
||||
details := sch.CreateServiceConnectorDetails{
|
||||
DisplayName: common.String(relayConnectorName),
|
||||
@@ -257,6 +261,45 @@ func (c *RealClient) EnsureRelayConnector(ctx context.Context, cred Credentials,
|
||||
return waitRelayConnector(ctx, sc, cred.TenancyOCID)
|
||||
}
|
||||
|
||||
// reconcileRelayCondition 对齐存量 Connector 的过滤条件:关键事件清单变更
|
||||
// (如去除 LaunchInstance)后,已建链路经「一键创建」幂等调用原地更新,无需拆除重建。
|
||||
func reconcileRelayCondition(ctx context.Context, sc sch.ServiceConnectorClient, id, condition string) error {
|
||||
got, err := sc.GetServiceConnector(ctx, sch.GetServiceConnectorRequest{ServiceConnectorId: &id})
|
||||
if err != nil {
|
||||
return fmt.Errorf("get service connector: %w", err)
|
||||
}
|
||||
if !relayConditionDiffers(got.Tasks, condition) {
|
||||
return nil
|
||||
}
|
||||
details := sch.UpdateServiceConnectorDetails{Tasks: []sch.TaskDetails{}}
|
||||
if condition != "" {
|
||||
details.Tasks = []sch.TaskDetails{sch.LogRuleTaskDetails{Condition: &condition}}
|
||||
}
|
||||
_, err = sc.UpdateServiceConnector(ctx, sch.UpdateServiceConnectorRequest{
|
||||
ServiceConnectorId: &id, UpdateServiceConnectorDetails: details,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("update service connector condition: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// relayConditionDiffers 判断现有任务集与期望条件是否不一致:
|
||||
// 期望形态是单条 LogRule 条件;任务数、类型或条件文本不同均视为漂移。
|
||||
func relayConditionDiffers(tasks []sch.TaskDetailsResponse, want string) bool {
|
||||
if want == "" {
|
||||
return len(tasks) > 0
|
||||
}
|
||||
if len(tasks) != 1 {
|
||||
return true
|
||||
}
|
||||
rule, ok := tasks[0].(sch.LogRuleTaskDetailsResponse)
|
||||
if !ok || rule.Condition == nil {
|
||||
return true
|
||||
}
|
||||
return *rule.Condition != want
|
||||
}
|
||||
|
||||
// findRelayConnector 按名查找存活 Connector。
|
||||
func findRelayConnector(ctx context.Context, sc sch.ServiceConnectorClient, tenancy string) (RelayResource, bool, error) {
|
||||
list, err := sc.ListServiceConnectors(ctx, sch.ListServiceConnectorsRequest{
|
||||
|
||||
Reference in New Issue
Block a user