Skip to content

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

Merged
merged 1 commit into from
Apr 2, 2025

Conversation

ssongliu
Copy link
Member

@ssongliu ssongliu commented Apr 2, 2025

Refs #8209

Copy link

f2c-ci-robot bot commented Apr 2, 2025

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
Copy link
Member

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:

  1. 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".
  2. Corrected Variable Names: Fixed a typo in bridgingNetworkSettings to brBridgeNetworkSettings.
  3. Ensured that data.Ipv4 and data.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.

Copy link

sonarqubecloud bot commented Apr 2, 2025

Copy link
Member

@wanghe-fit2cloud wanghe-fit2cloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@wanghe-fit2cloud
Copy link
Member

/approve

Copy link

f2c-ci-robot bot commented Apr 2, 2025

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot added the approved label Apr 2, 2025
@f2c-ci-robot f2c-ci-robot bot merged commit 6798d0c into dev Apr 2, 2025
6 checks passed
@f2c-ci-robot f2c-ci-robot bot deleted the pr@dev@fix_container_edit branch April 2, 2025 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants