Skip to content

Commit

Permalink
azure.go: refactor getRuntimeClassForPod
Browse files Browse the repository at this point in the history
  • Loading branch information
arc9693 committed May 23, 2024
1 parent 0b7c2c1 commit 9a22752
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions pkg/azurefile/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,24 @@ func getRuntimeClassForPod(ctx context.Context, kubeconfig, podName string, podN
kubeClient *clientset.Clientset
)
kubeCfg, err := getKubeConfig(kubeconfig, false)
if err == nil && kubeCfg != nil {
kubeClient, err = clientset.NewForConfig(kubeCfg)
if err != nil {
klog.Warningf("NewForConfig failed with error: %v", err)
return "", err
}
// Get runtime class for pod
if kubeClient != nil {
pod, err := kubeClient.CoreV1().Pods(podNameSpace).Get(ctx, podName, metav1.GetOptions{})
if err != nil {
klog.Warningf("Get pod(%s) failed with error: %v", podName, err)
return "", err
}
if pod.Spec.RuntimeClassName != nil {
return *pod.Spec.RuntimeClassName, nil
}
}
} else {
klog.Warningf("get kubeconfig(%s) failed with error: %v", kubeconfig, err)
if err != nil {
klog.Warningf("getKubeConfig(%s) failed with error: %v", kubeconfig, err)
return "", err
}
kubeClient, err = clientset.NewForConfig(kubeCfg)
if err != nil {
klog.Warningf("NewForConfig failed with error: %v", err)
return "", err
}
// Get runtime class for pod
pod, err := kubeClient.CoreV1().Pods(podNameSpace).Get(ctx, podName, metav1.GetOptions{})
if err != nil {
klog.Warningf("Get pod(%s) failed with error: %v", podName, err)
return "", err
}
if pod.Spec.RuntimeClassName != nil {
return *pod.Spec.RuntimeClassName, nil
}
return "", nil
}

Expand Down

0 comments on commit 9a22752

Please sign in to comment.