helm

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

README

helm

Helm is a go wrapper package which is meant to aid in the conversion of Helm Templates to Ansible Playbook Role(s). There are two main pieces of functionality included in this internal package:

  1. convert.go
  2. helmfuncs.go

convert.go

Contains the utility functions to convert from Helm -> Ansible Playbook Role.

helmfuncs.go

Helm abstracts custom Template functions in its parser (namely define, include, & Sprig functions), yet doesn't make the funcMap public. For more information see the Helm Engine funcMap abstraction.

That means that the functionality they add, which is quite useful, is not readily extendable through a Go client, since a normal Go client doesn't have the visibility to call non-exported module functions. Although this can be done through reflection (and probably should be done this way at some point), it was much easier to just copy in the functionality for now. Since the license is Apache License 2.0, and since we did not alter any copyright, this should be fine.

This file was modified slightly only to change the package name, and to export the "HelmFuncMap" function for use in other files.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HelmChartRef string

HelmChartRef is a global variable. This is not ideal, but it is necessary in this case in order to avoid a circular dependency issue. Essentially, the cmd package is originally responsible for determining the HelmChartRef via CLI interactions. This package cannot depend on the "cmd" package, as it would cause a circular dependency. The cmd package depends on our forked "text/template", and our "text/template" depends on the "helm" package. Thus, "helm" cannot depend on "cmd". This is a language limitation, and there may be more elegant ways to solve this in the future, but utilizing a global works for now, although it is ugly. "cmd" is instructed to set this global variable for later use.

Functions

func ArgIsLikelyBooleanYamlValue

func ArgIsLikelyBooleanYamlValue(arg string) (bool, error)

A heuristic to determine whether a given input argument is likely a boolean value. This is done through inspecting the charts Values. For example, say we have an arbitrary argument in a conditional "metrics". This function inspects the values file for the "metrics" definition. If metrics looks like the following: metrics: true or metrics: false then metrics is likely a boolean (i.e., its value is a boolean value). Otherwise, it is likely not a boolean.

func GetBasePathConfig

func GetBasePathConfig() (*pathconfig.PathConfig, error)

GetBasePathConfig ....

func GetValues

func GetValues(arg string) (*map[string][]*LogHelmReport, error)

GetValues takes a path that traverses a values that are stores in Values map and returns the value at the end of that path. Given the following data the value at path "chapter.one.title" is "PR Review".

chapter:
  one:
    title: "PR Review"

func IsBooleanYamlValue

func IsBooleanYamlValue(input *map[string]interface{}, path *[]string) (bool, error)

Determines whether path within the input context refers to a boolean type. Consulting a Helm Chart's values is helpful for determining whether a Helm Chart template conditional is checking for boolean equality v.s. definition.

func PreFixValuesWithItems

func PreFixValuesWithItems(sb *strings.Builder, itemField string, pathValues *map[string][]*LogHelmReport)

PreFixValuesWithItems...For single item list {% for item in hosts %}{{ item.name }}{% endfor %}, This function will prefix the list variables with a loop variable, within the body of the for loop. There is two cases , one with field name that needs to be prefixed with loop variables other condition is dot field name is replaced by loop variable

func PrintReportItems

func PrintReportItems(reports []*LogHelmReport)

LogReports - Printing report struct

func RemoveDollarPrefix

func RemoveDollarPrefix(sb *strings.Builder)

Remove $ from loop variables and body of the loop

Types

type HelmChartClient

type HelmChartClient struct {
	Chart      *chart.Chart
	ChartName  string
	PathConfig *pathconfig.PathConfig
}

HelmChartClient ....

func NewChartClient

func NewChartClient() *HelmChartClient

NewChartClient creates a new chart client

func (*HelmChartClient) LoadChartFrom

func (hc *HelmChartClient) LoadChartFrom(chartPath string) (err error)

LoadChart uses the chart client's values to retrieve the appropriate chart

type LogHelmReport

type LogHelmReport struct {
	Name         string
	NewLine      string
	OriginalLine string
	FieldName    string
	Action       string
	LineNumber   int
}

LogHelmReport - Collect Log data and print

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL