Skip to content

Commit

Permalink
jjjjjllllllll
Browse files Browse the repository at this point in the history
  • Loading branch information
dcbw committed Jun 9, 2021
1 parent bc17da6 commit ac6f1a4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
8 changes: 4 additions & 4 deletions go-controller/pkg/cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (pr *PodRequest) cmdAdd(podLister corev1listers.PodLister, useOVSExternalID

response := &Response{}
if !config.UnprivilegedMode {
response.Result, err = pr.getCNIResult(podInterfaceInfo)
response.Result, err = pr.getCNIResult(podInterfaceInfo, podLister, kclient)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -176,7 +176,7 @@ func (pr *PodRequest) cmdCheck(podLister corev1listers.PodLister, useOVSExternal
}
for _, ip := range result.IPs {
if err = waitForPodInterface(pr.ctx, result.Interfaces[*ip.Interface].Mac, []*net.IPNet{&ip.Address},
hostIfaceName, ifaceID, ofPort, useOVSExternalIDs); err != nil {
hostIfaceName, ifaceID, ofPort, useOVSExternalIDs, namespace, podName, podLister, kclient); err != nil {
return nil, fmt.Errorf("error while waiting on OVN pod interface: %s ip: %v, error: %v", ifaceID, ip, err)
}
}
Expand Down Expand Up @@ -230,8 +230,8 @@ func HandleCNIRequest(request *PodRequest, podLister corev1listers.PodLister, us
}

// getCNIResult get result from pod interface info.
func (pr *PodRequest) getCNIResult(podInterfaceInfo *PodInterfaceInfo) (*current.Result, error) {
interfacesArray, err := pr.ConfigureInterface(pr.PodNamespace, pr.PodName, podInterfaceInfo)
func (pr *PodRequest) getCNIResult(podInterfaceInfo *PodInterfaceInfo, podLister corev1listers.PodLister, kclient kubernetes.Interface) (*current.Result, error) {
interfacesArray, err := pr.ConfigureInterface(pr.PodNamespace, pr.PodName, podInterfaceInfo, podLister, kclient)
if err != nil {
return nil, fmt.Errorf("failed to configure pod interface: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go-controller/pkg/cni/cnishim.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (p *Plugin) CmdAdd(args *skel.CmdArgs) error {
result = response.Result
} else {
pr, _ := cniRequestToPodRequest(req)
result, err = pr.getCNIResult(response.PodIFInfo)
result, err = pr.getCNIResult(response.PodIFInfo, nil, nil)
if err != nil {
err = fmt.Errorf("failed to get CNI Result from pod interface info %v: %v", response.PodIFInfo, err)
klog.Error(err.Error())
Expand Down
10 changes: 6 additions & 4 deletions go-controller/pkg/cni/helper_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"strconv"
"strings"

"k8s.io/client-go/kubernetes"
corev1listers "k8s.io/client-go/listers/core/v1"
"k8s.io/klog/v2"

"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util"
Expand Down Expand Up @@ -252,7 +254,7 @@ func setupSriovInterface(netns ns.NetNS, containerID, ifName string, ifInfo *Pod

// ConfigureOVS performs OVS configurations in order to set up Pod networking
func ConfigureOVS(ctx context.Context, namespace string, podName string, hostIfaceName string,
ifInfo *PodInterfaceInfo, sandboxID string) error {
ifInfo *PodInterfaceInfo, sandboxID string, podLister corev1listers.PodLister, kclient kubernetes.Interface) error {
klog.Infof("ConfigureOVS: namespace: %s, podName: %s", namespace, podName)
ifaceID := fmt.Sprintf("%s_%s", namespace, podName)

Expand Down Expand Up @@ -307,7 +309,7 @@ func ConfigureOVS(ctx context.Context, namespace string, podName string, hostIfa
return err
}

if err = waitForPodInterface(ctx, ifInfo.MAC.String(), ifInfo.IPs, hostIfaceName, ifaceID, ofPort, ifInfo.CheckExtIDs); err != nil {
if err = waitForPodInterface(ctx, ifInfo.MAC.String(), ifInfo.IPs, hostIfaceName, ifaceID, ofPort, ifInfo.CheckExtIDs, namespace, podName, podLister, kclient); err != nil {
if ifInfo.CheckExtIDs {
return fmt.Errorf("error while waiting on OVS.Interface.external-ids:ovn-installed for pod: %v", err)
} else {
Expand All @@ -318,7 +320,7 @@ func ConfigureOVS(ctx context.Context, namespace string, podName string, hostIfa
}

// ConfigureInterface sets up the container interface
func (pr *PodRequest) ConfigureInterface(namespace string, podName string, ifInfo *PodInterfaceInfo) ([]*current.Interface, error) {
func (pr *PodRequest) ConfigureInterface(namespace string, podName string, ifInfo *PodInterfaceInfo, podLister corev1listers.PodLister, kclient kubernetes.Interface) ([]*current.Interface, error) {
netns, err := ns.GetNS(pr.Netns)
if err != nil {
return nil, fmt.Errorf("failed to open netns %q: %v", pr.Netns, err)
Expand All @@ -344,7 +346,7 @@ func (pr *PodRequest) ConfigureInterface(namespace string, podName string, ifInf
}

if !ifInfo.IsSmartNic {
err = ConfigureOVS(pr.ctx, namespace, podName, hostIface.Name, ifInfo, pr.SandboxID)
err = ConfigureOVS(pr.ctx, namespace, podName, hostIface.Name, ifInfo, pr.SandboxID, podLister, kclient)
if err != nil {
return nil, err
}
Expand Down
33 changes: 32 additions & 1 deletion go-controller/pkg/cni/ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"strings"
"time"

"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util"

"k8s.io/client-go/kubernetes"
corev1listers "k8s.io/client-go/listers/core/v1"
"k8s.io/klog/v2"
kexec "k8s.io/utils/exec"
)
Expand Down Expand Up @@ -233,21 +237,47 @@ func doPodFlowsExist(queries []openflowQuery) bool {
return true
}

func waitForPodInterface(ctx context.Context, mac string, ifAddrs []*net.IPNet, ifaceName, ifaceID string, ofPort int, checkExternalIDs bool) error {
func getPodMAC(ctx context.Context, namespace, name string, podLister corev1listers.PodLister, kclient kubernetes.Interface) (string, error) {
annotations, err := GetPodAnnotations(ctx, podLister, kclient, namespace, name, isOvnReady)
if err != nil {
return "", err
}
annot, err := util.UnmarshalPodAnnotation(annotations)
if err != nil {
return "", err
}

return annot.MAC.String(), nil
}

func waitForPodInterface(ctx context.Context, mac string, ifAddrs []*net.IPNet, ifaceName, ifaceID string,
ofPort int, checkExternalIDs bool, namespace, name string, podLister corev1listers.PodLister, kclient kubernetes.Interface) error {
var queries []openflowQuery
if checkExternalIDs {
queries = getMinimalFlowQueries(mac, ofPort)
} else {
queries = getLegacyFlowQueries(mac, ifAddrs, ofPort)
}
timeout := time.After(20 * time.Second)
var tries uint
for {
select {
case <-ctx.Done():
return fmt.Errorf("canceled while waiting for OVS port binding")
case <-timeout:
return fmt.Errorf("timed out while waiting for OVS port %s/%s binding to %s %s ", ifaceName, ifaceID, mac, ifAddrs)
default:
if tries%5 == 0 && podLister != nil && kclient != nil {
// Check every second whether the MAC address we are looking for is still the right one
newMAC, err := getPodMAC(ctx, namespace, name, podLister, kclient)
if err != nil {
klog.Warningf("#### failed to get pod %s/%s MAC: %v", namespace, name, err)
} else if newMAC != mac {
klog.Warningf("#### pod %s/%s MAC changed from %s -> %s; canceling wait for OVS port binding", namespace, name, mac, newMAC)
return fmt.Errorf("pod MAC changed while waiting for OVS port binding")
}
}

if err := isIfaceIDSet(ifaceName, ifaceID); err != nil {
return err
}
Expand All @@ -262,6 +292,7 @@ func waitForPodInterface(ctx context.Context, mac string, ifAddrs []*net.IPNet,
}

// try again later
tries++
time.Sleep(200 * time.Millisecond)
}
}
Expand Down
2 changes: 1 addition & 1 deletion go-controller/pkg/node/node_smartnic.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (n *OvnNode) addRepPort(pod *kapi.Pod, vfRepName string, ifInfo *cni.PodInt
return fmt.Errorf("failed to get smart-nic annotation. %v", err)
}

err := cni.ConfigureOVS(context.TODO(), pod.Namespace, pod.Name, vfRepName, ifInfo, smartNicCD.SandboxId)
err := cni.ConfigureOVS(context.TODO(), pod.Namespace, pod.Name, vfRepName, ifInfo, smartNicCD.SandboxId, nil, nil)
if err != nil {
return err
}
Expand Down

0 comments on commit ac6f1a4

Please sign in to comment.