Incorporate review comments in #58

Print error in case of errror (for debuggability) and remove
isJSON() becuase none called it.
This commit is contained in:
Tomofumi Hayashi
2018-04-24 11:29:44 +09:00
committed by Kuralamudhan Ramakrishnan
parent 0bdadc7f39
commit 6d12cd74ac

View File

@@ -41,7 +41,7 @@ func createK8sClient(kubeconfig string) (*kubernetes.Clientset, error) {
// uses the current context in kubeconfig // uses the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig) config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil { if err != nil {
return nil, fmt.Errorf("createK8sClient: failed to get context for the kubeconfig %v, refer Multus README.md for the usage guide", kubeconfig) return nil, fmt.Errorf("createK8sClient: failed to get context for the kubeconfig %v, refer Multus README.md for the usage guide: %v", kubeconfig, err)
} }
// creates the clientset // creates the clientset
@@ -54,7 +54,7 @@ func getPodNetworkAnnotation(client *kubernetes.Clientset, k8sArgs types.K8sArgs
pod, err := client.Pods(string(k8sArgs.K8S_POD_NAMESPACE)).Get(fmt.Sprintf("%s", string(k8sArgs.K8S_POD_NAME)), metav1.GetOptions{}) pod, err := client.Pods(string(k8sArgs.K8S_POD_NAMESPACE)).Get(fmt.Sprintf("%s", string(k8sArgs.K8S_POD_NAME)), metav1.GetOptions{})
if err != nil { if err != nil {
return annot, fmt.Errorf("getPodNetworkAnnotation: failed to query the pod %v in out of cluster comm", string(k8sArgs.K8S_POD_NAME)) return annot, fmt.Errorf("getPodNetworkAnnotation: failed to query the pod %v in out of cluster comm: %v", string(k8sArgs.K8S_POD_NAME), err)
} }
return pod.Annotations["kubernetes.v1.cni.cncf.io/networks"], nil return pod.Annotations["kubernetes.v1.cni.cncf.io/networks"], nil
@@ -119,11 +119,6 @@ func parsePodNetworkObject(podnetwork string) ([]map[string]interface{}, error)
return podNet, nil return podNet, nil
} }
func isJSON(str string) bool {
var js json.RawMessage
return json.Unmarshal([]byte(str), &js) == nil
}
func getpluginargs(name string, args string, primary bool, ifname string) (string, error) { func getpluginargs(name string, args string, primary bool, ifname string) (string, error) {
var netconf string var netconf string
var tmpargs []string var tmpargs []string