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
chore: Refactoring cloud provider initialization to merge v1 and v2 driver implementations. #1060
chore: Refactoring cloud provider initialization to merge v1 and v2 driver implementations. #1060
Conversation
Hi @landreasyan. 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 Once the patch is verified, the new status will be reflected by the 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. |
/ok-to-test |
pkg/azureutils/azure_disk_utils.go
Outdated
// GetKubeConfig gets config object from config file | ||
func GetKubeConfig(kubeconfig string) (config *rest.Config, err error) { | ||
// attempt to read the in-cluster config | ||
config, err = rest.InClusterConfig() |
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.
this func is changing the original behavior, any reason why change this?
azuredisk-csi-driver/pkg/azureutils/azure_disk_utils.go
Lines 445 to 461 in 36b2a9a
func getKubeClient(kubeconfig string) (*kubernetes.Clientset, error) { | |
var ( | |
config *rest.Config | |
err error | |
) | |
if kubeconfig != "" { | |
if config, err = clientcmd.BuildConfigFromFlags("", kubeconfig); err != nil { | |
return nil, err | |
} | |
} else { | |
if config, err = rest.InClusterConfig(); err != nil { | |
return nil, err | |
} | |
} | |
return kubernetes.NewForConfig(config) | |
} |
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.
I am trying to merge the behaviors we had in the v1 and v2 drivers. The recommended approach is to read the in cluster config and then fall back to kubeconfig if it fails. The behavior is essentially the same in the old implementation as well. Was there a reason to prioritize kubeconfig over the in cluster one?
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.
If kubeConfig
is not empty, it means that it was specified on the command line. In this case, it should probably take precedence here.
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.
But if we are running inside a cluster and our driver runs inside a pod, is there a scenario we where we would prefer the kubeconfig
rather than the in-cluster config? From what I understand, the kubeconfig
is mostly important for testing when the suite does not actually run inside a pod.
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.
if kubeconfig
is set by user, it must be honored first:
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.") |
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.
I have reverted the changes to the getter and kept the old logic.
ec190e4
to
75de0fe
Compare
pkg/azureutils/azure_disk_utils.go
Outdated
if err != nil && !os.IsNotExist(err) && err != rest.ErrNotInCluster { | ||
return nil, fmt.Errorf("failed to get KubeClient: %v", err) | ||
} | ||
az, err := GetCloudProviderFromClient(kubeClient, secretName, secretNamespace, userAgent) |
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.
return GetCloudProviderFromClient(kubeClient, secretName, secretNamespace, userAgent)
Renaming function names. Reverting kubeconfig getter changes. Remove unittest that is dependent on env. Adding warning logs on kubeconfig failure.
75de0fe
to
0d24269
Compare
/lgtm |
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
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: andyzhangx, landreasyan 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 |
What type of PR is this?
Currently, v1 and v2 drivers have separate implementation for initializing the cloud provider. This PR is to refactor and merge these differences in order to eliminate any duplicate code.
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Requirements:
Special notes for your reviewer:
Release note: