@@ -43,18 +43,18 @@ func (t *componentHostNetworkTransformer) Transform(ctx graph.TransformContext,
4343 }
4444
4545 synthesizedComp := transCtx .SynthesizeComponent
46- ports , err := allocateHostPorts (synthesizedComp )
46+ ports , err := t . allocateHostPorts (synthesizedComp )
4747 if err != nil {
4848 return err
4949 }
5050
5151 comp := transCtx .Component
52- updateObjectsWithAllocatedPorts (synthesizedComp , comp , ports )
52+ t . updateObjectsWithAllocatedPorts (synthesizedComp , comp , ports )
5353
5454 return nil
5555}
5656
57- func allocateHostPorts (synthesizedComp * component.SynthesizedComponent ) (map [string ]map [string ]int32 , error ) {
57+ func ( t * componentHostNetworkTransformer ) allocateHostPorts (synthesizedComp * component.SynthesizedComponent ) (map [string ]map [string ]int32 , error ) {
5858 ports := map [string ]map [string ]bool {}
5959 for _ , c := range synthesizedComp .HostNetwork .ContainerPorts {
6060 for _ , p := range c .Ports {
@@ -65,18 +65,18 @@ func allocateHostPorts(synthesizedComp *component.SynthesizedComponent) (map[str
6565 }
6666 }
6767
68- pm := intctrlutil .GetPortManager ()
68+ pm := intctrlutil .GetPortManager (synthesizedComp . Network )
6969 needAllocate := func (c string , p string ) bool {
7070 containerPorts , ok := ports [c ]
7171 if ! ok {
7272 return false
7373 }
7474 return containerPorts [p ]
7575 }
76- return allocateHostPortsWithFunc (pm , synthesizedComp , needAllocate )
76+ return t . allocateHostPortsWithFunc (pm , synthesizedComp , needAllocate )
7777}
7878
79- func allocateHostPortsWithFunc (pm * intctrlutil.PortManager , synthesizedComp * component.SynthesizedComponent ,
79+ func ( t * componentHostNetworkTransformer ) allocateHostPortsWithFunc (pm intctrlutil.PortManager , synthesizedComp * component.SynthesizedComponent ,
8080 needAllocate func (string , string ) bool ) (map [string ]map [string ]int32 , error ) {
8181 ports := map [string ]map [string ]int32 {}
8282 insert := func (c , pk string , pv int32 ) {
@@ -87,7 +87,7 @@ func allocateHostPortsWithFunc(pm *intctrlutil.PortManager, synthesizedComp *com
8787 }
8888 for _ , c := range synthesizedComp .PodSpec .Containers {
8989 for _ , p := range c .Ports {
90- portKey := intctrlutil . BuildHostPortName (synthesizedComp .ClusterName , synthesizedComp .Name , c .Name , p .Name )
90+ portKey := pm . PortKey (synthesizedComp .ClusterName , synthesizedComp .Name , c .Name , p .Name )
9191 if needAllocate (c .Name , p .Name ) {
9292 port , err := pm .AllocatePort (portKey )
9393 if err != nil {
@@ -104,7 +104,7 @@ func allocateHostPortsWithFunc(pm *intctrlutil.PortManager, synthesizedComp *com
104104 return ports , nil
105105}
106106
107- func updateObjectsWithAllocatedPorts (synthesizedComp * component.SynthesizedComponent ,
107+ func ( t * componentHostNetworkTransformer ) updateObjectsWithAllocatedPorts (synthesizedComp * component.SynthesizedComponent ,
108108 comp * appsv1.Component , ports map [string ]map [string ]int32 ) {
109109 synthesizedComp .PodSpec .HostNetwork = true
110110 if comp .Spec .Network != nil && comp .Spec .Network .DNSPolicy != nil {
0 commit comments