@@ -14,6 +14,7 @@ import (
1414 "github.com/netobserv/network-observability-operator/internal/pkg/manager/status"
1515 "github.com/netobserv/network-observability-operator/internal/pkg/watchers"
1616 configv1 "github.com/openshift/api/config/v1"
17+ operatorv1 "github.com/openshift/api/operator/v1"
1718 "gopkg.in/yaml.v2"
1819 appsv1 "k8s.io/api/apps/v1"
1920 ascv2 "k8s.io/api/autoscaling/v2"
@@ -232,59 +233,92 @@ func reconcileMonitoringCerts(ctx context.Context, info *reconcilers.Common, tls
232233}
233234
234235func (r * Reconciler ) getOpenShiftSubnets (ctx context.Context ) ([]flowslatest.SubnetLabel , error ) {
235- var subnets []flowslatest.SubnetLabel
236-
237236 // Pods and Services subnets are found in CNO config
238- if r .mgr .ClusterInfo .HasCNO () {
239- network := & configv1.Network {}
240- err := r .Get (ctx , types.NamespacedName {Name : "cluster" }, network )
241- if err != nil {
242- return nil , fmt .Errorf ("can't get Network information: %w" , err )
243- }
244- var podCIDRs []string
245- for _ , podsNet := range network .Spec .ClusterNetwork {
246- podCIDRs = append (podCIDRs , podsNet .CIDR )
247- }
248- if len (podCIDRs ) > 0 {
249- subnets = append (subnets , flowslatest.SubnetLabel {
250- Name : "Pods" ,
251- CIDRs : podCIDRs ,
252- })
253- }
254- if len (network .Spec .ServiceNetwork ) > 0 {
255- subnets = append (subnets , flowslatest.SubnetLabel {
256- Name : "Services" ,
257- CIDRs : network .Spec .ServiceNetwork ,
258- })
259- }
260- if network .Spec .ExternalIP != nil && len (network .Spec .ExternalIP .AutoAssignCIDRs ) > 0 {
261- subnets = append (subnets , flowslatest.SubnetLabel {
262- Name : "ExternalIP" ,
263- CIDRs : network .Spec .ExternalIP .AutoAssignCIDRs ,
264- })
265- }
237+ if ! r .mgr .ClusterInfo .HasCNO () {
238+ return nil , nil
239+ }
240+
241+ var pods , services , machines , extIPs []string
242+
243+ network := & configv1.Network {}
244+ err := r .Get (ctx , types.NamespacedName {Name : "cluster" }, network )
245+ if err != nil {
246+ return nil , fmt .Errorf ("can't get Network (config) information: %w" , err )
247+ }
248+ for _ , podsNet := range network .Spec .ClusterNetwork {
249+ pods = append (pods , podsNet .CIDR )
250+ }
251+ services = network .Spec .ServiceNetwork
252+ // API server
253+ // TODO: get IP from EndpointSlice kubernetes
254+ services = append (services , "172.20.0.1/32" )
255+ if network .Spec .ExternalIP != nil && len (network .Spec .ExternalIP .AutoAssignCIDRs ) > 0 {
256+ extIPs = network .Spec .ExternalIP .AutoAssignCIDRs
266257 }
267258
268259 // Nodes subnet found in CM cluster-config-v1 (kube-system)
269260 cm := & corev1.ConfigMap {}
270261 if err := r .Get (ctx , types.NamespacedName {Name : "cluster-config-v1" , Namespace : "kube-system" }, cm ); err != nil {
271262 return nil , fmt .Errorf (`can't read "cluster-config-v1" ConfigMap: %w` , err )
272263 }
273- machines , err := readMachineNetworks (cm )
264+ // Machines
265+ machines , err = readMachineFromConfig (cm )
274266 if err != nil {
275267 return nil , err
276268 }
277269
278- if len (machines ) > 0 {
279- subnets = append (subnets , machines ... )
270+ // Additional OVN subnets
271+ networkOp := & operatorv1.Network {}
272+ err = r .Get (ctx , types.NamespacedName {Name : "cluster" }, network )
273+ if err != nil {
274+ return nil , fmt .Errorf ("can't get Network (operator) information: %w" , err )
280275 }
276+ // Additional CIDRs: https://github.com/openshift/cluster-network-operator/blob/fda7a9f07ab6f78d032d310cdd77f21d04f1289a/pkg/network/ovn_kubernetes.go#L76-L77
277+ internalSubnet := "100.64.0.0/16"
278+ transitSwitchSubnet := "100.88.0.0/16"
279+ masqueradeSubnet := "169.254.0.0/17"
280+ if networkOp .Spec .DefaultNetwork .OVNKubernetesConfig != nil {
281+ ovnk := networkOp .Spec .DefaultNetwork .OVNKubernetesConfig
282+ if ovnk .V4InternalSubnet != "" {
283+ internalSubnet = ovnk .V4InternalSubnet
284+ }
285+ if ovnk .IPv4 != nil && ovnk .IPv4 .InternalTransitSwitchSubnet != "" {
286+ transitSwitchSubnet = ovnk .IPv4 .InternalTransitSwitchSubnet
287+ }
288+ }
289+ machines = append (machines , internalSubnet )
290+ machines = append (machines , transitSwitchSubnet )
291+ machines = append (machines , masqueradeSubnet )
281292
293+ var subnets []flowslatest.SubnetLabel
294+ if len (machines ) > 0 {
295+ subnets = append (subnets , flowslatest.SubnetLabel {
296+ Name : "Machines" ,
297+ CIDRs : machines ,
298+ })
299+ }
300+ if len (pods ) > 0 {
301+ subnets = append (subnets , flowslatest.SubnetLabel {
302+ Name : "Pods" ,
303+ CIDRs : pods ,
304+ })
305+ }
306+ if len (services ) > 0 {
307+ subnets = append (subnets , flowslatest.SubnetLabel {
308+ Name : "Services" ,
309+ CIDRs : services ,
310+ })
311+ }
312+ if len (extIPs ) > 0 {
313+ subnets = append (subnets , flowslatest.SubnetLabel {
314+ Name : "ExternalIP" ,
315+ CIDRs : extIPs ,
316+ })
317+ }
282318 return subnets , nil
283319}
284320
285- func readMachineNetworks (cm * corev1.ConfigMap ) ([]flowslatest.SubnetLabel , error ) {
286- var subnets []flowslatest.SubnetLabel
287-
321+ func readMachineFromConfig (cm * corev1.ConfigMap ) ([]string , error ) {
288322 type ClusterConfig struct {
289323 Networking struct {
290324 MachineNetwork []struct {
@@ -307,12 +341,6 @@ func readMachineNetworks(cm *corev1.ConfigMap) ([]flowslatest.SubnetLabel, error
307341 for _ , cidr := range config .Networking .MachineNetwork {
308342 cidrs = append (cidrs , cidr .CIDR )
309343 }
310- if len (cidrs ) > 0 {
311- subnets = append (subnets , flowslatest.SubnetLabel {
312- Name : "Machines" ,
313- CIDRs : cidrs ,
314- })
315- }
316344
317- return subnets , nil
345+ return cidrs , nil
318346}
0 commit comments