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

TestGetKubeConfig unit test failing #1294

Merged

Conversation

RomanBednar
Copy link
Contributor

What type of PR is this?
/kind test
/kind bug

What this PR does / why we need it:

Fixes a failing unit test.

Which issue(s) this PR fixes:

Fixes #1293

Requirements:

Special notes for your reviewer:

Release note:

none

@k8s-ci-robot k8s-ci-robot added kind/test kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 7, 2023
@@ -400,14 +394,6 @@ users:
envVariableHasConfig: false,
envVariableConfigIsValid: false,
},
{
desc: "[failure] invalid kube config passed",
Copy link
Member

Choose a reason for hiding this comment

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

is it possible only skip this test in OpenShift coreos?

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO an unit test that checks system directories is a bad test. [failure] invalid kube config passed tests getKubeConfig() with an empty kubeconfig file.

This leads to this call stack:

clientcmd.(*DeferredLoadingClientConfig).ClientConfig (merged_client_builder.go:120) k8s.io/client-go/tools/clientcmd
clientcmd.BuildConfigFromFlags (client_config.go:627) k8s.io/client-go/tools/clientcmd
azurefile.getKubeConfig (azure.go:156) sigs.k8s.io/azurefile-csi-driver/pkg/azurefile
azurefile.TestGetKubeConfig (azure_test.go:422) sigs.k8s.io/azurefile-csi-driver/pkg/azurefile

DeferredLoadingClientConfig.ClientConfig() then fails to load the empty kubeconfig, but as a fallback, it tries to load in-cluster config. And that's where it finds out that it's just a Pod in our CI and loads Kubernetes service account and therefore succeeds, instead of returning error.

// check for in-cluster configuration and use it
if config.icc.Possible() {
klog.V(4).Infof("Using in-cluster configuration")
return config.icc.ClientConfig()
}

With the env. variables unset, Possible() it will return error here:

// Possible returns true if loading an inside-kubernetes-cluster is possible.
func (config *inClusterClientConfig) Possible() bool {
fi, err := os.Stat("/var/run/secrets/kubernetes.io/serviceaccount/token")
return os.Getenv("KUBERNETES_SERVICE_HOST") != "" &&
os.Getenv("KUBERNETES_SERVICE_PORT") != "" &&
err == nil && !fi.IsDir()
}

I don't know what magic Kubernetes CI does so that Possible() fails, most probably it does not create /var/run/secrets/kubernetes.io/serviceaccount/token. But an unit test result should not depend on presence of any files in /var/run.

Copy link
Member

@andyzhangx andyzhangx 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 Jun 7, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andyzhangx, RomanBednar

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 Jun 7, 2023
@andyzhangx
Copy link
Member

/retest

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. kind/test lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

TestGetKubeConfig unit test failing
4 participants