fleet.yaml

fleet.yaml 文件为包添加选项。任何包含 fleet.yaml 文件的目录会自动转换为包。

有关使用 fleet.yaml 自定义包的更多信息,请参见 Git 储存库内容

fleet.yaml 的内容对应于 FleetYAML 结构体在 fleetyaml.go 中,包含 BundleSpec

完整示例

Details
fleet.yaml
# The default namespace to be applied to resources. This field is not used to
# enforce or lock down the deployment to a specific namespace, but instead
# provide the default value of the namespace field if one is not specified in
# the manifests.
#
# Default: default
defaultNamespace: default

# All resources will be assigned to this namespace and if any cluster scoped
# resource exists the deployment will fail.
#
# Default: ""
namespace: default

# namespaceLabels are labels that will be appended to the namespace created by
# Fleet.
namespaceLabels:
  key: value

# namespaceAnnotations are annotations that will be appended to the namespace
# created by Fleet.
namespaceAnnotations:
  key: value

# Name of the bundle. If not specified, the bundle name will be computed based
# on the GitRepo's name, and the path from which the bundle is created.
# Default: ""
name: my-great-bundle

# Optional map of labels, that are set at the bundle and can be used in a
# dependsOn.selector
labels:
  key: value

kustomize:
  # Use a custom folder for kustomize resources. This folder must contain a
  # kustomization.yaml file.
  dir: ./kustomize

helm:

  # These options control how "fleet apply" downloads the chart
  # (See `Helm Options` below for more details)
  #
  chart: ./chart

  # A https URL to a Helm repo to download the chart from, or an OCI registry
  # URL (oci://...). For OCI registries, repo is the canonical field and no
  # chart name is needed. For standard Helm repos, the value of `chart` is used
  # as the chart name to look up in the repository.
  repo: https://charts.rancher.io

  # The version of the chart or semver constraint of the chart to find. If a
  # constraint is specified, it is evaluated each time git changes.
  # (See `Helm Options` below for more details)
  version: 0.1.0

  # By default fleet downloads any dependency found in a helm chart.  Use
  # disableDependencyUpdate: true to disable this feature.
  disableDependencyUpdate: false

  ### These options only work for helm-type bundles.
  #
  # Any values that should be placed in the `values.yaml` and passed to helm
  # during install.
  values:

    any-custom: value

    # All labels on Rancher clusters are available using
    # global.fleet.clusterLabels.LABELNAME These can now be accessed directly as
    # variables The variable's value will be an empty string if the referenced
    # cluster label does not exist on the targeted cluster.
    variableName: global.fleet.clusterLabels.LABELNAME

    # See Templating notes below for more information on templating.
    templatedLabel: "${ .ClusterLabels.LABELNAME }-foo"

    valueFromEnv:
      "${ .ClusterLabels.ENV }": ${ .ClusterValues.someValue | upper | quote }

  # Path to any values files that need to be passed to helm during install.
  valuesFiles:
    - values1.yaml
    - values2.yaml

  # Allow to use values files from configmaps or secrets defined in the
  # downstream clusters.
  valuesFrom:
    - configMapKeyRef:
        name: configmap-values
        # default to namespace of bundle
        namespace: default
        key: values.yaml
    - secretKeyRef:
        name: secret-values
        namespace: default
        key: values.yaml

  ### These options control how fleet-agent deploys the bundle, they also apply
  ### for kustomize- and manifest-style bundles.
  #
  # A custom release name to deploy the chart as. If not specified a release name
  # will be generated by combining the invoking GitRepo.name + GitRepo.path.
  releaseName: my-release
  #
  # Makes helm skip the check for its own annotations
  takeOwnership: false
  #
  # Override immutable resources. This could be dangerous.
  force: false
  #
  # Set the Helm --atomic flag when upgrading
  atomic: false
  #
  # Disable go template pre-processing on the fleet values
  disablePreProcess: false
  #
  # Disable DNS resolution in Helm's template functions
  disableDNS: false
  #
  # Skip evaluation of the values.schema.json file
  skipSchemaValidation: false
  #
  # If set and timeoutSeconds provided, will wait until all Jobs have been
  # completed before marking the GitRepo as ready.  It will wait for as long as
  # timeoutSeconds.
  waitForJobs: true

# A paused bundle will not update downstream clusters but instead mark the bundle
# as OutOfSync. One can then manually confirm that a bundle should be deployed to
# the downstream clusters.
#
# Default: false
paused: false

# If rolloutStrategy is not defined in the fleet.yaml file, Fleet uses default rollout values.
rolloutStrategy:

  # A number or percentage of clusters that can be unavailable during an update
  # of a bundle. This follows the same basic approach as a deployment rollout
  # strategy. Once the number of clusters meets unavailable state update will be
  # paused. Default value is 100% which doesn't take effect on update.
  #
  # default: 100%
  maxUnavailable: 15%

  # A number or percentage of cluster partitions that can be unavailable during
  # an update of a bundle.
  #
  # default: 0
  maxUnavailablePartitions: 20%

  # A number or percentage of how to automatically partition clusters if not
  # specific partitioning strategy is configured.
  # The default value is defined in rolloutStrategy.maxUnavailable
  autoPartitionSize: 10%

  # The minimum number of clusters that need to be present before
  # auto-partitioning is enabled. If the number of target clusters is less
  # than this value, all clusters will be placed in a single partition.
  #
  # default: 200
  autoPartitionThreshold: 100

  # The maximum number of new BundleDeployments that can be created in a
  # single reconciliation. This limits the rate at which new deployments are
  # staged when a bundle is first applied to many clusters.
  #
  # default: 50
  maxNew: 50

  # A list of definitions of partitions.  If any target clusters do not match
  # the configuration they are added to partitions at the end following the
  # autoPartitionSize.
  partitions:

    # A user friend name given to the partition used for Display (optional).
    # default: ""
    - name: canary

      # A number or percentage of clusters that can be unavailable in this
      # partition before this partition is treated as done.
      # default: 10%
      maxUnavailable: 10%

      # Selector matching cluster labels to include in this partition
      clusterSelector:
        matchLabels:
          env: prod

      # OR, if selecting by ClusterGroup labels:
      clusterGroupSelector:
        matchLabels:
          env: prod

      # A cluster group name to include in this partition
      clusterGroup: agroup


# Target customization are used to determine how resources should be modified
# per target Targets are evaluated in order and the first one to match a cluster
# is used for that cluster.
targetCustomizations:

  # The name of target. If not specified a default name of the format
  # "target000" will be used. This value is mostly for display
  - name: prod

    # Custom namespace value overriding the value at the root.
    namespace: newvalue

    # Custom defaultNamespace value overriding the value at the root.
    defaultNamespace: newdefaultvalue

    # Custom kustomize options overriding the options at the root.
    kustomize: {}

    # Custom Helm options override the options at the root.
    helm: {}

    # If using raw YAML these are names that map to overlays/{name} that will be
    # used to replace or patch a resource. If you wish to customize the file
    # ./subdir/resource.yaml then a file
    # ./overlays/myoverlay/subdir/resource.yaml will replace the base file.  A
    # file named ./overlays/myoverlay/subdir/resource_patch.yaml will patch the
    # base file.  A patch can in JSON Patch or JSON Merge format or a strategic
    # merge patch for builtin Kubernetes types. Refer to "Raw YAML Resource
    # Customization" below for more information.
    yaml:
      overlays:
        - custom2
        - custom3

    # A selector used to match clusters.  The structure is the standard
    # metav1.LabelSelector format. If clusterGroupSelector or clusterGroup is
    # specified, clusterSelector will be used only to further refine the
    # selection after clusterGroupSelector and clusterGroup is evaluated.
    clusterSelector:
      matchLabels:
        env: prod

    # A selector used to match a specific cluster by name. When using Fleet in
    # Rancher, make sure to put the name of the clusters.fleet.cattle.io
    # resource.
    clusterName: dev-cluster

    # A selector used to match cluster groups.
    clusterGroupSelector:
      matchLabels:
        region: us-east

    # A specific clusterGroup by name that will be selected.
    clusterGroup: group1

    # Resources will not be deployed in the matched clusters if doNotDeploy is
    # true.
    doNotDeploy: false

    # Drift correction removes any external change made to resources managed by
    # Fleet.  It performs a helm rollback, which uses a three-way merge strategy
    # by default.  It will try to update all resources by doing a PUT request if
    # force is enabled.  Three-way strategic merge might fail when updating an
    # item inside of an array as it will try to add a new item instead of
    # replacing the existing one.  This can be fixed by using force.  Keep in
    # mind that resources might be recreated if force is enabled.  Failed
    # rollback will be removed from the helm history unless keepFailHistory is
    # set to true.
    correctDrift:
      enabled: false
      force: false # Warning: it might recreate resources if set to true
      keepFailHistory: false

# dependsOn allows you to configure dependencies to other bundles. The current
# bundle will only be deployed, after all dependencies are deployed an
# accepted state. The default accepted state is the Ready state.
dependsOn:

  # Format:
  #     <GITREPO-NAME>-<BUNDLE_PATH> with all path separators replaced by "-"
  #
  # Example:
  #
  #      GitRepo name "one", Bundle path "/multi-cluster/hello-world"
  #      results in "one-multi-cluster-hello-world".
  #
  # Note:
  #
  #   Bundle names are limited to 53 characters long. If longer they will be
  #   shortened:
  #
  #     opni-fleet-examples-fleets-opni-ui-plugin-operator-crd becomes
  #     opni-fleet-examples-fleets-opni-ui-plugin-opera-021f7
  - name: one-multi-cluster-hello-world
      acceptedStates:
        - Ready
        - Modified
  # Select bundles to depend on based on their label.
  - selector:
      matchLabels:
        app: weak-monkey
    acceptedStates:
      - Ready
      - Modified

# Ignore fields when monitoring a Bundle. This can be used when Fleet thinks
# some conditions in Custom Resources makes the Bundle to be in an error state
# when it shouldn't.
ignore:

  # Conditions to be ignored
  conditions:

    # In this example a condition will be ignored if it contains
    # {"type": "Active", "status", "False"}
    - type: Active
      status: "False"

# Override targets defined in the GitRepo. The Bundle will not have any targets
# from the GitRepo if overrideTargets is provided.
overrideTargets:
  - clusterSelector:
      matchLabels:
        env: dev

通用包配置

这些选项定义了包本身的基本属性和行为,并适用于所有包类型。

选项 说明 适用范围

paused

如果为真,则该包不会在下游集群上更新。相反,它将被标记为 OutOfSync。然后您可以手动批准部署。

所有

labels

在包级别设置的键值对映射。这些可以在 dependsOn.selector 中用于定义依赖关系。

所有

dependsOn

此包依赖的包列表。当前包仅在所有依赖项处于接受状态后才会部署。接受状态对应于任何有效的 包状态

所有

ignore

指定在监控包状态时要忽略的字段。有助于防止自定义资源产生虚假错误状态。

所有

overrideTargets

覆盖 GitRepo 中定义的任何目标的目标自定义列表。

所有

命名空间配置

这些选项控制资源将被部署的 Kubernetes 命名空间。

选项 说明 适用范围

defaultNamespace

默认命名空间,用于未指定命名空间的资源。

所有

namespace

将捆绑包中的所有资源分配到此命名空间。如果存在任何集群范围的资源,则失败。

所有

namespaceLabels

要添加到由SUSE® Rancher Prime Continuous Delivery创建的命名空间的标签。

所有

namespaceAnnotations

要添加到由SUSE® Rancher Prime Continuous Delivery创建的命名空间的注释。

所有

Helm捆绑包配置

所有捆绑包都使用Helm进行部署,但这些选项特定于*Helm风格捆绑包*(具有`Chart.yaml`文件的捆绑包)。

在`fleet.yaml`根目录下定义的`helm.chart`、`helm.repo`和`helm.version`设置决定了Fleet下载哪个Helm图表。

Fleet在初始捆绑包创建阶段下载图表。这发生在处理`targetCustomizations`之前。因此,`targetCustomizations`不能用于为单个集群选择不同的图表源,例如:

  • 不同的本地图表目录

  • 单独的Helm储存库

  • 不同的OCI注册表

如果特定集群必须使用不同的注册表或图表源(例如,由于网络或防火墙限制),请使用单独的`GitRepo`资源或不同的包路径进行配置。

图表源

这些选项指定如何下载图表。引用可以是本地路径、go-getter URL、Helm储存库或OCI Helm储存库。

选项 说明 适用范围

helm.chart

Helm图表位置(本地路径或go-getter URL)。对于OCI注册表,请改用`helm.repo`(见下文)。

Helm

helm.repo

Helm 储存库或 OCI 注册表的 URL (oci://…​)。

Helm

helm.version

Chart 版本或 semver 约束。在每次 git 更改时重新评估。

Helm

helm.disableDependencyUpdate

如果为真,则禁用自动依赖项下载。

Helm

图表引用可以是以下之一:

  • 本地路径 (chart)

  • go-getter URL (chart)

  • OCI 图表 URL (repo: oci://…​)

  • Helm 储存库 (repo + chart + 可选 version)

  • OCI Helm 储存库 (repo: oci://…​ + 可选 version)

helm.repo

对于 OCI 储存库,helm.repo 是 OCI URL 的规范字段。像这样使用:

helm:
  repo: "oci://ghcr.io/fleetrepoci/guestbook"
  version: "0.1.0"  # optional

这与在 HelmOp 资源 中引用 OCI 注册表的方式一致。

helm.chart

指定 Helm 图表的本地路径或 go-getter URL。当 helm.repo 设置为标准(非 OCI)Helm 储存库 URL 时,helm.chart 在该储存库中保存图表名称。

如果通过 helmSecretName 定义了 SSH 密钥的秘密,则会自动注入。

如果 fleet.yaml 文件位于嵌入图表目录之外,则必须使用 helm.chart 明确引用该图表。 否则,SUSE® Rancher Prime Continuous Delivery 将无法安装图表,Helm 特定字段如 valuesFilesvaluesFrom 将无效。

限制:从 Git 下载带有自定义 CA 包的 Helm 图表不起作用。 如果在`helmSecretName`中引用的秘密中配置了CA捆绑包,它将被忽略。 有关详细信息,请参见 fleet#3646

已弃用:在`helm.chart`中放置OCI URL(例如`oci://…​`)已弃用。 请改用`helm.repo`来处理OCI URL。

# Deprecated - still works, but produces a warning in Fleet logs:
helm:
  chart: "oci://ghcr.io/fleetrepoci/guestbook"

# Preferred:
helm:
  repo: "oci://ghcr.io/fleetrepoci/guestbook"

helm.version

确定从 OCI 储存库下载哪个图表。

OCI 储存库不支持 semver 标签中的 ` 字符。Helm在推送图表时会自动将``替换为`_。 在`fleet.yaml`中使用`+`版本;SUSE® Rancher Prime Continuous Delivery在内部执行相同的替换。

自定义Helm图表值的选项。

选项 说明 适用范围

helm.values

作为自定义值传递给Helm的键值对。支持模板化。

Helm

helm.valuesFiles

传递给Helm的值文件路径。

Helm

helm.valuesFrom

从下游集群的ConfigMaps或Secrets加载值。

Helm

不必指定图表自己的`values.yaml`。默认情况下始终使用。

有关更多信息,请参见使用Helm值

有关值处理阶段,请参阅包生命周期

值模板化

SUSE® Rancher Prime Continuous Delivery支持Go模板表达式以满足高级模板需求。 请参阅 Sprig模板函数以获取可用的函数。

避免使用产生随机输出的函数(例如,uuidv4),因为它们会触发重新部署。

您可以使用CLI测试值模板,参考fleet-target

模板上下文键:

  • .ClusterValues

  • .ClusterLabels

  • .ClusterAnnotations

  • .ClusterName

  • .ClusterNamespace

示例:

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

SUSE® Rancher Prime Continuous Delivery模板使用`${ }`分隔符(而不是Helm的`{{ }}`)。使用反引号转义它们:

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

输出:

foo-bar-${PWD}

使用模板时,防止空值。

示例:

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

Helm 部署

这些选项控制Fleet代理如何部署资源。 它们也适用于*kustomize-和*清单样式包

选项 说明 适用范围

helm.releaseName

自定义发布名称。默认为生成的名称。

所有

helm.takeOwnership

跳过注释检查。

所有

helm.force

覆盖不可变资源。

所有

helm.atomic

使用Helm `--atomic`标志。

所有

helm.waitForJobs

在将GitRepo标记为准备好之前,等待所有作业完成。

所有

helm.disablePreProcess

禁用Go模板预处理。

所有

helm.disableDNS

禁用模板中的DNS解析。

所有

helm.skipSchemaValidation

跳过`values.schema.json`验证。

所有

Kustomize 配置

在从包含 kustomization.yaml 文件的目录进行部署时使用。

选项

说明

适用范围

kustomize.dir

Kustomize 资源的自定义文件夹。必须包含一个 kustomization.yaml 文件。

Kustomize

部署策略(滚动更新)

这些选项控制更新在集群中的滚动方式。

选项 说明 适用范围

rolloutStrategy.maxUnavailable

更新期间最大不可用集群数量。

所有

rolloutStrategy.maxUnavailablePartitions

更新期间最大不可用分区数量。

所有

rolloutStrategy.autoPartitionSize

集群的自动分区大小。

所有

rolloutStrategy.autoPartitionThreshold

启用自动分区所需的最小集群数量。低于此阈值时,所有集群将被放置在一个分区中。

所有

rolloutStrategy.maxNew

每次协调可以分阶段的新 BundleDeployments 的最大数量。默认值为 50。

所有

rolloutStrategy.partitions

定义分阶段滚动更新的集群分区。

所有

有关更多信息,请参见 滚动策略

目标和自定义

这些选项允许您为特定集群或集群组自定义部署。

选项 说明 适用范围

targetCustomizations

每个目标修改资源的规则列表。

所有

targetCustomizations.name

自定义的显示名称。

所有

targetCustomizations.clusterSelector

集群的 Kubernetes 标签选择器。

所有

targetCustomizations.clusterGroup

目标集群组的名称。

所有

targetCustomizations.clusterGroupSelector

集群组的标签选择器。

所有

targetCustomizations.clusterName

目标特定集群的名称。

所有

targetCustomizations.doNotDeploy

防止部署到匹配的集群。

所有

targetCustomizations.namespace

覆盖根级别的命名空间。

所有

targetCustomizations.defaultNamespace

覆盖根级别的默认命名空间。

所有

targetCustomizations.helm

覆盖根级别的 Helm 配置。

所有

targetCustomizations.kustomize

覆盖根级别的Kustomize配置。

Kustomize

targetCustomizations.yaml.overlays

覆盖名称以替换或修补YAML资源。

原始YAML

targetCustomizations.correctDrift

启用托管资源的漂移修正。

所有

支持的自定义项

在目标自定义中覆盖 Helm 图表版本可能会增加包的大小。 因为 SUSE® Rancher Prime Continuous Delivery 将包存储在 etcd 中,这可能会超过 etcd 的 blob 大小限制。 有关详细信息,请参阅 Fleet#1650