Skip to content
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

Update workload network when ns network label has changed #47574

Merged
merged 11 commits into from
Nov 22, 2023

Conversation

hanxiaop
Copy link
Member

@hanxiaop hanxiaop commented Oct 25, 2023

Please provide a description of this PR:
Currently, if the network is configured in the system namespace, changing the network requires restarting the pod to update the workload network. I think the workload should be updated dynamically without a restart, when the network changes. This would allow the requests to work without restarting the pod in the same network as the ztunnel.

@hanxiaop hanxiaop requested a review from a team as a code owner October 25, 2023 10:21
@istio-policy-bot istio-policy-bot added area/networking release-notes-none Indicates a PR that does not require release notes. labels Oct 25, 2023
@istio-testing istio-testing added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Oct 25, 2023
@hanxiaop hanxiaop force-pushed the update-workload-network-ns branch from 9a2b045 to 689c1b7 Compare October 25, 2023 10:22
@istio-testing istio-testing added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 25, 2023
Copy link
Member

@howardjohn howardjohn left a comment

Choose a reason for hiding this comment

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

Can you add a test and comments (in code) why this is needed?

@istio-testing istio-testing added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 26, 2023
@hanxiaop hanxiaop force-pushed the update-workload-network-ns branch from 1f97412 to 3f78631 Compare October 26, 2023 08:49
@hanxiaop
Copy link
Member Author

Can you add a test and comments (in code) why this is needed?

@howardjohn Added, PTAL

@hanxiaop hanxiaop requested a review from howardjohn October 26, 2023 08:52
@hanxiaop hanxiaop requested a review from hzxuzhonghu October 31, 2023 03:23
@hanxiaop
Copy link
Member Author

@howardjohn could you also take a look? I've added tests and comments.

@hanxiaop hanxiaop force-pushed the update-workload-network-ns branch from 62f155b to d3cb904 Compare October 31, 2023 03:36
@@ -955,6 +956,24 @@ func (c *Controller) AdditionalPodSubscriptions(
return shouldSubscribe
}

// syncAllWorkloadsForAmbient refreshes all ambient workloads.
func (c *Controller) syncAllWorkloadsForAmbient() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this needs to process k8s gateway resources since Waypoints currently have a network in their key.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should this be related to the render logic of waypoint template? What I've noticed is that when we set values.global.network and process the waypoint template, only the ISTIO_META_NETWORK environment variable is set; the topology.istio.io/network label is not. This results in the network being evaluated differently for waypoints compared to sidecars.

// 1. check the pod/workloadEntry label
if nw := labels[label.TopologyNetwork.Name]; nw != "" {
return network.ID(nw)
}
// 2. check the system namespace labels
if nw := c.networkFromSystemNamespace(); nw != "" {
return nw
}

If the waypoint will have the same behavior as the sidecar injection, then its network will not be affected by this PR. Otherwise, this PR will change the network of the waypoint, even if the ISTIO_META_NETWORK environment variable is set ( from topology.istio.io/network) - which is incorrect.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point. Right now it's really broken. We inject that network label on the Pod, but the waypoint logic looks at the k8s Gateway which likely won't have the network label.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have observed at least once a case where a new Istiod processes the Waypint/Gateway resource first, then the namespace. This results in the ambientindex storing /waypointIP when it should be network/waypointIP.

Copy link
Member Author

Choose a reason for hiding this comment

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

This results in the ambientindex storing /waypointIP when it should be network/waypointIP.

This makes sense based on my tests with the waypoint network. If we can inject the network label similarly like sidecar injection, then regardless of whether the gateway resource is processed first, the network key of the waypoint will not be affected. I'll take a look to see if we can handle this in the template or deploymentcontroller.

Copy link
Member Author

@hanxiaop hanxiaop Nov 1, 2023

Choose a reason for hiding this comment

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

So would we edit the deployment on network change causing a rollout? Network change should be very rare/close to 1-time so I would be okay with this.

This wouldn't. Originally when the network was changed, we had to rollout the deployment to push new network config change, but now we can dynamically update it to ztunnel without a rollout.

Have to be careful that we don't trigger the deployment when istiod hasn't determined the network properly on startup.

I'll verify this.

Copy link
Member

Choose a reason for hiding this comment

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

Any update on "verify" this @hanxiaop ?

Copy link
Member Author

@hanxiaop hanxiaop Nov 20, 2023

Choose a reason for hiding this comment

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

@linsun This PR looks good. It works only when the istio-system network label changes, but not during startup. The traffic behavior aligns with the description provided.
However I do see some issues for the ztunnel network setup during the test.

Copy link
Member Author

@hanxiaop hanxiaop Nov 20, 2023

Choose a reason for hiding this comment

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

There is one issue with this PR where the ztunnel network may be inaccurately represented in the ztunnel config dump: since it processes all workloads after the network label changes, the ztunnel pod network might also be incorrectly altered - even if its network has already been set. Originally, without this PR, the ztunnel network might also be inaccurate if the pod was updated(like annotation updates), as they both share the same syncPod logic. BTW this won't affect the actual traffic behavior of ztunnel since the network is configured as environmental variables during installation and not changed, only the workload configdump shows the incorrect network value.

With some research, I think this is not directly related to this PR. However, we need to address these issues:

  1. We currently lack a uniformed method for setting the ztunnel network during installation, so the network of ztunnel's workload info is altered incorrectly.
  2. The behavior of the ztunnel network for network="" is different from that in proxies. In proxies, network="" implies that the network is reachable. In contrast, for ztunnel, it simply means the network is an empty string without any value. If it does not exactly match the network, the traffic will be unrecognized.

May need @stevenctl to confirm if these are problems. The first one is related to this PR.

Copy link
Member

Choose a reason for hiding this comment

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

For ztunnel, now it can only get the network from ENV NETWORK

@hanxiaop hanxiaop added the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label Oct 31, 2023
@stevenctl
Copy link
Contributor

@howardjohn I have observed at least once a case where a new Istiod processes the Waypint/Gateway resource first, then the namespace. This results in the ambientindex storing /waypointIP when it should be network/waypointIP.

Even if we're not supporting multi-network this could break local traffic

@linsun
Copy link
Member

linsun commented Oct 31, 2023

Hi @hanxiaop - thanks for the great work on this!

  • Does workload require restart/rollout with syncAllWorkloadsForAmbient?
  • I assume the work is scoped to when system namespace network changes, not when any workload namespace network label is changed, is this correct?

We may need a release note to properly communicate any expected downtime if there is any with network label changes.

@hanxiaop
Copy link
Member Author

hanxiaop commented Nov 1, 2023

@linsun

Does workload require restart/rollout with syncAllWorkloadsForAmbient?

No, this is to dynamically sync the new network configuration of the workloads and push it to the ztunnel.

I assume the work is scoped to when system namespace network changes, not when any workload namespace network label is changed, is this correct?

This is correct.

@hanxiaop hanxiaop removed the release-notes-none Indicates a PR that does not require release notes. label Nov 1, 2023
@hanxiaop hanxiaop force-pushed the update-workload-network-ns branch from d3cb904 to 24186ea Compare November 17, 2023 08:29
@hanxiaop hanxiaop force-pushed the update-workload-network-ns branch from 61f745d to 0b7a9fd Compare November 20, 2023 06:32
@hanxiaop hanxiaop removed the do-not-merge/work-in-progress Block merging of a PR because it isn't ready yet. label Nov 20, 2023
@hanxiaop hanxiaop force-pushed the update-workload-network-ns branch from 76e0721 to 7bc69a4 Compare November 20, 2023 07:01
Copy link
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

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

LGTM

@linsun
Copy link
Member

linsun commented Nov 20, 2023

@linsun

Does workload require restart/rollout with syncAllWorkloadsForAmbient?

No, this is to dynamically sync the new network configuration of the workloads and push it to the ztunnel.

I assume the work is scoped to when system namespace network changes, not when any workload namespace network label is changed, is this correct?

This is correct.

Thanks @hanxiaop!

@howardjohn i think this one is good to go, your tests comments are addressed as well

Co-authored-by: Lin Sun <lin.sun@solo.io>
@howardjohn howardjohn dismissed their stale review November 21, 2023 20:56

concerns addressed

@hanxiaop
Copy link
Member Author

hanxiaop commented Nov 22, 2023

@hzxuzhonghu @linsun Can I get an approval for this? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/networking size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants