Skip to content

Commit 1389ce3

Browse files
committed
metrics: update testdata including iterating the example-metrics.txt
1 parent 5d999b8 commit 1389ce3

File tree

5 files changed

+36
-30
lines changed

5 files changed

+36
-30
lines changed

pkg/metrics/testdata/README.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,55 @@ If there are intended changes this file needs to get regenerated to make the tes
1010
This could be done via:
1111

1212
```sh
13-
go run generate \
14-
./pkg/customresourcestate/generate/generator/testdata/ \
15-
> ./pkg/customresourcestate/generate/generator/testdata/foo-config.yaml
13+
go run ./cmd/controller-gen metrics crd \
14+
paths=./pkg/metrics/testdata \
15+
output:dir=./pkg/metrics/testdata
1616
```
1717

1818
Or by using the go:generate marker inside [foo_types.go](foo_types.go):
1919

2020
```sh
21-
go generate ./pkg/customresourcestate/generate/generator/testdata/
21+
go generate ./pkg/metrics/testdata/
2222
```
2323

24-
## Example files: foo-cr-example.yaml and foo-cr-example-metrics.txt
24+
## Example files: metrics.yaml, rbac.yaml and example-metrics.txt
2525

26-
There is also an example CR ([foo-cr-example.yaml](foo-cr-example.yaml)) and resulting example metrics ([foo-cr-example-metrics.txt](foo-cr-example-metrics.txt)).
26+
There is also an example CR ([example-foo.yaml](example-foo.yaml)) and resulting example metrics ([example-metrics.txt](example-metrics.txt)).
2727

2828
The example metrics file got created by:
2929

30-
1. Generating a CustomResourceDefinition yaml by using [controller-gen](https://github.com/kubernetes-sigs/kubebuilder/blob/master/docs/book/src/reference/controller-gen.md):
30+
1. Generating a CustomResourceDefinition and Kube-State-Metrics configration file:
3131

3232
```sh
33-
controller-gen crd paths=./pkg/customresourcestate/generate/generator/testdata/ output:dir=./pkg/customresourcestate/generate/generator/testdata/
33+
go generate ./pkg/metrics/testdata/
3434
```
3535

3636
2. Creating a cluster using [kind](https://kind.sigs.k8s.io/)
37+
38+
```sh
39+
kind create cluster
40+
```
41+
3742
3. Applying the CRD and example CR to the cluster:
3843

3944
```sh
40-
kubectl apply -f /pkg/customresourcestate/generate/generator/testdata/bar.example.com_foos.yaml
41-
kubectl apply -f /pkg/customresourcestate/generate/generator/testdata/foo-cr-example.yaml
45+
kubectl apply -f ./pkg/metrics/testdata/bar.example.com_foos.yaml
46+
kubectl apply -f ./pkg/metrics/testdata/example-foo.yaml
4247
```
4348

4449
4. Running kube-state-metrics with the provided configuration file:
4550

4651
```sh
47-
go run ./ --kubeconfig $HOME/.kube/config --custom-resource-state-only \
48-
--custom-resource-state-config-file pkg/customresourcestate/generate/generator/testdata/foo-config.yaml
52+
docker run --net=host -ti --rm \
53+
-v $HOME/.kube/config:/config \
54+
-v $(pwd):/data \
55+
registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.13.0 \
56+
--kubeconfig /config --custom-resource-state-only \
57+
--custom-resource-state-config-file /data/pkg/metrics/testdata/foo-config.yaml
4958
```
5059

5160
5. Querying the metrics endpoint in a second terminal:
5261

5362
```sh
54-
curl localhost:8080/metrics > ./pkg/customresourcestate/generate/generator/testdata/foo-cr-example-metrics.txt
63+
curl localhost:8080/metrics > ./pkg/metrics/testdata/foo-cr-example-metrics.txt
5564
```

pkg/metrics/testdata/bar.example.com_foos.yaml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.8.0
7-
creationTimestamp: null
6+
controller-gen.kubebuilder.io/version: (devel)
87
name: foos.bar.example.com
98
spec:
109
group: bar.example.com
@@ -21,14 +20,19 @@ spec:
2120
description: Foo is a test object.
2221
properties:
2322
apiVersion:
24-
description: 'APIVersion defines the versioned schema of this representation
25-
of an object. Servers should convert recognized schemas to the latest
26-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
23+
description: |-
24+
APIVersion defines the versioned schema of this representation of an object.
25+
Servers should convert recognized schemas to the latest internal value, and
26+
may reject unrecognized values.
27+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
2728
type: string
2829
kind:
29-
description: 'Kind is a string value representing the REST resource this
30-
object represents. Servers may infer this from the endpoint the client
31-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
30+
description: |-
31+
Kind is a string value representing the REST resource this object represents.
32+
Servers may infer this from the endpoint the client submits requests to.
33+
Cannot be updated.
34+
In CamelCase.
35+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
3236
type: string
3337
metadata:
3438
type: object
@@ -68,9 +72,3 @@ spec:
6872
type: object
6973
served: true
7074
storage: true
71-
status:
72-
acceptedNames:
73-
kind: ""
74-
plural: ""
75-
conditions: []
76-
storedVersions: []

pkg/metrics/testdata/foo-cr-example-metrics.txt renamed to pkg/metrics/testdata/example-metrics.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# HELP foo_created Unix creation timestamp.
22
# TYPE foo_created gauge
3-
foo_created{customresource_group="bar.example.com",customresource_kind="Foo",customresource_version="foo",name="bar"} 1.697543739e+09
3+
foo_created{customresource_group="bar.example.com",customresource_kind="Foo",customresource_version="foo",name="bar"} 1.724940463e+09
44
# HELP foo_owner Owner references.
55
# TYPE foo_owner info
66
foo_owner{customresource_group="bar.example.com",customresource_kind="Foo",customresource_version="foo",name="bar",owner_is_controller="true",owner_kind="foo",owner_name="foo",owner_uid="someuid"} 1

pkg/metrics/testdata/foo_types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ limitations under the License.
1919
// The below marker can be used to regenerate the `foo-config.yaml` file by running
2020
// the following command:
2121
// $ go generate ./pkg/customresourcestate/generate/generator/testdata
22-
//go:generate sh -c "go run ../../../cmd/controller-gen metrics output:metrics:dir=. paths=./"
23-
//go:generate sh -c "controller-gen crd paths=./ output:stdout > foo-crd.yaml"
22+
//go:generate sh -c "go run ../../../cmd/controller-gen crd metrics paths=./ output:dir=."
2423

2524
// +groupName=bar.example.com
2625
package foo

0 commit comments

Comments
 (0)