helmify

repository·main·Indexed 23 days ago

https://github.com/arttor/helmify

A CLI tool that converts Kubernetes manifests and Kustomize output into Helm charts. It is specifically designed to simplify packaging Kubernetes operators built with Operator-SDK or Kubebuilder. Helmify supports a wide range of resources including Workloads, Networking, Storage, RBAC, Configuration, Webhooks, and CRDs.

Tokens
2.2K
Snippets
6
Records
14
Agent score
81%

What's inside helmify

  1. Supported Kubernetes resources

    main

    Helmify supports the following Kubernetes resource types:

    • Workloads: Deployment, DaemonSet, StatefulSet, Job, CronJob
    • Networking: Service, Ingress
    • Storage: PersistentVolumeClaim
    • RBAC: ServiceAccount, Role, ClusterRole, RoleBinding, ClusterRoleBinding
    • Configuration: ConfigMap, Secret
    • Webhooks: Certificate, Issuer, ValidatingWebhookConfiguration
    • CRDs: CustomResourceDefinition
  2. Integrate Helmify into Operator-SDK or Kubebuilder projects

    main

    To automate Helm chart generation within an Operator-SDK or Kubebuilder project, modify your Makefile to include Helmify in the helm target.

    For Operator-SDK < v1.23.0

    Add these lines to your Makefile:

    HELMIFY = $(shell pwd)/bin/helmify
    helmify:
    	$(call go-get-tool,$(HELMIFY),github.com/arttor/helmify/cmd/helmify@v0.3.7)
    
    helm: manifests kustomize helmify
    	$(KUSTOMIZE) build config/default | $(HELMIFY)

    For Operator-SDK >= v1.23.0

    Add these lines to your Makefile:

    HELMIFY ?= $(LOCALBIN)/helmify
    
    .PHONY: helmify
    helmify: $(HELMIFY) ## Download helmify locally if necessary.
    $(HELMIFY): $(LOCALBIN)
    	test -s $(LOCALBIN)/helmify || GOBIN=$(LOCALBIN) go install github.com/arttor/helmify/cmd/helmify@latest
            
    helm: manifests kustomize helmify
    	$(KUSTOMIZE) build config/default | $(HELMIFY)

    After updating the Makefile, run make helm in the project root. This will generate a Helm chart named chart in the chart directory.

    make helm
  3. How to implement a new Kubernetes object template

    main

    To add support for a new type of Kubernetes object in Helmify, follow these steps:

    1. Implement the helmify.Processor interface. Place your implementation in the pkg/processor package.
    2. Register your new processor in pkg/app/app.go.
    3. Add a relevant input sample to test_data/kustomize.output to ensure it is processed correctly.
  4. Install Helmify

    main

    You can install Helmify using Homebrew on macOS or Linux, or by downloading the binary directly from the GitHub Releases page.

    Homebrew:

    brew install arttor/tap/helmify

    Manual Installation:

    1. Download the suitable binary for your system from the Releases page.
    2. Unpack the binary.
    3. Add the binary to your PATH.
    brew install arttor/tap/helmify
  5. Use Helmify via CLI

    main

    Helmify converts Kubernetes manifests into Helm charts. It accepts a CHART_NAME as an optional argument (defaults to chart). You can provide manifests via stdin (piping) or via the -f flag.

    Using Pipes (stdin)

    # From a single file
    cat my-app.yaml | helmify mychart
    
    # From all yaml files in a directory
    awk 'FNR==1 && NR!=1  {print "---"}{print}' /<my_directory>/*.yaml | helmify mychart
    
    # From Kustomize output
    kustomize build <kustomize_dir> | helmify mychart

    Using Filesystem Flags

    # Single file
    helmify -f /my_directory/my-app.yaml mychart
    
    # Entire directory
    helmify -f /my_directory mychart
    
    # Recursive directory scan
    helmify -f /my_directory -r mychart
    
    # Multiple sources (files and directories)
    helmify -f ./first_dir -f ./second_dir/my_deployment.yaml -f ./third_dir mychart
    cat my-app.yaml | helmify mychart
  6. Configure CRD installation in Helmify

    main

    Helmify provides two mutually exclusive ways to handle Custom Resource Definitions (CRDs). You cannot use --crd-dir and --optional-crds at the same time.

    1. Using the crds/ directory: Use --crd-dir. This places CRDs into a crds directory within the chart.
      • Note: Helm does not template files in the crds/ directory. This is recommended for following Helm best practices for CRDs.
    2. Using optional CRDs via values: Use --optional-crds. This enables optional CRD installation through the values.yaml file.
  7. Usage and examples of the helmify CLI

    main

    Helmify converts Kubernetes resources from standard input (stdin) or specified files/directories into a Helm chart.

    Basic Usage: helmify [flags] CHART_NAME

    • CHART_NAME is optional. If omitted, the default is chart.
    • CHART_NAME can be a path, e.g., deploy/charts/mychart.
  8. Generate a Helm chart for a Kubernetes Operator

    main

    You can use helmify to convert the output of tools like Operator-SDK or Kubebuilder (e.g., Kustomize outputs) into a Helm chart. This is useful for packaging operators for distribution via Helm.

    To generate a chart from a Kustomize output file, pipe the content into the helmify command followed by the desired output directory.

    cat test_data/k8s-operator-kustomize.output | go run ./cmd/helmify examples/operator
  9. Generate a Helm chart for a typical Kubernetes application

    main

    You can use helmify to convert standard Kubernetes manifests (containing Deployments, Services, ConfigMaps, Secrets, etc.) into a Helm chart.

    To generate a chart from a YAML file, pipe the file content into the helmify command followed by the desired output directory.

    cat test_data/sample-app.yaml | go run ./cmd/helmify examples/app
  10. Reference Helmify CLI options

    main

    Helmify provides several flags to customize the generated chart and how manifests are processed.

    flagdescriptionsample
    -h, --helpPrints helphelmify -h
    -fFile source for k8s manifests (directory or file), multiple sources supportedhelmify -f ./test_data
    -rScan file directory recursively. Used only if -f providedhelmify -f ./test_data -r
    -vEnable verbose output. Prints WARN and INFOhelmify -v
    -vvEnable very verbose output. Also prints DEBUGhelmify -vv
    --versionPrint helmify versionhelmify --version
    --crd-dirPlace CRDs in their own folder per Helm 3 docs. Note: CRD templating is not supported by Helmhelmify --crd-dir
    --image-pull-secretsAllows the user to use existing secrets as imagePullSecretshelmify --image-pull-secrets
    --original-nameUse the object's original name instead of adding the chart's release name as a common prefixhelmify --original-name
    --cert-manager-as-subchartInstalls cert-manager as a subcharthelmify --cert-manager-as-subchart
    --cert-manager-versionSpecify cert-manager subchart version (default v1.12.2)helmify --cert-manager-version=v1.12.2
    --cert-manager-install-crdInstall cert-manager CRD as part of the subchart (default true)helmify --cert-manager-install-crd
    --preserve-nsUse the object's original namespace instead of a common namespace (default false)helmify --preserve-ns
    --add-webhook-optionAdds an option to enable/disable webhook installation
    --optional-crdsEnable optional CRD installation through values
  11. Run the Helmify process with Start()

    main

    The Start function is the primary application entrypoint used to process Kubernetes resource inputs into a Helm chart. It accepts an io.Reader for input (such as os.Stdin) and a config.Config object.

    Key behaviors:

    • Validation: It validates the provided configuration before proceeding.
    • Logging: It sets the log level based on the Verbose and VeryVerbose flags in the configuration.
    • Input Handling: If config.Files is populated, it walks through those files. If config.Files is empty, it reads from the provided stdin reader.
    • Processing: It initializes a suite of built-in processors for various Kubernetes resources (e.g., Deployment, Service, Secret, RBAC, Webhook, etc.) and executes the Helm chart creation.
    • Signal Handling: It listens for os.Interrupt, syscall.SIGINT, and syscall.SIGTERM to allow for graceful shutdown.
    package app
    
    import (
    	"io"
    	"github.com/arttor/helmify/pkg/config"
    )
    
    // Start - application entrypoint for processing input to a Helm chart.
    func Start(stdin io.Reader, config config.Config) error {
        // ... implementation
    }