Skip to content

Commit

Permalink
add ns annotation to enable default pod subnet in custom vpc
Browse files Browse the repository at this point in the history
Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>
  • Loading branch information
cnvergence committed Jul 12, 2024
1 parent 51c1002 commit 7166eeb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
5 changes: 5 additions & 0 deletions charts/kube-ovn/templates/kube-ovn-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1570,12 +1570,17 @@ spec:
- jsonPath: .spec.namespaces
name: Namespaces
type: string
- jsonPath: .status.defaultLogicalSwitch
name: DefaultLogicalSwitch
type: string
name: v1
schema:
openAPIV3Schema:
properties:
spec:
properties:
defaultSubnet:
type: string
enableExternal:
type: boolean
enableBfd:
Expand Down
17 changes: 16 additions & 1 deletion pkg/controller/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (c *Controller) handleAddNamespace(key string) error {
}
namespace := cachedNs.DeepCopy()

var ls, ippool string
var ls, ds, ippool string
var lss, cidrs, excludeIps []string
subnets, err := c.subnetsLister.List(labels.Everything())
if err != nil {
Expand All @@ -142,6 +142,17 @@ func (c *Controller) handleAddNamespace(key string) error {
break
}
}

if s.Spec.Vpc != "" || s.Spec.Vpc != c.config.ClusterRouter {
vpc, err := c.vpcsLister.Get(s.Spec.Vpc)
if err != nil {
klog.Errorf("failed to get custom vpc %v", err)
return err
}
if s.Name == vpc.Spec.DefaultSubnet {
ds = s.Name
}
}
}

for _, p := range ippools {
Expand Down Expand Up @@ -190,10 +201,14 @@ func (c *Controller) handleAddNamespace(key string) error {
} else if namespace.Annotations[util.LogicalSwitchAnnotation] == strings.Join(lss, ",") &&
namespace.Annotations[util.CidrAnnotation] == strings.Join(cidrs, ";") &&
namespace.Annotations[util.ExcludeIpsAnnotation] == strings.Join(excludeIps, ";") &&
namespace.Annotations[util.DefaultVPCSubnetAnnotation] == ds &&
namespace.Annotations[util.IPPoolAnnotation] == ippool {
return nil
}

if ds != "" {
namespace.Annotations[util.DefaultVPCSubnetAnnotation] = ds
}
namespace.Annotations[util.LogicalSwitchAnnotation] = strings.Join(lss, ",")
namespace.Annotations[util.CidrAnnotation] = strings.Join(cidrs, ";")
namespace.Annotations[util.ExcludeIpsAnnotation] = strings.Join(excludeIps, ";")
Expand Down
8 changes: 8 additions & 0 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,14 @@ func (c *Controller) getPodDefaultSubnet(pod *v1.Pod) (*kubeovnv1.Subnet, error)
klog.Error(err)
return nil, err
}
if _, ok := ns.Annotations[util.DefaultVPCSubnetAnnotation]; ok {
subnet, err = c.subnetsLister.Get(ns.Annotations[util.DefaultVPCSubnetAnnotation])
if err != nil {
klog.Errorf("failed to get subnet %v", err)
return nil, err
}
return subnet, nil
}

subnetNames := ns.Annotations[util.LogicalSwitchAnnotation]
for _, subnetName := range strings.Split(subnetNames, ",") {
Expand Down
5 changes: 3 additions & 2 deletions pkg/util/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ const (
IngressRateAnnotation = "ovn.kubernetes.io/ingress_rate"
EgressRateAnnotation = "ovn.kubernetes.io/egress_rate"

PortNameAnnotation = "ovn.kubernetes.io/port_name"
LogicalSwitchAnnotation = "ovn.kubernetes.io/logical_switch"
PortNameAnnotation = "ovn.kubernetes.io/port_name"
LogicalSwitchAnnotation = "ovn.kubernetes.io/logical_switch"
DefaultVPCSubnetAnnotation = "ovn.kubernetes.io/default_vpc_subnet"

TunnelInterfaceAnnotation = "ovn.kubernetes.io/tunnel_interface"

Expand Down

0 comments on commit 7166eeb

Please sign in to comment.