Skip to content
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

kubeadm: Replace the yaml in the log/comments with a generic term. #130345

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

HirazawaUi
Copy link
Contributor

@HirazawaUi HirazawaUi commented Feb 21, 2025

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

  1. Currently, kubeadm supports both yaml and json configuration file types, but in our log output, we only explicitly mention the yaml format.
  2. We haven't printed warning logs for unknown GVKs in all the documentMapToXXX functions. To ensure consistent behavior across the documentMapToXXX functions and to provide sufficient warnings to users, we should print warning logs.

Which issue(s) this PR fixes:

Fixes kubernetes/kubeadm#3163 kubernetes/kubeadm#3162

Special notes for your reviewer:

To make the functions appear more consistent, I also renamed the SplitYAMLDocuments function to SplitYAMLOrJSONDocuments. If this is an unnecessary change, I can roll it back.

Does this PR introduce a user-facing change?

kubeadm: Use generic terminology in logs instead of direct mentions of yaml/json.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 21, 2025
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/kubeadm sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 21, 2025
@carlory
Copy link
Member

carlory commented Feb 24, 2025

/release-note-none
/lgtm

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Feb 24, 2025
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 24, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 4de94b209ce33e899d62167ce8ea44456d8afa39

Copy link
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

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

thanks for the pr @HirazawaUi

Comment on lines +432 to +378
for _, format := range formats {
t.Run(fmt.Sprintf("%s_%s", tt.name, format.name), func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

since you are adding multi format testing for init and upgrade config, should you also add it to reset and join config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

@neolit123
Copy link
Member

Does this PR introduce a user-facing change?

needs a simple release note explaining the user facing aspect of the change.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Feb 24, 2025
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 24, 2025
}

if obj == nil {
t.Error("Unexpected nil return value")
got, _ := LoadJoinConfigurationFromFile(tt.cfgPath, options)
Copy link
Member

Choose a reason for hiding this comment

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

why not use bytestojoinconfiguration instead of writing a file and reading it
we should make this consistent across xconfiguration_tests.go.

}

if obj == nil {
t.Error("Unexpected nil return value")
got, _ := LoadResetConfigurationFromFile(tt.cfgPath, options)
Copy link
Member

Choose a reason for hiding this comment

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

again we should use bytestoresetconfiguration here instead of writing and loading

the load* functions can have another simple test, maybe

@neolit123
Copy link
Member

neolit123 commented Feb 26, 2025

running some e2e
https://github.com/neolit123/kubeadm-test/actions/runs/13548136535
edit; it's passing

Copy link
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

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

there are still some minor consistency problems, but the refactor is turning out nicely.
thanks

t.Errorf("LoadOrDefaultUpgradeConfiguration returned unexpected diff (-want,+got):\n%s", diff)
}
})
got, _ := LoadOrDefaultUpgradeConfiguration(tt.cfgPath, tt.cfg, options)
Copy link
Member

@neolit123 neolit123 Feb 26, 2025

Choose a reason for hiding this comment

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

we should remove the TestLoadUpgradeConfigurationFromFile function if other xconfiguration_test files no longer test the load functions and move the relevant test cases to the test function that tests the BytesTo* function

or just add a very simple TestLoadOrDefaultXConfiguration test everywhere that just makes sure that the function doesn't fail for a simple config.

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 added TestLoadXFromFile tests for reset and join, but could not add one for init since ComponentConfigs cannot be exported.

Copy link
Member

Choose a reason for hiding this comment

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

not sure i understand, can you please provide an example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For example:

The kubeletConfig struct in the componentconfigs directory is unexported (non-public).
ref:

type kubeletConfig struct {
configBase
config kubeletconfig.KubeletConfiguration
}

When executing the BytesToInitConfiguration function, we will assign
default values to InitConfiguration.ComponentConfigs["kubelet.config.k8s.io"].kubeletConfig.

However, since kubeletConfig is unexported, we cannot reference it in the util/config directory, making comparisons impossible.

Copy link
Member

@neolit123 neolit123 Feb 27, 2025

Choose a reason for hiding this comment

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

wouldn't this work?

cmp.Diff(got, tt.want, cmpopts.IgnoreFields{kubeadmapi.InitConfiguration{}, "ComponentConfigs"})

also i checked the latest contents of the latest pr, here is a more detailed explanation, what i meant earlier:

for each xconfiguration_test.go file, we should have:

  • a detailed test for TestBytesToXConfiguration with various test cases
  • a TestLoadXConfigurationFromFile with just a single case testing that a file loads, that's all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cmp.Diff(got, tt.want, cmpopts.IgnoreFields{kubeadmapi.InitConfiguration{}, "ComponentConfigs"})

Yes, this will work perfectly.

  • a TestLoadXConfigurationFromFile with just a single case testing that a file loads, that's all

I think I understand your point. However, replicating the tests for TestLoadXConfigurationFromFile is quite convenient for me, so I provided them with the same test cases as TestLoadUpgradeConfigurationFromFile (my initial thought was that more test cases are always better than simple ones, especially when they are straightforward to copy/implement). Would this be considered redundant? If there are other considerations and we only need a simple test case, I can revert these unit tests.

Copy link
Member

@neolit123 neolit123 Feb 27, 2025

Choose a reason for hiding this comment

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

yes, its redundant. for the TestLoadXConfigurationFromFile, we just need a simple load test without content comparison.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All right. I will add the unit tests for BytesToInitConfiguration tomorrow and revert some of the test cases from the latest commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes have been made based on comments.

@HirazawaUi HirazawaUi force-pushed the kubeadm-yaml-json branch 6 times, most recently from cb8b9ba to 3bc4963 Compare February 28, 2025 14:46
@HirazawaUi
Copy link
Contributor Author

/retest

Copy link
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

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

you could organize the commits better. remove all _test.go changes from commit 1 as it's supposed to only change output and move them to the last commits about test consistency. currently commit 1 makes changes to tests and later the last commit also changes the same tests.

also for all TestLoadXConfigurationFromFile functions make it use the two test cases:

  • missing file
  • valid config

@HirazawaUi HirazawaUi force-pushed the kubeadm-yaml-json branch 2 times, most recently from 0335aea to a2a6a5e Compare March 3, 2025 10:59
if (err != nil) != tc.expectedError {
t.Fatalf("failed DocMapToUpgradeConfiguration:\n\texpected error: %t\n\t actual error: %v", tc.expectedError, err)
}
if err == nil {
if diff := cmp.Diff(*cfg, tc.expectedCfg, cmpopts.IgnoreFields(kubeadmapi.UpgradeConfiguration{}, "Timeouts")); diff != "" {
t.Fatalf("DocMapToUpgradeConfiguration returned unexpected diff (-want,+got):\n%s", diff)
t.Fatalf("BytesToUpgradeConfiguration returned unexpected diff (-want,+got):\n%s", diff)
Copy link
Member

Choose a reason for hiding this comment

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

move this change from commit add BytesToXConfiguration function to the last commit with tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking and fixing problems caused by rebase, just a moment.

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 still put the changes to this unit test in the fourth commit because we removed the DocMapToUpgradeConfiguration function in this commit. If we don’t modify this unit test, it will fail in the fourth commit.

Copy link
Member

@neolit123 neolit123 Mar 3, 2025

Choose a reason for hiding this comment

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

isn't it possible to move the delete of DocMapToUpgradeConfiguration also in the last commit?
the delete seems like a unit tests refactor too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense and has been changed as suggested.

@HirazawaUi
Copy link
Contributor Author

you could organize the commits better. remove all _test.go changes from commit 1 as it's supposed to only change output and move them to the last commits about test consistency. currently commit 1 makes changes to tests and later the last commit also changes the same tests.

also for all TestLoadXConfigurationFromFile functions make it use the two test cases:

  • missing file
  • valid config

The content of the historical commits has been modified according to this suggestion.

@neolit123
Copy link
Member

neolit123 commented Mar 3, 2025

/lgtm
/approve
thanks

/hold
let's remove the hold once ci passes here and in the external repo:
https://github.com/neolit123/kubeadm-test/actions/runs/13632680478/job/38103832447
https://github.com/neolit123/kubeadm-test/actions/runs/13632722131/job/38103965538

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

LGTM label has been added.

Git tree hash: 636194a98151cf78f663a3457a37c15406e361f3

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: HirazawaUi, neolit123

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:

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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 3, 2025
@HirazawaUi
Copy link
Contributor Author

Thank you for your patient review!

@neolit123
Copy link
Member

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. area/kubeadm cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clarify configuration file handling behavior during loading
4 participants