@@ -24,7 +24,8 @@ import (
2424 "strings"
2525
2626 corev1 "k8s.io/api/core/v1"
27- "k8s.io/apimachinery/pkg/types"
27+ "k8s.io/apimachinery/pkg/fields"
28+ "k8s.io/apimachinery/pkg/labels"
2829 "k8s.io/klog/v2"
2930 "sigs.k8s.io/controller-runtime/pkg/client"
3031 "sigs.k8s.io/controller-runtime/pkg/log"
@@ -104,15 +105,15 @@ func syncChunk(ctx context.Context, client client.Client, replication *api.Repli
104105 sourceSplits := strings .Split (* replication .Spec .Source .URI , "://" )
105106 addresses := strings .Split (sourceSplits [1 ], "@" )
106107 nodeName , blobPath := addresses [0 ], addresses [1 ]
107- nodeIP , err := nodeIP (ctx , client , nodeName )
108+ addr , err := peerAddr (ctx , client , nodeName )
108109 if err != nil {
109110 return err
110111 }
111112
112113 // The destination URI looks like localhost://<path-to-your-file>
113114 destSplits := strings .Split (* replication .Spec .Destination .URI , "://" )
114115
115- if err := recvChunk (blobPath , destSplits [1 ], nodeIP ); err != nil {
116+ if err := recvChunk (blobPath , destSplits [1 ], addr ); err != nil {
116117 logger .Error (err , "failed to sync chunk" )
117118 return err
118119 }
@@ -196,15 +197,22 @@ func parseURI(uri string) (host string, address string) {
196197 return splits [0 ], splits [1 ]
197198}
198199
199- func nodeIP (ctx context.Context , client client.Client , nodeName string ) (string , error ) {
200- node := corev1.Node {}
201- if err := client .Get (ctx , types.NamespacedName {Name : nodeName }, & node ); err != nil {
200+ func peerAddr (ctx context.Context , c client.Client , nodeName string ) (string , error ) {
201+ fieldSelector := fields .OneTermEqualSelector ("spec.nodeName" , nodeName )
202+ listOptions := & client.ListOptions {
203+ FieldSelector : fieldSelector ,
204+ // HACK: the label is hacked, we must set it explicitly in the daemonSet.
205+ LabelSelector : labels .SelectorFromSet (map [string ]string {"app" : "manta-agent" }),
206+ }
207+
208+ pods := corev1.PodList {}
209+ if err := c .List (ctx , & pods , listOptions ); err != nil {
202210 return "" , err
203211 }
204- for _ , address := range node .Status .Addresses {
205- if address .Type == "InternalIP" {
206- return address .Address , nil
207- }
212+
213+ if len (pods .Items ) != 1 {
214+ return "" , fmt .Errorf ("got more than one pod per node for daemonSet" )
208215 }
209- return "" , fmt .Errorf ("can't get node internal IP" )
216+
217+ return pods .Items [0 ].Status .PodIP , nil
210218}
0 commit comments