Skip to content

Commit

Permalink
support multinetwork policy
Browse files Browse the repository at this point in the history
Signed-off-by: Yun Zhou <[email protected]>
  • Loading branch information
cathy-zhou committed Feb 12, 2022
1 parent 65e9ebe commit 9b96c2a
Show file tree
Hide file tree
Showing 46 changed files with 2,200 additions and 143 deletions.
8 changes: 8 additions & 0 deletions dist/images/daemonset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ OVN_EGRESSIP_ENABLE=
OVN_EGRESSFIREWALL_ENABLE=
OVN_DISABLE_OVN_IFACE_ID_VER="false"
OVN_MULTI_NETWORK_ENABLE=
OVN_MULTI_NETWORKPOLICY_ENABLE=
OVN_V4_JOIN_SUBNET=""
OVN_V6_JOIN_SUBNET=""
OVN_NETFLOW_TARGETS=""
Expand Down Expand Up @@ -194,6 +195,9 @@ while [ "$1" != "" ]; do
--multi-network-enable)
OVN_MULTI_NETWORK_ENABLE=$VALUE
;;
--multi-networkpolicy-enable)
OVN_MULTI_NETWORKPOLICY_ENABLE=$VALUE
;;
--v4-join-subnet)
OVN_V4_JOIN_SUBNET=$VALUE
;;
Expand Down Expand Up @@ -288,6 +292,8 @@ ovn_disable_ovn_iface_id_ver=${OVN_DISABLE_OVN_IFACE_ID_VER}
echo "ovn_disable_ovn_iface_id_ver: ${ovn_disable_ovn_iface_id_ver}"
ovn_multi_network_enable=${OVN_MULTI_NETWORK_ENABLE}
echo "ovn_multi_network_enable: ${ovn_multi_network_enable}"
ovn_multi_networkpolicy_enable=${OVN_MULTI_NETWORKPOLICY_ENABLE}
echo "ovn_multi_networkpolicy_enable: ${ovn_multi_networkpolicy_enable}"
ovn_hybrid_overlay_net_cidr=${OVN_HYBRID_OVERLAY_NET_CIDR}
echo "ovn_hybrid_overlay_net_cidr: ${ovn_hybrid_overlay_net_cidr}"
ovn_disable_snat_multiple_gws=${OVN_DISABLE_SNAT_MULTIPLE_GWS}
Expand Down Expand Up @@ -404,6 +410,7 @@ ovn_image=${image} \
ovn_v6_join_subnet=${ovn_v6_join_subnet} \
ovn_multicast_enable=${ovn_multicast_enable} \
ovn_egress_ip_enable=${ovn_egress_ip_enable} \
ovn_multi_network_enable=${ovn_multi_network_enable} \
ovn_netflow_targets=${ovn_netflow_targets} \
ovn_sflow_targets=${ovn_sflow_targets} \
ovn_ipfix_targets=${ovn_ipfix_targets} \
Expand Down Expand Up @@ -435,6 +442,7 @@ ovn_image=${image} \
ovn_egress_ip_enable=${ovn_egress_ip_enable} \
ovn_egress_firewall_enable=${ovn_egress_firewall_enable} \
ovn_multi_network_enable=${ovn_multi_network_enable} \
ovn_multi_networkpolicy_enable=${ovn_multi_networkpolicy_enable} \
ovn_ssl_en=${ovn_ssl_en} \
ovn_master_count=${ovn_master_count} \
ovn_gateway_mode=${ovn_gateway_mode} \
Expand Down
10 changes: 10 additions & 0 deletions dist/images/ovnkube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ ovn_egressfirewall_enable=${OVN_EGRESSFIREWALL_ENABLE:-false}
ovn_disable_ovn_iface_id_ver=${OVN_DISABLE_OVN_IFACE_ID_VER:-false}
#OVN_MULTI_NETWORK_ENABLE - enable multiple network support for ovn-kubernetes
ovn_multi_network_enable=${OVN_MULTI_NETWORK_ENABLE:-false}
#OVN_MULTI_NETWORKPOLICY_ENABLE - enable multi network policy for ovn-kubernetes
ovn_multi_networkpolicy_enable=${OVN_MULTI_NETWORKPOLICY_ENABLE:-false}
ovn_acl_logging_rate_limit=${OVN_ACL_LOGGING_RATE_LIMIT:-"20"}
ovn_netflow_targets=${OVN_NETFLOW_TARGETS:-}
ovn_sflow_targets=${OVN_SFLOW_TARGETS:-}
Expand Down Expand Up @@ -932,12 +934,19 @@ ovn-master() {
egressfirewall_enabled_flag="--enable-egress-firewall"
fi
echo "egressfirewall_enabled_flag=${egressfirewall_enabled_flag}"

multi_network_enabled_flag=
if [[ ${ovn_multi_network_enable} == "true" ]]; then
multi_network_enabled_flag="--enable-multi-network"
fi
echo "multi_network_enabled_flag=${multi_network_enabled_flag}"

multi_networkpolicy_enabled_flag=
if [[ ${ovn_multi_networkpolicy_enable} == "true" ]]; then
multi_networkpolicy_enabled_flag="--enable-multi-networkpolicy"
fi
echo "multi_networkpolicy_enabled_flag=${multi_networkpolicy_enabled_flag}"

ovnkube_master_metrics_bind_address="${metrics_endpoint_ip}:9409"

echo "=============== ovn-master ========== MASTER ONLY"
Expand All @@ -964,6 +973,7 @@ ovn-master() {
${egressip_enabled_flag} \
${egressfirewall_enabled_flag} \
${multi_network_enabled_flag} \
${multi_networkpolicy_enabled_flag} \
--metrics-bind-address ${ovnkube_master_metrics_bind_address} \
--host-network-namespace ${ovn_host_network_namespace} &

Expand Down
5 changes: 5 additions & 0 deletions dist/templates/ovn-setup.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ rules:
resources:
- network-attachment-definitions
verbs: ["list", "get", "watch"]
- apiGroups:
- k8s.cni.cncf.io
resources:
- multi-networkpolicies
verbs: ["list", "get", "watch"]


---
Expand Down
2 changes: 2 additions & 0 deletions dist/templates/ovnkube-master.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ spec:
value: "{{ ovn_egress_firewall_enable }}"
- name: OVN_MULTI_NETWORK_ENABLE
value: "{{ ovn_multi_network_enable }}"
- name: OVN_MULTI_NETWORKPOLICY_ENABLE
value: "{{ ovn_multi_networkpolicy_enable }}"
- name: OVN_HYBRID_OVERLAY_NET_CIDR
value: "{{ ovn_hybrid_overlay_net_cidr }}"
- name: OVN_DISABLE_SNAT_MULTIPLE_GWS
Expand Down
1 change: 1 addition & 0 deletions go-controller/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/coreos/go-iptables v0.4.5
github.com/google/uuid v1.2.0
github.com/gorilla/mux v1.8.0
github.com/k8snetworkplumbingwg/multi-networkpolicy v0.0.0-20200914073308-0f33b9190170
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.1.1-0.20210510153419-66a699ae3b05
github.com/miekg/dns v1.1.31
github.com/mitchellh/copystructure v1.2.0
Expand Down
6 changes: 5 additions & 1 deletion go-controller/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ github.com/juju/utils v0.0.0-20180808125547-9dfc6dbfb02b/go.mod h1:6/KLg8Wz/y2KV
github.com/juju/version v0.0.0-20161031051906-1f41e27e54f2/go.mod h1:kE8gK5X0CImdr7qpSKl3xB2PmpySSmfj7zVbkZFs81U=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/k8snetworkplumbingwg/multi-networkpolicy v0.0.0-20200914073308-0f33b9190170 h1:rtPle+U5e7Fia0j44gm+p5QMgOIXXB3A8GtFeCCh8Kk=
github.com/k8snetworkplumbingwg/multi-networkpolicy v0.0.0-20200914073308-0f33b9190170/go.mod h1:CF9uYILB8GY25A/6Hhi1AWKc29qbyLu8r7Gs+uINGZE=
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.1.1-0.20210510153419-66a699ae3b05 h1:vIZIhdbcm2eoTzSyaBQqgKLHzymSBbXpudf+2Wv4FNM=
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.1.1-0.20210510153419-66a699ae3b05/go.mod h1:+1DpV8uIwteAhxNO0lgRox8gHkTG6w3OeDfAlg+qqjA=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
Expand Down Expand Up @@ -928,8 +930,9 @@ k8s.io/code-generator v0.23.3/go.mod h1:S0Q1JVA+kSzTI1oUvbKAxZY/DYbA/ZUb4Uknog12
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92 h1:PgoMI/L1Nu5Vmvgm+vGheLuxKST8h6FMOqggyAFtHPc=
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/klog v0.3.0 h1:0VPpR+sizsiivjIfIAQH/rl8tan6jvWkS7lU+0di3lE=
k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
k8s.io/klog/v2 v2.9.0/go.mod h1:hy9LJ/NvuK+iVyP4Ehqva4HxZG/oXyIS3n3Jmire4Ec=
Expand All @@ -938,6 +941,7 @@ k8s.io/klog/v2 v2.30.0/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6/go.mod h1:GRQhZsXIAJ1xR0C9bd8UpWHZ5plfAS9fzPjJuQ6JL3E=
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 h1:E3J9oCLlaobFUqsjG9DfKbP2BmgwBL2p7pn0A3dG9W4=
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65/go.mod h1:sX9MT8g7NVZM5lVL/j8QyCCJe8YSMW30QvGZWaCIDIk=
k8s.io/utils v0.0.0-20200327001022-6496210b90e8/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20211116205334-6203023598ed h1:ck1fRPWPJWsMd8ZRFsWc6mh/zHp5fZ/shhbrgPUxDAE=
k8s.io/utils v0.0.0-20211116205334-6203023598ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
Expand Down
3 changes: 2 additions & 1 deletion go-controller/pkg/cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ func HandleCNIRequest(request *PodRequest, podLister corev1listers.PodLister, us
var response *Response
var err, err1 error

klog.Infof("%s %s starting CNI request %+v", request, request.Command, request)
klog.Infof("%s %s starting CNI request (%+v) DeviceID(%q) for pod %s/%s network %s", request, request.Command, request,
request.CNIConf.DeviceID, request.PodNamespace, request.PodName, request.effectiveNADName)
switch request.Command {
case CNIAdd:
response, err = request.cmdAdd(kubeAuth, podLister, useOVSExternalIDs, kclient)
Expand Down
13 changes: 10 additions & 3 deletions go-controller/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,10 @@ type KubernetesConfig struct {

// OVNKubernetesFeatureConfig holds OVN-Kubernetes feature enhancement config file parameters and command-line overrides
type OVNKubernetesFeatureConfig struct {
EnableEgressIP bool `gcfg:"enable-egress-ip"`
EnableEgressFirewall bool `gcfg:"enable-egress-firewall"`
EnableMultiNetwork bool `gcfg:"enable-multi-network"`
EnableEgressIP bool `gcfg:"enable-egress-ip"`
EnableEgressFirewall bool `gcfg:"enable-egress-firewall"`
EnableMultiNetwork bool `gcfg:"enable-multi-network"`
EnableMultiNetworkPolicy bool `gcfg:"enable-multi-networkpolicy"`
}

// GatewayMode holds the node gateway mode
Expand Down Expand Up @@ -838,6 +839,12 @@ var OVNK8sFeatureFlags = []cli.Flag{
Destination: &cliConfig.OVNKubernetesFeature.EnableMultiNetwork,
Value: OVNKubernetesFeature.EnableMultiNetwork,
},
&cli.BoolFlag{
Name: "enable-multi-networkpolicy",
Usage: "Configure to use multiple networkAttachmentDefinition CRD feature with ovn-kubernetes.",
Destination: &cliConfig.OVNKubernetesFeature.EnableMultiNetworkPolicy,
Value: OVNKubernetesFeature.EnableMultiNetworkPolicy,
},
}

// K8sFlags capture Kubernetes-related options
Expand Down
40 changes: 40 additions & 0 deletions go-controller/pkg/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import (
ocpcloudnetworkinformerfactory "github.com/openshift/client-go/cloudnetwork/informers/externalversions"
ocpcloudnetworklister "github.com/openshift/client-go/cloudnetwork/listers/cloudnetwork/v1"

multinetworkpolicyapi "github.com/k8snetworkplumbingwg/multi-networkpolicy/pkg/apis/k8s.cni.cncf.io/v1beta1"
multinetworkpolicyscheme "github.com/k8snetworkplumbingwg/multi-networkpolicy/pkg/client/clientset/versioned/scheme"
multinetworkpolicyinformerfactory "github.com/k8snetworkplumbingwg/multi-networkpolicy/pkg/client/informers/externalversions"

networkattachmentdefinitionapi "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
networkattachmentdefinitionscheme "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/clientset/versioned/scheme"
networkattachmentdefinitioninformerfactory "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/informers/externalversions"
Expand Down Expand Up @@ -52,6 +56,7 @@ type WatchFactory struct {
efFactory egressfirewallinformerfactory.SharedInformerFactory
cpipcFactory ocpcloudnetworkinformerfactory.SharedInformerFactory
nadFactory networkattachmentdefinitioninformerfactory.SharedInformerFactory
mnpFactory multinetworkpolicyinformerfactory.SharedInformerFactory
informers map[reflect.Type]*informer

stopChan chan struct{}
Expand Down Expand Up @@ -86,6 +91,7 @@ var (
egressIPType reflect.Type = reflect.TypeOf(&egressipapi.EgressIP{})
cloudPrivateIPConfigType reflect.Type = reflect.TypeOf(&ocpcloudnetworkapi.CloudPrivateIPConfig{})
networkattachmentdefinitionType reflect.Type = reflect.TypeOf(&networkattachmentdefinitionapi.NetworkAttachmentDefinition{})
multinetworkpolicyType reflect.Type = reflect.TypeOf(&multinetworkpolicyapi.MultiNetworkPolicy{})
)

// NewMasterWatchFactory initializes a new watch factory for the master or master+node processes.
Expand All @@ -102,6 +108,7 @@ func NewMasterWatchFactory(ovnClientset *util.OVNClientset) (*WatchFactory, erro
efFactory: egressfirewallinformerfactory.NewSharedInformerFactory(ovnClientset.EgressFirewallClient, resyncInterval),
cpipcFactory: ocpcloudnetworkinformerfactory.NewSharedInformerFactory(ovnClientset.CloudNetworkClient, resyncInterval),
nadFactory: networkattachmentdefinitioninformerfactory.NewSharedInformerFactory(ovnClientset.NetworkAttchDefClient, resyncInterval),
mnpFactory: multinetworkpolicyinformerfactory.NewSharedInformerFactory(ovnClientset.MultiNetworkPolicyClient, resyncInterval),
informers: make(map[reflect.Type]*informer),
stopChan: make(chan struct{}),
}
Expand All @@ -115,6 +122,9 @@ func NewMasterWatchFactory(ovnClientset *util.OVNClientset) (*WatchFactory, erro
if err := networkattachmentdefinitionapi.AddToScheme(networkattachmentdefinitionscheme.Scheme); err != nil {
return nil, err
}
if err := multinetworkpolicyapi.AddToScheme(multinetworkpolicyscheme.Scheme); err != nil {
return nil, err
}
// For Services and Endpoints, pre-populate the shared Informer with one that
// has a label selector excluding headless services.
wf.iFactory.InformerFor(&kapi.Service{}, func(c kubernetes.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
Expand Down Expand Up @@ -191,6 +201,13 @@ func NewMasterWatchFactory(ovnClientset *util.OVNClientset) (*WatchFactory, erro
return nil, err
}
}
if config.OVNKubernetesFeature.EnableMultiNetworkPolicy {
wf.informers[multinetworkpolicyType], err = newInformer(multinetworkpolicyType,
wf.mnpFactory.K8sCniCncfIo().V1beta1().MultiNetworkPolicies().Informer())
if err != nil {
return nil, err
}
}
return wf, nil
}

Expand Down Expand Up @@ -234,6 +251,15 @@ func (wf *WatchFactory) Start() error {
}
}
}
if config.OVNKubernetesFeature.EnableMultiNetworkPolicy && wf.mnpFactory != nil {
wf.mnpFactory.Start(wf.stopChan)
for oType, synced := range wf.mnpFactory.WaitForCacheSync(wf.stopChan) {
if !synced {
return fmt.Errorf("error in syncing cache for %v informer", oType)
}
}
}

return nil
}

Expand Down Expand Up @@ -366,6 +392,10 @@ func getObjectMeta(objType reflect.Type, obj interface{}) (*metav1.ObjectMeta, e
if networkattachmentdefinition, ok := obj.(*networkattachmentdefinitionapi.NetworkAttachmentDefinition); ok {
return &networkattachmentdefinition.ObjectMeta, nil
}
case multinetworkpolicyType:
if multinetworkpolicy, ok := obj.(*multinetworkpolicyapi.MultiNetworkPolicy); ok {
return &multinetworkpolicy.ObjectMeta, nil
}
}
return nil, fmt.Errorf("cannot get ObjectMeta from type %v", objType)
}
Expand Down Expand Up @@ -515,6 +545,16 @@ func (wf *WatchFactory) RemoveCloudPrivateIPConfigHandler(handler *Handler) {
wf.removeHandler(cloudPrivateIPConfigType, handler)
}

// AddMultiNetworkPolicyHandler adds a handler function that will be executed on MultiNetworkPolicy object changes
func (wf *WatchFactory) AddMultiNetworkPolicyHandler(handlerFuncs cache.ResourceEventHandler, processExisting func([]interface{})) *Handler {
return wf.addHandler(multinetworkpolicyType, "", nil, handlerFuncs, processExisting)
}

// RemoveMultiNetworkPolicyHandler removes an MultiNetworkPolicy object event handler function
func (wf *WatchFactory) RemoveMultiNetworkPolicyHandler(handler *Handler) {
wf.removeHandler(multinetworkpolicyType, handler)
}

// AddNamespaceHandler adds a handler function that will be executed on Namespace object changes
func (wf *WatchFactory) AddNamespaceHandler(handlerFuncs cache.ResourceEventHandler, processExisting func([]interface{})) *Handler {
return wf.addHandler(namespaceType, "", nil, handlerFuncs, processExisting)
Expand Down
3 changes: 3 additions & 0 deletions go-controller/pkg/factory/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

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

multinetworkpolicylister "github.com/k8snetworkplumbingwg/multi-networkpolicy/pkg/client/listers/k8s.cni.cncf.io/v1beta1"
networkattachmentdefinitionlister "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/listers/k8s.cni.cncf.io/v1"
egressfirewalllister "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressfirewall/v1/apis/listers/egressfirewall/v1"

Expand Down Expand Up @@ -382,6 +383,8 @@ func newInformerLister(oType reflect.Type, sharedInformer cache.SharedIndexInfor
return cloudprivateipconfiglister.NewCloudPrivateIPConfigLister(sharedInformer.GetIndexer()), nil
case networkattachmentdefinitionType:
return networkattachmentdefinitionlister.NewNetworkAttachmentDefinitionLister(sharedInformer.GetIndexer()), nil
case multinetworkpolicyType:
return multinetworkpolicylister.NewMultiNetworkPolicyLister(sharedInformer.GetIndexer()), nil
}

return nil, fmt.Errorf("cannot create lister from type %v", oType)
Expand Down
32 changes: 16 additions & 16 deletions go-controller/pkg/libovsdbops/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,6 @@ func findRouter(nbClient libovsdbclient.Client, router *nbdb.LogicalRouter) (*nb
return &routers[0], nil
}

// FindRoutersWitherExternalIds Looks up all routers in the cache based on given externalIDs
func FindRoutersWitherExternalIds(nbClient libovsdbclient.Client, externalIDs map[string]string) ([]nbdb.LogicalRouter, error) {
routers := []nbdb.LogicalRouter{}
ctx, cancel := context.WithTimeout(context.Background(), types.OVSDBTimeout)
defer cancel()
err := nbClient.WhereCache(func(item *nbdb.LogicalRouter) bool {
for k, v := range externalIDs {
if item.ExternalIDs[k] != v {
return false
}
}
return true
}).List(ctx, &routers)
return routers, err
}

func AddLoadBalancersToRouterOps(nbClient libovsdbclient.Client, ops []libovsdb.Operation, router *nbdb.LogicalRouter, lbs ...*nbdb.LoadBalancer) ([]libovsdb.Operation, error) {
if ops == nil {
ops = []libovsdb.Operation{}
Expand Down Expand Up @@ -122,6 +106,22 @@ func RemoveLoadBalancersFromRouterOps(nbClient libovsdbclient.Client, ops []libo
return ops, nil
}

// FindRoutersWitherExternalIds Looks up all routers in the cache based on given externalIDs
func FindRoutersWitherExternalIds(nbClient libovsdbclient.Client, externalIDs map[string]string) ([]nbdb.LogicalRouter, error) {
routers := []nbdb.LogicalRouter{}
ctx, cancel := context.WithTimeout(context.Background(), types.OVSDBTimeout)
defer cancel()
err := nbClient.WhereCache(func(item *nbdb.LogicalRouter) bool {
for k, v := range externalIDs {
if item.ExternalIDs[k] != v {
return false
}
}
return true
}).List(ctx, &routers)
return routers, err
}

func ListRoutersWithLoadBalancers(nbClient libovsdbclient.Client) ([]nbdb.LogicalRouter, error) {
routers := &[]nbdb.LogicalRouter{}
ctx, cancel := context.WithTimeout(context.Background(), types.OVSDBTimeout)
Expand Down
2 changes: 1 addition & 1 deletion go-controller/pkg/ovn/address_set/address_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func NewOvnAddressSetFactory(netNameInfo util.NetNameInfo, nbClient libovsdbclie
}

// ovnAddressSetFactory implements the AddressSetFactory interface
var _ AddressSetFactory = &ovnAddressSetFactory{}
//var _ AddressSetFactory = &ovnAddressSetFactory{}

// NewAddressSet returns a new address set object
func (asf *ovnAddressSetFactory) NewAddressSet(name string, ips []net.IP) (AddressSet, error) {
Expand Down
2 changes: 1 addition & 1 deletion go-controller/pkg/ovn/egressip.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ func (oc *Controller) addPodEgressIPAssignments(name string, statusAssignments [
// addLogicalPort has finished successfully setting up networking for
// the pod, so we can proceed with retrieving its IP and deleting the
// external GW configuration created in addLogicalPort for the pod.
logicalPort, err := oc.logicalPortCache.get(util.GetLogicalPortName(pod.Namespace, pod.Name, types.DefaultNetworkName, true))
logicalPort, err := oc.logicalPortCache.get(util.GetLogicalPortName(pod.Namespace, pod.Name, types.DefaultNetworkName, !oc.nadInfo.IsSecondary))
if err != nil {
return nil
}
Expand Down
Loading

0 comments on commit 9b96c2a

Please sign in to comment.