Kustomize metadata.name 特定种类:
Kustomize metadata.name for a specific kind:
我是 Kustomize 的新手,我想知道:
- 如何在特定的 yaml 中“修补”metadata.name,例如:RedisInstance。
我尝试为特定的 yaml(种类:RedisInstance)设置 nameSuffix,但没有成功。
Kustomization.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
我认为您不能使用 patchesStrategicMerge
来做到这一点:name
字段用于匹配应应用补丁的资源,因此:
- 您指定旧名称,资源匹配但名称未更改
- 您指定了新名称但资源未匹配
好消息是可以用 patchesJson6902:
Kustomization.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
All of the fields of the target, i.e. group, version, kind and name are mandatory
You may specify multiple operations in the same patch file
我是 Kustomize 的新手,我想知道:
- 如何在特定的 yaml 中“修补”metadata.name,例如:RedisInstance。
我尝试为特定的 yaml(种类:RedisInstance)设置 nameSuffix,但没有成功。
Kustomization.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
我认为您不能使用 patchesStrategicMerge
来做到这一点:name
字段用于匹配应应用补丁的资源,因此:
- 您指定旧名称,资源匹配但名称未更改
- 您指定了新名称但资源未匹配
好消息是可以用 patchesJson6902:
Kustomization.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
All of the fields of the target, i.e. group, version, kind and name are mandatory
You may specify multiple operations in the same patch file