3

The README for kustomize says that

It's like make, in that what it does is declared in a file, and it's like sed, in that it emits edited text.

Does this analogy extend beyond the fact that files are used to declare what is needed?

Or, is kustomize backward chaining like make in that it reads all command input before working out what it has to do rather than work sequentially and step through the command input like bash working through a shell script?

EDIT: Jeff Regan, of the Kustomize team in Google, explains the model for the way kustomize works towards the beginning of his talk Kustomize: Kubernetes Configuration Customization. He also shows how kustomize may be daisy chained so the output of one kustomize may serve as the input to another kustomize. It seems that, as pointed out by ITChap below, kustomize starts by gathering all the resources referenced in the kustomization.yml file in the base dir. It the executes sequentially in a series of steps to perform the required substitutions and transformations interatively. Repeating the substitution/tranformation step as often as needed to complete. It then spits out the generated YAML on stdout. So I would say that it is not backward chaining like make but rather somewhere in between. HTH.

4

1 回答 1

2

到目前为止我注意到的是,kustomize 将首先积累所有基础资源的内容,然后应用kustomization.yml文件中的转换。如果您有多个级别的叠加层,它似乎不会将结果从一个级别传递到下一个级别。

让我们考虑以下几点:

./base/pod.yml

apiVersion: v1
kind: Pod
metadata:
  name: test
spec:
  containers:
  - name: test
    image: busybox

./base/kustomization.yml

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

./overlays/l1/kustomization.yml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
bases:
  - ../base
nameSuffix: "-l1"

./overlays/l2/kustomization.yml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
bases:
  - ../l1
nameSuffix: "-l2"

运行时,kustomize build overlays/l2您将获得一个test-l1-l2按预期命名的 pod。

但是,如果您尝试修补基本 pod,则必须使用以下方法引用该 pod:

patchesJson6902:
- target:
    version: v1
    kind: Pod
    name: test
  path: patch.yml

在你的./overlays/l1/kustomization.yml 也在./overlays/l2/kustomization.yml在应用 l2 的补丁时,引用的资源仍然是test并且不是test-l1

我不太了解 kustomize,无法理解其背后的意图,但这些是我的观察。希望它能回答你的问题。

PS:这可能会随着https://github.com/kubernetes-sigs/kustomize/issues/1036而改变

于 2019-06-06T12:38:16.837 回答