Config Template

The config template is defined with CUE language. To describe the config parameter, storage structure and extension features. His rendering works similarly to the Definition.

  1. Create multiple configs with the same type. Such as the Image Registry and the Helm Repository.
  2. Define certain parameters and check the validity.
  3. Write the config to the Nacos server. Reference
  4. Render and generate the Secret or Other resources by the parameters. Such as the Grafana template.
  5. Need to classify the configs and list them.

There are many Out-of-Box templates you could refer to.

More templates let’s find in the addon catalog.

A sample template should include sections:

  • metadata(Required)
  1. metadata: {
  2. name: "terraform-alibaba"
  3. alias: "Terraform Provider for Alibaba Cloud"
  4. sensitive: true
  5. scope: "system"
  6. description: "Terraform Provider for Alibaba Cloud"
  7. }

Define the base info for this template.

  • template.parameter(Required)
  1. template: {
  2. parameter: {
  3. //+usage=The name of Terraform Provider for Alibaba Cloud, default is `default`
  4. name: *"default" | string
  5. //+usage=Get ALICLOUD_ACCESS_KEY per this guide https://help.aliyun.com/knowledge_detail/38738.html
  6. ALICLOUD_ACCESS_KEY: string
  7. //+usage=Get ALICLOUD_SECRET_KEY per this guide https://help.aliyun.com/knowledge_detail/38738.html
  8. ALICLOUD_SECRET_KEY: string
  9. //+usage=Get ALICLOUD_REGION by picking one RegionId from Alibaba Cloud region list https://www.alibabacloud.com/help/doc-detail/72379.htm
  10. ALICLOUD_REGION: string
  11. }
  12. }
  • template.output
  1. output: {
  2. apiVersion: "v1"
  3. kind: "Secret"
  4. metadata: {
  5. name: context.name
  6. namespace: context.namespace
  7. }
  8. type: "Opaque"
  9. stringData: credentials: strings.Join([creds1, creds2], "\n")
  10. }

This section is not required, If you want to specify, it must be a Secret.

  • template.outputs
  1. outputs: {
  2. "grafana": {
  3. apiVersion: "o11y.prism.oam.dev/v1alpha1"
  4. kind: "Grafana"
  5. metadata: {
  6. name: context.name
  7. }
  8. spec: {
  9. endpoint: parameter.endpoint
  10. if parameter.auth != _|_ {
  11. access: {
  12. if parameter.auth.username != _|_ && parameter.auth.password != _|_ {
  13. username: parameter.auth.username
  14. password: parameter.auth.password
  15. }
  16. if parameter.auth.token != _|_ {
  17. token: parameter.auth.token
  18. }
  19. }
  20. }
  21. }
  22. }
  23. }

This section defines the output resources other than Secret. They will be created after the config is created and deleted after the config is deleted.

  • template.nacos
  1. nacos: {
  2. // The endpoint can not references the parameter.
  3. endpoint: {
  4. // Users must create a config base the nacos-server template firstly.
  5. name: "nacos"
  6. }
  7. format: parameter.contentType
  8. // could references the parameter
  9. metadata: {
  10. dataId: parameter.dataId
  11. group: parameter.group
  12. if parameter.appName != _|_ {
  13. appName: parameter.appName
  14. }
  15. if parameter.namespaceId != _|_ {
  16. namespaceId: parameter.namespaceId
  17. }
  18. if parameter.tenant != _|_ {
  19. tenant: parameter.tenant
  20. }
  21. if parameter.tag != _|_ {
  22. tag: parameter.tag
  23. }
  24. }
  25. content: parameter.content
  26. }

This section is not required if you don’t want to create a Nacos config template.

  1. Create or update a template
  1. vela config-template apply -f template.cue
  1. Show the parameters of the template
  1. vela config-template show <Template Name>

We could copy the cue script to others. But, The addon is a common carrier to share the user-friendly config templates to more community users.

This is an example:

  1. ├── config-templates
  2. ├── image-registry.cue
  3. ├── nacos-config.cue
  4. └── nacos-server.cue
  5. ├── metadata.yaml
  6. ├── parameter.cue
  7. ├── readme.md
  8. ├── readme_cn.md
  9. ├── resources
  10. ├── apiserver.cue
  11. └── velaux.cue

When installing this addon, the templates will be applied to the hub cluster.

Last updated on Aug 4, 2023 by Daniel Higuero