Skip to content

Commit

Permalink
fix: use kube namespace instead of full path
Browse files Browse the repository at this point in the history
  • Loading branch information
arcln committed Feb 17, 2021
1 parent 381f3dc commit be144ad
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (collector *collector) getMetricsForCertificate(certData *parsedCertificate
trimmedFilePath = path.Join(prefix, path.Join(pathComponents[trimComponentsCount:]...))
baseLabels = append(baseLabels, "filename", "filepath")
} else {
trimmedFilePath = ref.path
trimmedFilePath = strings.Split(ref.path, "/")[1]
baseLabels = append(baseLabels, "secret_name", "secret_namespace")
}

Expand Down
4 changes: 3 additions & 1 deletion internal/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,16 +451,18 @@ func testSinglePEM(t *testing.T, expired float64, notBefore time.Time) {
func checkLabels(t *testing.T, labels []*model.LabelPair, path string, isKube bool) {
assert.Len(t, labels, 15, "Missing labels")

pathOrNamespace := path
baseLabels := []string{"serial_number", "filepath", "filename"}
if isKube {
baseLabels = []string{"serial_number", "secret_namespace", "secret_name"}
pathOrNamespace = strings.Split(path, "/")[1]
}

for _, label := range labels {
if label.GetName() == baseLabels[2] {
assert.Equal(t, filepath.Base(path), label.GetValue(), "Invalid label value for %s", label.GetName())
} else if label.GetName() == baseLabels[1] {
assert.Equal(t, path, label.GetValue(), "Invalid label value for %s", label.GetName())
assert.Equal(t, pathOrNamespace, label.GetValue(), "Invalid label value for %s", label.GetName())
} else if label.GetName() == baseLabels[0] {
assert.Equal(t, "1", label.GetValue(), "Invalid label value for %s", label.GetName())
} else {
Expand Down

0 comments on commit be144ad

Please sign in to comment.