lingsamuel commented on code in PR #1306:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/1306#discussion_r1000221301


##########
pkg/providers/apisix/apisix_upstream.go:
##########
@@ -339,6 +404,114 @@ func (c *apisixUpstreamController) sync(ctx 
context.Context, ev *types.Event) er
        return err
 }
 
+func (c *apisixUpstreamController) updateExternalNodes(ctx context.Context, au 
*configv2.ApisixUpstream, old *configv2.ApisixUpstream, newUps 
*apisixv1.Upstream) error {
+       clusterName := c.Config.APISIX.DefaultClusterName
+
+       // TODO: if old is not nil, diff the external nodes change first
+
+       upsName := apisixv1.ComposeExternalUpstreamName(au.Namespace, au.Name)
+
+       ups, err := c.APISIX.Cluster(clusterName).Upstream().Get(ctx, upsName)
+       if err != nil {
+               if err != apisixcache.ErrNotFound {
+                       log.Errorf("failed to get upstream %s: %s", upsName, 
err)
+                       c.RecordEvent(au, corev1.EventTypeWarning, 
utils.ResourceSyncAborted, err)
+                       c.recordStatus(au, utils.ResourceSyncAborted, err, 
metav1.ConditionFalse, au.GetGeneration())
+                       return err
+               }
+               // Do nothing if not found
+       } else {
+               nodes, err := 
c.translator.TranslateApisixUpstreamExternalNodes(au)
+               if err != nil {
+                       log.Errorf("failed to translate upstream external nodes 
%s: %s", upsName, err)
+                       c.RecordEvent(au, corev1.EventTypeWarning, 
utils.ResourceSyncAborted, err)
+                       c.recordStatus(au, utils.ResourceSyncAborted, err, 
metav1.ConditionFalse, au.GetGeneration())
+                       return err
+               }
+               if newUps != nil {
+                       newUps.Metadata = ups.Metadata
+                       ups = newUps
+               }
+
+               ups.Nodes = nodes
+               if _, err := 
c.APISIX.Cluster(clusterName).Upstream().Update(ctx, ups); err != nil {
+                       log.Errorw("failed to update external nodes upstream",
+                               zap.Error(err),
+                               zap.Any("upstream", ups),
+                               zap.Any("ApisixUpstream", au),
+                               zap.String("cluster", clusterName),
+                       )
+                       c.RecordEvent(au, corev1.EventTypeWarning, 
utils.ResourceSyncAborted, err)
+                       c.recordStatus(au, utils.ResourceSyncAborted, err, 
metav1.ConditionFalse, au.GetGeneration())
+                       return err
+               }
+       }
+       return nil
+}
+
+func (c *apisixUpstreamController) syncRelationship(ev *types.Event, auKey 
string, au kube.ApisixUpstream) {
+       obj := ev.Object.(kube.ApisixUpstreamEvent)
+
+       if obj.GroupVersion != config.ApisixV2 {
+               return
+       }
+
+       var (
+               old    *configv2.ApisixUpstream
+               newObj *configv2.ApisixUpstream
+       )
+
+       if ev.Type == types.EventUpdate {
+               old = obj.OldObject.V2()
+       } else if ev.Type == types.EventDelete {
+               old = ev.Tombstone.(kube.ApisixUpstream).V2()
+       }
+
+       if ev.Type != types.EventDelete {
+               newObj = au.V2()
+       }
+
+       var (
+               //oldExternalDomains  []string
+               //newExternalDomains  []string
+               oldExternalServices []string
+               newExternalServices []string
+       )
+       if old != nil {
+               for _, node := range old.Spec.ExternalNodes {
+                       if node.Type == configv2.ExternalTypeDomain {
+                               //oldExternalDomains = 
append(oldExternalDomains, node.Name)

Review Comment:
   This function is used to track references to external services so that we 
can be notified when the external service changes.
   The domain doesn't need such track.



-- 
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]

Reply via email to