fix: Fixed an update failure when the container network is bridge#8290
fix: Fixed an update failure when the container network is bridge#8290f2c-ci-robot[bot] merged 1 commit intodevfrom
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
| } | ||
| } | ||
|
|
||
| data.Cmd = oldContainer.Config.Cmd |
There was a problem hiding this comment.
The given code appears to have some redundancy and unnecessary logic that can be simplified. Specifically, when dealing with the bridge network, both IPv4 and IPv6 addresses are being checked for null values before assigning them to data.Ipv4 and data.Ipv6, respectively. This logic is repeated twice.
Here's an optimized version of the function:
func (u *ContainerService) ContainerInfo(req dto.OperationWithName) (*dto.ContainerInfo, error) {
oldContainer, err := u.getOldContainer(req.Name)
if err != nil {
return nil, err
}
networkSettings := oldContainer.NetworkSettings
brBridgeNetworkSettings := networkSettings.Networks["bridge"]
if brBridgeNetworkSettings.IPAMConfig == nil || data.Network == "bridge" {
data.Ipv4 = bridgingNetworkSettings.IPAMConfig.IPv4Address
data.Ipv6 = bridgingNetworkSettings.IPAMConfig.IPv6Address
} else {
data.Ipv4 = bridgingNetworkSettings.IPAddress
}
data.Cmd = oldContainer.Config.Cmd
// Continue processing...
return &info, nilKey Changes:
- Simplified Logic: Removed the redundant checks for IPAMConfig and only assign IPs if either the container is on a different network than "bridge" or there is no IPAM configuration associated with the "bridge".
- Corrected Variable Names: Fixed a typo in
bridgingNetworkSettingstobrBridgeNetworkSettings. - Ensured that
data.Ipv4anddata.Ipv6are properly assigned based on whether the container is on a different network or not.
These changes should improve readability and potentially reduce complexity while maintaining correctness and functionality.
|
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wanghe-fit2cloud The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |



Refs #8209