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

Refactor kubelet config validation tests #105360

Conversation

shuheiktgw
Copy link
Contributor

What type of PR is this?

/sig node
/kind cleanup
/area test

What this PR does / why we need it:

The background is described in #105029. I also noticed several minor problems in the validations so I fixed them:

  • Missing the invalid validation: prefix
  • Not showing a flag in an error message. For example CPUCFSQuotaPeriod
  • Not showing a given value in an error message. For example NodeStatusMaxImages
  • Not showing possible options in an error message. For example TopologyManagerPolicy
  • Unnecessary capitalization. For example ShutdownGracePeriod
  • Use a case statement to validate options. For example MemorySwap.SwapBehavior
  • Use %q instead of %v if necessary. For example EnforceNodeAllocatable
  • And a few other minor fixes (I'll leave a comment on them)

Which issue(s) this PR fixes:

Fixes #105029

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Kubelet config validation error messages are updated

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

None

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/node Categorizes an issue or PR as relevant to SIG Node. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. area/test 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. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Sep 30, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @shuheiktgw. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 30, 2021
@@ -217,7 +224,7 @@ func ValidateKubeletConfiguration(kc *kubeletconfig.KubeletConfiguration) error
allErrors = append(allErrors, fmt.Errorf("invalid configuration: memoryThrottlingFactor is required when MemoryQoS feature flag is enabled"))
}
if kc.MemoryThrottlingFactor != nil && (*kc.MemoryThrottlingFactor <= 0 || *kc.MemoryThrottlingFactor > 1.0) {
allErrors = append(allErrors, fmt.Errorf("invalid configuration: memoryThrottlingFactor %v must be greater than 0 and less than or equal to 1.0", kc.MemoryThrottlingFactor))
allErrors = append(allErrors, fmt.Errorf("invalid configuration: memoryThrottlingFactor %v must be greater than 0 and less than or equal to 1.0", *kc.MemoryThrottlingFactor))
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'm pretty sure a used doesn't want to see a memory location 😄

}
if _, err := cpuset.Parse(kc.ReservedSystemCPUs); err != nil {
allErrors = append(allErrors, fmt.Errorf("unable to parse reservedSystemCPUs (--reserved-cpus), error: %v", err))
allErrors = append(allErrors, fmt.Errorf("invalid configuration: unable to parse reservedSystemCPUs (--reserved-cpus) %v, error: %w", kc.ReservedSystemCPUs, err))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better to use %w for an error

}
if kc.ShutdownGracePeriod.Duration > 0 && kc.ShutdownGracePeriod.Duration < time.Duration(time.Second) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Casting time.Second to time.Duration is unnecessary

}

if localFeatureGate.Enabled(features.GracefulNodeShutdown) {
if kc.ShutdownGracePeriod.Duration < 0 || kc.ShutdownGracePeriodCriticalPods.Duration < 0 || kc.ShutdownGracePeriodCriticalPods.Duration > kc.ShutdownGracePeriod.Duration {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Merged this validation with the later one to simplify the logic

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@@ -14,22 +14,25 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package validation
package validation_test
Copy link
Member

Choose a reason for hiding this comment

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

s/validation_test/validation/g

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 thought that was one of the best practices to remove test files whenever we don't have to call unexported methods/functions from a test file but no? I found some test files with the _test suffix in this project but it does not seem that popular though...

Ref: https://pkg.go.dev/cmd/go@master#hdr-Test_packages

Test files that declare a package with the suffix "_test" will be compiled as a separate package, and then linked and run with the main test binary.

Copy link
Member

Choose a reason for hiding this comment

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

Kubernetes doesn't necessarily follow all golang conventions, we do this very inconsistently in kubelet:

ehashman@fedora:~/src/k8s$ git grep 'package .\+_test' pkg/kubelet/
pkg/kubelet/container/runtime_cache_test.go:package container_test
pkg/kubelet/envvars/envvars_test.go:package envvars_test
pkg/kubelet/kubelet_dockerless_test.go:package kubelet_test
pkg/kubelet/runtimeclass/runtimeclass_manager_test.go:package runtimeclass_test

We can leave this as is or not, I don't think it really matters.

@pacoxu
Copy link
Member

pacoxu commented Sep 30, 2021

/test pull-kubernetes-unit

    validation_reserved_memory_test.go:116: expected error reserved memory may not be zero for NUMA node 0 and resource "memory", got invalid configuration: reserved memory may not be zero for NUMA node 0 and resource "memory"
FAIL
FAIL	k8s.io/kubernetes/pkg/kubelet/apis/config/validation	0.653s

The test cannot pass in my PC.

@pacoxu pacoxu added this to Triage in SIG Node PR Triage Sep 30, 2021
@shuheiktgw
Copy link
Contributor Author

shuheiktgw commented Sep 30, 2021

Whoops, I haven't noticed there are already tests for the ReservedMemory configurations, thanks! I removed the duplicate tests and updated the existing ones 👍

@shuheiktgw shuheiktgw requested a review from pacoxu October 4, 2021 06:05
@shuheiktgw
Copy link
Contributor Author

@pacoxu Sorry I forgot to reassign this PR to you after I fixed it! Would you review the PR again? 🙏

@ehashman
Copy link
Member

ehashman commented Oct 6, 2021

/ok-to-test
/triage accepted
/priority important-longterm

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. 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. labels Oct 6, 2021
@shuheiktgw
Copy link
Contributor Author

@ehashman I've squashed the commits to two! 🙏

@shuheiktgw
Copy link
Contributor Author

/retest

Copy link
Member

@ehashman ehashman left a comment

Choose a reason for hiding this comment

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

/lgtm

@ehashman ehashman moved this from Waiting on Author to Needs Approver in SIG Node PR Triage Nov 18, 2021
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 18, 2021
@ehashman
Copy link
Member

/assign @liggitt

Looks like this is an API reviewers only OWNERS file

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 18, 2021
@wzshiming wzshiming moved this from Needs Approver to Waiting on Author in SIG Node PR Triage Nov 18, 2021
@shuheiktgw shuheiktgw force-pushed the refactor_kubelet_config_validation_tests branch from 9301e80 to 2acdaeb Compare November 18, 2021 13:38
@k8s-ci-robot k8s-ci-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 18, 2021
@shuheiktgw
Copy link
Contributor Author

Rebased the PR and resolved the conflicts

@shuheiktgw
Copy link
Contributor Author

/retest

Copy link
Member

@ehashman ehashman left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 22, 2021
@liggitt
Copy link
Member

liggitt commented Nov 23, 2021

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, pacoxu, shuheiktgw

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 Nov 23, 2021
@k8s-triage-robot
Copy link

The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass.

This bot retests PRs for certain kubernetes repos according to the following rules:

  • The PR does have any do-not-merge/* labels
  • The PR does not have the needs-ok-to-test label
  • The PR is mergeable (does not have a needs-rebase label)
  • The PR is approved (has cncf-cla: yes, lgtm, approved labels)
  • The PR is failing tests required for merge

You can:

/retest

@ehashman
Copy link
Member

flake #106125
/retest-required

@reylejano
Copy link
Member

/milestone clear
Release Managers are cutting 1.23.0-rc.0 and creating the release-1.23 branch

@k8s-ci-robot k8s-ci-robot removed this from the v1.23 milestone Nov 24, 2021
@pacoxu
Copy link
Member

pacoxu commented Nov 24, 2021

/test pull-kubernetes-e2e-kind-ipv6

@ehashman
Copy link
Member

boo flakes, this will have to land when 1.24 opens :\

@ehashman ehashman moved this from Waiting on Author to Done in SIG Node PR Triage Dec 6, 2021
@k8s-ci-robot k8s-ci-robot merged commit b685b39 into kubernetes:master Dec 8, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.24 milestone Dec 8, 2021
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/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/node Categorizes an issue or PR as relevant to SIG Node. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Development

Successfully merging this pull request may close these issues.

Improve unit tests for Kubelet configuration APIs
8 participants