无法删除“ sizelimit”使用kustomize的属性
我有sizelimit
emptydir
在我的模板基本文件中设置为2GI。我想删除sizelimit
,只有emptyDir:{}
。我一直无法使用Kustomization叠加层来实现这一目标。我将在下面详细说明我的文件夹结构和kustomization yamls。
文件夹结构:
application
├── majorbase
│ ├── kustomization.yaml
│ └── resources
│ └── web-template.yaml
├── minorbase
│ ├── kustomization.yaml
│ └── resources
└── myoverlays
├── kustomization.yaml
└── resources
└── my-new-web.yaml
文件夹myoverlays
在其kustomization中包含以下内容。yaml文件
bases:
- ../minorbase
patchesStrategicMerge:
- resources/my-new-web.yaml
文件夹minorbase
inter.yaml文件中包含以下内容
bases:
- ../majorbase
文件夹majorbase
在其kustomization中包含以下内容。yaml文件
resources:
- resources/web-template.yaml
我想在Major Base/template中编辑的部分。
volumes:
- name: test-vol
emptyDir:
sizeLimit: "2Gi"
上述配置需要使用以下叠加层进行更新。
volumes:
- name: test-vol
emptyDir: {}
这是我的问题所在。每当我在覆盖层中删除sizelimit
时,Kustomization只会选择基数中提到的2GI值。当我提到sizelimit
(例如“ 1GI””中的“ 1GI”时,Kustomization正在拾取更改。这种行为的原因是什么?有可能实现我想在这里做的事情吗?
I have sizeLimit
property under emptyDir
set to 2Gi in my template base file. I want to remove the sizelimit
and just have emptyDir: {}
. I've been unable to achieve this using Kustomization overlays. I will detail my folder structure and kustomization yamls below.
Folder Structure:
application
├── majorbase
│ ├── kustomization.yaml
│ └── resources
│ └── web-template.yaml
├── minorbase
│ ├── kustomization.yaml
│ └── resources
└── myoverlays
├── kustomization.yaml
└── resources
└── my-new-web.yaml
The folder myoverlays
contains the following contents in it's kustomization.yaml file
bases:
- ../minorbase
patchesStrategicMerge:
- resources/my-new-web.yaml
The folder minorbase
contains the following contents in it's kustomization.yaml file
bases:
- ../majorbase
The folder majorbase
contains the following contents in it's kustomization.yaml file
resources:
- resources/web-template.yaml
The section I want to edit looks like this in the majorbase/template.
volumes:
- name: test-vol
emptyDir:
sizeLimit: "2Gi"
The above configuration needs to be updated using overlays as below.
volumes:
- name: test-vol
emptyDir: {}
This is where my problem lies. Kustomization just picks the 2Gi value mentioned in the base whenever I remove the sizelimit
in my overlays. When I mention different value to sizeLimit
such as "1Gi" in my overlays file, kustomization is picking up the change. What is the cause of this behaviour? Is it possible to achieve what I'm trying to do here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NB:此答案假定了近期的Kustomize(我本地运行4.5.2)。您的示例使用不推荐的语法(
bases
部分被弃用版本2.1.0中的“ noreferrer”>,例如)。您的问题是您使用了
strategicmerge
修补程序,并且您正在与{“ sizelimit”:“ 26Gi”合并和空的地图(
。如果您将一个空的地图与任何东西合并,那是一个无关的:您最终得到了“任何东西”。{}
) }要明确删除元素,您有一些选择。
您可以使用
$ patch:替换
指令(您可以找到一个此处)要使kustomize 替换emptydir
元素,而不是合并内容。看起来像:相应的
kustomization.yaml
可能看起来很像:另外,您可以使用JSONPATCH补丁,这非常适合明确删除字段:
where
kustomization.yaml
> yaml 看起来像:您可以找到此在这里的完整跑步演示。
NB: This answer assumes a recent version of Kustomize (I'm running 4.5.2 locally). Your examples are using deprecated syntax (the
bases
section was deprecated in version 2.1.0, for example).Your problem is that you're using a
strategicMerge
patch, and you're merging and empty map ({}
) with{"sizeLimit": "26gi"}
. If you merge an empty map with anything, it's a no-op: you end up with the "anything".To explicitly delete an element, you have a few choices.
You can use the
$patch: replace
directive (you can find an example of that here) to have Kustomize replace theemptyDir
element, rather than merging the contents. That would look like:The corresponding
kustomization.yaml
might look something like:Alternately, you can use a JSONPatch patch, which is good for explicitly deleting fields:
Where
kustomization.yaml
would look like:You can find a complete runnable demonstration of this here.