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

Remove the dormant container during intercept with --replace. #3761

Merged
merged 7 commits into from
Jan 6, 2025

Conversation

thallgren
Copy link
Member

There's no need to have a dormant container because the traffic-agent
can serve as the replacement itself. That way, there's no need to
redirect ports either, which means that there's no need to rename ports
or use an init-container.

An annotation is added to the pod to cater for when multiple injections
happen due to replace-policy, so that injections that follow the one
when an app-container is removed can reproduce the traffic-agent
container, taking its ports, mounts, and environment into account.

When the traffic-manager shuts down, it must uninstall agents
unconditionally, without concerns about the "inject" annotation.

Signed-off-by: Thomas Hallgren <thomas@tada.se>
Signed-off-by: Thomas Hallgren <thomas@tada.se>
There's no need to have a dormant container because the traffic-agent
can serve as the replacement itself. That way, there's no need to
redirect ports either, which means that there's no need to rename ports
or use an init-container.

An annotation is added to the pod to cater for when multiple injections
happen due to replace-policy, so that injections that follow the one
when an app-container is removed can reproduce the traffic-agent
container, taking its ports, mounts, and environment into account.

Closes #3758

Signed-off-by: Thomas Hallgren <thomas@tada.se>
The `tunnel.ConnID` still used the `net.IP`. This commit changes the
constructor to use `netip.AddrPort` for host and destination instead
of separate combos of `net.IP` and `uint16`.

Signed-off-by: Thomas Hallgren <thomas@tada.se>
Signed-off-by: Thomas Hallgren <thomas@tada.se>
@thallgren thallgren requested a review from P0lip January 5, 2025 11:20
@thallgren thallgren added the ok to test Applied by maintainers when a PR is ready to have tests run on it label Jan 5, 2025
@github-actions github-actions bot removed the ok to test Applied by maintainers when a PR is ready to have tests run on it label Jan 5, 2025
Copy link
Contributor

@P0lip P0lip left a comment

Choose a reason for hiding this comment

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

Just one typo.
I like the swap of net.IP with netip.AddrPort

pkg/forwarder/interceptor.go Outdated Show resolved Hide resolved
// skips contain defaults assigned by Kubernetes that are not zero values
if dlog.MaxLogLevel(ctx) >= dlog.LogLevelDebug {
diff := cmp.Diff(a, b,
cmp.Comparer(compareProbes),
Copy link
Contributor

Choose a reason for hiding this comment

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

a minor one too, but we already have options below, so could dedupe it a bit

func containerEqual(ctx context.Context, a, b *core.Container) bool {
	// skips contain defaults assigned by Kubernetes that are not zero values
	options := cmp.Options{
		cmp.Comparer(compareProbes),
		cmp.Comparer(compareVolumeMounts),
		cmpopts.IgnoreFields(core.Container{}, "ImagePullPolicy", "Resources", "TerminationMessagePath", "TerminationMessagePolicy"),
	}
	if dlog.MaxLogLevel(ctx) >= dlog.LogLevelDebug {
		diff := cmp.Diff(a, b, options...)
		if diff != "" {
			dlog.Debug(ctx, diff)
		}
		return diff == ""
	}
	return cmp.Equal(a, b, options...)
}


func eachConfiguredContainer(configureContainers []*core.Container, config *Sidecar, f func(*core.Container, *Container)) {
for i, cn := range configureContainers {
f(cn, config.Containers[i])
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible that a container will be nil at runtime?
Technically from the perspective of ConfiguredContainers function that might be the case if we're unable to find the configured container.
If so, we may want to filter out nil values here as the callbacks we pass to eachConfiguredContainer will panic due to them expecting a non-nil value.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, A nil entry in the configContainers should never be possible, but looking at the ConfiguredContainers function, I realize that if the pod.Spec.Containers for some reason is out of sync with the config.Containers, and no longer contain all the containers that were present at the time when the config.Containers was generated, then that could actually happen.

thallgren and others added 2 commits January 6, 2025 15:19
Co-authored-by: Jakub Rożek <jrozek@datawire.io>
Signed-off-by: Thomas Hallgren <thomas@tada.se>
- Dedup compare options.
- Add nil-check in `eachConfiguredContainer`

Signed-off-by: Thomas Hallgren <thomas@tada.se>
@thallgren thallgren added the ok to test Applied by maintainers when a PR is ready to have tests run on it label Jan 6, 2025
@github-actions github-actions bot removed the ok to test Applied by maintainers when a PR is ready to have tests run on it label Jan 6, 2025
@thallgren thallgren merged commit c0f247a into release/v2 Jan 6, 2025
11 checks passed
@thallgren thallgren deleted the thallgren/drop-replaced branch January 6, 2025 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow customisation of sleeperImage in --replace mode for compliance with cluster restrictions
2 participants