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

fix: fix RandomName's dash when no prefix provided #327

Merged
merged 2 commits into from
Oct 7, 2023

Conversation

pmalek
Copy link
Contributor

@pmalek pmalek commented Sep 29, 2023

What type of PR is this?

/kind bug

What this PR does / why we need it:

Currently envconf.RandomName() return a string with an empty prefix when no prefix was provided even though the godoc states:

If prefix is omitted, the then entire name is random char.

This PR fixes it by checking if an empty prefix was provided.

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

fixes `envconfg.RandomName() returning a string beginning with `-` when an empty prefix is provided

Additional documentation e.g., Usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Sep 29, 2023
@k8s-ci-robot k8s-ci-robot added sig/testing Categorizes an issue or PR as relevant to SIG Testing. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 29, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @pmalek. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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 size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Sep 29, 2023
@ShwethaKumbla
Copy link
Member

/ok-to-test

@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. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 29, 2023
@pmalek
Copy link
Contributor Author

pmalek commented Sep 29, 2023

@ShwethaKumbla I've removed my change w.r.t usage of deprecated math/rand.Seed.

I'd be happy to resolve that in a separate pr but please advise on the linter issue.

make verify-golangci-lint returns an error because when I change the file the error from rand.Read(p) is not checked. I don't want to change the signature (to include the returned error) without consulting the maintainers first.

Copy link
Contributor

@harshanarayana harshanarayana left a comment

Choose a reason for hiding this comment

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

This for this changes @pmalek . Left a minor comment.

const maxLen = 64

t.Run("no prefix yields random name without dash", func(t *testing.T) {
out := RandomName("", int(rand.Int31n(maxLen)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to use the math.rand based value for the input? Can it not be a pre-defined 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.

👍 Changed to use a constant prefix length

@pmalek
Copy link
Contributor Author

pmalek commented Oct 2, 2023

An unrelated test seems to have failed 🤔

 === RUN   TestKwokCluster/appsv1/deployment/pod_ready
    kwok_test.go:73: context deadline exceeded
--- FAIL: TestKwokCluster (120.02s)
    --- FAIL: TestKwokCluster/appsv1/deployment (120.02s)
        --- FAIL: TestKwokCluster/appsv1/deployment/deployment_creation (60.00s)
        --- FAIL: TestKwokCluster/appsv1/deployment/pod_ready (60.00s)
panic: interface conversion: interface {} is nil, not *v1.Deployment [recovered]
	panic: interface conversion: interface {} is nil, not *v1.Deployment
goroutine 45 [running]:
testing.tRunner.func1.2({0x20b1620, 0xc00020a000})
	/usr/local/go/src/testing/testing.go:1526 +0x372
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1529 +0x650
panic({0x20b1620, 0xc00020a000})
	/usr/local/go/src/runtime/panic.go:890 +0x263
sigs.k8s.io/e2e-framework/examples/kwok/kwok_with_config.TestKwokCluster.func4({0x2582730, 0xc000586090}, 0xc00031c9c0, 0x2581b00?)
	/home/prow/go/src/sigs.k8s.io/e2e-framework/examples/kwok/kwok_with_config/kwok_test.go:78 +0x165
sigs.k8s.io/e2e-framework/pkg/env.(*testEnv).executeSteps(0xc00014f830, {0x2582730, 0xc000586090}, 0xc000586902?, {0xc000366220, 0x1, 0x2ce1120?})
	/home/prow/go/src/sigs.k8s.io/e2e-framework/pkg/env/env.go:428 +0x136
sigs.k8s.io/e2e-framework/pkg/env.(*testEnv).execFeature.func1(0xc00031c9c0)
	/home/prow/go/src/sigs.k8s.io/e2e-framework/pkg/env/env.go:486 +0x7ac
testing.tRunner(0xc00031c9c0, 0xc0002be1b0)
	/usr/local/go/src/testing/testing.go:1576 +0x217
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:1629 +0x806 

@pmalek
Copy link
Contributor Author

pmalek commented Oct 2, 2023

/retest

@pmalek
Copy link
Contributor Author

pmalek commented Oct 2, 2023

Another unrelated failure :(

https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_e2e-framework/327/pull-e2e-framework-test/1708826099758141440

         --- FAIL: TestTableDriven/Random_numbers/less_than_equal_64 (0.00s)
panic: invalid argument to Int31n [recovered]
	panic: invalid argument to Int31n
goroutine 15 [running]:
testing.tRunner.func1.2({0x2022aa0, 0x2554a30})
	/usr/local/go/src/testing/testing.go:1526 +0x372
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1529 +0x650
panic({0x2022aa0, 0x2554a30})
	/usr/local/go/src/runtime/panic.go:890 +0x263
math/rand.(*Rand).Int31n(0xc000225500, 0x0)
	/usr/local/go/src/math/rand/rand.go:138 +0x126
sigs.k8s.io/e2e-framework/examples/table.TestTableDriven.func2({0x256d580, 0xc000225560}, 0xc000183040, 0x0?)
	/home/prow/go/src/sigs.k8s.io/e2e-framework/examples/table/table_test.go:62 +0xac
sigs.k8s.io/e2e-framework/pkg/env.(*testEnv).executeSteps(0xc0002254a0, {0x256d580, 0xc000225560}, 0x599?, {0xc0005a9e88, 0x1, 0x0?})
	/home/prow/go/src/sigs.k8s.io/e2e-framework/pkg/env/env.go:428 +0x136
sigs.k8s.io/e2e-framework/pkg/env.(*testEnv).execFeature.func1.1(0xc000183040)
	/home/prow/go/src/sigs.k8s.io/e2e-framework/pkg/env/env.go:466 +0x125
testing.tRunner(0xc000183040, 0xc000225860)
	/usr/local/go/src/testing/testing.go:1576 +0x217
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:1629 +0x806
FAIL	sigs.k8s.io/e2e-framework/examples/table	0.082s 

/retest

@harshanarayana
Copy link
Contributor

/retest

@harshanarayana
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 7, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: harshanarayana, pmalek

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 Oct 7, 2023
@k8s-ci-robot k8s-ci-robot merged commit 74e7870 into kubernetes-sigs:main Oct 7, 2023
4 checks passed
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. 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. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants