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

feat(flux): add kube-state-metrics #2440

Merged
merged 1 commit into from
Jan 30, 2024
Merged

feat(flux): add kube-state-metrics #2440

merged 1 commit into from
Jan 30, 2024

Conversation

jazzlyn
Copy link
Collaborator

@jazzlyn jazzlyn commented Jan 30, 2024

No description provided.

Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@tyriis-automation
Copy link
Contributor

--- kubernetes/talos-flux/apps/observability/kube-prometheus-stack/app Kustomization: flux-system/apps-kube-prometheus-stack HelmRelease: observability/kube-prometheus-stack

+++ kubernetes/talos-flux/apps/observability/kube-prometheus-stack/app Kustomization: flux-system/apps-kube-prometheus-stack HelmRelease: observability/kube-prometheus-stack

@@ -36,19 +36,12 @@

     coreDns:
       enabled: true
     fullnameOverride: prometheus
     grafana:
       enabled: false
       forceDeployDashboards: true
-    kube-state-metrics:
-      fullnameOverride: kube-state-metrics
-      prometheus:
-        monitor:
-          enabled: true
-      selfMonitor:
-        enabled: true
     kubeApiServer:
       enabled: true
     kubeControllerManager:
       enabled: false
       endpoints:
       - 192.168.1.51
@@ -113,8 +106,10 @@

       - effect: NoSchedule
         operator: Exists
   valuesFrom:
   - kind: ConfigMap
     name: alertmanager-values-g449hk5h68
   - kind: ConfigMap
+    name: kube-state-metrics-values-gfkcdkg4mt
+  - kind: ConfigMap
     name: prometheus-values-8cbfbkckkc
 
--- kubernetes/talos-flux/apps/observability/kube-prometheus-stack/app Kustomization: flux-system/apps-kube-prometheus-stack ConfigMap: observability/kube-state-metrics-values-gfkcdkg4mt

+++ kubernetes/talos-flux/apps/observability/kube-prometheus-stack/app Kustomization: flux-system/apps-kube-prometheus-stack ConfigMap: observability/kube-state-metrics-values-gfkcdkg4mt

@@ -0,0 +1,299 @@

+---
+apiVersion: v1
+data:
+  values.yaml: |
+    ---
+    kube-state-metrics:
+      fullnameOverride: kube-state-metrics
+      metricLabelsAllowlist:
+        - pods=[*]
+        - deployments=[*]
+        - persistentvolumeclaims=[*]
+      selfMonitor:
+        enabled: true
+      prometheus:
+        monitor:
+          enabled: true
+          relabelings:
+            - action: replace
+              regex: (.*)
+              replacement: $1
+              sourceLabels:
+                - __meta_kubernetes_pod_node_name
+              targetLabel: kubernetes_node
+      rbac:
+        extraRules:
+          - apiGroups:
+              - source.toolkit.fluxcd.io
+              - kustomize.toolkit.fluxcd.io
+              - helm.toolkit.fluxcd.io
+              - notification.toolkit.fluxcd.io
+              - image.toolkit.fluxcd.io
+            resources:
+              - gitrepositories
+              - buckets
+              - helmrepositories
+              - helmcharts
+              - ocirepositories
+              - kustomizations
+              - helmreleases
+              - alerts
+              - providers
+              - receivers
+              - imagerepositories
+              - imagepolicies
+              - imageupdateautomations
+            verbs: ["list", "watch"]
+      customResourceState:
+        enabled: true
+        config:
+          spec:
+            resources:
+              - groupVersionKind:
+                  group: kustomize.toolkit.fluxcd.io
+                  version: v1
+                  kind: Kustomization
+                metricNamePrefix: gotk
+                metrics:
+                  - name: "resource_info"
+                    help: "The current state of a GitOps Toolkit resource."
+                    each:
+                      type: Info
+                      info:
+                        labelsFromPath:
+                          name: [metadata, name]
+                    labelsFromPath:
+                      exported_namespace: [metadata, namespace]
+                      ready: [status, conditions, "[type=Ready]", status]
+                      suspended: [spec, suspend]
+                      revision: [status, lastAppliedRevision]
+                      source_name: [spec, sourceRef, name]
+              - groupVersionKind:
+                  group: helm.toolkit.fluxcd.io
+                  version: v2beta2
+                  kind: HelmRelease
+                metricNamePrefix: gotk
+                metrics:
+                  - name: "resource_info"
+                    help: "The current state of a GitOps Toolkit resource."
+                    each:
+                      type: Info
+                      info:
+                        labelsFromPath:
+                          name: [metadata, name]
+                    labelsFromPath:
+                      exported_namespace: [metadata, namespace]
+                      ready: [status, conditions, "[type=Ready]", status]
+                      suspended: [spec, suspend]
+                      revision: [status, lastAppliedRevision]
+                      chart_name: [spec, chart, spec, chart]
+                      chart_source_name: [spec, chart, spec, sourceRef, name]
+              - groupVersionKind:
+                  group: source.toolkit.fluxcd.io
+                  version: v1
+                  kind: GitRepository
+                metricNamePrefix: gotk
+                metrics:
+                  - name: "resource_info"
+                    help: "The current state of a GitOps Toolkit resource."
+                    each:
+                      type: Info
+                      info:
+                        labelsFromPath:
+                          name: [metadata, name]
+                    labelsFromPath:
+                      exported_namespace: [metadata, namespace]
+                      ready: [status, conditions, "[type=Ready]", status]
+                      suspended: [spec, suspend]
+                      revision: [status, artifact, revision]
+                      url: [spec, url]
+              - groupVersionKind:
+                  group: source.toolkit.fluxcd.io
+                  version: v1beta2
+                  kind: Bucket
+                metricNamePrefix: gotk
+                metrics:
+                  - name: "resource_info"
+                    help: "The current state of a GitOps Toolkit resource."
+                    each:
+                      type: Info
+                      info:
+                        labelsFromPath:
+                          name: [metadata, name]
+                    labelsFromPath:
+                      exported_namespace: [metadata, namespace]
+                      ready: [status, conditions, "[type=Ready]", status]
+                      suspended: [spec, suspend]
+                      revision: [status, artifact, revision]
+                      endpoint: [spec, endpoint]
+                      bucket_name: [spec, bucketName]
+              - groupVersionKind:
+                  group: source.toolkit.fluxcd.io
+                  version: v1beta2
+                  kind: HelmRepository
+                metricNamePrefix: gotk
+                metrics:
+                  - name: "resource_info"
+                    help: "The current state of a GitOps Toolkit resource."
+                    each:
+                      type: Info
+                      info:
+                        labelsFromPath:
+                          name: [metadata, name]
+                    labelsFromPath:
+                      exported_namespace: [metadata, namespace]
+                      ready: [status, conditions, "[type=Ready]", status]
+                      suspended: [spec, suspend]
+                      revision: [status, artifact, revision]
+                      url: [spec, url]
+              - groupVersionKind:
+                  group: source.toolkit.fluxcd.io
+                  version: v1beta2
+                  kind: HelmChart
+                metricNamePrefix: gotk
+                metrics:
+                  - name: "resource_info"
+                    help: "The current state of a GitOps Toolkit resource."
+                    each:
+                      type: Info
+                      info:
+                        labelsFromPath:
+                          name: [metadata, name]
+                    labelsFromPath:
+                      exported_namespace: [metadata, namespace]
+                      ready: [status, conditions, "[type=Ready]", status]
+                      suspended: [spec, suspend]
+                      revision: [status, artifact, revision]
+                      chart_name: [spec, chart]
+                      chart_version: [spec, version]
+              - groupVersionKind:
+                  group: source.toolkit.fluxcd.io
+                  version: v1beta2
+                  kind: OCIRepository
+                metricNamePrefix: gotk
+                metrics:
+                  - name: "resource_info"
+                    help: "The current state of a GitOps Toolkit resource."
+                    each:
+                      type: Info
+                      info:
+                        labelsFromPath:
+                          name: [metadata, name]
+                    labelsFromPath:
+                      exported_namespace: [metadata, namespace]
+                      ready: [status, conditions, "[type=Ready]", status]
+                      suspended: [spec, suspend]
+                      revision: [status, artifact, revision]
+                      url: [spec, url]
+              - groupVersionKind:
+                  group: notification.toolkit.fluxcd.io
+                  version: v1beta3
+                  kind: Alert
+                metricNamePrefix: gotk
+                metrics:
+                  - name: "resource_info"
+                    help: "The current state of a GitOps Toolkit resource."
+                    each:
+                      type: Info
+                      info:
+                        labelsFromPath:
+                          name: [metadata, name]
+                    labelsFromPath:
+                      exported_namespace: [metadata, namespace]
+                      suspended: [spec, suspend]
+              - groupVersionKind:
+                  group: notification.toolkit.fluxcd.io
+                  version: v1beta3
+                  kind: Provider
+                metricNamePrefix: gotk
+                metrics:
+                  - name: "resource_info"
+                    help: "The current state of a GitOps Toolkit resource."
+                    each:
+                      type: Info
+                      info:
+                        labelsFromPath:
+                          name: [metadata, name]
+                    labelsFromPath:
+                      exported_namespace: [metadata, namespace]
+                      suspended: [spec, suspend]
+              - groupVersionKind:
+                  group: notification.toolkit.fluxcd.io
+                  version: v1
+                  kind: Receiver
+                metricNamePrefix: gotk
+                metrics:
+                  - name: "resource_info"
+                    help: "The current state of a GitOps Toolkit resource."
+                    each:
+                      type: Info
+                      info:
+                        labelsFromPath:
+                          name: [metadata, name]
+                    labelsFromPath:
+                      exported_namespace: [metadata, namespace]
+                      ready: [status, conditions, "[type=Ready]", status]
+                      suspended: [spec, suspend]
+                      webhook_path: [status, webhookPath]
[Diff truncated by flux-local]

@tyriis-automation
Copy link
Contributor

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ EDITORCONFIG editorconfig-checker 3 0 0.02s
✅ REPOSITORY gitleaks yes no 2.14s
✅ YAML prettier 3 0 0.78s
✅ YAML yamllint 3 0 0.47s

See detailed report in MegaLinter reports
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security

@tyriis-automation
Copy link
Contributor

--- HelmRelease: observability/kube-prometheus-stack ClusterRole: observability/kube-state-metrics

+++ HelmRelease: observability/kube-prometheus-stack ClusterRole: observability/kube-state-metrics

@@ -208,7 +208,37 @@

   - storage.k8s.io
   resources:
   - volumeattachments
   verbs:
   - list
   - watch
+- apiGroups:
+  - apiextensions.k8s.io
+  resources:
+  - customresourcedefinitions
+  verbs:
+  - list
+  - watch
+- apiGroups:
+  - source.toolkit.fluxcd.io
+  - kustomize.toolkit.fluxcd.io
+  - helm.toolkit.fluxcd.io
+  - notification.toolkit.fluxcd.io
+  - image.toolkit.fluxcd.io
+  resources:
+  - gitrepositories
+  - buckets
+  - helmrepositories
+  - helmcharts
+  - ocirepositories
+  - kustomizations
+  - helmreleases
+  - alerts
+  - providers
+  - receivers
+  - imagerepositories
+  - imagepolicies
+  - imageupdateautomations
+  verbs:
+  - list
+  - watch
 
--- HelmRelease: observability/kube-prometheus-stack Deployment: observability/kube-state-metrics

+++ HelmRelease: observability/kube-prometheus-stack Deployment: observability/kube-state-metrics

@@ -41,12 +41,18 @@

           type: RuntimeDefault
       containers:
       - name: kube-state-metrics
         args:
         - --port=8080
         - --resources=certificatesigningrequests,configmaps,cronjobs,daemonsets,deployments,endpoints,horizontalpodautoscalers,ingresses,jobs,leases,limitranges,mutatingwebhookconfigurations,namespaces,networkpolicies,nodes,persistentvolumeclaims,persistentvolumes,poddisruptionbudgets,pods,replicasets,replicationcontrollers,resourcequotas,secrets,services,statefulsets,storageclasses,validatingwebhookconfigurations,volumeattachments
+        - --metric-labels-allowlist=pods=[*],deployments=[*],persistentvolumeclaims=[*]
+        - --custom-resource-state-config-file=/etc/customresourcestate/config.yaml
+        volumeMounts:
+        - name: customresourcestate-config
+          mountPath: /etc/customresourcestate
+          readOnly: true
         imagePullPolicy: IfNotPresent
         image: registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.10.1
         ports:
         - containerPort: 8080
           name: http
         - containerPort: 8081
@@ -75,7 +81,11 @@

           timeoutSeconds: 5
         securityContext:
           allowPrivilegeEscalation: false
           capabilities:
             drop:
             - ALL
+      volumes:
+      - name: customresourcestate-config
+        configMap:
+          name: kube-state-metrics-customresourcestate-config
 
--- HelmRelease: observability/kube-prometheus-stack ServiceMonitor: observability/kube-state-metrics

+++ HelmRelease: observability/kube-prometheus-stack ServiceMonitor: observability/kube-state-metrics

@@ -17,9 +17,23 @@

     matchLabels:
       app.kubernetes.io/name: kube-state-metrics
       app.kubernetes.io/instance: kube-prometheus-stack
   endpoints:
   - port: http
     honorLabels: true
+    relabelings:
+    - action: replace
+      regex: (.*)
+      replacement: $1
+      sourceLabels:
+      - __meta_kubernetes_pod_node_name
+      targetLabel: kubernetes_node
   - port: metrics
     honorLabels: true
+    relabelings:
+    - action: replace
+      regex: (.*)
+      replacement: $1
+      sourceLabels:
+      - __meta_kubernetes_pod_node_name
+      targetLabel: kubernetes_node
 
--- HelmRelease: observability/kube-prometheus-stack ConfigMap: observability/kube-state-metrics-customresourcestate-config

+++ HelmRelease: observability/kube-prometheus-stack ConfigMap: observability/kube-state-metrics-customresourcestate-config

@@ -0,0 +1,435 @@

+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: kube-state-metrics-customresourcestate-config
+  namespace: observability
+  labels:
+    app.kubernetes.io/managed-by: Helm
+    app.kubernetes.io/component: metrics
+    app.kubernetes.io/part-of: kube-state-metrics
+    app.kubernetes.io/name: kube-state-metrics
+    app.kubernetes.io/instance: kube-prometheus-stack
+    release: kube-prometheus-stack
+data:
+  config.yaml: |
+    spec:
+      resources:
+      - groupVersionKind:
+          group: kustomize.toolkit.fluxcd.io
+          kind: Kustomization
+          version: v1
+        metricNamePrefix: gotk
+        metrics:
+        - each:
+            info:
+              labelsFromPath:
+                name:
+                - metadata
+                - name
+            type: Info
+          help: The current state of a GitOps Toolkit resource.
+          labelsFromPath:
+            exported_namespace:
+            - metadata
+            - namespace
+            ready:
+            - status
+            - conditions
+            - '[type=Ready]'
+            - status
+            revision:
+            - status
+            - lastAppliedRevision
+            source_name:
+            - spec
+            - sourceRef
+            - name
+            suspended:
+            - spec
+            - suspend
+          name: resource_info
+      - groupVersionKind:
+          group: helm.toolkit.fluxcd.io
+          kind: HelmRelease
+          version: v2beta2
+        metricNamePrefix: gotk
+        metrics:
+        - each:
+            info:
+              labelsFromPath:
+                name:
+                - metadata
+                - name
+            type: Info
+          help: The current state of a GitOps Toolkit resource.
+          labelsFromPath:
+            chart_name:
+            - spec
+            - chart
+            - spec
+            - chart
+            chart_source_name:
+            - spec
+            - chart
+            - spec
+            - sourceRef
+            - name
+            exported_namespace:
+            - metadata
+            - namespace
+            ready:
+            - status
+            - conditions
+            - '[type=Ready]'
+            - status
+            revision:
+            - status
+            - lastAppliedRevision
+            suspended:
+            - spec
+            - suspend
+          name: resource_info
+      - groupVersionKind:
+          group: source.toolkit.fluxcd.io
+          kind: GitRepository
+          version: v1
+        metricNamePrefix: gotk
+        metrics:
+        - each:
+            info:
+              labelsFromPath:
+                name:
+                - metadata
+                - name
+            type: Info
+          help: The current state of a GitOps Toolkit resource.
+          labelsFromPath:
+            exported_namespace:
+            - metadata
+            - namespace
+            ready:
+            - status
+            - conditions
+            - '[type=Ready]'
+            - status
+            revision:
+            - status
+            - artifact
+            - revision
+            suspended:
+            - spec
+            - suspend
+            url:
+            - spec
+            - url
+          name: resource_info
+      - groupVersionKind:
+          group: source.toolkit.fluxcd.io
+          kind: Bucket
+          version: v1beta2
+        metricNamePrefix: gotk
+        metrics:
+        - each:
+            info:
+              labelsFromPath:
+                name:
+                - metadata
+                - name
+            type: Info
+          help: The current state of a GitOps Toolkit resource.
+          labelsFromPath:
+            bucket_name:
+            - spec
+            - bucketName
+            endpoint:
+            - spec
+            - endpoint
+            exported_namespace:
+            - metadata
+            - namespace
+            ready:
+            - status
+            - conditions
+            - '[type=Ready]'
+            - status
+            revision:
+            - status
+            - artifact
+            - revision
+            suspended:
+            - spec
+            - suspend
+          name: resource_info
+      - groupVersionKind:
+          group: source.toolkit.fluxcd.io
+          kind: HelmRepository
+          version: v1beta2
+        metricNamePrefix: gotk
+        metrics:
+        - each:
+            info:
+              labelsFromPath:
+                name:
+                - metadata
+                - name
+            type: Info
+          help: The current state of a GitOps Toolkit resource.
+          labelsFromPath:
+            exported_namespace:
+            - metadata
+            - namespace
+            ready:
+            - status
+            - conditions
+            - '[type=Ready]'
+            - status
+            revision:
+            - status
+            - artifact
+            - revision
+            suspended:
+            - spec
+            - suspend
+            url:
+            - spec
+            - url
+          name: resource_info
+      - groupVersionKind:
+          group: source.toolkit.fluxcd.io
+          kind: HelmChart
+          version: v1beta2
+        metricNamePrefix: gotk
+        metrics:
+        - each:
+            info:
+              labelsFromPath:
+                name:
+                - metadata
+                - name
+            type: Info
+          help: The current state of a GitOps Toolkit resource.
+          labelsFromPath:
+            chart_name:
+            - spec
+            - chart
+            chart_version:
+            - spec
+            - version
+            exported_namespace:
+            - metadata
+            - namespace
+            ready:
+            - status
+            - conditions
+            - '[type=Ready]'
+            - status
+            revision:
+            - status
+            - artifact
+            - revision
+            suspended:
+            - spec
+            - suspend
+          name: resource_info
+      - groupVersionKind:
+          group: source.toolkit.fluxcd.io
+          kind: OCIRepository
+          version: v1beta2
+        metricNamePrefix: gotk
+        metrics:
+        - each:
+            info:
+              labelsFromPath:
+                name:
+                - metadata
+                - name
+            type: Info
+          help: The current state of a GitOps Toolkit resource.
+          labelsFromPath:
+            exported_namespace:
+            - metadata
+            - namespace
+            ready:
+            - status
+            - conditions
+            - '[type=Ready]'
+            - status
+            revision:
+            - status
+            - artifact
+            - revision
+            suspended:
+            - spec
+            - suspend
+            url:
+            - spec
+            - url
+          name: resource_info
+      - groupVersionKind:
+          group: notification.toolkit.fluxcd.io
+          kind: Alert
+          version: v1beta3
+        metricNamePrefix: gotk
+        metrics:
+        - each:
+            info:
+              labelsFromPath:
+                name:
+                - metadata
+                - name
+            type: Info
+          help: The current state of a GitOps Toolkit resource.
+          labelsFromPath:
+            exported_namespace:
+            - metadata
+            - namespace
+            suspended:
+            - spec
+            - suspend
+          name: resource_info
+      - groupVersionKind:
+          group: notification.toolkit.fluxcd.io
+          kind: Provider
+          version: v1beta3
+        metricNamePrefix: gotk
+        metrics:
+        - each:
+            info:
+              labelsFromPath:
+                name:
+                - metadata
+                - name
+            type: Info
+          help: The current state of a GitOps Toolkit resource.
+          labelsFromPath:
+            exported_namespace:
+            - metadata
+            - namespace
+            suspended:
+            - spec
+            - suspend
+          name: resource_info
+      - groupVersionKind:
+          group: notification.toolkit.fluxcd.io
+          kind: Receiver
+          version: v1
+        metricNamePrefix: gotk
+        metrics:
+        - each:
+            info:
+              labelsFromPath:
+                name:
+                - metadata
+                - name
+            type: Info
+          help: The current state of a GitOps Toolkit resource.
+          labelsFromPath:
+            exported_namespace:
+            - metadata
+            - namespace
+            ready:
+            - status
+            - conditions
+            - '[type=Ready]'
+            - status
+            suspended:
+            - spec
+            - suspend
+            webhook_path:
+            - status
+            - webhookPath
+          name: resource_info
+      - groupVersionKind:
+          group: image.toolkit.fluxcd.io
+          kind: ImageRepository
+          version: v1beta2
+        metricNamePrefix: gotk
+        metrics:
+        - each:
+            info:
+              labelsFromPath:
+                name:
+                - metadata
+                - name
+            type: Info
+          help: The current state of a GitOps Toolkit resource.
+          labelsFromPath:
+            exported_namespace:
+            - metadata
+            - namespace
+            image:
+            - spec
+            - image
+            ready:
+            - status
+            - conditions
+            - '[type=Ready]'
+            - status
+            suspended:
+            - spec
+            - suspend
+          name: resource_info
+      - groupVersionKind:
+          group: image.toolkit.fluxcd.io
+          kind: ImagePolicy
+          version: v1beta2
+        metricNamePrefix: gotk
+        metrics:
+        - each:
+            info:
+              labelsFromPath:
[Diff truncated by flux-local]

@jazzlyn jazzlyn merged commit 69c00ed into main Jan 30, 2024
13 checks passed
@jazzlyn jazzlyn deleted the feature/flux-add-metrics branch January 30, 2024 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant