Skip to content

Commit 96a7c1d

Browse files
Merge pull request #1617 from raptorsun/feature/MON-2208
[MON-2208] Add Oauth2 settings to prometheusK8s.remoteWrite config
2 parents d7ba4ed + e63ae8d commit 96a7c1d

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [1578](https://github.com/openshift/cluster-monitoring-operator/pull/1578) Add temporary cluster id label to remote write relabel configs.
88
- [#1350](https://github.com/openshift/cluster-monitoring-operator/pull/1350) Support label scrape limits in user-workload monitoring
99
- [#1601](https://github.com/openshift/cluster-monitoring-operator/pull/1601) Expose the /federate endpoint of UWM Prometheus as a service
10+
- [#1617](https://github.com/openshift/cluster-monitoring-operator/pull/1617) Add Oauth2 setting to PrometheusK8s remoteWrite config
1011

1112
## 4.10
1213

Diff for: pkg/manifests/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ type RemoteWriteSpec struct {
164164
QueueConfig *monv1.QueueConfig `json:"queueConfig,omitempty"`
165165
// MetadataConfig configures the sending of series metadata to remote storage.
166166
MetadataConfig *monv1.MetadataConfig `json:"metadataConfig,omitempty"`
167+
// OAuth2 configures OAuth2 authentication for remote write.
168+
OAuth2 *monv1.OAuth2 `json:"oauth2,omitempty"`
167169
}
168170

169171
type PrometheusK8sConfig struct {

Diff for: pkg/manifests/manifests.go

+1
Original file line numberDiff line numberDiff line change
@@ -4228,6 +4228,7 @@ func addRemoteWriteConfigs(clusterID string, rw []monv1.RemoteWriteSpec, rwTarge
42284228
BearerTokenFile: target.BearerTokenFile,
42294229
ProxyURL: target.ProxyURL,
42304230
MetadataConfig: target.MetadataConfig,
4231+
OAuth2: target.OAuth2,
42314232
}
42324233
if target.TLSConfig != nil {
42334234
rwConf.TLSConfig = &monv1.TLSConfig{

Diff for: pkg/manifests/manifests_test.go

+66
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,72 @@ func TestPrometheusK8sRemoteWriteURLs(t *testing.T) {
12271227
}
12281228
}
12291229

1230+
func TestPrometheusK8sRemoteWriteOauth2(t *testing.T) {
1231+
expectedOauth2Config := monv1.OAuth2{
1232+
ClientID: monv1.SecretOrConfigMap{
1233+
Secret: &v1.SecretKeySelector{
1234+
LocalObjectReference: v1.LocalObjectReference{
1235+
Name: "oauth2-credentials",
1236+
},
1237+
Key: "id",
1238+
},
1239+
},
1240+
ClientSecret: v1.SecretKeySelector{
1241+
LocalObjectReference: v1.LocalObjectReference{
1242+
Name: "oauth2-credentials",
1243+
},
1244+
Key: "secret",
1245+
},
1246+
TokenURL: "https://example.com/oauth2/token",
1247+
Scopes: []string{"scope1", "scope2"},
1248+
EndpointParams: map[string]string{
1249+
"param1": "value1",
1250+
"param2": "value2",
1251+
},
1252+
}
1253+
c, err := NewConfigFromString(`prometheusK8s:
1254+
remoteWrite:
1255+
- url: https://test.remotewrite.com/api/write
1256+
remoteTimeout: 30s
1257+
oauth2:
1258+
clientId:
1259+
secret:
1260+
name: oauth2-credentials
1261+
key: id
1262+
clientSecret:
1263+
name: oauth2-credentials
1264+
key: secret
1265+
tokenUrl: https://example.com/oauth2/token
1266+
scopes:
1267+
- scope1
1268+
- scope2
1269+
endpointParams:
1270+
param1: value1
1271+
param2: value2
1272+
`)
1273+
if err != nil {
1274+
t.Fatal(err)
1275+
}
1276+
1277+
f := NewFactory("openshift-monitoring", "openshift-user-workload-monitoring", c, defaultInfrastructureReader(), &fakeProxyReader{}, NewAssets(assetsPath), &APIServerConfig{}, &configv1.Console{})
1278+
p, err := f.PrometheusK8s(
1279+
&v1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
1280+
&v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
1281+
)
1282+
if err != nil {
1283+
t.Fatal(err)
1284+
}
1285+
1286+
if p.Spec.RemoteWrite[0].URL != "https://test.remotewrite.com/api/write" {
1287+
t.Errorf("want remote write URL https://test.remotewrite.com/api/write, got %v", p.Spec.RemoteWrite[0].URL)
1288+
}
1289+
1290+
if !reflect.DeepEqual(p.Spec.RemoteWrite[0].OAuth2, &expectedOauth2Config) {
1291+
t.Errorf("want OAuth2 config %v, got %v", expectedOauth2Config, p.Spec.RemoteWrite[0].OAuth2)
1292+
}
1293+
1294+
}
1295+
12301296
func TestPrometheusK8sConfiguration(t *testing.T) {
12311297
c, err := NewConfigFromString(`prometheusK8s:
12321298
retention: 25h

0 commit comments

Comments
 (0)