@@ -22,6 +22,7 @@ import (
2222 "fmt"
2323 "io"
2424 "net/http"
25+ "os"
2526 "strconv"
2627 "time"
2728
@@ -46,6 +47,13 @@ import (
4647)
4748
4849var httpClient = & http.Client {Timeout : 10 * time .Second }
50+ var operatorPort = "8080"
51+
52+ func init () {
53+ if port := os .Getenv ("PORT" ); port != "" {
54+ operatorPort = port
55+ }
56+ }
4957
5058// SetupPodWebhookWithManager registers the webhook for Pod in the manager.
5159func SetupPodWebhookWithManager (mgr ctrl.Manager , portAllocator * portallocator.PortAllocator , indexAllocator * indexallocator.IndexAllocator , pricingProvider pricing.PricingProvider ) error {
@@ -386,7 +394,7 @@ func (m *TensorFusionPodMutator) assignDeviceAllocationIndex(ctx context.Context
386394 var indexErr error
387395 podIdentifier := pod .Name
388396 if podIdentifier == "" {
389- // For Deployment/StatefulSet created pods, Name might be empty, use GenerateName + UID
397+ // For Deployment/StatefulSet created pods, Name might be empty, use GenerateName + UID(maybe empty)
390398 podIdentifier = pod .GenerateName + string (pod .UID )
391399 }
392400
@@ -576,7 +584,7 @@ func (m *TensorFusionPodMutator) assignClusterHostPortFromLeader(pod *corev1.Pod
576584 return 0 , fmt .Errorf ("operator leader IP not found" )
577585 }
578586
579- urlStr := fmt .Sprintf ("http://%s:8080/ assign-host-port?podName=%s" , leaderIP , pod .Name )
587+ urlStr := fmt .Sprintf ("http://%s:%s/api/ assign-host-port?podName=%s" , leaderIP , operatorPort , pod .Name )
580588 req , err := http .NewRequest ("GET" , urlStr , nil )
581589 if err != nil {
582590 return 0 , err
@@ -613,7 +621,7 @@ func (m *TensorFusionPodMutator) assignIndexFromLeader(ctx context.Context, pod
613621 if podIdentifier == "" {
614622 podIdentifier = pod .GenerateName + string (pod .UID )
615623 }
616- urlStr := fmt .Sprintf ("http://%s:8080/ assign-index?podName=%s" , leaderIP , podIdentifier )
624+ urlStr := fmt .Sprintf ("http://%s:%s/api/ assign-index?podName=%s" , leaderIP , operatorPort , podIdentifier )
617625 req , err := http .NewRequestWithContext (ctx , "GET" , urlStr , nil )
618626 if err != nil {
619627 return 0 , err
0 commit comments