Skip to content

Commit bfe6e19

Browse files
committed
add Oauth2 settings to PrometheusK8s config
1 parent 3ceaaaf commit bfe6e19

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
@@ -4,6 +4,7 @@
44

55
- [#1567](https://github.com/openshift/cluster-monitoring-operator/pull/1567) Enable validating webhook for AlertmanagerConfig customer resources
66
- [#1557](https://github.com/openshift/cluster-monitoring-operator/pull/1557) Removing grafana from monitoring stack
7+
- [#1617](https://github.com/openshift/cluster-monitoring-operator/pull/1617) Add Oauth2 setting to PrometheusK8s remoteWrite config
78

89
## 4.10
910

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 configs. Requires Prometheus versions 2.27.0+.
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
@@ -4205,6 +4205,7 @@ func addRemoteWriteConfigs(clusterID string, rw []monv1.RemoteWriteSpec, rwTarge
42054205
BearerTokenFile: target.BearerTokenFile,
42064206
ProxyURL: target.ProxyURL,
42074207
MetadataConfig: target.MetadataConfig,
4208+
OAuth2: target.OAuth2,
42084209
}
42094210
if target.TLSConfig != nil {
42104211
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)