Skip to content

Commit

Permalink
mgmt, fix containergroup npe when port protocol is null (#27234)
Browse files Browse the repository at this point in the history
* fix npe for container group when port protocol is null

* changelog

* revert changelog
  • Loading branch information
XiaofeiCao authored Feb 22, 2022
1 parent ff8345c commit c11f056
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.azure.resourcemanager.containerinstance.models.ContainerGroupNetworkProtocol;
import com.azure.resourcemanager.containerinstance.models.ContainerGroupRestartPolicy;
import com.azure.resourcemanager.containerinstance.models.ContainerGroupSubnetId;
import com.azure.resourcemanager.containerinstance.models.ContainerNetworkProtocol;
import com.azure.resourcemanager.containerinstance.models.ContainerPort;
import com.azure.resourcemanager.containerinstance.models.DnsConfiguration;
import com.azure.resourcemanager.containerinstance.models.Event;
import com.azure.resourcemanager.containerinstance.models.ImageRegistryCredential;
Expand Down Expand Up @@ -189,6 +191,13 @@ protected void initializeChildrenFromInner() {
if (this.innerModel().containers() != null && this.innerModel().containers().size() > 0) {
for (Container containerInstance : this.innerModel().containers()) {
this.containers.put(containerInstance.name(), containerInstance);
if (containerInstance.ports() != null) {
for (ContainerPort port : containerInstance.ports()) {
if (port.protocol() == null) {
port.withProtocol(ContainerNetworkProtocol.TCP);
}
}
}
}
}

Expand All @@ -214,6 +223,9 @@ protected void initializeChildrenFromInner() {
List<Port> tcpPorts = new ArrayList<>();
List<Port> udpPorts = new ArrayList<>();
for (Port port : this.innerModel().ipAddress().ports()) {
if (port.protocol() == null) {
port.withProtocol(ContainerGroupNetworkProtocol.TCP);
}
if (port.protocol().equals(ContainerGroupNetworkProtocol.TCP)) {
tcpPorts.add(port);
} else if (port.protocol().equals(ContainerGroupNetworkProtocol.UDP)) {
Expand Down

0 comments on commit c11f056

Please sign in to comment.