fleet.yaml

The fleet.yaml file adds options to a bundle. Any directory with a fleet.yaml is automatically turned into bundle.

For more information on how to use the fleet.yaml to customize bundles see Git Repository Contents.

The content of the fleet.yaml corresponds to the FleetYAML struct at pkg/apis/fleet.cattle.io/v1alpha1/fleetyaml.go, which contains the BundleSpec.

Reference

Full YAML reference

fleet.yaml

  1. # The default namespace to be applied to resources. This field is not used to
  2. # enforce or lock down the deployment to a specific namespace, but instead
  3. # provide the default value of the namespace field if one is not specified in
  4. # the manifests.
  5. #
  6. # Default: default
  7. defaultNamespace: default
  8. # All resources will be assigned to this namespace and if any cluster scoped
  9. # resource exists the deployment will fail.
  10. #
  11. # Default: ""
  12. namespace: default
  13. # namespaceLabels are labels that will be appended to the namespace created by
  14. # Fleet.
  15. namespaceLabels:
  16. key: value
  17. # namespaceAnnotations are annotations that will be appended to the namespace
  18. # created by Fleet.
  19. namespaceAnnotations:
  20. key: value
  21. # Optional map of labels, that are set at the bundle and can be used in a
  22. # dependsOn.selector
  23. labels:
  24. key: value
  25. kustomize:
  26. # Use a custom folder for kustomize resources. This folder must contain a
  27. # kustomization.yaml file.
  28. dir: ./kustomize
  29. helm:
  30. # These options control how "fleet apply" downloads the chart
  31. # (See `Helm Options` below for more details)
  32. #
  33. chart: ./chart
  34. # A https URL to a Helm repo to download the chart from. It's typically easier
  35. # to just use `chart` field and refer to a tgz file. If repo is used the
  36. # value of `chart` will be used as the chart name to lookup in the Helm
  37. # repository.
  38. repo: https://charts.rancher.io
  39. # The version of the chart or semver constraint of the chart to find. If a
  40. # constraint is specified, it is evaluated each time git changes.
  41. # (See `Helm Options` below for more details)
  42. version: 0.1.0
  43. # By default fleet downloads any dependency found in a helm chart. Use
  44. # disableDependencyUpdate: true to disable this feature.
  45. disableDependencyUpdate: false
  46. ### These options only work for helm-type bundles.
  47. #
  48. # Any values that should be placed in the `values.yaml` and passed to helm
  49. # during install.
  50. values:
  51. any-custom: value
  52. # All labels on Rancher clusters are available using
  53. # global.fleet.clusterLabels.LABELNAME These can now be accessed directly as
  54. # variables The variable's value will be an empty string if the referenced
  55. # cluster label does not exist on the targeted cluster.
  56. variableName: global.fleet.clusterLabels.LABELNAME
  57. # See Templating notes below for more information on templating.
  58. templatedLabel: "${ .ClusterLabels.LABELNAME }-foo"
  59. valueFromEnv:
  60. "${ .ClusterLabels.ENV }": ${ .ClusterValues.someValue | upper | quote }
  61. # Path to any values files that need to be passed to helm during install.
  62. valuesFiles:
  63. - values1.yaml
  64. - values2.yaml
  65. # Allow to use values files from configmaps or secrets defined in the
  66. # downstream clusters.
  67. valuesFrom:
  68. - configMapKeyRef:
  69. name: configmap-values
  70. # default to namespace of bundle
  71. namespace: default
  72. key: values.yaml
  73. - secretKeyRef:
  74. name: secret-values
  75. namespace: default
  76. key: values.yaml
  77. ### These options control how fleet-agent deploys the bundle, they also apply
  78. ### for kustomize- and manifest-style bundles.
  79. #
  80. # A custom release name to deploy the chart as. If not specified a release name
  81. # will be generated by combining the invoking GitRepo.name + GitRepo.path.
  82. releaseName: my-release
  83. #
  84. # Makes helm skip the check for its own annotations
  85. takeOwnership: false
  86. #
  87. # Override immutable resources. This could be dangerous.
  88. force: false
  89. #
  90. # Set the Helm --atomic flag when upgrading
  91. atomic: false
  92. #
  93. # Disable go template pre-processing on the fleet values
  94. disablePreProcess: false
  95. #
  96. # Disable DNS resolution in Helm's template functions
  97. disableDNS: false
  98. #
  99. # Skip evaluation of the values.schema.json file
  100. skipSchemaValidation: false
  101. #
  102. # If set and timeoutSeconds provided, will wait until all Jobs have been
  103. # completed before marking the GitRepo as ready. It will wait for as long as
  104. # timeoutSeconds.
  105. waitForJobs: true
  106. # A paused bundle will not update downstream clusters but instead mark the bundle
  107. # as OutOfSync. One can then manually confirm that a bundle should be deployed to
  108. # the downstream clusters.
  109. #
  110. # Default: false
  111. paused: false
  112. # If rolloutStrategy is not defined in the fleet.yaml file, Fleet uses default rollout values.
  113. rolloutStrategy:
  114. # A number or percentage of clusters that can be unavailable during an update
  115. # of a bundle. This follows the same basic approach as a deployment rollout
  116. # strategy. Once the number of clusters meets unavailable state update will be
  117. # paused. Default value is 100% which doesn't take effect on update.
  118. #
  119. # default: 100%
  120. maxUnavailable: 15%
  121. # A number or percentage of cluster partitions that can be unavailable during
  122. # an update of a bundle.
  123. #
  124. # default: 0
  125. maxUnavailablePartitions: 20%
  126. # A number or percentage of how to automatically partition clusters if not
  127. # specific partitioning strategy is configured.
  128. # The default value is defined in rolloutStrategy.maxUnavailable
  129. autoPartitionSize: 10%
  130. # A list of definitions of partitions. If any target clusters do not match
  131. # the configuration they are added to partitions at the end following the
  132. # autoPartitionSize.
  133. partitions:
  134. # A user friend name given to the partition used for Display (optional).
  135. # default: ""
  136. - name: canary
  137. # A number or percentage of clusters that can be unavailable in this
  138. # partition before this partition is treated as done.
  139. # default: 10%
  140. maxUnavailable: 10%
  141. # Selector matching cluster labels to include in this partition
  142. clusterSelector:
  143. matchLabels:
  144. env: prod
  145. # OR, if selecting by ClusterGroup labels:
  146. clusterGroupSelector:
  147. matchLabels:
  148. env: prod
  149. # A cluster group name to include in this partition
  150. clusterGroup: agroup
  151. # Target customization are used to determine how resources should be modified
  152. # per target Targets are evaluated in order and the first one to match a cluster
  153. # is used for that cluster.
  154. targetCustomizations:
  155. # The name of target. If not specified a default name of the format
  156. # "target000" will be used. This value is mostly for display
  157. - name: prod
  158. # Custom namespace value overriding the value at the root.
  159. namespace: newvalue
  160. # Custom defaultNamespace value overriding the value at the root.
  161. defaultNamespace: newdefaultvalue
  162. # Custom kustomize options overriding the options at the root.
  163. kustomize: {}
  164. # Custom Helm options override the options at the root.
  165. helm: {}
  166. # If using raw YAML these are names that map to overlays/{name} that will be
  167. # used to replace or patch a resource. If you wish to customize the file
  168. # ./subdir/resource.yaml then a file
  169. # ./overlays/myoverlay/subdir/resource.yaml will replace the base file. A
  170. # file named ./overlays/myoverlay/subdir/resource_patch.yaml will patch the
  171. # base file. A patch can in JSON Patch or JSON Merge format or a strategic
  172. # merge patch for builtin Kubernetes types. Refer to "Raw YAML Resource
  173. # Customization" below for more information.
  174. yaml:
  175. overlays:
  176. - custom2
  177. - custom3
  178. # A selector used to match clusters. The structure is the standard
  179. # metav1.LabelSelector format. If clusterGroupSelector or clusterGroup is
  180. # specified, clusterSelector will be used only to further refine the
  181. # selection after clusterGroupSelector and clusterGroup is evaluated.
  182. clusterSelector:
  183. matchLabels:
  184. env: prod
  185. # A selector used to match a specific cluster by name. When using Fleet in
  186. # Rancher, make sure to put the name of the clusters.fleet.cattle.io
  187. # resource.
  188. clusterName: dev-cluster
  189. # A selector used to match cluster groups.
  190. clusterGroupSelector:
  191. matchLabels:
  192. region: us-east
  193. # A specific clusterGroup by name that will be selected.
  194. clusterGroup: group1
  195. # Resources will not be deployed in the matched clusters if doNotDeploy is
  196. # true.
  197. doNotDeploy: false
  198. # Drift correction removes any external change made to resources managed by
  199. # Fleet. It performs a helm rollback, which uses a three-way merge strategy
  200. # by default. It will try to update all resources by doing a PUT request if
  201. # force is enabled. Three-way strategic merge might fail when updating an
  202. # item inside of an array as it will try to add a new item instead of
  203. # replacing the existing one. This can be fixed by using force. Keep in
  204. # mind that resources might be recreated if force is enabled. Failed
  205. # rollback will be removed from the helm history unless keepFailHistory is
  206. # set to true.
  207. correctDrift:
  208. enabled: false
  209. force: false # Warning: it might recreate resources if set to true
  210. keepFailHistory: false
  211. # dependsOn allows you to configure dependencies to other bundles. The current
  212. # bundle will only be deployed, after all dependencies are deployed and in a
  213. # Ready state.
  214. dependsOn:
  215. # Format:
  216. # <GITREPO-NAME>-<BUNDLE_PATH> with all path separators replaced by "-"
  217. #
  218. # Example:
  219. #
  220. # GitRepo name "one", Bundle path "/multi-cluster/hello-world"
  221. # results in "one-multi-cluster-hello-world".
  222. #
  223. # Note:
  224. #
  225. # Bundle names are limited to 53 characters long. If longer they will be
  226. # shortened:
  227. #
  228. # opni-fleet-examples-fleets-opni-ui-plugin-operator-crd becomes
  229. # opni-fleet-examples-fleets-opni-ui-plugin-opera-021f7
  230. - name: one-multi-cluster-hello-world
  231. # Select bundles to depend on based on their label.
  232. - selector:
  233. matchLabels:
  234. app: weak-monkey
  235. # Ignore fields when monitoring a Bundle. This can be used when Fleet thinks
  236. # some conditions in Custom Resources makes the Bundle to be in an error state
  237. # when it shouldn't.
  238. ignore:
  239. # Conditions to be ignored
  240. conditions:
  241. # In this example a condition will be ignored if it contains
  242. # {"type": "Active", "status", "False"}
  243. - type: Active
  244. status: "False"
  245. # Override targets defined in the GitRepo. The Bundle will not have any targets
  246. # from the GitRepo if overrideTargets is provided.
  247. overrideTargets:
  248. - clusterSelector:
  249. matchLabels:
  250. env: dev

Helm Options

Main options

chart

This specifies a custom location for the Helm chart. This can refer to any go-getter URL or OCI registry based Helm chart URL, e.g. oci://ghcr.io/fleetrepoci/guestbook. This allows one to download charts from many different locations. go-getter URLs support adding a digest to validate the download. If the repo field is set, this field is the name of the chart to lookup.

It is possible to download the chart from a Git repository, e.g. by using [[email protected]](https://fleet.rancher.io/cdn-cgi/l/email-protection):rancher/fleet-examples//single-cluster/helm. If a secret for the SSH key was defined in the GitRepo via helmSecretName, it will be injected into the chart URL.

fleet.yaml - 图1chart reference depending on fleet.yaml location

If a fleet.yaml file is located outside of an embedded chart’s directory, then it must explicitly reference the chart using a helm.chart field. Otherwise, Fleet will not install the chart.

This also means that if no helm.chart field is specified in such a case, then Helm-specific fields like valuesFiles or valuesFrom will not have any effect.

It is not necessary to specify a chart’s own values.yaml via valuesFiles:. It will always be used as a default when the agent installs the chart. See Using Helm Values.

See Using Helm Values for more details.

fleet.yaml - 图2note

fleet.yaml - 图3Limitation: downloading Helm charts from git with custom CA bundles

Git repositories can be downloaded via unauthenticated http, by using for example: git::http://github.com/rancher/fleet-examples/single-cluster/helm.

However, this does not work with custom CA bundles at this point: if a CA bundle is configured in a secret referenced in helmSecretName, will not be used, which will result in the git job displaying errors such as SSL certificate problem: unable to get local issuer certificate when running fleet apply to generate a bundle.

See fleet#3646 for more details.

version

The version also determines which chart to download from OCI registries.

fleet.yaml - 图4+ character support

OCI registries don’t support the + character, which is supported by semver. When pushing a Helm chart with a tag containing the + character, Helm automatically replaces + with ‘_‘ before uploading it.

You should use the version with the + in fleet.yaml, as the _ character is not supported by semver and Fleet also replaces + with _ when accessing the OCI registry.

How fleet-agent deploys the bundle

These options also apply to kustomize- and manifest-style bundles. They control how the fleet-agent deploys the bundle. All bundles are converted into Helm charts and deployed with the Helm SDK. These options are often similar to the Helm CLI options for install and update.

  • releaseName
  • takeOwnership
  • force
  • atomic
  • disablePreProcess
  • disableDNS
  • skipSchemaValidation
  • waitForJobs

Helm Chart Download Options

These options are for Helm-style bundles, they specify how to download the chart.

  • chart
  • repo
  • version

The reference to the chart can be either:

  • a local path in the cloned Git repository, specified by chart.
  • a go-getter URL, specified by chart. This can be used to download a tarball of the chart. go-getter also allows to download a chart from a Git repo.
  • OCI chart URL, specified by chart. This can be used to download a chart directly from a OCI server. It uses the Helm SDK to download the chart.
  • a Helm repository, specified by repo and optionally version.
  • an OCI Helm repository, specified by repo and optionally version.

Helm Chart Value Options

Options for the downloaded Helm chart.

  • values
  • valuesFiles
  • valueFrom

Values

Values are processed in different stages of the Bundle lifecycle

  • fleet.yaml values: and valuesFile: are added to the bundle’s values when it is created.
  • helm values templating, e.g. with ${ } happens when the bundle is targeted at a cluster, cluster labels filled in, etc.
  • When the agent installs the chart, values from valuesFrom are read. Then Helm templating {{ }} is processed.

Templating

It is possible to specify the keys and values as go template strings for advanced templating needs. Most of the functions from the sprig templating library are available. This can be turned off in fleet.yaml, by setting disablePreProcess, e.g. to avoid conflicts with other templating languages.

Note that if the functions output changes with every call, e.g. uuidv4, the bundle will get redeployed.

You can test values templating with the CLI against existing clusters.

The template context has the following keys:

  • .ClusterValues are retrieved from target cluster’s spec.templateValues
  • .ClusterLabels and .ClusterAnnotations are the labels and annotations in the cluster resource.
  • .ClusterName as the fleet’s cluster resource name.
  • .ClusterNamespace as the namespace in which the cluster resource exists.

To access Labels or Annotations by their key name:

  1. ${ get .ClusterLabels "management.cattle.io/cluster-display-name" }

Note: The fleet.yaml must be valid yaml. Templating uses ${ } as delims, unlike Helm which uses {{ }}. These fleet.yaml template delimiters can be escaped using backticks, eg.:

  1. foo-bar-${`${PWD}`}

will result in the following text:

  1. foo-bar-${PWD}

fleet.yaml - 图5empty values

It is easier to use global.fleet.clusterLabels.LABELNAME instead of templating. When using templating, make sure to protect against null values.

Example:

  1. ${ if hasKey .ClusterLabels "LABELNAME" }${ .ClusterLabels.LABELNAME }${ else }missing${ end}