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

kubernetes: use namespace selector where possible #179

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion prober/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package prober
import (
"context"
"fmt"
"regexp"
"strings"

"github.com/bmatcuk/doublestar/v2"
Expand All @@ -22,6 +23,8 @@ var (
// ErrKubeBadTarget is returned when the target doesn't match the
// expected form for the kubernetes prober
ErrKubeBadTarget = fmt.Errorf("Target secret must be provided in the form: <namespace>/<name>")

globPattern = regexp.MustCompile(`^.*(\*|\?|\{|\}|\[|\])+.*$`)
)

// ProbeKubernetes collects certificate metrics from kubernetes.io/tls Secrets
Expand All @@ -43,8 +46,15 @@ func probeKubernetes(ctx context.Context, target string, module config.Module, r
ns := parts[0]
name := parts[1]

// If the namespace contains a glob pattern then we need to filter on
// all the secrets in the cluster
selector := ns
if globPattern.MatchString(ns) {
selector = ""
}

var tlsSecrets []v1.Secret
secrets, err := client.CoreV1().Secrets("").List(ctx, metav1.ListOptions{FieldSelector: "type=kubernetes.io/tls"})
secrets, err := client.CoreV1().Secrets(selector).List(ctx, metav1.ListOptions{FieldSelector: "type=kubernetes.io/tls"})
if err != nil {
return err
}
Expand Down