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

Make the kernel generateInterfaceName function public #1607

Merged

Conversation

glazychev-art
Copy link
Contributor

@glazychev-art glazychev-art commented Apr 3, 2024

Description

Issue link

networkservicemesh/integration-k8s-gke#435

How Has This Been Tested?

  • Added unit testing to cover
  • Tested manually
  • Tested by integration testing
  • Have not tested

Types of changes

  • Bug fix
  • New functionality
  • Documentation
  • Refactoring
  • CI

Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>
Copy link

codecov bot commented Apr 3, 2024

Codecov Report

Attention: Patch coverage is 35.71429% with 9 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (main@f0105d6). Click here to learn what that means.

Files Patch % Lines
pkg/tools/nanoid/utils.go 0.00% 9 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1607   +/-   ##
=======================================
  Coverage        ?   67.42%           
=======================================
  Files           ?      264           
  Lines           ?    12493           
  Branches        ?        0           
=======================================
  Hits            ?     8424           
  Misses          ?     3545           
  Partials        ?      524           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>
Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>

// GenerateLinuxInterfaceName - returns a random interface name with "nsm" prefix
// to achieve a 1% chance of name collision, you need to generate approximately 68 billon names
func GenerateLinuxInterfaceName(generator func(int) (string, error)) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func GenerateLinuxInterfaceName(generator func(int) (string, error)) (string, error) {
func GenerateLinuxInterfaceName() (string, error) {

// to achieve a 1% chance of name collision, you need to generate approximately 68 billon names
func GenerateLinuxInterfaceName(generator func(int) (string, error)) (string, error) {
ifIDLen := kernelmech.LinuxIfMaxLength - len(ifPrefix)
id, err := generator(ifIDLen)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
id, err := generator(ifIDLen)
id, err := RandomString(ifIDLen, WithAlphabet(...))

@@ -58,7 +58,7 @@ func (m *kernelMechanismServer) Request(ctx context.Context, request *networkser
if m.interfaceName != "" {
mechanism.SetInterfaceName(m.interfaceName)
} else {
ifname, err := generateInterfaceName(m.interfaceNameGenerator)
ifname, err := nanoid.GenerateLinuxInterfaceName(m.interfaceNameGenerator)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ifname, err := nanoid.GenerateLinuxInterfaceName(m.interfaceNameGenerator)
ifname, err := nanoid.GenerateLinuxInterfaceName()

@denis-tingaikin denis-tingaikin merged commit 1f50c95 into networkservicemesh:main Apr 4, 2024
17 checks passed
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