Helm Generator
Sometimes it is desired to write a component operator (using component-operator-runtime) for some cluster component, which already has a productive Helm chart. Then it can make sense to use the HelmGenerator implementation of the Generator interface included in this module:
package helm
func NewHelmGenerator(
fsys fs.FS,
chartPath string,
clnt client.Client,
) (*HelmGenerator, error)
Here:
fsysmust be an implementation offs.FS, such asembed.FS; or it can be passed as nil; then, all file operations will be executed on the current OS filesystem.chartPathis the directory containing the used Helm chart; iffsyswas provided, this has to be a relative path; otherwise, it will be interpreted with respect to the OS filesystem (as an absolute path, or relative to the current working directory of the controller).clntshould be a client for the local cluster (i.e. the cluster where the component object exists).
It should be noted that HelmGenerator does not use the Helm SDK; instead it tries to emulate the Helm behavior as good as possible.
A few differences and restrictions arise from this:
Not all Helm template functions are supported. To be exact,
toTomlis not supported; all other functions should be supported, but may behave more strictly in error situtations.Not all builtin variables are supported; the following restrictions apply:
- the
.Releasebuiltin is supported; note thatRelease.IsInstallis set totrueduring the first reconcile iteration of the component (precisely, ifstatus.revisionequals 1), andRelease.IsUpgradeis set to the inverse ofRelease.IsInstall; also note thatRelease.Revisionincreases whenever the component manifest, or one of its references (such as referenced secrets) changes - for the
.Chartbuiltin, only.Chart.Name,.Chart.Version,.Chart.Type,.Chart.AppVersion,.Chart.Dependenciesare supported - for the
.Capabilitiesbuiltin, only.Capabilities.KubeVersionand.Capabilities.APIVersionsare supported - the
.Templatebuiltin is fully supported - the
.Filesbuiltin is supported but does not return any of the paths reserved by Helm (such asChart.yaml,templates/and so on).
- the
Regarding hooks,
pre-deleteandpost-deletehooks are not allowed; test and rollback hooks are ignored, andpre-install,post-install,pre-upgrade,post-upgradehooks might be handled in a sligthly different way:- install hooks added later to objects of an already installed release are applied with the next reconcile, although this is not the ‘install’ case (i.e.
status.revisionnot equal to 1) - objects using
pre-install,post-installorpre-ugprade,post-upgradeare applied only once per reconcile (early), and, if the deletion policyhook-succeededis set, are deleted late - obsolete hook objects (that is, objects created by a hook, which are no longer part of the manifest) are deleted immediately, unless they have
helm.sh/resource-policy: keep; note that in this case, they will not be deleted at all, even if the component is finally deleted.
Hook weights will be handled in a compatible way; hook deletion policy
hook-failedis not allowed, butbefore-hook-creationandhook-succeededshould work as expected.- install hooks added later to objects of an already installed release are applied with the next reconcile, although this is not the ‘install’ case (i.e.
The
.helmignorefile is currently not evaluated; in particular, files can be accessed through.Filesaltough they are listed in.helmignore.