Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Integrate kube-state-metrics and CR config into tilt. #7095

Merged
merged 1 commit into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/$(BIN_DIR))
E2E_FRAMEWORK_DIR := $(TEST_DIR)/framework
CAPD_DIR := $(TEST_DIR)/infrastructure/docker
GO_INSTALL := ./scripts/go_install.sh
OBSERVABILITY_DIR := hack/observability

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

Expand Down Expand Up @@ -209,7 +210,7 @@ ALL_GENERATE_MODULES = core kubeadm-bootstrap kubeadm-control-plane capd

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

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

.PHONY: generate-metrics-config
generate-metrics-config: $(ENVSUBST_BIN) ## Generate ./hack/observability/kube-state-metrics/crd-config.yaml
OUTPUT_FILE="${OBSERVABILITY_DIR}/kube-state-metrics/crd-config.yaml"; \
METRICS_DIR="${OBSERVABILITY_DIR}/kube-state-metrics/metrics"; \
echo "# This file was auto-generated via: make generate-metrics-config" > "$${OUTPUT_FILE}"; \
cat "$${METRICS_DIR}/header.yaml" >> "$${OUTPUT_FILE}"; \
for resource in cluster kubeadmcontrolplane machine machinedeployment machinehealthcheck machineset; do \
cat "$${METRICS_DIR}/$${resource}.yaml"; \
RESOURCE="$${resource}" ${ENVSUBST_BIN} < "$${METRICS_DIR}/common_metrics.yaml"; \
if [[ "$${resource}" != "cluster" ]]; then \
cat "$${METRICS_DIR}/owner_metric.yaml"; \
fi \
done >> "$${OUTPUT_FILE}"; \

.PHONY: generate-diagrams
generate-diagrams: ## Generate diagrams for *.plantuml files
$(MAKE) -C docs diagrams
Expand Down
4 changes: 4 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ def deploy_observability():
k8s_yaml(read_file("./.tiltbuild/yaml/prometheus.observability.yaml"), allow_duplicates = True)
k8s_resource(workload = "prometheus-server", new_name = "prometheus", port_forwards = "9090", extra_pod_selectors = [{"app": "prometheus"}], labels = ["observability"])

if "kube-state-metrics" in settings.get("deploy_observability", []):
k8s_yaml(read_file("./.tiltbuild/yaml/kube-state-metrics.observability.yaml"), allow_duplicates = True)
k8s_resource(workload = "kube-state-metrics", new_name = "kube-state-metrics", extra_pod_selectors = [{"app": "kube-state-metrics"}], labels = ["observability"])

if "visualizer" in settings.get("deploy_observability", []):
k8s_yaml(read_file("./.tiltbuild/yaml/visualizer.observability.yaml"), allow_duplicates = True)
k8s_resource(
Expand Down
13 changes: 12 additions & 1 deletion docs/book/src/developer/tilt.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,20 @@ kustomize_substitutions:
{{#/tabs }}

**deploy_observability** ([string], default=[]): If set, installs on the dev cluster one of more observability
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).
tools.
Important! This feature requires the `helm` command to be available in the user's path.

Supported values are:

* `grafana`*: To create dashboards and query `loki` as well as `prometheus`.
* `kube-state-metrics`: For exposing metrics for kubernetes and CAPI resources to `prometheus`.
* `loki`: To receive and store logs.
* `prometheus`*: For collecting metrics from Kubernetes.
* `promtail`: For providing pod logs to `loki`.
* `visualizer`*: Visualize Cluster API resources for each cluster, provide quick access to the specs and status of any resource.

\*: Note: the UI will be accessible via a link in the tilt console
fabriziopandini marked this conversation as resolved.
Show resolved Hide resolved

**debug** (Map{string: Map} default{}): A map of named configurations for the provider. The key is the name of the provider.

Supported settings:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
helmCharts:
- name: kube-state-metrics
repo: https://prometheus-community.github.io/helm-charts
namespace: observability
releaseName: kube-state-metrics
valuesFile: values.yaml
77 changes: 77 additions & 0 deletions hack/observability/kube-state-metrics/chart/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
image:
tag: v2.6.0
Copy link
Member

@sbueringer sbueringer Aug 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good if we can drop the pinned tag in a follow-up PR once the corresponding Helm chart is out
(just that when we pull the latest chart the pinned tag and the chart don't run out of sync)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, the latest chart still refers 2.5.0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's open an issue to track this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done: #7143

pullPolicy: IfNotPresent

# Add the CR configuration from the config map.
volumeMounts:
- mountPath: /etc/config
name: config-volume

volumes:
- configMap:
name: kube-state-metrics-crd-config
name: config-volume

extraArgs:
- "--custom-resource-state-config-file=/etc/config/crd-config.yaml"

rbac:
extraRules:
- apiGroups:
- cluster.x-k8s.io
resources:
- clusters
- machinedeployments
- machinesets
- machines
- machinehealthchecks
verbs:
- get
- list
- watch
- apiGroups:
- controlplane.cluster.x-k8s.io
resources:
- kubeadmcontrolplanes
verbs:
- get
- list
- watch

collectors:
# CAPI CRs
- clusters
- machinedeployments
- machinesets
- machines
- machinehealthchecks
- kubeadmcontrolplanes
# We need to define all default collectors too, otherwise the helm chart does not include this resources in rbac
- certificatesigningrequests
- configmaps
- cronjobs
- daemonsets
- deployments
- endpoints
- horizontalpodautoscalers
- ingresses
- jobs
- limitranges
- mutatingwebhookconfigurations
- namespaces
- networkpolicies
- nodes
- persistentvolumeclaims
- persistentvolumes
- poddisruptionbudgets
- pods
- replicasets
- replicationcontrollers
- resourcequotas
- secrets
- services
- statefulsets
- storageclasses
- validatingwebhookconfigurations
- volumeattachments
# - verticalpodautoscalers # not a default resource, see also: https://github.com/kubernetes/kube-state-metrics#enabling-verticalpodautoscalers
Loading