Skip to content

Conversation

rashmichandrashekar
Copy link
Contributor

@rashmichandrashekar rashmichandrashekar commented Jul 9, 2025

What this PR does / why we need it:
Fixes bug where some option values are overriden with config file but not others.
Provides optional behavior for backward compatiblity

How does this change affect the cardinality of KSM: (increases, decreases or does not change cardinality)
Does not change cardinality

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #2704

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jul 9, 2025
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 9, 2025
@rashmichandrashekar rashmichandrashekar changed the title support overrides Fix: Config file overrides apply to some fields but not other Jul 9, 2025
@rashmichandrashekar rashmichandrashekar changed the title Fix: Config file overrides apply to some fields but not other fix: Config file overrides apply to some fields but not other Jul 9, 2025
@dgrisonnet
Copy link
Member

/assign @rexagod
/cc
/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jul 10, 2025
@rashmichandrashekar
Copy link
Contributor Author

Hi @rexagod - You have been assigned as a reviewer. Could you please review this PR? Thanks!

@rashmichandrashekar
Copy link
Contributor Author

@dgrisonnet @CatherineF-dev - Gentle ping, pls take a look at the pr and provide your review, thanks!

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 17, 2025
@rashmichandrashekar
Copy link
Contributor Author

@CatherineF-dev - Added tests as per your feedback, pls take a look. Thanks!

@@ -378,6 +379,45 @@ func RunKubeStateMetrics(ctx context.Context, opts *options.Options) error {
return nil
}

func configureResourcesAndMetrics(opts *options.Options, configFile []byte) *options.Options {
// If the config file is set, we will overwrite the opts with the config file.
// This is only needed for types that are a slice of structs because the default behaviour of yaml.Unmarshal is to append instead of overwrite
Copy link
Member

@rexagod rexagod Jul 21, 2025

Choose a reason for hiding this comment

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

Suggested change
// This is only needed for types that are a slice of structs because the default behaviour of yaml.Unmarshal is to append instead of overwrite
func configureResourcesAndMetrics(opts *options.Options, configFile []byte) *options.Options {
// If the config file is set, we will overwrite the opts with the config file.
// This is only needed for maps because the default behaviour of yaml.Unmarshal is to append keys (and overwrite any conflicting ones).

I'd suggest adding a comment about the config file taking precedence over options in the flag description.

Also, I believe we need to do this for AnnotationsAllowList and LabelsAllowList as well?

Copy link
Contributor Author

@rashmichandrashekar rashmichandrashekar Jul 21, 2025

Choose a reason for hiding this comment

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

Good catch. Added this too. @rexagod - please take a look

@richabanker
Copy link
Contributor

@rashmichandrashekar this seems to be running into some CI failures.

@rashmichandrashekar
Copy link
Contributor Author

@rashmichandrashekar this seems to be running into some CI failures.

Thanks @richabanker. Could you pls retrigger the runs?

@mrueg
Copy link
Member

mrueg commented Jul 25, 2025

Triggered the CI run

/ok-to-test
/lgtm

for others to review:
/hold

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. labels Jul 25, 2025
@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jul 25, 2025
@rashmichandrashekar
Copy link
Contributor Author

Pinging other reviewers - @dgrisonnet @CatherineF-dev - This PR is waiting on additional reviewers. Could you pls take a look? Thanks!

@rexagod
Copy link
Member

rexagod commented Jul 29, 2025

I'd suggest adding a comment about the config file taking precedence over options in the flag description.

I believe this is remaining here?

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 29, 2025
@rashmichandrashekar
Copy link
Contributor Author

I'd suggest adding a comment about the config file taking precedence over options in the flag description.

I believe this is remaining here?

Thanks! added

@CatherineF-dev
Copy link
Contributor

In apiserver, command-line arguments override any settings provided in a configuration file.

https://kubernetes.io/docs/tasks/administer-cluster/kubelet-config-file/#start-a-kubelet-process-configured-via-the-config-file

@richabanker and I find standard practice is using command-line arguments to override configuration file.
@dgrisonnet

If so, is your project blocked by this? Could you find other ways?

@rashmichandrashekar
Copy link
Contributor Author

rashmichandrashekar commented Jul 30, 2025

In apiserver, command-line arguments override any settings provided in a configuration file.

https://kubernetes.io/docs/tasks/administer-cluster/kubelet-config-file/#start-a-kubelet-process-configured-via-the-config-file

@richabanker and I find standard practice is using command-line arguments to override configuration file. @dgrisonnet

If so, is your project blocked by this? Could you find other ways?

@CatherineF-dev - The current behavior is that the config file overrides the cli args. This PR is making it consistent for all params. Yes, if the change is to break this behavior, it is blocking.

@rashmichandrashekar
Copy link
Contributor Author

/ok-to-test

@richabanker
Copy link
Contributor

/lgtm

Re-iterating from the sig meeting, since this fix makes the behavior of overriding CLI flags with config file consistent for slice params, makes sense to me to have this fix merged now.

While this is opposite to the pattern we have for the main K8s components, but this was a choice made early on, which will require a separate dedicated discussion/enhancement if we want to adopt that for KSM due to the breaking nature of the change.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 31, 2025
@richabanker
Copy link
Contributor

/hold
for @CatherineF-dev and @rexagod to express any outstanding concerns

Copy link
Member

@rexagod rexagod left a comment

Choose a reason for hiding this comment

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

Could you please squash the commits here as well?

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 5, 2025
@rashmichandrashekar
Copy link
Contributor Author

/ok-to-test

1 similar comment
@rashmichandrashekar
Copy link
Contributor Author

/ok-to-test

@rashmichandrashekar rashmichandrashekar force-pushed the rashmi/ksm-config-override branch from 9ad6c65 to 9211476 Compare August 6, 2025 02:30
@rashmichandrashekar
Copy link
Contributor Author

Could you please squash the commits here as well?

Done

@rashmichandrashekar
Copy link
Contributor Author

@rexagod - Addressed all comments. pls take a look

@CatherineF-dev
Copy link
Contributor

/lgtm on using config file to override command flags.
/hold for others

@rexagod
Copy link
Member

rexagod commented Aug 6, 2025

/lgtm
/unhold

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Aug 6, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CatherineF-dev, mrueg, rashmichandrashekar, rexagod, richabanker

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [CatherineF-dev,mrueg,rexagod]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit d680e8c into kubernetes:main Aug 6, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Config file overrides apply to some fields but not other
7 participants