无法删除“ sizelimit”使用kustomize的属性

发布于 2025-01-25 11:49:40 字数 1369 浏览 2 评论 0原文

我有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨巷深深 2025-02-01 11:49:40

NB:此答案假定了近期的Kustomize(我本地运行4.5.2)。您的示例使用不推荐的语法(bases部分被弃用版本2.1.0中的“ noreferrer”>,例如)。


您的问题是您使用了strategicmerge修补程序,并且您正在与{“ sizelimit”:“ 26Gi”合并和空的地图({}) }。如果您将一个空的地图与任何东西合并,那是一个无关的:您最终得到了“任何东西”。

要明确删除元素,您有一些选择。

您可以使用$ patch:替换指令(您可以找到一个此处)要使kustomize 替换 emptydir元素,而不是合并内容。看起来像:

apiVersion: v1
kind: Pod
metadata:
  name: example
spec:
  volumes:
    - name: test-vol
      emptyDir:
        $patch: replace

相应的kustomization.yaml可能看起来很像:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ../../base

patches:
  - path: resources/my-new-web.yaml

另外,您可以使用JSONPATCH补丁,这非常适合明确删除字段:

- path: /spec/volumes/0/emptyDir/sizeLimit
  op: remove

where kustomization.yaml> yaml 看起来像:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ....//base

patches:
  - target:
      kind: Pod
      name: example
    path: resources/my-new-web.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 the emptyDir element, rather than merging the contents. That would look like:

apiVersion: v1
kind: Pod
metadata:
  name: example
spec:
  volumes:
    - name: test-vol
      emptyDir:
        $patch: replace

The corresponding kustomization.yaml might look something like:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ../../base

patches:
  - path: resources/my-new-web.yaml

Alternately, you can use a JSONPatch patch, which is good for explicitly deleting fields:

- path: /spec/volumes/0/emptyDir/sizeLimit
  op: remove

Where kustomization.yaml would look like:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ....//base

patches:
  - target:
      kind: Pod
      name: example
    path: resources/my-new-web.yaml

You can find a complete runnable demonstration of this here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文