Skip to content

Conversation

BoleynSu
Copy link
Contributor

@BoleynSu BoleynSu commented May 9, 2025

Proposed Changes

Set --config to avoid using legacy defaults

Types of Changes

New Feature
It should be a no-op for now but prevents future issues.

Verification

kubectl get --raw "/api/v1/nodes/$NODENAME/proxy/configz" | jq | grep readOnlyPort # should output "readOnlyPort": 0, with default setup

Testing

kubectl get --raw "/api/v1/nodes/$NODENAME/proxy/configz" | jq | grep readOnlyPort # should output "readOnlyPort": 0, with default setup

Linked Issues

User-Facing Change

kubelet: Set --config to avoid using legacy defaults

Further Comments

It also help avoid similar issues as #12164 in the future. I.e. we do not need to explicity override defaults by using cli flags.

@BoleynSu BoleynSu requested a review from a team as a code owner May 9, 2025 22:03
@BoleynSu
Copy link
Contributor Author

BoleynSu commented May 9, 2025

@brandond PTAL

@@ -185,6 +185,7 @@ func defaultKubeletConfig(cfg *daemonconfig.Agent) (*kubeletconfig.KubeletConfig
NodeStatusReportFrequency: metav1.Duration{Duration: time.Minute * 5},
NodeStatusUpdateFrequency: metav1.Duration{Duration: time.Second * 10},
ProtectKernelDefaults: cfg.ProtectKernelDefaults,
ReadOnlyPort: 0,
Copy link
Member

@brandond brandond May 9, 2025

Choose a reason for hiding this comment

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

You read the k/k issue. This field will be omitted from the output unless set to a nonzero value, why bother?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@brandond brandond May 9, 2025

Choose a reason for hiding this comment

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

Check the output on disk, and tell me what you see as the value of this field when the config is marshalled to yaml. Can you get the zero value to appear?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do not need to have 0 in the yaml file. Not having it is equivalent to having it as 0.

Copy link
Member

@brandond brandond May 9, 2025

Choose a reason for hiding this comment

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

Right so why did you add it back to this struct if it doesn't end up in the yaml file?

You could probably resolve this by just making your other changes without reverting the commit that removed this.

@@ -48,11 +49,9 @@ func kubeletArgsAndConfig(cfg *config.Agent) (map[string]string, *kubeletconfig.
return nil, nil, err
}
argsMap := map[string]string{
"config": filepath.Join(cfg.KubeletConfigDir, "00-"+version.Program+"-defaults.conf"),
Copy link
Member

@brandond brandond May 9, 2025

Choose a reason for hiding this comment

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

This will result in loading the config twice, first as the config, and then again as a drop-in. As discussed in the upstream issue, there are critical differences in behavior wrt defaults when the config file is loaded as config vs a config drop-in. I'm not confident that this will result in the behavior we want in terms of allowing users to provide their own config files or drop-ins that are loaded before or after our defaults.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. We can move the default config to etc/kubelet.conf to avoid parsing it twice as I commented in the k/k issue. However, the current PR still works and is the simple change to fix the issue.

Copy link
Contributor Author

@BoleynSu BoleynSu May 9, 2025

Choose a reason for hiding this comment

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

The k/k logic for loading config is as follows
config := legacyDefault{}
config = apply flags to config
if --config is set: config = load --config // note that this throw away config above
if --config-dir is set: config = merge config with --config-dir
if --config or --config-dir is set: config = apply flags to config

when applying flags, it is doing config.Flag = read(--flag, default = config.Flag)

Copy link
Member

Choose a reason for hiding this comment

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

it is currently "fixed" by using the CLI flag, as we previously did. If you're going to revert and rework an existing change it would be good to provide some justification as to why it is an improvement over the current behavior.

Ideally this would be done in the appropriate place in our PR template - instead of just deleting the template and saying "fixes X" with a link to an already-closed issue.

@brandond
Copy link
Member

brandond commented May 9, 2025

If you want to open a new issue (using the issue template) describing the current problem this addresses, and fill out the PR template, we can consider this.

@BoleynSu
Copy link
Contributor Author

BoleynSu commented May 9, 2025

If you want to open a new issue (using the issue template) describing the current problem this addresses, and fill out the PR template, we can consider this.

I have updated the description. Hope it is more clear. The title of the PR is also stating the issue it tries to fix.

@brandond
Copy link
Member

brandond commented May 9, 2025

We still need a new issue for our QA team to test, describing what you're trying to fix or improve. The issue you linked has already been tested and closed.

Also please fill out the PR template - since you deleted it when opening the PR, you can find it here: https://raw.githubusercontent.com/k3s-io/k3s/refs/heads/master/.github/PULL_REQUEST_TEMPLATE.md

@BoleynSu
Copy link
Contributor Author

BoleynSu commented May 9, 2025

Added an issue and updated the description.

@BoleynSu
Copy link
Contributor Author

BoleynSu commented May 9, 2025

I will overlay another commit to put default config in etc/kubelet.conf. If it can be a breaking change, feel free to remove the last commit.

@brandond
Copy link
Member

brandond commented May 9, 2025

Drop the revert commit - there's no need to re-add 0 to the struct - and then make the rest of your changes on top of that.

@BoleynSu
Copy link
Contributor Author

BoleynSu commented May 9, 2025

please take another look

@BoleynSu BoleynSu force-pushed the kubelet-config branch 2 times, most recently from 19adc84 to 6cbc639 Compare May 9, 2025 23:15
Comment on lines +69 to +71
if err := writeKubeletConfig(cfg.KubeletConfig, defaultConfig); err != nil {
return pkgerrors.WithMessage(err, "generate default kubelet configuration")
Copy link
Member

@brandond brandond May 9, 2025

Choose a reason for hiding this comment

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

Should we remove the old drop-in at "00-"+version.Program+"-defaults.conf" if it exists? If we're going to generate our defaults in a new path, we should clean up the file generated by previous releases to avoid leaving unwanted drop-ins behind that will override what is currently expected. This could cause unexpected behavior when upgrading.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure if the whole agent directory will be regenerated or not upon upgrade. If not, I agree we should remove "00-"+version.Program+"-defaults.conf"

Copy link
Member

@brandond brandond May 9, 2025

Choose a reason for hiding this comment

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

no, things do not get cleaned out of there when upgrading. We also intentionally leave the kubelet config dir alone so that users can put their own stuff in it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the PR. I did not check the err returned by Remove. I guess it should be fine?

Fixes k3s-io#12310
It also help avoid similar issues as k3s-io#12164 in the future. I.e. we do not need to explicity override defaults by using cli flags.

Signed-off-by: Boleyn Su <[email protected]>
Copy link

codecov bot commented May 13, 2025

Codecov Report

Attention: Patch coverage is 0% with 14 lines in your changes missing coverage. Please review.

Project coverage is 19.89%. Comparing base (925726c) to head (b297c99).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
pkg/daemons/agent/agent.go 0.00% 10 Missing ⚠️
pkg/agent/config/config.go 0.00% 2 Missing ⚠️
pkg/daemons/agent/agent_linux.go 0.00% 1 Missing ⚠️
pkg/daemons/agent/agent_windows.go 0.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (925726c) and HEAD (b297c99). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (925726c) HEAD (b297c99)
e2etests 1 0
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #12309       +/-   ##
===========================================
- Coverage   40.55%   19.89%   -20.67%     
===========================================
  Files         187      184        -3     
  Lines       19279    19220       -59     
===========================================
- Hits         7819     3824     -3995     
- Misses      10270    14965     +4695     
+ Partials     1190      431      -759     
Flag Coverage Δ
e2etests ?
unittests 19.89% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants