-
Notifications
You must be signed in to change notification settings - Fork 146
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
TestGetKubeConfig unit test failing #1294
Conversation
@@ -400,14 +394,6 @@ users: | |||
envVariableHasConfig: false, | |||
envVariableConfigIsValid: false, | |||
}, | |||
{ | |||
desc: "[failure] invalid kube config passed", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
azurefile-csi-driver/vendor/k8s.io/client-go/tools/clientcmd/merged_client_builder.go
Lines 119 to 123 in ae84f9a
// 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:
azurefile-csi-driver/vendor/k8s.io/client-go/tools/clientcmd/client_config.go
Lines 603 to 609 in 817a13b
// 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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[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 |
/retest |
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: