0

我是 Kustomize 的新手,我想知道:

  • 如何在特定的 yaml 中“修补”metadata.name,例如:RedisInstance。

我尝试将 nameSuffix 设置为特定的 yaml(种类:RedisInstance),但没有成功。

自定义.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: community-organization-uat-product

bases:
- ../../../../common/base/custom/gcp
- ../../../../common/base/custom/gcp/organization

commonAnnotations:
  cnrm.cloud.google.com/managed: "true"
  cnrm.cloud.google.com/project-id: community-organization-uat-product

patchesStrategicMerge:
- 1-cXXXXX-patch.yaml
- 3-mXXXXX-patch.yaml
- 4-mXXXXX-patch.yaml
- 5-cXXXXX-patch.yaml
- 6-mXXXXX-patch.yaml
- 7-memorystore-patch.yaml

这是我的补丁:

7-memorystore-patch.yaml

apiVersion: redis.cnrm.cloud.google.com/v1beta1
kind: RedisInstance
metadata:
  name: memorystore-redis
spec:
  displayName: memorystore-redis-organization-community-uat
  memorySizeGb: 2
  redisVersion: REDIS_5_0
  reservedIpRange: 10.1XXXXX/29

memorystore.yaml

apiVersion: redis.cnrm.cloud.google.com/v1beta1
kind: RedisInstance
metadata:
  name: memorystore-redis
spec:
  displayName: Value defined by Kustomize
  region: XXXX
  connectMode: PRIVATE_SERVICE_ACCESS
  locationId: usXXXX
  memorySizeGb: Value defined by Kustomize
  redisVersion: REDIS_5_0
  reservedIpRange: Value defined by Kustomize
  tier: BASIC
4

1 回答 1

7

我不认为你可以用patchesStrategicMerge:name字段来匹配应该应用补丁的资源,所以要么:

  • 您指定旧名称,资源会匹配但名称不会更改
  • 您指定了新名称,但资源不匹配

好消息是它可以通过patchJson6902来完成:

自定义化.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

# ...

patchesJson6902:
  - target:
      group: redis.cnrm.cloud.google.com
      version: v1beta1
      kind: RedisInstance
      name: memorystore-redis
    path: redisInstanceNamePatch.yaml

redisInstanceNamePatch.yaml

- op: replace
  path: /metadata/name
  value: NewName

目标的所有字段,即组、版本、种类和名称都是必填项

您可以在同一个补丁文件中指定多个操作

于 2020-10-13T21:19:36.023 回答