This doc is used to introduce how to create an AddOn using Go template.
We have an example in helloworld.
- Need to import templates files into embed.FS.
- Create and start templateAgentAddon instance like this:
mgr, err := addonmanager.New(controllerContext.KubeConfig) if err != nil { return err } agentAddon, err := addonfactory.NewAgentAddonFactory(addonName, FS, "manifests/templates"). WithGetValuesFuncs(getValues, addonfactory.GetValuesFromAddonAnnotation). WithAgentRegistrationOption(registrationOption). BuildTemplateAgentAddon() if err != nil { return err } mgr.AddAgent(agentAddon) mgr.Start(ctx)
We also name the config for the template as Values.
AddOn built-in values
ClusterNameAddonInstallNamespaceHubKubeConfigSecret(used when the AddOn is needed to register to the Hub cluster)
In the list of GetValuesFuncs, the values from the big index Func will override the one from low index Func.
The built-in Values will override the Values got from the list of GetValuesFuncs.
The config variable names should begin with uppercase. We can use StructToValues to convert config struct to Values.
We support a helper GetValuesFunc named GetValuesFromAddonAnnotation which can get values from annotation of ManagedClusterAddon.
The key of Values in annotation is addon.open-cluster-management.io/values,
and the value should be a valid json string which has key-value format.