Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vmscrapeconfig: authorization section in sd configs works properly … #949

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions controllers/factory/vmagent/scrapeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,92 @@ digitalocean_sd_configs:
endpoint_params:
timeout: 5s
token_url: http://some-token-url
`,
},
{
name: "configs with auth and empty type",
args: args{
cr: victoriametricsv1beta1.VMAgent{},
m: &victoriametricsv1beta1.VMScrapeConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "sc-auth",
Namespace: "default",
},
Spec: victoriametricsv1beta1.VMScrapeConfigSpec{
HTTPSDConfigs: []victoriametricsv1beta1.HTTPSDConfig{
{
URL: "http://www.test1.com",
Authorization: &victoriametricsv1beta1.Authorization{
Type: "Bearer",
},
},
{
URL: "http://www.test2.com",
Authorization: &victoriametricsv1beta1.Authorization{
Credentials: &v1.SecretKeySelector{Key: "cred"},
},
},
{
URL: "http://www.test3.com",
Authorization: &victoriametricsv1beta1.Authorization{
Type: "Bearer",
CredentialsFile: "file",
},
},
},
KubernetesSDConfigs: []victoriametricsv1beta1.KubernetesSDConfig{
{
Role: "endpoints",
Authorization: &victoriametricsv1beta1.Authorization{
Type: "Bearer",
},
},
{
Role: "endpoints",
Authorization: &victoriametricsv1beta1.Authorization{
Credentials: &v1.SecretKeySelector{Key: "cred"},
},
},
{
Role: "endpoints",
Authorization: &victoriametricsv1beta1.Authorization{
Type: "Bearer",
CredentialsFile: "file",
},
},
},
},
},
ssCache: &scrapesSecretsCache{
authorizationSecrets: map[string]string{
"scrapeConfig/default/sc-auth/httpsd/1": "auth-secret",
"scrapeConfig/default/sc-auth/kubesd/1": "auth-secret",
},
},
},
want: `job_name: scrapeConfig/default/sc-auth
honor_labels: false
relabel_configs: []
http_sd_configs:
- url: http://www.test1.com
- url: http://www.test2.com
authorization:
type: Bearer
credentials: auth-secret
- url: http://www.test3.com
authorization:
type: Bearer
credentials_file: file
kubernetes_sd_configs:
- role: endpoints
- role: endpoints
authorization:
type: Bearer
credentials: auth-secret
- role: endpoints
authorization:
type: Bearer
credentials_file: file
`,
},
}
Expand Down
8 changes: 6 additions & 2 deletions controllers/factory/vmagent/vmagent_scrapeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ func buildVMScrapeParams(namespace, cacheKey string, cfg *victoriametricsv1beta1
}

func addAuthorizationConfig(dst yaml.MapSlice, cacheKey string, cfg *victoriametricsv1beta1.Authorization, authorizationCache map[string]string) yaml.MapSlice {
if cfg == nil || len(cfg.Type) == 0 {
if cfg == nil {
// fast path
return dst
}
Expand All @@ -1436,7 +1436,11 @@ func addAuthorizationConfig(dst yaml.MapSlice, cacheKey string, cfg *victoriamet
return dst
}
var r yaml.MapSlice
r = append(r, yaml.MapItem{Key: "type", Value: cfg.Type})
authType := cfg.Type
if len(authType) == 0 {
authType = "Bearer"
}
r = append(r, yaml.MapItem{Key: "type", Value: authType})
if len(secretValue) > 0 {
r = append(r, yaml.MapItem{Key: "credentials", Value: secretValue})
} else {
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ aliases:
- [operator](./README.md): adds `spec.pause` field to `VMAgent`, `VMAlert`, `VMAuth`, `VMCluster`, `VMAlertmanager` and `VMSingle`. It allows to suspend object reconcile by operator. See this [issue](https://github.com/VictoriaMetrics/operator/issues/943) for details. Thanks @just1900
- [vmagent](./api.md#vmagent): set `status.selector` field. It allows correctly use `VPA` with `vmagent`. See this [issue](https://github.com/VictoriaMetrics/operator/issues/693) for details.
- [prometheus-converter](./README.md): fixes bug with prometheus-operator ScrapeConfig converter. Only copy `spec` field for it. See this [issue](https://github.com/VictoriaMetrics/operator/issues/942) for details.
- [vmscrapeconfig](./resources/vmscrapeconfig.md): `authorization` section in sd configs works properly with empty `type` field (default value for this field is `Bearer`).

<a name="v0.43.5"></a>

Expand Down
Loading