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 listener only mode guest agent #7446

Merged
merged 7 commits into from
Sep 11, 2024

Conversation

Nino-K
Copy link
Member

@Nino-K Nino-K commented Sep 10, 2024

This PR removes the iptable's listener creation functionality since we no longer rely on the WSL listener forwarding functionality in the virtual network. In addition, previously we did not call the host-switch API for the entries in iptables. This PR addresses that issue. In addition, it removes iptables package which was redundant. The original idea behind scraping the iptables was to pickup the portmaps in /proc/net/tcp that were placed in there from CNI portmap plugin. However, we subscribe directly to the k8s API, and we pick up all the port mapping directly from the API in kube/watcher package.

Fixes: #7447
and
Fixes: #7129
and
Fixes: #6944
Related: #6944

@Nino-K Nino-K requested a review from mook-as September 10, 2024 16:39
Copy link
Contributor

@mook-as mook-as left a comment

Choose a reason for hiding this comment

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

I think we need to refactor how we add/remove port mappings, so that if one of the three things we do (add listener, expose, and sending to wsl-proxy) fails, we have a unified approach to dealing with errors. That can either be keep going (to get partial forwarding), or rollback all three. Currently it's a… weird mish-mash?

src/go/guestagent/pkg/forwarder/serviceapi.go Outdated Show resolved Hide resolved
*ListenerTracker
}

// NewAPITracker creates a new instance of a API Tracker.
func NewAPITracker(forwarder forwarder.Forwarder, baseURL, tapIfaceIP string, isAdmin bool) *APITracker {
func NewAPITracker(ctx context.Context, wslProxyForwarder forwarder.Forwarder, baseURL, tapIfaceIP string, isAdmin, enableListeners bool) *APITracker {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's so many args here that it needs to be documented. When is enableListeners relevant?

We may want to consider e.g. functional options instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added documentation for the args. Also, I like the use of functional options, however, I can't see how it could benefit us in this case.

src/go/guestagent/pkg/tracker/apitracker.go Show resolved Hide resolved
hostPort, err := strconv.Atoi(portBinding.HostPort)
if err != nil {
log.Errorf("error converting hostPort: %s", err)
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

This also stops trying to call gVisor; is that the desired behaviour? (Same with the other error in the enableListeners block, and in Remove.)

src/go/guestagent/pkg/tracker/apitracker.go Outdated Show resolved Hide resolved
src/go/guestagent/pkg/tracker/apitracker.go Outdated Show resolved Hide resolved
@Nino-K
Copy link
Member Author

Nino-K commented Sep 11, 2024

I would need to make a follow-up PR to remove the enableIptables flag altogether.
It looks like it has to be part of this PR.

Signed-off-by: Nino Kodabande <[email protected]>
Copy link
Contributor

@mook-as mook-as left a comment

Choose a reason for hiding this comment

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

Looks great, just need to update the init.d file (and rebase to get rid of the merge conflict).

const isAdminInstall = await this.getIsAdminInstall();

const guestAgentConfig: Record<string, string> = {
LOG_DIR: await this.wslify(paths.logs),
GUESTAGENT_ADMIN_INSTALL: isAdminInstall ? 'true' : 'false',
GUESTAGENT_KUBERNETES: enableKubernetes ? 'true' : 'false',
GUESTAGENT_IPTABLES: iptables.toString(), // only enable IPTABLES for older K8s
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we edit /etc/init.d/guestagent or whatever it's called to drop the arg, then?

Copy link
Member Author

Choose a reason for hiding this comment

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

I missed it.

@Nino-K Nino-K force-pushed the remove-listener-only-mode-guest-agent branch from 25ffb9a to a00aa9d Compare September 11, 2024 17:59
Move all the Host Switch API calling code into its own
package so that it can be shared across.

Signed-off-by: Nino Kodabande <[email protected]>
When enableListeners flag is enabled we would also
call the host-switch service API in addition to adding
and removing the net listeners.

Signed-off-by: Nino Kodabande <[email protected]>
Signed-off-by: Nino Kodabande <[email protected]>
The original rationale for including the `enableListeners` flag in the `APITracker` was
to address specific Kubernetes versions that required a port forwarding fix. The need
for this fix was determined based on the Kubernetes version as follows:

- **Versions < 1.21**: No fix required.
- **Version 1.21**: Fix needed if the patch version is 12 or higher.
- **Version 1.22**: Fix needed if the patch version is 10 or higher.
- **Version 1.23**: Fix needed if the patch version is 7 or higher.
- **Versions >= 1.24**: Fix required.
- **Versions with a major version number other than 1**: Fix required.

Initially, the approach was to create local network listeners for these specific Kubernetes
versions to leverage the WSL listener forwarding feature. However, since we no longer depend
on WSL’s listener forwarding, we can now directly establish connections to the container
using the NodePort entries in iptables. As a result, the `enableListeners` flag is no longer
necessary for handling port forwarding fixes, and connections can be managed more directly
through iptables configurations. Therefore, calling the host switch API
should be adequate for all k8s services that either require the fix or
not.

Signed-off-by: Nino Kodabande <[email protected]>
@Nino-K Nino-K force-pushed the remove-listener-only-mode-guest-agent branch from a00aa9d to 0a4e92b Compare September 11, 2024 18:19
Signed-off-by: Nino Kodabande <[email protected]>
Signed-off-by: Nino Kodabande <[email protected]>
@Nino-K Nino-K force-pushed the remove-listener-only-mode-guest-agent branch from 0a4e92b to 0cd6df8 Compare September 11, 2024 18:26
@Nino-K Nino-K requested a review from mook-as September 11, 2024 18:28
@mook-as mook-as enabled auto-merge September 11, 2024 18:51
@mook-as mook-as merged commit bbdd8ae into main Sep 11, 2024
26 checks passed
@mook-as mook-as deleted the remove-listener-only-mode-guest-agent branch September 11, 2024 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants