Skip to content

fix(pkg/agent): merge kubelet config content with flag defaults#8777

Draft
abigailliang-aks-sig-node wants to merge 2 commits into
mainfrom
migrate-kubelet-config-file
Draft

fix(pkg/agent): merge kubelet config content with flag defaults#8777
abigailliang-aks-sig-node wants to merge 2 commits into
mainfrom
migrate-kubelet-config-file

Conversation

@abigailliang-aks-sig-node

Copy link
Copy Markdown

Summary

  • keep existing kubelet CLI filtering behavior unchanged
  • build kubelet config-file content from customKubeletConfig first
  • backfill only missing config-file fields from translated kubelet flags
  • add helper-based merge flow in GetKubeletConfigFileContent
  • add unit test to verify content values are not overwritten by flags while missing fields are filled

Behavior

  • if a field exists only in flags: include it in config-file content
  • if a field exists only in custom content: keep custom content
  • if both exist: custom content wins

Validation

  • go test ./pkg/agent -count 1

Copilot AI review requested due to automatic review settings June 26, 2026 01:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates how pkg/agent generates kubelet config-file JSON by merging sources: start from customKubeletConfig content and only backfill missing fields from flag-derived values, while keeping the existing kubelet CLI flag filtering behavior unchanged.

Changes:

  • Refactors GetKubeletConfigFileContent to build a content-derived config first, then merge in missing fields from the flag-derived config.
  • Introduces helper functions to merge config content and flags via a map-based merge.
  • Adds a unit test to verify that content values are not overwritten while missing fields are filled from flags.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/agent/utils.go Refactors kubelet config-file generation and adds helper-based merge logic; keeps CLI filtering semantics while preparing for a future “config-file authoritative” shift.
pkg/agent/utils_test.go Adds a unit test validating that content wins on conflicts and flags backfill missing fields.

Comment thread pkg/agent/utils.go Outdated
Comment thread pkg/agent/utils.go
Comment on lines +651 to +667
func mergeKubeletConfigContentFromFlags(contentConfig, flagConfig *datamodel.AKSKubeletConfiguration) *datamodel.AKSKubeletConfiguration {
contentMap := kubeletConfigToMap(contentConfig)
flagMap := kubeletConfigToMap(flagConfig)
mergeMissingConfigFields(contentMap, flagMap)

mergedBytes, _ := json.Marshal(contentMap)
mergedConfig := &datamodel.AKSKubeletConfiguration{}
_ = json.Unmarshal(mergedBytes, mergedConfig)
return mergedConfig
}

func kubeletConfigToMap(config *datamodel.AKSKubeletConfiguration) map[string]interface{} {
configBytes, _ := json.Marshal(config)
configMap := map[string]interface{}{}
_ = json.Unmarshal(configBytes, &configMap)
return configMap
}
@Azure Azure deleted a comment from github-actions Bot Jun 26, 2026
@abigailliang-aks-sig-node

Copy link
Copy Markdown
Author

@abigailliang-aks-sig-node please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree company="Microsoft"

@abigailliang-aks-sig-node abigailliang-aks-sig-node changed the title pkg/agent: merge kubelet config content with flag defaults fix(pkg/agent): merge kubelet config content with flag defaults Jun 26, 2026
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