Skip to content

Commit

Permalink
fix gc lsp statistic for multiple subnet
Browse files Browse the repository at this point in the history
  • Loading branch information
lut777 authored and zhangzujian committed Sep 16, 2021
1 parent da43e21 commit f5997a8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 11 deletions.
20 changes: 20 additions & 0 deletions pkg/controller/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ func (c *Controller) markAndCleanLSP() error {
continue
}
providerName := strings.ReplaceAll(k, util.AllocatedAnnotationSuffix, "")
isProviderovn, err := c.isOVNProvided(providerName, pod)
if err != nil {
klog.Errorf("determine if provider is ovn failed %v", err)
}
if !isProviderovn {
continue
}
ipNames = append(ipNames, ovs.PodNameToPortName(pod.Name, pod.Namespace, providerName))
}
}
Expand Down Expand Up @@ -525,3 +532,16 @@ func (c *Controller) gcStaticRoute() error {
}
return nil
}

func (c *Controller) isOVNProvided(providerName string, pod *corev1.Pod) (bool, error) {
ls := pod.Annotations[fmt.Sprintf(util.LogicalSwitchAnnotationTemplate, providerName)]
subnet, err := c.config.KubeOvnClient.KubeovnV1().Subnets().Get(context.Background(), ls, metav1.GetOptions{})
if err != nil {
klog.Errorf("parse annotation logical switch %s error %v", ls, err)
return false, err
}
if subnet.Spec.Provider != "ovn" {
return false, nil
}
return true, nil
}
47 changes: 37 additions & 10 deletions pkg/controller/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,43 @@ func (c *Controller) InitIPAM() error {
return err
}
for _, pod := range pods {
if isPodAlive(pod) &&
pod.Annotations[util.AllocatedAnnotation] == "true" &&
pod.Annotations[util.LogicalSwitchAnnotation] != "" {
_, _, _, err := c.ipam.GetStaticAddress(
fmt.Sprintf("%s/%s", pod.Namespace, pod.Name),
pod.Annotations[util.IpAddressAnnotation],
pod.Annotations[util.MacAddressAnnotation],
pod.Annotations[util.LogicalSwitchAnnotation])
if err != nil {
klog.Errorf("failed to init pod %s.%s address %s: %v", pod.Name, pod.Namespace, pod.Annotations[util.IpAddressAnnotation], err)
if isPodAlive(pod) && pod.Annotations[util.AllocatedAnnotation] == "true" {
if pod.Annotations[util.LogicalSwitchAnnotation] != "" {
_, _, _, err := c.ipam.GetStaticAddress(
fmt.Sprintf("%s/%s", pod.Namespace, pod.Name),
pod.Annotations[util.IpAddressAnnotation],
pod.Annotations[util.MacAddressAnnotation],
pod.Annotations[util.LogicalSwitchAnnotation])
if err != nil {
klog.Errorf("failed to init pod %s.%s address %s: %v", pod.Name, pod.Namespace, pod.Annotations[util.IpAddressAnnotation], err)
}
}
attachNetworks := pod.Annotations[util.AttachmentNetworkAnnotation]
if attachNetworks != "" {
attachments, err := util.ParsePodNetworkAnnotation(attachNetworks, pod.Namespace)
if err != nil {
klog.Errorf("failed to parse attach net for pod '%s', %v", pod.Name, err)
continue
}
for _, attach := range attachments {
var builder strings.Builder
builder.WriteString(attach.Name)
builder.WriteString(".")
if attach.Namespace == "" {
builder.WriteString("default")
} else {
builder.WriteString(attach.Namespace)
}

_, _, _, err := c.ipam.GetStaticAddress(
fmt.Sprintf("%s/%s", pod.Namespace, pod.Name),
pod.Annotations[fmt.Sprintf(util.IpAddressAnnotationTemplate, builder.String())],
pod.Annotations[fmt.Sprintf(util.MacAddressAnnotationTemplate, builder.String())],
pod.Annotations[fmt.Sprintf(util.LogicalSwitchAnnotationTemplate, builder.String())])
if err != nil {
klog.Errorf("failed to init pod %s.%s address %s: %v", pod.Name, pod.Namespace, pod.Annotations[util.IpAddressAnnotation], err)
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/network_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func parsePodNetworkObjectName(podnetwork string) (string, string, string, error
}
}

klog.Infof("parsePodNetworkObjectName: parsed: %s, %s, %s", netNsName, networkName, netIfName)
klog.V(5).Infof("parsePodNetworkObjectName: parsed: %s, %s, %s", netNsName, networkName, netIfName)
return netNsName, networkName, netIfName, nil
}

Expand Down

0 comments on commit f5997a8

Please sign in to comment.