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

Refactor metadata.go to test that k8s client is initialized iff ec2 metadata is unavailable #902

Closed
wants to merge 1 commit into from

Conversation

wongma7
Copy link
Contributor

@wongma7 wongma7 commented May 25, 2021

Is this a bug fix or adding new feature? /kind cleanup

What is this PR about? / Why do we need it? found in #897 that it's hard to test whether the k8s client has been initialized or not. in part because NewMetadataService accepts a kubernetes.Interface and you can't check if it's nil.

Refactored NewMetadataService to accept a func that returns a kubernetes.Interface... it's not pretty but should work.

(Also, I removed NewMetadata. Some of this code is hella confusing since we kept the naming of Metadata even though it can be constructed from k8s api now, not just ec2 instance metadata. I stopped short of renaming it, maybe to InstanceInfo or NodeInfo, because I already got a bit carried away with what is supposed to be a simple refactor, may do it later.)

What testing is done? TODO: e2e test on my eks cluster

  • instance metadata enabled (k8s client init should not be attempted, there should be no need to set Node Name env var)
  • instance metadata disabled (k8s client init should be attempted)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 25, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wongma7

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 25, 2021
@wongma7 wongma7 added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label May 25, 2021
@coveralls
Copy link

coveralls commented May 25, 2021

Pull Request Test Coverage Report for Build 1991

  • 70 of 85 (82.35%) changed or added relevant lines in 3 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.005%) to 79.13%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/driver/node.go 0 1 0.0%
pkg/cloud/metadata.go 69 83 83.13%
Files with Coverage Reduction New Missed Lines %
pkg/cloud/metadata.go 3 81.82%
Totals Coverage Status
Change from base Build 1988: 0.005%
Covered Lines: 2002
Relevant Lines: 2530

💛 - Coveralls

if m.GetInstanceID() != tc.identityDocument.InstanceID {
t.Fatalf("GetInstanceID() failed: expected %v, got %v", tc.identityDocument.InstanceID, m.GetInstanceID())
if clientsetInitialized == true {
t.Errorf("kubernetes client was unexpectedly initialized when metadata is available!")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here is the relevant part where we test that clientset initialization func did not get called.

rest of changes in this test file are mainly renaming and simplifying/collapsing some branching

@wongma7 wongma7 force-pushed the metadatarefactor branch from 1e97115 to 8e67b79 Compare May 25, 2021 23:31
@wongma7
Copy link
Contributor Author

wongma7 commented May 27, 2021

actually instead of manually testing I want #907 to test it.

existing kops job will check box 1
new eksctl job will check box 2.

@wongma7
Copy link
Contributor Author

wongma7 commented Jun 2, 2021

close in favor of #907

@wongma7 wongma7 closed this Jun 2, 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants