-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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
Refactor kubelet config validation tests #105360
Conversation
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 Once the patch is verified, the new status will be reflected by the 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. |
@@ -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)) |
There was a problem hiding this comment.
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)) | ||
} |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @wzshiming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @bobbypage
@@ -14,22 +14,25 @@ See the License for the specific language governing permissions and | |||
limitations under the License. | |||
*/ | |||
|
|||
package validation | |||
package validation_test |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
/test pull-kubernetes-unit
The test cannot pass in my PC. |
Whoops, I haven't noticed there are already tests for the ReservedMemory configurations, thanks! I removed the duplicate tests and updated the existing ones 👍 |
@pacoxu Sorry I forgot to reassign this PR to you after I fixed it! Would you review the PR again? 🙏 |
/ok-to-test |
@ehashman I've squashed the commits to two! 🙏 |
/retest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/assign @liggitt Looks like this is an API reviewers only OWNERS file |
9301e80
to
2acdaeb
Compare
Rebased the PR and resolved the conflicts |
/retest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve |
[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 |
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:
You can:
/retest |
flake #106125 |
/milestone clear |
/test pull-kubernetes-e2e-kind-ipv6 |
boo flakes, this will have to land when 1.24 opens :\ |
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:
invalid validation:
prefixCPUCFSQuotaPeriod
NodeStatusMaxImages
TopologyManagerPolicy
ShutdownGracePeriod
MemorySwap.SwapBehavior
%q
instead of%v
if necessary. For exampleEnforceNodeAllocatable
Which issue(s) this PR fixes:
Fixes #105029
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: