Skip to content

Add fieldManagerDefault configuration option + set field manager on non-SSA operations #258

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

Open
wants to merge 9 commits into
base: 6.13.4-hubspot
Choose a base branch
from

Conversation

mbc1990
Copy link

@mbc1990 mbc1990 commented May 22, 2025

Replaces #257.

For PUT operations, the client currently doesn't set a ?fieldManager query parameter at all, which causes the API server to infer one from the User-Agent header, which leaves resources created with kubectl-operators with all their fields owned by localhost-<pid>@<some macbook ID>. This causes conflicts later when tools such as k safe-apply are used on the same objects.

To fix this we want to make kubectl-operators set the same field manager that k safe-apply uses, and this PR updates the kubernetes client to make that configurable.

In addition to PUT, this uses the same field manger override value for PATCH requests that are not of the server-side apply PatchType.

The behavior of server-side apply, which already provides an API for configuring the field manager, is unchanged in the case of a user providing a field manager via the .withFieldManager call. When a user does not provide a field manager to a server-side apply operation, the client will use the fieldManagerDefault if it is set, otherwise it will use the existing default of fabric8.

I tested this manually with https://git.hubteam.com/HubSpot/kube-operators-tools/compare/build-with-fabric8-client-branch?expand=1 and verified that the client now sets the field manager with our provided default.

@@ -1348,6 +1349,15 @@ public void setMasterUrl(String masterUrl) {
this.masterUrl = ensureEndsWithSlash(ensureHttps(masterUrl, this));
}

@JsonProperty("fieldManagerOverride")
Copy link
Collaborator

Choose a reason for hiding this comment

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

fieldManagerDefault ?

Copy link
Author

Choose a reason for hiding this comment

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

@@ -204,6 +204,10 @@ public URL getResourceURLForWriteOperation(URL resourceURL) throws MalformedURLE
resourceURL = new URL(
URLUtils.join(resourceURL.toString(), "?fieldValidation=" + context.fieldValidation.parameterValue()));
}
if (config.getFieldManagerOverride() != null) {
resourceURL = new URLUtils.URLBuilder(resourceURL).addQueryParameter("fieldManager", config.getFieldManagerOverride()).build();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't match how the URL is built above - is that intentional?

Copy link
Author

Choose a reason for hiding this comment

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

My intention was to handle ?fieldValidation being present or absent. If it's not set, then we need to append a ? to the URL for the fieldManager parameter, but if it is set then we don't. But looking again at what URLUtils.join(...) does, it looks like it does actually handle this case, so I'll make the new logic consistent with that.

Copy link
Author

Choose a reason for hiding this comment

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

@@ -228,6 +232,9 @@ public URL getResourceURLForPatchOperation(URL resourceUrl, PatchContext patchCo
if (fieldManager == null && patchContext.getPatchType() == PatchType.SERVER_SIDE_APPLY) {
fieldManager = "fabric8";
}
if (fieldManager == null && patchContext.getPatchType() != PatchType.SERVER_SIDE_APPLY && config.getFieldManagerOverride() != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

patchContext.getPatchType() != PatchType.SERVER_SIDE_APPLY

Why do we want to preserve fabric8 as the field manager for server-side apply?

Copy link
Author

Choose a reason for hiding this comment

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

My intention was to avoid changing how server-side apply works, since it has some existing logic for setting managers eg via the PatchContext param, so I was worried it would expand the scope of this change too much. But I think overriding the default here with our config does make sense, since it'll only be reached if the field manager is left unset by that existing path.

Copy link
Author

Choose a reason for hiding this comment

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

9325c84 Uses the override config for server-side apply as well. In the case of no field manager override being set on the config, it falls back on the fabric8 default for server-side apply,.

@mbc1990 mbc1990 changed the title Add fieldManagerOverride configuration option so we can set the field manager on non-SSA operations Add fieldManagerDefault configuration option + set field manager on non-SSA operations May 27, 2025
@mbc1990 mbc1990 marked this pull request as ready for review May 27, 2025 17:55
@mbc1990 mbc1990 requested a review from nhirakawa May 27, 2025 17:55
@mbc1990
Copy link
Author

mbc1990 commented Jun 2, 2025

This is awaiting a parent pom canary opportunity

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.

3 participants