Skip to content

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

Draft
abigailliang-aks-sig-node wants to merge 5 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 5 commits into
mainfrom
migrate-kubelet-config-file

Conversation

@abigailliang-aks-sig-node

@abigailliang-aks-sig-node abigailliang-aks-sig-node commented Jun 26, 2026

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

Test Plan

  • auto tests(unit tests and e2e tests)
  • Manual Verification
    • Content precedence check: in utils_test.go, verify 1.the conflict case keeps content value for imageGCHighThresholdPercent. 2.maxPods is backfilled from flags when content omits it. 3. eventRecordQps is backfilled from --event-qps only when EventRecordQps is nil.
  • Regression/Compatibility Checks
    • Confirm no change to kubelet flag ordering/output behavior outside intended merge/backfill paths in [utils.go]
      Confirm no impact to non-kubelet parser fields in [helper.go].
  • E2E Spot Check
    • Run one Ubuntu scenario in default mode and one in scriptless mode to ensure no provisioning regression in kubelet bootstrap path.If infra flakes occur, collect logs and bastion output for kubelet effective config inspection

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
Copilot AI review requested due to automatic review settings June 26, 2026 22:56

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

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

Comment thread pkg/agent/utils.go
Comment on lines +640 to 641
configStringByte, _ := json.MarshalIndent(mergedConfig, "", " ")
return string(configStringByte)
Comment thread pkg/agent/utils.go
Comment on lines +644 to +660
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
}
Comment on lines +694 to +701
if cfg.EventRecordQps == nil {
if val, ok := flags["--event-qps"]; ok && val != "" {
if n, err := strconv.ParseInt(val, 10, 32); err == nil {
v := int32(n)
cfg.EventRecordQps = &v
}
}
}
Copilot AI review requested due to automatic review settings June 27, 2026 01:03

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

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

Comment thread pkg/agent/utils.go
Comment on lines +632 to +636
contentConfig := &datamodel.AKSKubeletConfiguration{
APIVersion: "kubelet.config.k8s.io/v1beta1",
Kind: "KubeletConfiguration",
FeatureGates: map[string]bool{},
}
Comment thread pkg/agent/utils.go
Comment on lines +649 to +652
mergedBytes, _ := json.Marshal(contentMap)
mergedConfig := &datamodel.AKSKubeletConfiguration{}
_ = json.Unmarshal(mergedBytes, mergedConfig)
return mergedConfig
Comment on lines 666 to +669
// getKubeletConfigFileContent converts kubelet flags we set to a file, and return the json content.
// Fields already set in KubeletConfigFileConfig take precedence; missing optional fields are
// backfilled from KubeletFlags so that kubelet does not fall back to v1beta1 defaults when AKS
// intends a specific value (e.g. --event-qps=0 must appear in the config file as 0, not 5).
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