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

chore: Refactoring cloud provider initialization to merge v1 and v2 driver implementations. #1060

Conversation

landreasyan
Copy link
Contributor

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:

none

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 29, 2021
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@andyzhangx
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 29, 2021
pkg/azureutils/azure_disk_utils.go Outdated Show resolved Hide resolved
pkg/azuredisk/controllerserver.go Outdated Show resolved Hide resolved
// 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()
Copy link
Member

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?

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)
}

Copy link
Contributor Author

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?

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Member

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.")

Copy link
Contributor Author

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.

@landreasyan landreasyan force-pushed the refactoring-cloud-provider-init branch 2 times, most recently from ec190e4 to 75de0fe Compare November 3, 2021 04:25
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)
Copy link
Member

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)

pkg/azureutils/azure_disk_utils.go Show resolved Hide resolved
pkg/azureutils/azure_disk_utils.go Show resolved Hide resolved
Renaming function names.

Reverting kubeconfig getter changes.

Remove unittest that is dependent on env.

Adding warning logs on kubeconfig failure.
@landreasyan landreasyan force-pushed the refactoring-cloud-provider-init branch from 75de0fe to 0d24269 Compare November 3, 2021 17:55
@edreed
Copy link
Collaborator

edreed commented Nov 3, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 3, 2021
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
/approve

@k8s-ci-robot
Copy link
Contributor

[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 /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 Nov 4, 2021
@k8s-ci-robot k8s-ci-robot merged commit c3bc779 into kubernetes-sigs:master Nov 4, 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. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants