Skip to content

Commit 4cf110e

Browse files
authored
Merge pull request #7095 from chrischdi/obs-ksm
✨ Integrate kube-state-metrics and CR config into tilt.
2 parents 896aff9 + f56802f commit 4cf110e

17 files changed

+1375
-2
lines changed

Makefile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/$(BIN_DIR))
5959
E2E_FRAMEWORK_DIR := $(TEST_DIR)/framework
6060
CAPD_DIR := $(TEST_DIR)/infrastructure/docker
6161
GO_INSTALL := ./scripts/go_install.sh
62+
OBSERVABILITY_DIR := hack/observability
6263

6364
export PATH := $(abspath $(TOOLS_BIN_DIR)):$(PATH)
6465

@@ -209,7 +210,7 @@ ALL_GENERATE_MODULES = core kubeadm-bootstrap kubeadm-control-plane capd
209210

210211
.PHONY: generate
211212
generate: ## Run all generate-manifests-*, generate-go-deepcopy-*, generate-go-conversions-* and generate-go-openapi targets
212-
$(MAKE) generate-modules generate-manifests generate-go-deepcopy generate-go-conversions generate-go-openapi
213+
$(MAKE) generate-modules generate-manifests generate-go-deepcopy generate-go-conversions generate-go-openapi generate-metrics-config
213214

214215
.PHONY: generate-manifests
215216
generate-manifests: $(addprefix generate-manifests-,$(ALL_GENERATE_MODULES)) ## Run all generate-manifests-* targets
@@ -434,6 +435,20 @@ generate-modules: ## Run go mod tidy to ensure modules are up to date
434435
cd $(TOOLS_DIR); go mod tidy
435436
cd $(TEST_DIR); go mod tidy
436437

438+
.PHONY: generate-metrics-config
439+
generate-metrics-config: $(ENVSUBST_BIN) ## Generate ./hack/observability/kube-state-metrics/crd-config.yaml
440+
OUTPUT_FILE="${OBSERVABILITY_DIR}/kube-state-metrics/crd-config.yaml"; \
441+
METRICS_DIR="${OBSERVABILITY_DIR}/kube-state-metrics/metrics"; \
442+
echo "# This file was auto-generated via: make generate-metrics-config" > "$${OUTPUT_FILE}"; \
443+
cat "$${METRICS_DIR}/header.yaml" >> "$${OUTPUT_FILE}"; \
444+
for resource in cluster kubeadmcontrolplane machine machinedeployment machinehealthcheck machineset; do \
445+
cat "$${METRICS_DIR}/$${resource}.yaml"; \
446+
RESOURCE="$${resource}" ${ENVSUBST_BIN} < "$${METRICS_DIR}/common_metrics.yaml"; \
447+
if [[ "$${resource}" != "cluster" ]]; then \
448+
cat "$${METRICS_DIR}/owner_metric.yaml"; \
449+
fi \
450+
done >> "$${OUTPUT_FILE}"; \
451+
437452
.PHONY: generate-diagrams
438453
generate-diagrams: ## Generate diagrams for *.plantuml files
439454
$(MAKE) -C docs diagrams

Tiltfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,10 @@ def deploy_observability():
480480
k8s_yaml(read_file("./.tiltbuild/yaml/prometheus.observability.yaml"), allow_duplicates = True)
481481
k8s_resource(workload = "prometheus-server", new_name = "prometheus", port_forwards = "9090", extra_pod_selectors = [{"app": "prometheus"}], labels = ["observability"])
482482

483+
if "kube-state-metrics" in settings.get("deploy_observability", []):
484+
k8s_yaml(read_file("./.tiltbuild/yaml/kube-state-metrics.observability.yaml"), allow_duplicates = True)
485+
k8s_resource(workload = "kube-state-metrics", new_name = "kube-state-metrics", extra_pod_selectors = [{"app": "kube-state-metrics"}], labels = ["observability"])
486+
483487
if "visualizer" in settings.get("deploy_observability", []):
484488
k8s_yaml(read_file("./.tiltbuild/yaml/visualizer.observability.yaml"), allow_duplicates = True)
485489
k8s_resource(

docs/book/src/developer/tilt.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,20 @@ kustomize_substitutions:
173173
{{#/tabs }}
174174

175175
**deploy_observability** ([string], default=[]): If set, installs on the dev cluster one of more observability
176-
tools. Supported values are `grafana`, `loki`, `visualizer`, `promtail` and/or `prometheus` (Note: the UI for `grafana`, `prometheus`, and `visualizer` will be accessible via a link in the tilt console).
176+
tools.
177177
Important! This feature requires the `helm` command to be available in the user's path.
178178

179+
Supported values are:
180+
181+
* `grafana`*: To create dashboards and query `loki` as well as `prometheus`.
182+
* `kube-state-metrics`: For exposing metrics for kubernetes and CAPI resources to `prometheus`.
183+
* `loki`: To receive and store logs.
184+
* `prometheus`*: For collecting metrics from Kubernetes.
185+
* `promtail`: For providing pod logs to `loki`.
186+
* `visualizer`*: Visualize Cluster API resources for each cluster, provide quick access to the specs and status of any resource.
187+
188+
\*: Note: the UI will be accessible via a link in the tilt console
189+
179190
**debug** (Map{string: Map} default{}): A map of named configurations for the provider. The key is the name of the provider.
180191

181192
Supported settings:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
helmCharts:
2+
- name: kube-state-metrics
3+
repo: https://prometheus-community.github.io/helm-charts
4+
namespace: observability
5+
releaseName: kube-state-metrics
6+
valuesFile: values.yaml
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
image:
2+
tag: v2.6.0
3+
pullPolicy: IfNotPresent
4+
5+
# Add the CR configuration from the config map.
6+
volumeMounts:
7+
- mountPath: /etc/config
8+
name: config-volume
9+
10+
volumes:
11+
- configMap:
12+
name: kube-state-metrics-crd-config
13+
name: config-volume
14+
15+
extraArgs:
16+
- "--custom-resource-state-config-file=/etc/config/crd-config.yaml"
17+
18+
rbac:
19+
extraRules:
20+
- apiGroups:
21+
- cluster.x-k8s.io
22+
resources:
23+
- clusters
24+
- machinedeployments
25+
- machinesets
26+
- machines
27+
- machinehealthchecks
28+
verbs:
29+
- get
30+
- list
31+
- watch
32+
- apiGroups:
33+
- controlplane.cluster.x-k8s.io
34+
resources:
35+
- kubeadmcontrolplanes
36+
verbs:
37+
- get
38+
- list
39+
- watch
40+
41+
collectors:
42+
# CAPI CRs
43+
- clusters
44+
- machinedeployments
45+
- machinesets
46+
- machines
47+
- machinehealthchecks
48+
- kubeadmcontrolplanes
49+
# We need to define all default collectors too, otherwise the helm chart does not include this resources in rbac
50+
- certificatesigningrequests
51+
- configmaps
52+
- cronjobs
53+
- daemonsets
54+
- deployments
55+
- endpoints
56+
- horizontalpodautoscalers
57+
- ingresses
58+
- jobs
59+
- limitranges
60+
- mutatingwebhookconfigurations
61+
- namespaces
62+
- networkpolicies
63+
- nodes
64+
- persistentvolumeclaims
65+
- persistentvolumes
66+
- poddisruptionbudgets
67+
- pods
68+
- replicasets
69+
- replicationcontrollers
70+
- resourcequotas
71+
- secrets
72+
- services
73+
- statefulsets
74+
- storageclasses
75+
- validatingwebhookconfigurations
76+
- volumeattachments
77+
# - verticalpodautoscalers # not a default resource, see also: https://github.com/kubernetes/kube-state-metrics#enabling-verticalpodautoscalers

0 commit comments

Comments
 (0)