diff --git a/charts/k8s-monitoring/Chart.lock b/charts/k8s-monitoring/Chart.lock index b2c2e2b5d7..9d111996b4 100644 --- a/charts/k8s-monitoring/Chart.lock +++ b/charts/k8s-monitoring/Chart.lock @@ -26,6 +26,9 @@ dependencies: - name: feature-pod-logs-via-kubernetes-api repository: "" version: 1.0.0 +- name: feature-kubernetes-manifests + repository: "" + version: 1.0.0 - name: feature-profiling repository: "" version: 1.0.0 @@ -38,5 +41,5 @@ dependencies: - name: alloy-operator repository: https://grafana.github.io/helm-charts version: 0.3.14 -digest: sha256:660387cc1740f69780420e72cdddd6eb497097901a524e5d5f20b8a59303e402 -generated: "2025-12-02T10:47:58.495-06:00" +digest: sha256:74d3926b919ff3580aecc7c990ca9b9e37b3a3d10a129cf61e3ba7deeaab6d6c +generated: "2025-12-02T14:05:13.070402-06:00" diff --git a/charts/k8s-monitoring/Chart.yaml b/charts/k8s-monitoring/Chart.yaml index a752c06d5b..10ea416cec 100644 --- a/charts/k8s-monitoring/Chart.yaml +++ b/charts/k8s-monitoring/Chart.yaml @@ -58,6 +58,11 @@ dependencies: repository: "" version: 1.0.0 condition: podLogsViaKubernetesApi.enabled + - alias: kubernetesManifests + name: feature-kubernetes-manifests + repository: "" + version: 1.0.0 + condition: kubernetesManifests.enabled - alias: profiling name: feature-profiling repository: "" diff --git a/charts/k8s-monitoring/README.md b/charts/k8s-monitoring/README.md index 746c967e2f..1da56c4b4b 100644 --- a/charts/k8s-monitoring/README.md +++ b/charts/k8s-monitoring/README.md @@ -248,6 +248,7 @@ details: | | clusterEvents(feature-cluster-events) | 1.0.0 | | | clusterMetrics(feature-cluster-metrics) | 1.0.0 | | | integrations(feature-integrations) | 1.0.0 | +| | kubernetesManifests(feature-kubernetes-manifests) | 1.0.0 | | | nodeLogs(feature-node-logs) | 1.0.0 | | | podLogs(feature-pod-logs) | 1.0.0 | | | podLogsViaKubernetesApi(feature-pod-logs-via-kubernetes-api) | 1.0.0 | @@ -393,6 +394,13 @@ details: | integrations | object | No integrations enabled | Service Integrations enables gathering telemetry data for common services and applications deployed to Kubernetes. To see the valid options, please see the [Service Integrations documentation](https://github.com/grafana/k8s-monitoring-helm/tree/main/charts/k8s-monitoring/charts/feature-integrations). | | integrations.destinations | list | `[]` | The destinations where integration metrics will be sent. If empty, all metrics-capable destinations will be used. | +### Features - Kubernetes Manifests + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| kubernetesManifests.destinations | list | `[]` | The destinations where logs will be sent. If empty, all logs-capable destinations will be used. | +| kubernetesManifests.enabled | bool | `false` | Enable gathering Kubernetes Manifests. | + ### Features - Node Logs | Key | Type | Default | Description | diff --git a/charts/k8s-monitoring/charts/feature-kubernetes-manifests/.helmignore b/charts/k8s-monitoring/charts/feature-kubernetes-manifests/.helmignore new file mode 100644 index 0000000000..2b29eaf564 --- /dev/null +++ b/charts/k8s-monitoring/charts/feature-kubernetes-manifests/.helmignore @@ -0,0 +1,6 @@ +docs +schema-mods +tests +Makefile +README.md +README.md.gotmpl diff --git a/charts/k8s-monitoring/charts/feature-kubernetes-manifests/Chart.lock b/charts/k8s-monitoring/charts/feature-kubernetes-manifests/Chart.lock new file mode 100644 index 0000000000..cc833191e5 --- /dev/null +++ b/charts/k8s-monitoring/charts/feature-kubernetes-manifests/Chart.lock @@ -0,0 +1,3 @@ +dependencies: [] +digest: sha256:643d5437104296e21d906ecb15b2c96ad278f20cfc4af53b12bb6069bd853726 +generated: "2024-08-28T15:09:37.347011-05:00" diff --git a/charts/k8s-monitoring/charts/feature-kubernetes-manifests/Chart.yaml b/charts/k8s-monitoring/charts/feature-kubernetes-manifests/Chart.yaml new file mode 100644 index 0000000000..7951325271 --- /dev/null +++ b/charts/k8s-monitoring/charts/feature-kubernetes-manifests/Chart.yaml @@ -0,0 +1,13 @@ +--- +apiVersion: v2 +name: feature-kubernetes-manifests +description: Kubernetes Observability feature for gathering Kubernetes manifests. +type: application +sources: + - https://github.com/grafana/k8s-monitoring-helm/tree/main/charts/k8s-monitoring/charts/feature-kubernetes-manifests +version: 1.0.0 +appVersion: 1.0.0 +maintainers: + - email: pete.wall@grafana.com + name: petewall +dependencies: [] diff --git a/charts/k8s-monitoring/charts/feature-kubernetes-manifests/Makefile b/charts/k8s-monitoring/charts/feature-kubernetes-manifests/Makefile new file mode 100644 index 0000000000..bd42e5f39b --- /dev/null +++ b/charts/k8s-monitoring/charts/feature-kubernetes-manifests/Makefile @@ -0,0 +1,51 @@ +HAS_HELM_UNITTEST := $(shell helm plugin list | grep unittest 2> /dev/null) + +.SECONDEXPANSION: +README.md: values.yaml Chart.yaml $$(wildcard README.md.gotmpl) + docker run --rm --platform linux/amd64 --volume $(shell pwd):/chart ghcr.io/grafana/helm-chart-toolbox-doc-generator --chart /chart > $@ + +Chart.lock: Chart.yaml + helm dependency update . + @touch Chart.lock # Ensure the timestamp is updated + +values.schema.json: values.yaml $$(wildcard schema-mods/*) + docker run --rm --platform linux/amd64 --volume $(shell pwd):/chart ghcr.io/grafana/helm-chart-toolbox-schema-generator --chart /chart > $@ + +.PHONY: clean +clean: + rm -f README.md values.schema.json + +.PHONY: build +build: README.md Chart.lock values.schema.json + +.PHONY: lint-shell +lint-shell: + @if command -v shellcheck &> /dev/null; then \ + shellcheck collect-manifests.sh; \ + else \ + docker run --rm -v $(shell pwd):/src --workdir /src koalaman/shellcheck:stable --rcfile .shellcheckrc templates/script.sh; \ + fi + +.PHONY: lint-helm +lint-helm: + helm lint . + ct lint --lint-conf ../../.lintconf.yaml --helm-dependency-extra-args=--skip-refresh --charts . + +.PHONY: lint +lint: lint-shell lint-helm + +.PHONY: test +test: build lint +ifdef HAS_HELM_UNITTEST + helm unittest . +else + docker run --rm --volume $(shell pwd):/apps helmunittest/helm-unittest:3.18.4-1.0.0 . +endif + +.PHONY: update-test-snapshots +update-test-snapshots: +ifdef HAS_HELM_UNITTEST + helm unittest . --update-snapshot +else + docker run --rm --volume $(shell pwd):/apps helmunittest/helm-unittest:3.18.4-1.0.0 . --update-snapshot +endif diff --git a/charts/k8s-monitoring/charts/feature-kubernetes-manifests/README.md b/charts/k8s-monitoring/charts/feature-kubernetes-manifests/README.md new file mode 100644 index 0000000000..6614de6050 --- /dev/null +++ b/charts/k8s-monitoring/charts/feature-kubernetes-manifests/README.md @@ -0,0 +1,64 @@ + + +# Feature: Kubernetes Manifests + +TODO + +## Usage + +```yaml +kubernetesManifests: + enabled: true + ... [values](#values) +``` + +## Testing + +This chart contains unit tests to verify the generated configuration. The hidden value `deployAsConfigMap` will render +the generated configuration into a ConfigMap object. While this ConfigMap is not used during regular operation, you can +use it to show the outcome of a given values file. + +The unit tests use this ConfigMap to create an object with the configuration that can be asserted against. To run the +tests, use `helm test`. + +Be sure perform actual integration testing in a live environment in the main [k8s-monitoring](../..) chart. + + +## Maintainers + +| Name | Email | Url | +| ---- | ------ | --- | +| petewall | | | + + + +## Source Code + +* + + + +## Values + +### Image + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| image | object | `{"digest":"","pullPolicy":"IfNotPresent","pullSecrets":[],"registry":"ghcr.io","repository":"grafana/helm-chart-toolbox-kubectl","tag":"0.1.3"}` | The image to run to get the Kubernetes manifests from this cluster. It must contain `kubectl` and `jq` at a minimum. | + +### General Settings + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| kinds | object | `{"cronjobs":{"gather":false},"daemonsets":{"gather":false},"deployments":{"gather":false},"pods":{"gather":false},"statefulsets":{"gather":false}}` | The kinds of manifests to gather. | +| namespaces | list | `[]` | Only gather manifests from these namespaces. If empty, gather from all. This affects the manifests gathered, but Also if this chart deploys ClusterRoles and ClusterRoleBindings or Roles and RoleBindings. | +| refreshInterval | string | `"1d"` | How frequently to refresh all manifests, regardless of if they have changed. At maximum, this should be set lower Than the retention period for your log storage. | + +### Other Values + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| global.image.registry | string | `""` | | diff --git a/charts/k8s-monitoring/charts/feature-kubernetes-manifests/README.md.gotmpl b/charts/k8s-monitoring/charts/feature-kubernetes-manifests/README.md.gotmpl new file mode 100644 index 0000000000..f9e27dbfb6 --- /dev/null +++ b/charts/k8s-monitoring/charts/feature-kubernetes-manifests/README.md.gotmpl @@ -0,0 +1,38 @@ + + +# Feature: Kubernetes Manifests + +TODO + +## Usage + +```yaml +kubernetesManifests: + enabled: true + ... [values](#values) +``` + +## Testing + +This chart contains unit tests to verify the generated configuration. The hidden value `deployAsConfigMap` will render +the generated configuration into a ConfigMap object. While this ConfigMap is not used during regular operation, you can +use it to show the outcome of a given values file. + +The unit tests use this ConfigMap to create an object with the configuration that can be asserted against. To run the +tests, use `helm test`. + +Be sure perform actual integration testing in a live environment in the main [k8s-monitoring](../..) chart. + + +{{ template "chart.maintainersSection" . }} + + + +{{ template "chart.sourcesSection" . }} + + +{{ template "chart.requirementsSection" . }} +{{ template "chart.valuesSection" . }} diff --git a/charts/k8s-monitoring/charts/feature-kubernetes-manifests/collect-manifests.sh b/charts/k8s-monitoring/charts/feature-kubernetes-manifests/collect-manifests.sh new file mode 100755 index 0000000000..ccee01cbd7 --- /dev/null +++ b/charts/k8s-monitoring/charts/feature-kubernetes-manifests/collect-manifests.sh @@ -0,0 +1,203 @@ +#!/bin/bash +set -o pipefail + +script_name="${0##*/}" +if [[ "${script_name}" == "bash" || "${script_name}" == "-bash" ]]; then + script_name="script.sh" +fi + +DefaultWatchTimeout=30s +ManifestRequestThrottling=0.1s +WatchRestartDelay=5 + +usage() { + echo "Usage: ${script_name} [OPTIONS]" + echo "" + echo "Collects Kubernetes manifests and saves them as files." + echo "" + echo "Resource manifests are stored at \${MANIFEST_DIR}///.json" + echo "" + echo "Requires the MANIFEST_DIR environment variable to be set to the target directory." + echo "" + echo "Options:" + echo " -k, --kind Kubernetes resource kind passed to \"kubectl get\"." + echo " Default: pods" + echo " -n, --namespace Namespace to scan. When omitted, all namespaces" + echo " are scanned." + echo " -f, --filters Comma or space separated list of jq selectors to drop" + echo " from the resource JSON. Default: \".status\"" + echo " --watch-timeout