Skip to content

Commit

Permalink
fix: Duplicate Container port fix (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
helayoty committed Nov 5, 2022
1 parent 460fcc1 commit 9cfab58
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
3 changes: 3 additions & 0 deletions e2e/fixtures/hpa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ spec:
- containerPort: 80
name: http
protocol: TCP
- containerPort: 443
name: https
protocol: TCP
- image: busybox
name: busybox
imagePullPolicy: Always
Expand Down
16 changes: 8 additions & 8 deletions pkg/provider/aci.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,11 @@ func (p *ACIProvider) CreatePod(ctx context.Context, pod *v1.Pod) error {
count = count + len(*container.Ports)
}
ports := make([]azaci.Port, 0, count)
for _, container := range *containers {
for _, containerPort := range *container.Ports {

for c := range *containers {
containerPorts := ((*containers)[c]).Ports
for p := range *containerPorts {
ports = append(ports, azaci.Port{
Port: containerPort.Port,
Port: (*containerPorts)[p].Port,
Protocol: "TCP",
})
}
Expand Down Expand Up @@ -533,7 +533,7 @@ func (p *ACIProvider) CreatePod(ctx context.Context, pod *v1.Pod) error {
p.amendVnetResources(*cg, pod)

log.G(ctx).Infof("start creating pod %v", pod.Name)
// TODO: Run in a go routine to not block workers, and use taracker.UpdatePodStatus() based on result.
// TODO: Run in a go routine to not block workers, and use tracker.UpdatePodStatus() based on result.
return p.azClientsAPIs.CreateContainerGroup(ctx, p.resourceGroup, pod.Namespace, pod.Name, cg)
}

Expand Down Expand Up @@ -1149,11 +1149,11 @@ func (p *ACIProvider) getContainers(pod *v1.Pod) (*[]azaci.Container, error) {
},
}

for _, p := range podContainers[c].Ports {
for i := range podContainers[c].Ports {
containerPorts := aciContainer.Ports
containerPortsList := append(*containerPorts, azaci.ContainerPort{
Port: &p.ContainerPort,
Protocol: getProtocol(p.Protocol),
Port: &podContainers[c].Ports[i].ContainerPort,
Protocol: getProtocol(podContainers[c].Ports[i].Protocol),
})
aciContainer.Ports = &containerPortsList
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/provider/aci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,12 @@ func TestCreatedPodWithContainerPort(t *testing.T) {
assert.Check(t, is.Equal(2, len(containers)), "2 Containers is expected")
assert.Check(t, is.Equal(len(container1Ports), len(tc.containerList[0].Ports)))
assert.Check(t, is.Equal(len(container2Ports), len(tc.containerList[1].Ports)))
for i := range tc.containerList[0].Ports {
assert.Equal(t, tc.containerList[0].Ports[i].ContainerPort, *(container1Ports[i]).Port, "Container ports are not equal")
}
for i := range tc.containerList[1].Ports {
assert.Equal(t, tc.containerList[0].Ports[i].ContainerPort, *(container1Ports[i]).Port, "Container ports are not equal")
}
return nil
}

Expand Down

0 comments on commit 9cfab58

Please sign in to comment.