-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
observability: move metrics to config and use sidecar in kube-state-m…
…etrics
- Loading branch information
Showing
27 changed files
with
248 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: kube-state-metrics-custom-resource-capi | ||
labels: | ||
kube-state-metrics/aggregate-to-manager: "true" | ||
rules: | ||
- apiGroups: | ||
- cluster.x-k8s.io | ||
resources: | ||
- clusterclasses | ||
- clusters | ||
- machinedeployments | ||
- machinepools | ||
- machinesets | ||
- machines | ||
- machinehealthchecks | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
- apiGroups: | ||
- controlplane.cluster.x-k8s.io | ||
resources: | ||
- kubeadmcontrolplanes | ||
verbs: | ||
- get | ||
- list | ||
- watch | ||
- apiGroups: | ||
- bootstrap.cluster.x-k8s.io | ||
resources: | ||
- kubeadmconfigs | ||
verbs: | ||
- get | ||
- list | ||
- watch |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
resources: | ||
- ./crd-clusterrole.yaml | ||
|
||
namespace: observability | ||
|
||
configMapGenerator: | ||
- name: kube-state-metrics-crd-config-capi | ||
files: | ||
- capi.yaml=crd-config.yaml | ||
options: | ||
disableNameSuffixHash: true | ||
labels: | ||
kube-state-metrics/custom-resource: "true" |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: kube-state-metrics-crd-sidecar-script | ||
data: | ||
compile.sh: | | ||
#!/bin/sh | ||
set -x | ||
SOURCE_DIR="/tmp" | ||
TARGET_FILE="/etc/config/crd-config.yaml" | ||
# This script will use a temporary file to only overwrite the target file once. | ||
TARGET_FILE_TMP="${TARGET_FILE}.tmp" | ||
# Create header | ||
cat << EOF > "${TARGET_FILE_TMP}" | ||
kind: CustomResourceStateMetrics | ||
spec: | ||
resources: | ||
EOF | ||
# Append custom resource config of all files but remove headers | ||
for f in $(ls -1 ${SOURCE_DIR}/*.yaml); do | ||
cat $f | grep -v -E -e '^(-|kind: CustomResourceStateMetrics|spec:| +resources:)' \ | ||
>> "${TARGET_FILE_TMP}" | ||
done | ||
# Overwrite target file | ||
mv "${TARGET_FILE_TMP}" "${TARGET_FILE}" |
46 changes: 46 additions & 0 deletions
46
hack/observability/kube-state-metrics/crd-sidecar-patch.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: kube-state-metrics | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- env: | ||
- name: LABEL | ||
value: kube-state-metrics/custom-resource | ||
- name: FOLDER | ||
value: /tmp | ||
- name: RESOURCE | ||
value: configmap | ||
- name: NAMESPACE | ||
value: observability | ||
- name: SCRIPT | ||
value: /script/compile.sh | ||
image: kiwigrid/k8s-sidecar:latest | ||
name: crd-sidecar | ||
volumeMounts: | ||
- mountPath: /etc/config | ||
name: config-volume | ||
- mountPath: /script | ||
name: compile-script | ||
initContainers: | ||
- command: | ||
- /bin/sh | ||
- -c | ||
- | | ||
cat << EOF > "/etc/config/crd-config.yaml" | ||
kind: CustomResourceStateMetrics | ||
spec: | ||
resources: [] | ||
EOF | ||
image: kiwigrid/k8s-sidecar:latest | ||
name: init-crd-config | ||
volumeMounts: | ||
- mountPath: /etc/config | ||
name: config-volume | ||
volumes: | ||
- configMap: | ||
defaultMode: 511 | ||
name: kube-state-metrics-crd-sidecar-script | ||
name: compile-script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,30 @@ | ||
resources: | ||
- ../namespace.yaml | ||
# The kube-state-metrics helm chart will reference a configmap with name `kube-state-metrics-crd-config`. | ||
# The configMapGenerator below will create the configmap and append a hash suffix calculated from its | ||
# content to the name. Kustomize will append the suffix hash to all references in the helm chart, but | ||
# only when the helm chart content is referenced in "resources". | ||
# This would not work if the helm chart is configured in this file via the "helmCharts" option. | ||
- ./chart | ||
# Aggregated ClusterRole and ClusterRoleBinding for kube-state-metrics crd resources. | ||
- rbac-crd-aggregation.yaml | ||
# Adds the configmap which contains the script to build the final crd configuration. | ||
- crd-sidecar-cm.yaml | ||
# Adds the core CAPI crd metrics configmap and CusterRole. | ||
- ../../../config/metrics | ||
|
||
namespace: observability | ||
|
||
configMapGenerator: | ||
- name: kube-state-metrics-crd-config | ||
files: | ||
- crd-config.yaml | ||
helmCharts: | ||
- name: kube-state-metrics | ||
repo: https://prometheus-community.github.io/helm-charts | ||
namespace: observability | ||
releaseName: kube-state-metrics | ||
valuesFile: values.yaml | ||
version: 5.12.1 | ||
|
||
helmGlobals: | ||
# Store chart in ".charts" folder instead of "charts". | ||
# Otherwise "go mod tidy" picks up dependencies of go files contained in the Helm Chart. | ||
# "go mod tidy" ignores folders that begin with ".": https://pkg.go.dev/cmd/go#hdr-Package_lists_and_patterns. | ||
chartHome: .charts | ||
|
||
patches: | ||
# Adds the sidecar container which assembles the final configuration for kube-state-metrics | ||
- path: crd-sidecar-patch.yaml | ||
target: | ||
kind: Deployment |
24 changes: 24 additions & 0 deletions
24
hack/observability/kube-state-metrics/rbac-crd-aggregation.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
# ClusterRole to aggregate other ClusterRoles for different Custom Resource Configurations | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: kube-state-metrics-aggregated-role | ||
aggregationRule: | ||
clusterRoleSelectors: | ||
- matchLabels: | ||
kube-state-metrics/aggregate-to-manager: "true" | ||
--- | ||
# ClusterRoleBinding for the aggregation role | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: kube-state-metrics-custom-resource-rolebinding | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: kube-state-metrics-aggregated-role | ||
subjects: | ||
- kind: ServiceAccount | ||
name: kube-state-metrics | ||
namespace: observability |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Add the CR configuration from the config map. | ||
volumeMounts: | ||
- mountPath: /etc/config | ||
name: config-volume | ||
|
||
volumes: | ||
- emptyDir: {} | ||
name: config-volume | ||
|
||
extraArgs: | ||
- "--custom-resource-state-config-file=/etc/config/crd-config.yaml" | ||
|
||
rbac: | ||
extraRules: | ||
- apiGroups: | ||
- apiextensions.k8s.io | ||
resources: | ||
- customresourcedefinitions | ||
verbs: | ||
- get | ||
- list | ||
- watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters