Skip to content
Open
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
42 changes: 27 additions & 15 deletions config/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,43 @@ type TargetConfig struct {
}

// UnmarshalYAML implements yaml.Unmarshaler interface.
func (d *TargetConfig) UnmarshalYAML(unmashal func(interface{}) error) error {
func (t *TargetConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
// If the input is a string, treat it as the Addr
var s string
if err := unmashal(&s); err == nil {
d.Addr = s
if err := unmarshal(&s); err == nil {
t.Addr = s
t.Labels = nil
return nil
}

var x map[string]map[string]string
if err := unmashal(&x); err != nil {
// Temporary map to capture raw data
raw := make(map[string]string)
if err := unmarshal(&raw); err != nil {
return err
}

for addr, l := range x {
d.Addr = addr
d.Labels = l
// Extract "host" key into Addr
if addr, ok := raw["host"]; ok {
t.Addr = addr
delete(raw, "host") // Remove from labels
}

// Store remaining keys as labels
t.Labels = raw
return nil
}

func (d TargetConfig) MarshalYAML() (interface{}, error) {
if d.Labels == nil {
return d.Addr, nil
func (t TargetConfig) MarshalYAML() (interface{}, error) {
// If there are no labels, just return the address as a string
if len(t.Labels) == 0 {
return t.Addr, nil
}

// Otherwise, construct a map with "host" as Addr and other labels
m := make(map[string]string)
m["host"] = t.Addr
for k, v := range t.Labels {
m[k] = v
}
ret := make(map[string]map[string]string)
ret[d.Addr] = d.Labels
return ret, nil

return m, nil
}
4 changes: 2 additions & 2 deletions config/testdata/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ targets:
- 8.8.8.8
- 8.8.4.4
- 2001:4860:4860::8888
- "2001:4860:4860::8844":
foo: "bar"
- host: "2001:4860:4860::8844"
foo: "bar"

dns:
refresh: 2m15s
Expand Down
2 changes: 1 addition & 1 deletion dist/charts/ping-exporter/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ metadata:
{{- include "ping_exporter.labels" . | nindent 4 }}
data:
config.yml: |
{{ toYaml .Values.config | indent 4 }}
{{ toYaml .Values.config | indent 4 }}
24 changes: 24 additions & 0 deletions dist/charts/ping-exporter/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{- if .Values.k8sresolver.create}}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: ping-exporter-endpoints
rules:
- apiGroups: [""]
resources: ["endpoints", "services"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: ping-exporter-endpoints
subjects:
- kind: ServiceAccount
name: {{ include "ping_exporter.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
roleRef:
kind: ClusterRole
name: ping-exporter-endpoints
apiGroup: rbac.authorization.k8s.io
{{- end }}
9 changes: 6 additions & 3 deletions dist/charts/ping-exporter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ podLabels: {}
# Rollout strategy, could be "Recreate" or "RollingUpdate"
strategy:
type: RollingUpdate

podSecurityContext: {}
# fsGroup: 2000

Expand Down Expand Up @@ -91,6 +91,8 @@ config:
- 2001:4860:4860::8888
- 2001:4860:4860::8844
- google.com
- host: www.facebook.com
mylabel: testlabel

dns:
refresh: 2m15s
Expand All @@ -110,5 +112,6 @@ serviceMonitor:
prometheusRules:
enabled: false

testConnection:
enabled: true
# add rbac to look up targets by service name
k8sresolver:
create: false
32 changes: 32 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ require (
github.com/sirupsen/logrus v1.9.3
gopkg.in/fsnotify.v1 v1.4.7
gopkg.in/yaml.v2 v2.4.0
k8s.io/apimachinery v0.32.0
k8s.io/client-go v0.32.0
tailscale.com v1.80.2
)

Expand All @@ -19,18 +21,35 @@ require (
github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dblohm7/wingoes v0.0.0-20240119213807-a09d6be7affa // indirect
github.com/digineo/go-logwrap v0.0.0-20181106161722-a178c58ea3f0 // indirect
github.com/emicklei/go-restful/v3 v3.11.2 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-json-experiment/json v0.0.0-20250103232110-6a9a0fde9288 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.20.4 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hdevalence/ed25519consensus v0.2.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/jsimonetti/rtnetlink v1.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mdlayher/netlink v1.7.3-0.20250113171957-fbb4dce95f42 // indirect
github.com/mdlayher/socket v0.5.0 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.62.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
Expand All @@ -42,9 +61,22 @@ require (
golang.org/x/crypto v0.35.0 // indirect
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
golang.org/x/net v0.36.0 // indirect
golang.org/x/oauth2 v0.25.0 // indirect
golang.org/x/sync v0.11.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/term v0.29.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/time v0.9.0 // indirect
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
google.golang.org/protobuf v1.36.1 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.32.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading
Loading