mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-06-30 09:31:59 +00:00
Properly initialize kubeClient in SetNetworkStatus method (#283)
* Properly initialize kubeClient in SetNetworkStatus method * Fix typo * Update error message * Extend logging for setNetworkStatus function
This commit is contained in:
parent
362a7d0bd6
commit
08a2623b8e
@ -81,9 +81,22 @@ func setKubeClientInfo(c *clientInfo, client KubeClient, k8sArgs *types.K8sArgs)
|
|||||||
c.Podname = string(k8sArgs.K8S_POD_NAME)
|
c.Podname = string(k8sArgs.K8S_POD_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetNetworkStatus(client KubeClient, k8sArgs *types.K8sArgs, netStatus []*types.NetworkStatus) error {
|
func SetNetworkStatus(client KubeClient, k8sArgs *types.K8sArgs, netStatus []*types.NetworkStatus, conf *types.NetConf) error {
|
||||||
|
logging.Debugf("SetNetworkStatus: %v, %v, %v, %v", client, k8sArgs, netStatus, conf)
|
||||||
|
|
||||||
|
client, err := GetK8sClient(conf.Kubeconfig, client)
|
||||||
|
if err != nil {
|
||||||
|
return logging.Errorf("SetNetworkStatus: %v", err)
|
||||||
|
}
|
||||||
|
if client == nil {
|
||||||
|
if len(conf.Delegates) == 0 {
|
||||||
|
// No available kube client and no delegates, we can't do anything
|
||||||
|
return logging.Errorf("must have either Kubernetes config or delegates, refer to Multus documentation for usage instructions")
|
||||||
|
}
|
||||||
|
logging.Debugf("SetNetworkStatus: kube client info is not defined, skip network status setup")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
logging.Debugf("SetNetworkStatus: %v, %v, %v", client, k8sArgs, netStatus)
|
|
||||||
podName := string(k8sArgs.K8S_POD_NAME)
|
podName := string(k8sArgs.K8S_POD_NAME)
|
||||||
podNamespace := string(k8sArgs.K8S_POD_NAMESPACE)
|
podNamespace := string(k8sArgs.K8S_POD_NAMESPACE)
|
||||||
pod, err := client.GetPod(podNamespace, podName)
|
pod, err := client.GetPod(podNamespace, podName)
|
||||||
|
@ -393,7 +393,7 @@ func cmdAdd(args *skel.CmdArgs, exec invoke.Exec, kubeClient k8s.KubeClient) (cn
|
|||||||
//set the network status annotation in apiserver, only in case Multus as kubeconfig
|
//set the network status annotation in apiserver, only in case Multus as kubeconfig
|
||||||
if n.Kubeconfig != "" && kc != nil {
|
if n.Kubeconfig != "" && kc != nil {
|
||||||
if !types.CheckSystemNamespaces(kc.Podnamespace, n.SystemNamespaces) {
|
if !types.CheckSystemNamespaces(kc.Podnamespace, n.SystemNamespaces) {
|
||||||
err = k8s.SetNetworkStatus(kubeClient, k8sArgs, netStatus)
|
err = k8s.SetNetworkStatus(kubeClient, k8sArgs, netStatus, n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, logging.Errorf("Multus: Err set the networks status: %v", err)
|
return nil, logging.Errorf("Multus: Err set the networks status: %v", err)
|
||||||
}
|
}
|
||||||
@ -486,7 +486,7 @@ func cmdDel(args *skel.CmdArgs, exec invoke.Exec, kubeClient k8s.KubeClient) err
|
|||||||
// unset the network status annotation in apiserver, only in case Multus as kubeconfig
|
// unset the network status annotation in apiserver, only in case Multus as kubeconfig
|
||||||
if in.Kubeconfig != "" {
|
if in.Kubeconfig != "" {
|
||||||
if !types.CheckSystemNamespaces(string(k8sArgs.K8S_POD_NAMESPACE), in.SystemNamespaces) {
|
if !types.CheckSystemNamespaces(string(k8sArgs.K8S_POD_NAMESPACE), in.SystemNamespaces) {
|
||||||
err := k8s.SetNetworkStatus(kubeClient, k8sArgs, nil)
|
err := k8s.SetNetworkStatus(kubeClient, k8sArgs, nil, in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// error happen but continue to delete
|
// error happen but continue to delete
|
||||||
logging.Errorf("Multus: Err unset the networks status: %v", err)
|
logging.Errorf("Multus: Err unset the networks status: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user