@@ -1088,11 +1088,7 @@ func TestPrometheusK8sRemoteWriteURLs(t *testing.T) {
1088
1088
name : "default config" ,
1089
1089
1090
1090
config : func () * Config {
1091
- c , err := NewConfigFromString ("" )
1092
- if err != nil {
1093
- t .Fatal (err )
1094
- }
1095
-
1091
+ c := NewDefaultConfig ()
1096
1092
return c
1097
1093
},
1098
1094
@@ -1102,11 +1098,7 @@ func TestPrometheusK8sRemoteWriteURLs(t *testing.T) {
1102
1098
name : "legacy telemetry" ,
1103
1099
1104
1100
config : func () * Config {
1105
- c , err := NewConfigFromString ("" )
1106
- if err != nil {
1107
- t .Fatal (err )
1108
- }
1109
-
1101
+ c := NewDefaultConfig ()
1110
1102
c .ClusterMonitoringConfiguration .TelemeterClientConfig .ClusterID = "123"
1111
1103
c .ClusterMonitoringConfiguration .TelemeterClientConfig .Token = "secret"
1112
1104
@@ -1119,11 +1111,7 @@ func TestPrometheusK8sRemoteWriteURLs(t *testing.T) {
1119
1111
name : "legacy telemetry and custom remote write" ,
1120
1112
1121
1113
config : func () * Config {
1122
- c , err := NewConfigFromString ("" )
1123
- if err != nil {
1124
- t .Fatal (err )
1125
- }
1126
-
1114
+ c := NewDefaultConfig ()
1127
1115
c .ClusterMonitoringConfiguration .TelemeterClientConfig .ClusterID = "123"
1128
1116
c .ClusterMonitoringConfiguration .TelemeterClientConfig .Token = "secret"
1129
1117
c .ClusterMonitoringConfiguration .PrometheusK8sConfig .RemoteWrite = []RemoteWriteSpec {{URL : "http://custom" }}
@@ -1139,11 +1127,7 @@ func TestPrometheusK8sRemoteWriteURLs(t *testing.T) {
1139
1127
name : "remote write telemetry" ,
1140
1128
1141
1129
config : func () * Config {
1142
- c , err := NewConfigFromString ("" )
1143
- if err != nil {
1144
- t .Fatal (err )
1145
- }
1146
-
1130
+ c := NewDefaultConfig ()
1147
1131
c .SetRemoteWrite (true )
1148
1132
c .ClusterMonitoringConfiguration .TelemeterClientConfig .ClusterID = "123"
1149
1133
c .ClusterMonitoringConfiguration .TelemeterClientConfig .Token = "secret"
@@ -1159,11 +1143,7 @@ func TestPrometheusK8sRemoteWriteURLs(t *testing.T) {
1159
1143
name : "remote write telemetry and custom remote write" ,
1160
1144
1161
1145
config : func () * Config {
1162
- c , err := NewConfigFromString ("" )
1163
- if err != nil {
1164
- t .Fatal (err )
1165
- }
1166
-
1146
+ c := NewDefaultConfig ()
1167
1147
c .SetRemoteWrite (true )
1168
1148
c .ClusterMonitoringConfiguration .TelemeterClientConfig .ClusterID = "123"
1169
1149
c .ClusterMonitoringConfiguration .TelemeterClientConfig .Token = "secret"
@@ -1181,11 +1161,7 @@ func TestPrometheusK8sRemoteWriteURLs(t *testing.T) {
1181
1161
name : "remote write telemetry with custom url and custom remote write" ,
1182
1162
1183
1163
config : func () * Config {
1184
- c , err := NewConfigFromString ("" )
1185
- if err != nil {
1186
- t .Fatal (err )
1187
- }
1188
-
1164
+ c := NewDefaultConfig ()
1189
1165
c .SetRemoteWrite (true )
1190
1166
c .ClusterMonitoringConfiguration .TelemeterClientConfig .TelemeterServerURL = "http://custom-telemeter"
1191
1167
c .ClusterMonitoringConfiguration .TelemeterClientConfig .ClusterID = "123"
@@ -1292,6 +1268,107 @@ func TestPrometheusK8sRemoteWriteOauth2(t *testing.T) {
1292
1268
}
1293
1269
1294
1270
}
1271
+ func TestRemoteWriteAuthorizationConfig (t * testing.T ) {
1272
+ for _ , tc := range []struct {
1273
+ name string
1274
+ config string
1275
+ checkFn []func (* testing.T , monv1.RemoteWriteSpec )
1276
+ }{
1277
+ {
1278
+ name : "basic authentication configuration" ,
1279
+ config : `prometheusK8s:
1280
+ remoteWrite:
1281
+ - url: "https://basicAuth.remotewrite.com/api/write"
1282
+ basicAuth:
1283
+ username:
1284
+ name: remoteWriteAuth
1285
+ key: user
1286
+ password:
1287
+ name: remoteWriteAuth
1288
+ key: password
1289
+ ` ,
1290
+ checkFn : []func (* testing.T , monv1.RemoteWriteSpec ){
1291
+ func (t * testing.T , target monv1.RemoteWriteSpec ) {
1292
+ if target .BasicAuth .Username .Name != "remoteWriteAuth" {
1293
+ t .Fatalf ("Name field not correct in section RemoteWriteSpec.BasicAuth.Username expected 'remoteWriteAuth', got %s" , target .BasicAuth .Username .Name )
1294
+ }
1295
+ if target .BasicAuth .Username .Key != "user" {
1296
+ t .Fatalf ("Key field not correct in section RemoteWriteSpec.BasicAuth.Username expected 'user', got %s" , target .BasicAuth .Username .Key )
1297
+ }
1298
+ if target .BasicAuth .Password .Name != "remoteWriteAuth" {
1299
+ t .Fatalf ("Name field not correct in section RemoteWriteSpec.BasicAuth.Password expected 'remoteWriteAuth', got %s" , target .BasicAuth .Password .Name )
1300
+ }
1301
+ if target .BasicAuth .Password .Key != "password" {
1302
+ t .Fatalf ("Key field not correct in section RemoteWriteSpec.BasicAuth.Password expected 'password', got %s" , target .BasicAuth .Password .Key )
1303
+ }
1304
+ },
1305
+ },
1306
+ },
1307
+ {
1308
+ name : "bearerTokenFile authentication configuration" ,
1309
+ config : `prometheusK8s:
1310
+ remoteWrite:
1311
+ - url: "https://bearerTokenFile.remotewrite.com/api/write"
1312
+ bearerTokenFile: "/secret/remoteWriteAuth"
1313
+ ` ,
1314
+ checkFn : []func (* testing.T , monv1.RemoteWriteSpec ){
1315
+ func (t * testing.T , target monv1.RemoteWriteSpec ) {
1316
+ if target .BearerTokenFile != "/secret/remoteWriteAuth" {
1317
+ t .Fatalf ("BearerTokenFile field not correct in section RemoteWriteSpec expected '/secret/remoteWriteAuth', got %s" , target .BearerTokenFile )
1318
+ }
1319
+ },
1320
+ },
1321
+ },
1322
+ {
1323
+ name : "authorization authentication configuration" ,
1324
+ config : `prometheusK8s:
1325
+ remoteWrite:
1326
+ - url: "https://authorization.remotewrite.com/api/write"
1327
+ authorization:
1328
+ type: Bearer
1329
+ credentials:
1330
+ name: remoteWriteAuth
1331
+ key: token
1332
+ ` ,
1333
+ checkFn : []func (* testing.T , monv1.RemoteWriteSpec ){
1334
+ func (t * testing.T , target monv1.RemoteWriteSpec ) {
1335
+ if target .Authorization .Type != "Bearer" {
1336
+ t .Fatalf ("Bearer field not correct in section RemoteWriteSpec expected 'Bearer', got %s" , target .Authorization .Type )
1337
+ }
1338
+ if target .Authorization .Credentials .Name != "remoteWriteAuth" {
1339
+ t .Fatalf ("Name field not correct in section RemoteWriteSpec.Authorization.Credentials expected 'remoteWriteAuth', got %s" , target .Authorization .Credentials .Name )
1340
+ }
1341
+ if target .Authorization .Credentials .Key != "token" {
1342
+ t .Fatalf ("Key field not correct in section RemoteWriteSpec.Authorization.Credentials expected 'token', got %s" , target .Authorization .Credentials .Key )
1343
+ }
1344
+ },
1345
+ },
1346
+ },
1347
+ } {
1348
+ t .Run (tc .name , func (t * testing.T ) {
1349
+ c , err := NewConfigFromString (tc .config )
1350
+ if err != nil {
1351
+ t .Fatal (err )
1352
+ }
1353
+ f := NewFactory ("openshift-monitoring" , "openshift-user-workload-monitoring" , c , defaultInfrastructureReader (), & fakeProxyReader {}, NewAssets (assetsPath ), & APIServerConfig {}, & configv1.Console {})
1354
+ p , err := f .PrometheusK8s (
1355
+ & v1.Secret {ObjectMeta : metav1.ObjectMeta {Name : "foo" }},
1356
+ & v1.ConfigMap {ObjectMeta : metav1.ObjectMeta {Name : "foo" }},
1357
+ )
1358
+ if err != nil {
1359
+ t .Fatal (err )
1360
+ }
1361
+ if len (p .Spec .RemoteWrite ) != len (tc .checkFn ) {
1362
+ t .Fatalf ("got %d check functions but only %d RemoteWrite targets" , len (tc .checkFn ), len (p .Spec .RemoteWrite ))
1363
+ }
1364
+
1365
+ for i , target := range p .Spec .RemoteWrite {
1366
+ tc .checkFn [i ](t , target )
1367
+ }
1368
+ })
1369
+
1370
+ }
1371
+ }
1295
1372
1296
1373
func TestPrometheusK8sConfiguration (t * testing.T ) {
1297
1374
c , err := NewConfigFromString (`prometheusK8s:
@@ -1753,6 +1830,9 @@ func TestPrometheusK8sAdditionalAlertManagerConfigsSecret(t *testing.T) {
1753
1830
& v1.Secret {ObjectMeta : metav1.ObjectMeta {Name : "foo" }},
1754
1831
& v1.ConfigMap {ObjectMeta : metav1.ObjectMeta {Name : "foo" }},
1755
1832
)
1833
+ if err != nil {
1834
+ t .Fatal (err )
1835
+ }
1756
1836
1757
1837
secrets := make (map [string ]struct {})
1758
1838
for _ , s := range p .Spec .Secrets {
0 commit comments