Skip to content

Commit

Permalink
Configure columns & filters for subnet labels
Browse files Browse the repository at this point in the history
Fix reading machine network
  • Loading branch information
jotak committed Feb 20, 2024
1 parent ab09645 commit 561327d
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 10 deletions.
5 changes: 4 additions & 1 deletion config/samples/flows_v1beta2_flowcollector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ spec:
# Append a unique cluster name to each record
# clusterName: <CLUSTER NAME>
# addZone: true
# subnetLabelling:
# subnetLabels:
# openShiftAutoDetect: true
# customLabels:
# - cidrs: []
# name: ""
metrics:
server:
port: 9102
Expand Down
32 changes: 32 additions & 0 deletions controllers/consoleplugin/config/static-frontend-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ columns:
default: false
width: 15
feature: zones
- id: SrcSubnetLabel
group: Source
name: Subnet Label
field: SrcSubnetLabel
filter: src_subnet_label
default: false
width: 10
feature: subnetLabels
- id: DstK8S_Name
group: Destination
name: Name
Expand Down Expand Up @@ -277,6 +285,14 @@ columns:
default: false
width: 15
feature: zones
- id: DstSubnetLabel
group: Destination
name: Subnet Label
field: DstSubnetLabel
filter: dst_subnet_label
default: false
width: 10
feature: subnetLabels
- id: K8S_Name
name: Names
calculated: getSrcOrDstValue(SrcK8S_Name,DstK8S_Name)
Expand Down Expand Up @@ -599,6 +615,16 @@ filters:
component: autocomplete
category: destination
hint: Specify a single zone.
- id: src_subnet_label
name: Subnet Label
component: autocomplete
category: source
hint: Specify a subnet label, or an empty string to get unmatched sources.
- id: dst_subnet_label
name: Subnet Label
component: autocomplete
category: destination
hint: Specify a subnet label, or an empty string to get unmatched destinations.
- id: src_resource
name: Resource
component: autocomplete
Expand Down Expand Up @@ -871,6 +897,9 @@ fields:
type: string
description: Source availability zone
lokiLabel: true
- name: SrcSubnetLabel
type: string
description: Source subnet label
- name: DstK8S_Name
type: string
description: Name of the destination Kubernetes object, such as Pod name, Service name or Node name.
Expand Down Expand Up @@ -908,6 +937,9 @@ fields:
type: string
description: Destination availability zone
lokiLabel: true
- name: DstSubnetLabel
type: string
description: Destination subnet label
- name: K8S_FlowLayer
type: string
description: "Flow layer: 'app' or 'infra'"
Expand Down
3 changes: 3 additions & 0 deletions controllers/consoleplugin/consoleplugin_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ func (b *builder) setFrontendConfig(fconf *config.FrontendConfig) error {
if helper.IsZoneEnabled(&b.desired.Processor) {
fconf.Features = append(fconf.Features, "zones")
}
if helper.IsSubnetLabelsEnabled(&b.desired.Processor) {
fconf.Features = append(fconf.Features, "subnetLabels")
}
return nil
}

Expand Down
36 changes: 27 additions & 9 deletions controllers/flp/flp_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,29 +301,47 @@ func (r *Reconciler) getOpenShiftSubnets(ctx context.Context) ([]flowslatest.Sub
if err := r.Get(ctx, types.NamespacedName{Name: "cluster-config-v1", Namespace: "kube-system"}, cm); err != nil {
return nil, fmt.Errorf(`can't read "cluster-config-v1" ConfigMap: %w`, err)
}
machines, err := readMachineNetworks(cm)
if err != nil {
return nil, err
}

if len(machines) > 0 {
subnets = append(subnets, machines...)
}

return subnets, nil
}

func readMachineNetworks(cm *corev1.ConfigMap) ([]flowslatest.SubnetLabel, error) {
var subnets []flowslatest.SubnetLabel

type clusterConfig struct {
type ClusterConfig struct {
Networking struct {
MachineNetwork struct {
CIDR []string
}
}
MachineNetwork []struct {
CIDR string `yaml:"cidr"`
} `yaml:"machineNetwork"`
} `yaml:"networking"`
}

var rawConfig string
var ok bool
if rawConfig, ok = cm.Data["install-config"]; !ok {
return nil, fmt.Errorf(`can't find key "install-config" in "cluster-config-v1" ConfigMap`)
}
var config clusterConfig
if err := yaml.Unmarshal([]byte(rawConfig), config); err != nil {
var config ClusterConfig
if err := yaml.Unmarshal([]byte(rawConfig), &config); err != nil {
return nil, fmt.Errorf(`can't deserialize content of "cluster-config-v1" ConfigMap: %w`, err)
}

if len(config.Networking.MachineNetwork.CIDR) > 0 {
var cidrs []string
for _, cidr := range config.Networking.MachineNetwork {
cidrs = append(cidrs, cidr.CIDR)
}
if len(cidrs) > 0 {
subnets = append(subnets, flowslatest.SubnetLabel{
Name: "Machines",
CIDRs: config.Networking.MachineNetwork.CIDR,
CIDRs: cidrs,
})
}

Expand Down
50 changes: 50 additions & 0 deletions controllers/flp/flp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1029,3 +1029,53 @@ func TestPipelineWithoutLoki(t *testing.T) {
pipeline,
)
}

func TestReadMachineNetworks(t *testing.T) {
cm := corev1.ConfigMap{
Data: map[string]string{
"install-config": `
additionalTrustBundlePolicy: Proxyonly
apiVersion: v1
baseDomain: my.openshift.com
compute:
- architecture: amd64
hyperthreading: Enabled
name: worker
platform: {}
replicas: 3
controlPlane:
architecture: amd64
hyperthreading: Enabled
name: master
platform: {}
replicas: 3
metadata:
creationTimestamp: null
name: my-cluster
networking:
clusterNetwork:
- cidr: 10.128.0.0/14
hostPrefix: 23
machineNetwork:
- cidr: 10.0.0.0/16
networkType: OVNKubernetes
serviceNetwork:
- 172.30.0.0/16
platform:
aws:
region: eu-west-3
publish: External`,
},
}

machines, err := readMachineNetworks(&cm)
assert.NoError(t, err)

assert.Equal(t,
[]flowslatest.SubnetLabel{
{
Name: "Machines",
CIDRs: []string{"10.0.0.0/16"},
},
}, machines)
}
4 changes: 4 additions & 0 deletions pkg/helper/flowcollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func IsZoneEnabled(spec *flowslatest.FlowCollectorFLP) bool {
return spec.AddZone != nil && *spec.AddZone
}

func IsSubnetLabelsEnabled(spec *flowslatest.FlowCollectorFLP) bool {
return AutoDetectOpenShiftNetworks(spec) || len(spec.SubnetLabels.CustomLabels) > 0
}

func PtrBool(b *bool) bool {
if b == nil {
return false
Expand Down

0 comments on commit 561327d

Please sign in to comment.