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

kubeadm unit test initalize global variables #100201

Merged
merged 1 commit into from Mar 15, 2021

Conversation

aojea
Copy link
Member

@aojea aojea commented Mar 12, 2021

/kind failing-test
/kind flake

NONE

xref https://testgrid.k8s.io/sig-testing-canaries#ci-kubernetes-generate-make-test-count10

Before it fail to run more than one time, the global variables weren't restored and the next iteration was using the previous value in the code under test, however, the test itself was using the new value.

go test -timeout 60s -count 2 -run TestCertsWithCSRs ./cmd/kubeadm/app/cmd/phases/init/
[certs] Generating CSR for apiserver instead of certificate
[certs] Generating "apiserver" key and CSR
[certs] Generating CSR for apiserver instead of certificate
[certs] Generating "apiserver" key and CSR
--- FAIL: TestCertsWithCSRs (0.06s)
    certs_test.go:82: couldn't load certificate "apiserver": could not load CSR file: could not load the CSR /tmp/009840433/apiserver.csr: failed to read file: open /tmp/009840433/apiserver.csr: no such file or directory
FAIL
FAIL    k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/init       0.143s
FAIL

Initialising the variables at the beginning of the test make the test idempotent.

go test -timeout 60s -count 20 -run TestCertsWithCSRs ./cmd/kubeadm/app/cmd/phases/init/
ok      k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/init       1.455s

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. kind/flake Categorizes issue or PR as related to a flaky test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. 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 Mar 12, 2021
@aojea
Copy link
Member Author

aojea commented Mar 12, 2021

/assign @liggitt @neolit123
/cc @BenTheElder
/sig testing

@k8s-ci-robot k8s-ci-robot added the sig/testing Categorizes an issue or PR as relevant to SIG Testing. label Mar 12, 2021
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Mar 12, 2021
@k8s-ci-robot k8s-ci-robot added area/kubeadm sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. labels Mar 12, 2021
Copy link
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

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

i would have suggested a refector to not have these global variables (grumble), but the flags that use them are deprecated:
https://github.com/kubernetes/kubernetes/blob/92af6be262e69b3cad821fbd175504d27cd2466c/cmd/kubeadm/app/cmd/phases/init/certs.go#L68-L72

with the removal of these flags, TestCertsWithCSRs can be removed as well, because there is already coverage elsewhere for this feature.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 13, 2021
@neolit123
Copy link
Member

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Mar 13, 2021
@pacoxu
Copy link
Member

pacoxu commented Mar 13, 2021

Need milestone 1.21?

@yangjunmyfm192085
Copy link
Contributor

/retest

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@aojea
Copy link
Member Author

aojea commented Mar 13, 2021

hmm failures seems related 👀

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 13, 2021
@@ -41,6 +41,12 @@ func (t *testCertsData) CertificateDir() string { return t.cfg.Certi
func (t *testCertsData) CertificateWriteDir() string { return t.cfg.CertificatesDir }

func TestCertsWithCSRs(t *testing.T) {
// restore global variables
defer func() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Jordan showed me the way :)
#100203 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

I mean… not using global vars anymore is better… but if the thing you're testing explicitly requires them, resetting once the test is over is good to do

@aojea
Copy link
Member Author

aojea commented Mar 13, 2021

we need milestone and lgtm @neolit123 @spiffxp

Copy link
Member

@neolit123 neolit123 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 Mar 13, 2021
Copy link
Member

@spiffxp spiffxp left a comment

Choose a reason for hiding this comment

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

/lgtm
/priority important-soon
/milestone v1.21

@k8s-ci-robot k8s-ci-robot added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Mar 14, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.21 milestone Mar 14, 2021
@k8s-ci-robot k8s-ci-robot removed the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Mar 14, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aojea, neolit123, spiffxp

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

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

1 similar comment
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@k8s-ci-robot k8s-ci-robot merged commit 854c2cc into kubernetes:master Mar 15, 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/kubeadm cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. kind/flake Categorizes issue or PR as related to a flaky test. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. 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. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants