Skip to content

Commit 8b0e797

Browse files
authored
Merge pull request #9390 from chrischdi/pr-ksm-sidecar
🌱 observability: move metrics to config and use sidecar in kube-state-metrics
2 parents b8ff771 + 4b4df56 commit 8b0e797

27 files changed

+244
-91
lines changed

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -554,16 +554,16 @@ generate-e2e-templates-main: $(KUSTOMIZE)
554554
$(KUSTOMIZE) build $(INMEMORY_TEMPLATES)/main/cluster-template --load-restrictor LoadRestrictionsNone > $(INMEMORY_TEMPLATES)/main/cluster-template.yaml
555555

556556
.PHONY: generate-metrics-config
557-
generate-metrics-config: $(ENVSUBST_BIN) ## Generate ./hack/observability/kube-state-metrics/crd-config.yaml
558-
OUTPUT_FILE="${OBSERVABILITY_DIR}/kube-state-metrics/crd-config.yaml"; \
559-
METRICS_DIR="${OBSERVABILITY_DIR}/kube-state-metrics/metrics"; \
557+
generate-metrics-config: $(ENVSUBST_BIN) ## Generate ./config/metrics/crd-metrics-config.yaml
558+
OUTPUT_FILE="./config/metrics/crd-metrics-config.yaml"; \
559+
METRIC_TEMPLATES_DIR="./config/metrics/templates"; \
560560
echo "# This file was auto-generated via: make generate-metrics-config" > "$${OUTPUT_FILE}"; \
561-
cat "$${METRICS_DIR}/header.yaml" >> "$${OUTPUT_FILE}"; \
561+
cat "$${METRIC_TEMPLATES_DIR}/header.yaml" >> "$${OUTPUT_FILE}"; \
562562
for resource in clusterclass cluster kubeadmcontrolplane kubeadmconfig machine machinedeployment machinehealthcheck machineset machinepool; do \
563-
cat "$${METRICS_DIR}/$${resource}.yaml"; \
564-
RESOURCE="$${resource}" ${ENVSUBST_BIN} < "$${METRICS_DIR}/common_metrics.yaml"; \
563+
cat "$${METRIC_TEMPLATES_DIR}/$${resource}.yaml"; \
564+
RESOURCE="$${resource}" ${ENVSUBST_BIN} < "$${METRIC_TEMPLATES_DIR}/common_metrics.yaml"; \
565565
if [[ "$${resource}" != "cluster" ]]; then \
566-
cat "$${METRICS_DIR}/owner_metric.yaml"; \
566+
cat "$${METRIC_TEMPLATES_DIR}/owner_metric.yaml"; \
567567
fi \
568568
done >> "$${OUTPUT_FILE}"; \
569569

Tiltfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,19 @@ def deploy_observability():
482482
objects = ["capi-visualizer:serviceaccount"],
483483
)
484484

485+
def deploy_kustomizations():
486+
for name in settings.get("deploy_kustomizations", []):
487+
yaml = read_file("./.tiltbuild/yaml/{}.kustomization.yaml".format(name))
488+
k8s_yaml(yaml)
489+
objs = decode_yaml_stream(yaml)
490+
print("objects")
491+
print(find_all_objects_names(objs))
492+
k8s_resource(
493+
new_name = name,
494+
objects = find_all_objects_names(objs),
495+
labels = ["kustomization"],
496+
)
497+
485498
def prepare_all():
486499
tools_arg = "--tools kustomize,envsubst,clusterctl "
487500
tilt_settings_file_arg = "--tilt-settings-file " + tilt_file
@@ -640,6 +653,8 @@ deploy_provider_crds()
640653

641654
deploy_observability()
642655

656+
deploy_kustomizations()
657+
643658
enable_providers()
644659

645660
cluster_templates()

config/metrics/crd-clusterrole.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: kube-state-metrics-custom-resource-capi
6+
labels:
7+
kube-state-metrics/aggregate-to-manager: "true"
8+
rules:
9+
- apiGroups:
10+
- cluster.x-k8s.io
11+
resources:
12+
- clusterclasses
13+
- clusters
14+
- machinedeployments
15+
- machinepools
16+
- machinesets
17+
- machines
18+
- machinehealthchecks
19+
verbs:
20+
- get
21+
- list
22+
- watch
23+
- apiGroups:
24+
- controlplane.cluster.x-k8s.io
25+
resources:
26+
- kubeadmcontrolplanes
27+
verbs:
28+
- get
29+
- list
30+
- watch
31+
- apiGroups:
32+
- bootstrap.cluster.x-k8s.io
33+
resources:
34+
- kubeadmconfigs
35+
verbs:
36+
- get
37+
- list
38+
- watch

config/metrics/kustomization.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
resources:
2+
- ./crd-clusterrole.yaml
3+
4+
namespace: observability
5+
6+
configMapGenerator:
7+
- name: kube-state-metrics-crd-config-capi
8+
files:
9+
- capi.yaml=crd-metrics-config.yaml
10+
options:
11+
disableNameSuffixHash: true
12+
labels:
13+
kube-state-metrics/custom-resource: "true"

hack/observability/kube-state-metrics/metrics/README.md renamed to config/metrics/templates/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
The make target `generate-metrics-config` is used to generate a single file which contains the Cluster API specific custom resource configuration for kube-state-metrics.
66

7-
To regenerate the file `../crd-config.yaml`, execute the `make generate-metrics-config` command.
7+
To regenerate the file `../crd-metrics-config.yaml`, execute the `make generate-metrics-config` command.

0 commit comments

Comments
 (0)