-
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.
add sidecar for kube-state-metrics and read crd config from cm + add …
…option to add kustomizations via tilt
- Loading branch information
Showing
9 changed files
with
187 additions
and
48 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
30 changes: 30 additions & 0 deletions
30
hack/observability/kube-state-metrics/chart/cm-crd-sidecar.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,30 @@ | ||
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}" |
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
46 changes: 46 additions & 0 deletions
46
hack/observability/kube-state-metrics/chart/patch-crd-sidecar.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 |
24 changes: 24 additions & 0 deletions
24
hack/observability/kube-state-metrics/chart/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
38 changes: 38 additions & 0 deletions
38
hack/observability/kube-state-metrics/crd-clusterrole.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,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 |
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,15 @@ | ||
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 | ||
- ./crd-clusterrole.yaml | ||
|
||
namespace: observability | ||
|
||
configMapGenerator: | ||
- name: kube-state-metrics-crd-config | ||
- name: kube-state-metrics-crd-config-capi | ||
files: | ||
- crd-config.yaml | ||
- capi.yaml=crd-config.yaml | ||
options: | ||
disableNameSuffixHash: true | ||
labels: | ||
kube-state-metrics/custom-resource: "true" |
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