Skip to content

Commit

Permalink
NETOBSERV-1734: change subnets order priority (netobserv#693)
Browse files Browse the repository at this point in the history
Make sure auto-detected openshift labels are appended at the end of the
subnets list, so that they have lower priority. It makes it possible to
override in-cluster subnets.
  • Loading branch information
jotak committed Jul 15, 2024
1 parent c28b290 commit 7430e41
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion controllers/flp/flp_pipeline_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func (b *PipelineBuilder) AddProcessorStages() error {
addZone := helper.IsZoneEnabled(&b.desired.Processor)

// Get all subnet labels
allLabels := append(b.detectedSubnets, b.desired.Processor.SubnetLabels.CustomLabels...)
allLabels := b.desired.Processor.SubnetLabels.CustomLabels
allLabels = append(allLabels, b.detectedSubnets...)
flpLabels := subnetLabelsToFLP(allLabels)

rules := api.NetworkTransformRules{
Expand Down
49 changes: 49 additions & 0 deletions controllers/flp/flp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1057,3 +1057,52 @@ publish: External`,
},
}, machines)
}

func TestPipelineWithSubnetLabels(t *testing.T) {
assert := assert.New(t)

cfg := flowslatest.FlowCollectorSpec{
Processor: flowslatest.FlowCollectorFLP{
SubnetLabels: flowslatest.SubnetLabels{
OpenShiftAutoDetect: ptr.To(true),
CustomLabels: []flowslatest.SubnetLabel{
{
Name: "Foo",
CIDRs: []string{"8.8.8.8/32"},
},
},
},
},
Loki: flowslatest.FlowCollectorLoki{Enable: ptr.To(false)},
}

b := monoBuilder("namespace", &cfg)
b.generic.detectedSubnets = []flowslatest.SubnetLabel{
{
Name: "Pods",
CIDRs: []string{"10.128.0.0/14"},
},
}
scm, _, err := b.staticConfigMap()
assert.NoError(err)
dcm, err := b.dynamicConfigMap()
assert.NoError(err)
cfs, pipeline := validatePipelineConfig(t, scm, dcm)
assert.Equal(
`[{"name":"grpc"},{"name":"enrich","follows":"grpc"},{"name":"prometheus","follows":"enrich"}]`,
pipeline,
)
assert.Equal(
[]api.NetworkTransformSubnetLabel{
{
Name: "Foo",
CIDRs: []string{"8.8.8.8/32"},
},
{
Name: "Pods",
CIDRs: []string{"10.128.0.0/14"},
},
},
cfs.Parameters[1].Transform.Network.SubnetLabels,
)
}

0 comments on commit 7430e41

Please sign in to comment.