Skip to content

Instantly share code, notes, and snippets.

@bergerx
Last active November 3, 2023 17:24
Show Gist options
  • Save bergerx/adad24dcd7cc360e1f36fbb98407b27b to your computer and use it in GitHub Desktop.
Save bergerx/adad24dcd7cc360e1f36fbb98407b27b to your computer and use it in GitHub Desktop.
repeated TYPE decleration in kube-state-metrics
minikube start
kubectl apply -f crd-foo.example.com.yaml -f crd-bar.example.com.yaml 
kubectl apply -f cr-foo.yaml -f cr-bar.yaml
go run main.go --custom-resource-state-only --custom-resource-state-config-file custom-resource-config-file.yaml --kubeconfig ~/.kube/config
kind: Bar
apiVersion: example.com/v1
metadata:
name: mybar
spec:
kind: Foo
apiVersion: example.com/v1
metadata:
name: myfoo
spec:
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: bars.example.com
spec:
group: example.com
scope: Cluster
names:
kind: Bar
singular: bar
plural: bars
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
x-kubernetes-preserve-unknown-fields: true
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: foos.example.com
spec:
group: example.com
scope: Cluster
names:
kind: Foo
singular: foo
plural: foos
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
x-kubernetes-preserve-unknown-fields: true
kind: CustomResourceStateMetrics
spec:
resources:
- groupVersionKind:
group: example.com
kind: "*"
version: v1
labelsFromPath:
name: [metadata, name]
namespace: [metadata, namespace]
metricNamePrefix: "cr"
metrics:
- name: creationtimestamp
each:
type: Gauge
gauge:
path: [metadata, creationTimestamp]
- name: resourceversion
each:
type: Gauge
gauge:
path: [metadata, resourceVersion]
# HELP cr_creationtimestamp
2
# TYPE cr_creationtimestamp gauge
3
cr_creationtimestamp{customresource_group="example.com",customresource_kind="Bar",customresource_version="v1",name="mybar"} 1.699031755e+09
4
# HELP cr_resourceversion
5
# TYPE cr_resourceversion gauge
6
cr_resourceversion{customresource_group="example.com",customresource_kind="Bar",customresource_version="v1",name="mybar"} 508820
7
# HELP cr_creationtimestamp
8
# TYPE cr_creationtimestamp gauge
9
cr_creationtimestamp{customresource_group="example.com",customresource_kind="Foo",customresource_version="v1",name="myfoo"} 1.699031755e+09
10
# HELP cr_resourceversion
11
# TYPE cr_resourceversion gauge
12
cr_resourceversion{customresource_group="example.com",customresource_kind="Foo",customresource_version="v1",name="myfoo"} 508819
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment