Skip to content

Commit

Permalink
Add secret key length check
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckal777 committed Dec 12, 2024
1 parent 94d471d commit f0447e6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (exporter *Exporter) filterSecrets(secrets []v1.Secret, includedLabels, exc
func (exporter *Exporter) checkHasIncludedType(secret *v1.Secret) (bool, error) {
for _, secretType := range exporter.KubeSecretTypes {
for key := range secret.Data {
if secretType.Matches(string(secret.Type), key) {
if len(secret.Data[key]) > 0 && secretType.Matches(string(secret.Type), key) {
return true, nil
}
}
Expand All @@ -268,7 +268,7 @@ func (exporter *Exporter) shrinkSecret(secret v1.Secret) v1.Secret {

for _, secretType := range exporter.KubeSecretTypes {
for key := range secret.Data {
if secretType.Matches(string(secret.Type), key) {
if len(secret.Data[key]) > 0 && secretType.Matches(string(secret.Type), key) {
result.Data[key] = secret.Data[key]
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func TestKubeEmptyStringKey(t *testing.T) {
},
}, func(m []model.MetricFamily) {
metrics := getMetricsForName(m, "x509_read_errors")
assert.Equal(t, 1., metrics[0].GetGauge().GetValue())
assert.Equal(t, 0., metrics[0].GetGauge().GetValue())
})
}

Expand Down

0 comments on commit f0447e6

Please sign in to comment.