This Go application parses the output of a helm template
or kubectl kustomize
command and extracts resource information, generating a CSV file with the extracted data.
- Go (version 1.17 or later)
- Helm (version 3 or later) (if using Helm)
- kubectl (if using Kustomize)
-
Install Go dependencies:
go mod init metrics go mod tidy
-
Save the code to a file:
Save the provided Go code to a file named
resource_extractor.go
.
-
Prepare your source:
-
For Helm: Use
helm pull
to download a Helm chart. For example, to download the Prometheus chart:helm pull prometheus-community/prometheus --untar
-
For Kustomize: Ensure you have a Kustomize directory ready.
-
-
Run the application:
Run the application with the source path and type as arguments:
go run resource_extractor.go --source <path-to-source> --type <helm|kustomize>
Replace
<path-to-source>
with the path to your Helm chart or Kustomize directory, and<helm|kustomize>
with the appropriate type. For example:go run resource_extractor.go --source prometheus --type helm
The application will parse the output for the specified source and create a CSV file with the extracted resources and volume claim templates. The CSV file will be named
<source-name>.csv
. -
Check the generated CSV file:
After running the application, you should see a CSV file named
<source-name>.csv
in the current directory. This file contains the extracted resource information.
-
Create a directory for the Helm chart:
mkdir -p my-charts cd my-charts
-
Pull the Prometheus Helm chart:
helm pull prometheus-community/prometheus --untar
-
Run the application:
go run ../resource_extractor.go --source prometheus --type helm
-
Check the generated CSV file:
ls prometheus.csv
To build the application and place it in a bin
directory for easier use:
-
Build the application:
go build -o bin/resource_extractor resource_extractor.go
-
Add the
bin
directory to your PATH:export PATH=$PATH:$(pwd)/bin
-
Run the application:
resource_extractor --source prometheus --type helm
This will allow you to run the application from anywhere without needing to specify the full path to the Go file.