11package openshift
22
33import (
4+ "encoding/json"
45 "fmt"
56 "os"
67 "path"
@@ -24,7 +25,18 @@ const (
2425 ocpMonitoringGroupByLabel = "namespace"
2526)
2627
27- func newOPAOpenShiftContainer (mode lokiv1.ModeType , secretVolumeName , tlsDir , minTLSVersion , ciphers string , withTLS bool , adminGroups []string ) corev1.Container {
28+ type Matchers struct {
29+ ByGroup map [string ]Matcher `json:"byGroup,omitempty"`
30+ ByTenant map [string ]Matcher `json:"byTenant,omitempty"`
31+ Default Matcher `json:"default,omitempty"`
32+ }
33+
34+ type Matcher struct {
35+ Keys []string `json:"keys,omitempty"`
36+ MatcherOp string `json:"op,omitempty"`
37+ }
38+
39+ func newOPAOpenShiftContainer (mode lokiv1.ModeType , secretVolumeName , tlsDir , minTLSVersion , ciphers string , withTLS bool , adminGroups []string ) (* corev1.Container , error ) {
2840 var (
2941 image string
3042 args []string
@@ -43,24 +55,48 @@ func newOPAOpenShiftContainer(mode lokiv1.ModeType, secretVolumeName, tlsDir, mi
4355 fmt .Sprintf ("--web.listen=:%d" , GatewayOPAHTTPPort ),
4456 fmt .Sprintf ("--web.internal.listen=:%d" , GatewayOPAInternalPort ),
4557 fmt .Sprintf ("--web.healthchecks.url=http://localhost:%d" , GatewayOPAHTTPPort ),
46- "--opa.skip-tenants=audit,infrastructure" ,
4758 fmt .Sprintf ("--opa.package=%s" , opaDefaultPackage ),
4859 }
4960
50- if len (adminGroups ) > 0 {
51- args = append (args , fmt .Sprintf ("--opa.admin-groups=%s" , strings .Join (adminGroups , "," )))
52- }
61+ if mode == lokiv1 .Openshift {
62+ matchers := Matchers {
63+ ByGroup : groupsToMatchers (adminGroups ),
64+ ByTenant : map [string ]Matcher {
65+ tenantAudit : {},
66+ tenantInfrastructure : {},
67+ tenantNetwork : {
68+ Keys : strings .Split (opaNetworkLabelMatchers , "," ),
69+ MatcherOp : "or" ,
70+ },
71+ },
72+ Default : Matcher {
73+ Keys : strings .Split (opaDefaultLabelMatchers , "," ),
74+ },
75+ }
5376
54- if mode != lokiv1 . OpenshiftNetwork {
55- args = append ( args , [] string {
56- fmt . Sprintf ( "--opa.matcher=%s" , opaDefaultLabelMatchers ),
57- "--opa.viaq-to-otel-migration=true" ,
58- } ... )
77+ matchersStr , err := json . Marshal ( matchers )
78+ if err != nil {
79+ return nil , err
80+ }
81+ args = append ( args , fmt . Sprintf ( "opa.matchersConfig=%s" , matchersStr ) )
5982 } else {
60- args = append (args , []string {
61- fmt .Sprintf ("--opa.matcher=%s" , opaNetworkLabelMatchers ),
62- "--opa.matcher-op=or" ,
63- }... )
83+ args = append (args , "--opa.skip-tenants=audit,infrastructure" )
84+
85+ if len (adminGroups ) > 0 {
86+ args = append (args , fmt .Sprintf ("--opa.admin-groups=%s" , strings .Join (adminGroups , "," )))
87+ }
88+
89+ if mode != lokiv1 .OpenshiftNetwork {
90+ args = append (args , []string {
91+ fmt .Sprintf ("--opa.matcher=%s" , opaDefaultLabelMatchers ),
92+ "--opa.viaq-to-otel-migration=true" ,
93+ }... )
94+ } else {
95+ args = append (args , []string {
96+ fmt .Sprintf ("--opa.matcher=%s" , opaNetworkLabelMatchers ),
97+ "--opa.matcher-op=or" ,
98+ }... )
99+ }
64100 }
65101
66102 if withTLS {
@@ -90,7 +126,7 @@ func newOPAOpenShiftContainer(mode lokiv1.ModeType, secretVolumeName, tlsDir, mi
90126 args = append (args , fmt .Sprintf (`--openshift.mappings=%s=%s` , t , opaDefaultAPIGroup ))
91127 }
92128
93- return corev1.Container {
129+ return & corev1.Container {
94130 Name : opaContainerName ,
95131 Image : image ,
96132 Args : args ,
@@ -131,5 +167,14 @@ func newOPAOpenShiftContainer(mode lokiv1.ModeType, secretVolumeName, tlsDir, mi
131167 FailureThreshold : 12 ,
132168 },
133169 VolumeMounts : volumeMounts ,
170+ }, nil
171+ }
172+
173+ func groupsToMatchers (groups []string ) map [string ]Matcher {
174+ matchers := map [string ]Matcher {}
175+ for _ , group := range groups {
176+ matchers [group ] = Matcher {}
134177 }
178+
179+ return matchers
135180}
0 commit comments