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

feat(api): add consistent hash table size api #3348

Merged
merged 6 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/v1alpha1/loadbalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type ConsistentHash struct {

// The table size for consistent hashing, must be prime number limited to 5000011.
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add CEL to validate it must be prime number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like CEL in Kubernetes 1 doesn't support complex validation logic like IsPrime function. But we can validate whether table size is prime number when translating ClientTrafficPolicy to IR.

func IsPrime(n int) bool {
    if n <= 1 {
        return false
    }
    for i := 2; i*i <= n; i++ {
        if n%i == 0 {
            return false
        }
    }
    return true
}

Footnotes

  1. https://kubernetes.io/docs/reference/using-api/cel/#cel-options-language-features-and-libraries

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM

//
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Minimum=2
// +kubebuilder:validation:Maximum=5000011
// +kubebuilder:default=65537
// +optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ spec:
prime number limited to 5000011.
format: int64
maximum: 5000011
minimum: 1
minimum: 2
type: integer
type:
description: ConsistentHashType defines the type of input
Expand Down