Add Gocritic

This also fixes the issues laid out by gocritic
This commit is contained in:
Sargun Dhillon
2020-12-05 19:09:18 -08:00
parent ffbfe19e78
commit d29adf5ce3
7 changed files with 34 additions and 30 deletions

View File

@@ -24,17 +24,7 @@ func ClientsetFromEnv(kubeConfigPath string) (*kubernetes.Clientset, error) {
)
if kubeConfigPath != "" {
_, err = os.Stat(kubeConfigPath)
if err == nil {
config, err = clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeConfigPath},
&clientcmd.ConfigOverrides{},
).ClientConfig()
} else if os.IsNotExist(err) {
config, err = rest.InClusterConfig()
} else {
return nil, err
}
config, err = clientsetFromEnvKubeConfigPath(kubeConfigPath)
} else {
config, err = rest.InClusterConfig()
}
@@ -46,6 +36,20 @@ func ClientsetFromEnv(kubeConfigPath string) (*kubernetes.Clientset, error) {
return kubernetes.NewForConfig(config)
}
func clientsetFromEnvKubeConfigPath(kubeConfigPath string) (*rest.Config, error) {
_, err := os.Stat(kubeConfigPath)
if os.IsNotExist(err) {
return rest.InClusterConfig()
}
if err != nil {
return nil, err
}
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeConfigPath},
&clientcmd.ConfigOverrides{},
).ClientConfig()
}
// PodInformerFilter is a filter that you should use when creating a pod informer for use with the pod controller.
func PodInformerFilter(node string) kubeinformers.SharedInformerOption {
return kubeinformers.WithTweakListOptions(func(options *metav1.ListOptions) {