<p><strong>Is there a way to extend the kustomize image transformer to recognise more keys as image specifiers?</strong> Like the <a href="https://github.com/kubernetes-sigs/kustomize/blob/master/examples/transformerconfigs/README.md#name-reference-transformer" rel="nofollow noreferrer"><code>nameReference</code> transformer</a> does for the <code>namePrefix</code> and <code>nameSuffix</code> transformers.</p>
<p><a href="https://github.com/kubernetes-sigs/kustomize/blob/master/examples/transformerconfigs/README.md" rel="nofollow noreferrer">The Kustomize <code>images:</code> transformer</a> is very useful for image replacement and registry renaming in k8s manifests.</p>
<p>But it <a href="https://github.com/kubernetes-sigs/kustomize/issues/686" rel="nofollow noreferrer">only supports types that embed <code>PodTemplate</code></a> and maybe some hardcoded types. CRDs that don't use <code>PodTemplate</code> are not handled despite them being <em>very</em> common. Examples include the <code>kube-prometheus</code> <code>Prometheus</code> and <code>AlertManager</code> resources and the <code>opentelemetry-operator</code> <code>OpenTelemetryCollector</code> resource.</p>
<p>As a result you land up having to maintain a bunch of messy strategic merge or json patches to prefix such images with a trusted registry or the like.</p>
<hr />
<p>Here's an example of the problem as things stand. Say I have to deploy everything prefixed with <code>mytrusted.registry</code> with an <code>images:</code> transformer list. For the sake of brevity here I'll use a dummy one that replaces all matched images with <code>MATCHED</code>, so I don't have to list them all:</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - &quot;https://github.com/prometheus-operator/kube-prometheus&quot;
images:
  - name: &quot;(.*)&quot;
    newName: &quot;MATCHED&quot;
    newTag: &quot;fake&quot;
</code></pre>
<p>You'd expect the only images in the result to be &quot;MATCHED:fake&quot;, but in reality:</p>
<pre><code>$ kustomize build  | grep 'image: .*' | sort | uniq -c
     12         image: MATCHED:fake
      1   image: quay.io/prometheus/alertmanager:v0.24.0
      1   image: quay.io/prometheus/prometheus:v2.34.0
</code></pre>
<p>the images in the <code>kind: Prometheus</code> and <code>kind: AlertManager</code> resources don't get matched because they are not a <code>PodTemplate</code>.</p>
<p>You have to write a custom patch for these, which creates mess like this <code>kustomization.yaml</code> content:</p>
<pre><code>patches:
  - path: prometheus_image.yaml
    target:
      kind: Prometheus
  - path: alertmanager_image.yaml
    target:
      kind: Alertmanager
</code></pre>
<p>with <code>prometheus_image.yaml</code>:</p>
<pre><code>apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
      name: ignored
spec:
      image: &quot;MATCHED:fake&quot;
</code></pre>
<p>and <code>alertmanager_image.yaml</code>:</p>
<pre><code>apiVersion: monitoring.coreos.com/v1
kind: Alertmanager
metadata:
      name: ignored
spec:
      image: &quot;MATCHED:fake&quot;
</code></pre>
<p>which is IMO ghastly.</p>
<p>What I <em>want</em> to be able to do is tell <code>Kustomize</code>'s image transformer about it, like it can be extended with custom configmap generators, etc, like the following <em>unsupported and imaginary pseudocode</em> modeled on the existing <a href="https://github.com/kubernetes-sigs/kustomize/blob/master/examples/transformerconfigs/README.md#name-reference-transformer" rel="nofollow noreferrer"><code>nameReference</code> transformer</a></p>
<pre><code>imageReference:
  - kind: Prometheus
    fieldSpecs:
      - spec/image
</code></pre>

<p>Just after writing this up I finally stumbled on the answer: Kustomize does support <a href="https://github.com/kubernetes-sigs/kustomize/blob/master/examples/transformerconfigs/images/README.md" rel="noreferrer">image transformer configs</a>.</p>
<p>The correct way to express the above would be a <code>image_transformer_config.yaml</code> file containing:</p>
<pre><code>images:
  - path: spec/image
    kind: Prometheus
  - path: spec/image
    kind: Alertmanager
</code></pre>
<p>and a <code>kustomization.yaml</code> entry referencing it, like</p>
<pre><code>configurations:
  - image_transformer_config.yaml
</code></pre>
<p>This appears to work fine when imported as a <code>Component</code> too.</p>
<p>It's even <a href="https://github.com/kubernetes-sigs/kustomize/blob/master/examples/transformerconfigs/README.md#images-transformer" rel="noreferrer">pointed out by the transformer docs</a> so I'm going to blame this one on being blind.</p>
