diff --git a/docs/mutatingwebhookconfiguration-metrics.md b/docs/mutatingwebhookconfiguration-metrics.md
index 565711ff9c..9edec0239f 100644
--- a/docs/mutatingwebhookconfiguration-metrics.md
+++ b/docs/mutatingwebhookconfiguration-metrics.md
@@ -5,3 +5,4 @@
| kube_mutatingwebhookconfiguration_info | Gauge | `mutatingwebhookconfiguration`=<mutatingwebhookconfiguration-name>
`namespace`=<mutatingwebhookconfiguration-namespace> | EXPERIMENTAL |
| kube_mutatingwebhookconfiguration_created | Gauge | `mutatingwebhookconfiguration`=<mutatingwebhookconfiguration-name>
`namespace`=<mutatingwebhookconfiguration-namespace> | EXPERIMENTAL |
| kube_mutatingwebhookconfiguration_metadata_resource_version | Gauge | `mutatingwebhookconfiguration`=<mutatingwebhookconfiguration-name>
`namespace`=<mutatingwebhookconfiguration-namespace> | EXPERIMENTAL |
+| kube_mutatingwebhookconfiguration_webhook_clientconfig_service | Gauge | `mutatingwebhookconfiguration`=<mutatingwebhookconfiguration-name>
`namespace`=<mutatingwebhookconfiguration-namespace>
`webhook_name`=<webhook-name>
`service_name`=<webhook-service-name>
`service_namespace`=<webhook-service-namespace>| EXPERIMENTAL |
diff --git a/docs/validatingwebhookconfiguration-metrics.md b/docs/validatingwebhookconfiguration-metrics.md
index 1131b15cfa..9966f18a57 100644
--- a/docs/validatingwebhookconfiguration-metrics.md
+++ b/docs/validatingwebhookconfiguration-metrics.md
@@ -5,3 +5,4 @@
| kube_validatingwebhookconfiguration_info | Gauge | `validatingwebhookconfiguration`=<validatingwebhookconfiguration-name>
`namespace`=<validatingwebhookconfiguration-namespace> | EXPERIMENTAL |
| kube_validatingwebhookconfiguration_created | Gauge | `validatingwebhookconfiguration`=<validatingwebhookconfiguration-name>
`namespace`=<validatingwebhookconfiguration-namespace> | EXPERIMENTAL |
| kube_validatingwebhookconfiguration_metadata_resource_version | Gauge | `validatingwebhookconfiguration`=<validatingwebhookconfiguration-name>
`namespace`=<validatingwebhookconfiguration-namespace> | EXPERIMENTAL |
+| kube_validatingwebhookconfiguration_webhook_clientconfig_service | Gauge | `validatingwebhookconfiguration`=<validatingwebhookconfiguration-name>
`namespace`=<validatingwebhookconfiguration-namespace>
`webhook_name`=<webhook-name>
`service_name`=<webhook-service-name>
`service_namespace`=<webhook-service-namespace>| EXPERIMENTAL |
diff --git a/internal/store/mutatingwebhookconfiguration.go b/internal/store/mutatingwebhookconfiguration.go
index 917ca1e799..0b900107d8 100644
--- a/internal/store/mutatingwebhookconfiguration.go
+++ b/internal/store/mutatingwebhookconfiguration.go
@@ -82,6 +82,32 @@ var (
}
}),
),
+ *generator.NewFamilyGeneratorWithStability(
+ "kube_mutatingwebhookconfiguration_webhook_clientconfig_service",
+ "Service used by the apiserver to connect to a mutating webhook.",
+ metric.Gauge,
+ basemetrics.ALPHA,
+ "",
+ wrapMutatingWebhookConfigurationFunc(func(mwc *admissionregistrationv1.MutatingWebhookConfiguration) *metric.Family {
+ ms := []*metric.Metric{}
+ for _, webhook := range mwc.Webhooks {
+ var serviceName, serviceNamespace string
+ if webhook.ClientConfig.Service != nil {
+ serviceName = webhook.ClientConfig.Service.Name
+ serviceNamespace = webhook.ClientConfig.Service.Namespace
+ }
+
+ ms = append(ms, &metric.Metric{
+ LabelKeys: []string{"webhook_name", "service_name", "service_namespace"},
+ LabelValues: []string{webhook.Name, serviceName, serviceNamespace},
+ Value: 1,
+ })
+ }
+ return &metric.Family{
+ Metrics: ms,
+ }
+ }),
+ ),
}
)
diff --git a/internal/store/mutatingwebhookconfiguration_test.go b/internal/store/mutatingwebhookconfiguration_test.go
index 325a18ae28..90cb49e5af 100644
--- a/internal/store/mutatingwebhookconfiguration_test.go
+++ b/internal/store/mutatingwebhookconfiguration_test.go
@@ -28,6 +28,7 @@ import (
func TestMutatingWebhookConfigurationStore(t *testing.T) {
startTime := 1501569018
metav1StartTime := metav1.Unix(int64(startTime), 0)
+ externalURL := "example.com"
cases := []generateMetricsTestCase{
{
@@ -69,6 +70,37 @@ func TestMutatingWebhookConfigurationStore(t *testing.T) {
`,
MetricNames: []string{"kube_mutatingwebhookconfiguration_created", "kube_mutatingwebhookconfiguration_info", "kube_mutatingwebhookconfiguration_metadata_resource_version"},
},
+ {
+ Obj: &admissionregistrationv1.MutatingWebhookConfiguration{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "mutatingwebhookconfiguration3",
+ Namespace: "ns3",
+ CreationTimestamp: metav1StartTime,
+ ResourceVersion: "abcdef",
+ },
+ Webhooks: []admissionregistrationv1.MutatingWebhook{
+ {
+ Name: "webhook_with_service",
+ ClientConfig: admissionregistrationv1.WebhookClientConfig{
+ Service: &admissionregistrationv1.ServiceReference{Name: "svc", Namespace: "ns"},
+ },
+ },
+ {
+ Name: "webhook_with_external_url",
+ ClientConfig: admissionregistrationv1.WebhookClientConfig{
+ URL: &externalURL,
+ },
+ },
+ },
+ },
+ Want: `
+ # HELP kube_mutatingwebhookconfiguration_webhook_clientconfig_service Service used by the apiserver to connect to a mutating webhook.
+ # TYPE kube_mutatingwebhookconfiguration_webhook_clientconfig_service gauge
+ kube_mutatingwebhookconfiguration_webhook_clientconfig_service{webhook_name="webhook_with_external_url",namespace="ns3",service_name="",service_namespace="",mutatingwebhookconfiguration="mutatingwebhookconfiguration3"} 1
+ kube_mutatingwebhookconfiguration_webhook_clientconfig_service{webhook_name="webhook_with_service",namespace="ns3",service_name="svc",service_namespace="ns",mutatingwebhookconfiguration="mutatingwebhookconfiguration3"} 1
+ `,
+ MetricNames: []string{"kube_mutatingwebhookconfiguration_webhook_clientconfig_service"},
+ },
}
for i, c := range cases {
c.Func = generator.ComposeMetricGenFuncs(mutatingWebhookConfigurationMetricFamilies)
diff --git a/internal/store/validatingwebhookconfiguration.go b/internal/store/validatingwebhookconfiguration.go
index da698acdd0..c3a7418ca8 100644
--- a/internal/store/validatingwebhookconfiguration.go
+++ b/internal/store/validatingwebhookconfiguration.go
@@ -82,6 +82,32 @@ var (
}
}),
),
+ *generator.NewFamilyGeneratorWithStability(
+ "kube_validatingwebhookconfiguration_webhook_clientconfig_service",
+ "Service used by the apiserver to connect to a validating webhook.",
+ metric.Gauge,
+ basemetrics.ALPHA,
+ "",
+ wrapValidatingWebhookConfigurationFunc(func(vwc *admissionregistrationv1.ValidatingWebhookConfiguration) *metric.Family {
+ ms := []*metric.Metric{}
+ for _, webhook := range vwc.Webhooks {
+ var serviceName, serviceNamespace string
+ if webhook.ClientConfig.Service != nil {
+ serviceName = webhook.ClientConfig.Service.Name
+ serviceNamespace = webhook.ClientConfig.Service.Namespace
+ }
+
+ ms = append(ms, &metric.Metric{
+ LabelKeys: []string{"webhook_name", "service_name", "service_namespace"},
+ LabelValues: []string{webhook.Name, serviceName, serviceNamespace},
+ Value: 1,
+ })
+ }
+ return &metric.Family{
+ Metrics: ms,
+ }
+ }),
+ ),
}
)
diff --git a/internal/store/validatingwebhookconfiguration_test.go b/internal/store/validatingwebhookconfiguration_test.go
index fc64eb2e4b..9fa131e71d 100644
--- a/internal/store/validatingwebhookconfiguration_test.go
+++ b/internal/store/validatingwebhookconfiguration_test.go
@@ -28,6 +28,7 @@ import (
func TestValidatingWebhookConfigurationStore(t *testing.T) {
startTime := 1501569018
metav1StartTime := metav1.Unix(int64(startTime), 0)
+ externalURL := "example.com"
cases := []generateMetricsTestCase{
{
@@ -69,6 +70,37 @@ func TestValidatingWebhookConfigurationStore(t *testing.T) {
`,
MetricNames: []string{"kube_validatingwebhookconfiguration_created", "kube_validatingwebhookconfiguration_info", "kube_validatingwebhookconfiguration_metadata_resource_version"},
},
+ {
+ Obj: &admissionregistrationv1.ValidatingWebhookConfiguration{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "validatingwebhookconfiguration3",
+ Namespace: "ns3",
+ CreationTimestamp: metav1StartTime,
+ ResourceVersion: "abcdef",
+ },
+ Webhooks: []admissionregistrationv1.ValidatingWebhook{
+ {
+ Name: "webhook_with_service",
+ ClientConfig: admissionregistrationv1.WebhookClientConfig{
+ Service: &admissionregistrationv1.ServiceReference{Name: "svc", Namespace: "ns"},
+ },
+ },
+ {
+ Name: "webhook_with_external_url",
+ ClientConfig: admissionregistrationv1.WebhookClientConfig{
+ URL: &externalURL,
+ },
+ },
+ },
+ },
+ Want: `
+ # HELP kube_validatingwebhookconfiguration_webhook_clientconfig_service Service used by the apiserver to connect to a validating webhook.
+ # TYPE kube_validatingwebhookconfiguration_webhook_clientconfig_service gauge
+ kube_validatingwebhookconfiguration_webhook_clientconfig_service{webhook_name="webhook_with_external_url",namespace="ns3",service_name="",service_namespace="",validatingwebhookconfiguration="validatingwebhookconfiguration3"} 1
+ kube_validatingwebhookconfiguration_webhook_clientconfig_service{webhook_name="webhook_with_service",namespace="ns3",service_name="svc",service_namespace="ns",validatingwebhookconfiguration="validatingwebhookconfiguration3"} 1
+ `,
+ MetricNames: []string{"kube_validatingwebhookconfiguration_webhook_clientconfig_service"},
+ },
}
for i, c := range cases {
c.Func = generator.ComposeMetricGenFuncs(validatingWebhookConfigurationMetricFamilies)