mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 10:30:59 +00:00
update docs site
This commit is contained in:
@@ -305,236 +305,6 @@
|
||||
|
||||
|
||||
|
||||
<ul class="td-sidebar-nav__section pr-md-3">
|
||||
<li class="td-sidebar-nav__section-title">
|
||||
<a href="/kustomize/guides/cmd/" class="align-left pl-0 pr-2 collapsed td-sidebar-link td-sidebar-link__section">Command Line Options</a>
|
||||
</li>
|
||||
<ul>
|
||||
<li class="collapse " id="kustomizeguidescmd">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<ul class="td-sidebar-nav__section pr-md-3">
|
||||
<li class="td-sidebar-nav__section-title">
|
||||
<a href="/kustomize/guides/cmd/build/" class="align-left pl-0 pr-2 collapsed td-sidebar-link td-sidebar-link__section">build</a>
|
||||
</li>
|
||||
<ul>
|
||||
<li class="collapse " id="kustomizeguidescmdbuild">
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<ul class="td-sidebar-nav__section pr-md-3">
|
||||
<li class="td-sidebar-nav__section-title">
|
||||
<a href="/kustomize/guides/cmd/cfg/" class="align-left pl-0 pr-2 collapsed td-sidebar-link td-sidebar-link__section">cfg</a>
|
||||
</li>
|
||||
<ul>
|
||||
<li class="collapse " id="kustomizeguidescmdcfg">
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<ul class="td-sidebar-nav__section pr-md-3">
|
||||
<li class="td-sidebar-nav__section-title">
|
||||
<a href="/kustomize/guides/cmd/create/" class="align-left pl-0 pr-2 collapsed td-sidebar-link td-sidebar-link__section">create</a>
|
||||
</li>
|
||||
<ul>
|
||||
<li class="collapse " id="kustomizeguidescmdcreate">
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<ul class="td-sidebar-nav__section pr-md-3">
|
||||
<li class="td-sidebar-nav__section-title">
|
||||
<a href="/kustomize/guides/cmd/edit/" class="align-left pl-0 pr-2 collapsed td-sidebar-link td-sidebar-link__section">edit</a>
|
||||
</li>
|
||||
<ul>
|
||||
<li class="collapse " id="kustomizeguidescmdedit">
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<ul class="td-sidebar-nav__section pr-md-3">
|
||||
<li class="td-sidebar-nav__section-title">
|
||||
<a href="/kustomize/guides/cmd/fn/" class="align-left pl-0 pr-2 collapsed td-sidebar-link td-sidebar-link__section">fn</a>
|
||||
</li>
|
||||
<ul>
|
||||
<li class="collapse " id="kustomizeguidescmdfn">
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<ul class="td-sidebar-nav__section pr-md-3">
|
||||
<li class="td-sidebar-nav__section-title">
|
||||
<a href="/kustomize/guides/cmd/help/" class="align-left pl-0 pr-2 collapsed td-sidebar-link td-sidebar-link__section">help</a>
|
||||
</li>
|
||||
<ul>
|
||||
<li class="collapse " id="kustomizeguidescmdhelp">
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<ul class="td-sidebar-nav__section pr-md-3">
|
||||
<li class="td-sidebar-nav__section-title">
|
||||
<a href="/kustomize/guides/cmd/install-completion/" class="align-left pl-0 pr-2 collapsed td-sidebar-link td-sidebar-link__section">install-completion</a>
|
||||
</li>
|
||||
<ul>
|
||||
<li class="collapse " id="kustomizeguidescmdinstall-completion">
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<ul class="td-sidebar-nav__section pr-md-3">
|
||||
<li class="td-sidebar-nav__section-title">
|
||||
<a href="/kustomize/guides/cmd/live/" class="align-left pl-0 pr-2 collapsed td-sidebar-link td-sidebar-link__section">live</a>
|
||||
</li>
|
||||
<ul>
|
||||
<li class="collapse " id="kustomizeguidescmdlive">
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<ul class="td-sidebar-nav__section pr-md-3">
|
||||
<li class="td-sidebar-nav__section-title">
|
||||
<a href="/kustomize/guides/cmd/version/" class="align-left pl-0 pr-2 collapsed td-sidebar-link td-sidebar-link__section">version</a>
|
||||
</li>
|
||||
<ul>
|
||||
<li class="collapse " id="kustomizeguidescmdversion">
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<ul class="td-sidebar-nav__section pr-md-3">
|
||||
<li class="td-sidebar-nav__section-title">
|
||||
<a href="/kustomize/guides/components/" class="align-left pl-0 pr-2 collapsed td-sidebar-link td-sidebar-link__section">Kustomize Components</a>
|
||||
@@ -588,25 +358,6 @@
|
||||
|
||||
|
||||
|
||||
<nav id="TableOfContents">
|
||||
<ul>
|
||||
<li><a href="#specification-in-kustomizationyaml">Specification in <code>kustomization.yaml</code></a></li>
|
||||
<li><a href="#configuration">Configuration</a></li>
|
||||
<li><a href="#placement">Placement</a></li>
|
||||
<li><a href="#execution">Execution</a>
|
||||
<ul>
|
||||
<li></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#authoring">Authoring</a>
|
||||
<ul>
|
||||
<li><a href="#exec-plugins">Exec plugins</a></li>
|
||||
<li><a href="#go-plugins">Go plugins</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
@@ -643,274 +394,8 @@
|
||||
<h1>Kustomize Plugins</h1>
|
||||
<div class="lead">Kustomize plugins guide</div>
|
||||
<meta http-equiv="refresh" content="0; url=https://kubectl.docs.kubernetes.io/guides/extending_kustomize/plugins" />
|
||||
<p>Kustomize offers a plugin framework allowing people to write their own resource <em>generators</em>
|
||||
and <em>transformers</em>.</p>
|
||||
<p>Write a plugin when changing <a href="https://github.com/kubernetes-sigs/kustomize/tree/master/examples/generatorOptions.md">generator options</a>
|
||||
or <a href="https://github.com/kubernetes-sigs/kustomize/tree/master/examples/transformerconfigs">transformer configs</a> doesn’t meet your needs.</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p>A <em>generator</em> plugin could be a helm chart
|
||||
inflator, or a plugin that emits all the
|
||||
components (deployment, service, scaler,
|
||||
ingress, etc.) needed by someone’s <a href="https://12factor.net">12-factor</a>
|
||||
application, based on a smaller number of free
|
||||
variables.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>A <em>transformer</em> plugin might perform special
|
||||
container command line edits, or any other
|
||||
transformation beyond those provided by the
|
||||
builtin (<code>namePrefix</code>, <code>commonLabels</code>, etc.)
|
||||
transformers.</p>
|
||||
</li>
|
||||
</ul>
|
||||
<h2 id="specification-in-kustomizationyaml">Specification in <code>kustomization.yaml</code></h2>
|
||||
<p>Start by adding a <code>generators</code> and/or <code>transformers</code>
|
||||
field to your kustomization.</p>
|
||||
<p>Each field accepts a string list:</p>
|
||||
<blockquote>
|
||||
<pre><code>generators:
|
||||
- relative/path/to/some/file.yaml
|
||||
- relative/path/to/some/kustomization
|
||||
- /absolute/path/to/some/kustomization
|
||||
- https://github.com/org/repo/some/kustomization
|
||||
<p>Moved to <a href="https://github.com/kubernetes-sigs/cli-experimental">https://github.com/kubernetes-sigs/cli-experimental</a></p>
|
||||
|
||||
transformers:
|
||||
- {as above}
|
||||
</code></pre></blockquote>
|
||||
<p>The value of each entry in a <code>generators</code> or
|
||||
<code>transformers</code> list must be a relative path to a
|
||||
YAML file, or a path or URL to a <a href="/kustomize/api-reference/glossary#kustomization">kustomization</a>.
|
||||
This is the same format as demanded by the
|
||||
<code>resources</code> field.</p>
|
||||
<p>YAML files are read from disk directly. Paths or
|
||||
URLs leading to kustomizations trigger an
|
||||
in-process kustomization run. Each of the
|
||||
resulting objects is now further interpreted by
|
||||
kustomize as a <em>plugin configuration</em> object.</p>
|
||||
<h2 id="configuration">Configuration</h2>
|
||||
<p>A kustomization file could have the following lines:</p>
|
||||
<pre><code>generators:
|
||||
- chartInflator.yaml
|
||||
</code></pre><p>Given this, the kustomization process would expect
|
||||
to find a file called <code>chartInflator.yaml</code> in the
|
||||
kustomization <a href="/kustomize/api-reference/glossary#kustomization-root">root</a>.</p>
|
||||
<p>This is the plugin’s configuration file;
|
||||
it contains a YAML configuration object.</p>
|
||||
<p>The file <code>chartInflator.yaml</code> could contain:</p>
|
||||
<pre><code>apiVersion: someteam.example.com/v1
|
||||
kind: ChartInflator
|
||||
metadata:
|
||||
name: notImportantHere
|
||||
chartName: minecraft
|
||||
</code></pre><p><strong>The <code>apiVersion</code> and <code>kind</code> fields are
|
||||
used to locate the plugin.</strong></p>
|
||||
<p>Thus, these fields are required. They are also
|
||||
required because a kustomize plugin configuration
|
||||
object is also a <a href="/kustomize/api-reference/glossary#kubernetes-style-object">k8s object</a>.</p>
|
||||
<p>To get the plugin ready to generate or transform,
|
||||
it is given the entire contents of the
|
||||
configuration file.</p>
|
||||
<p>For more examples of plugin configuration YAML,
|
||||
browse the unit tests below the <a href="https://github.com/kubernetes-sigs/kustomize/tree/master/plugin/builtin">plugins</a> root,
|
||||
e.g. the tests for <a href="https://github.com/kubernetes-sigs/kustomize/tree/master/plugin/someteam.example.com/v1/chartinflator/ChartInflator_test.go">ChartInflator</a> or
|
||||
<a href="https://github.com/kubernetes-sigs/kustomize/tree/master/plugin/builtin/prefixsuffixtransformer/PrefixSuffixTransformer_test.go">NameTransformer</a>.</p>
|
||||
<h2 id="placement">Placement</h2>
|
||||
<p>Each plugin gets its own dedicated directory named</p>
|
||||
<pre><code>$XDG_CONFIG_HOME/kustomize/plugin
|
||||
/${apiVersion}/LOWERCASE(${kind})
|
||||
</code></pre><p>The default value of <a href="https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html"><code>XDG_CONFIG_HOME</code></a> is
|
||||
<code>$HOME/.config</code>.</p>
|
||||
<p>The one-plugin-per-directory requirement eases
|
||||
creation of a plugin bundle (source, tests, plugin
|
||||
data files, etc.) for sharing.</p>
|
||||
<p>In the case of a <a href="#go-plugins">Go plugin</a>, it also
|
||||
allows one to provide a <code>go.mod</code> file for the
|
||||
single plugin, easing resolution of package
|
||||
version dependency skew.</p>
|
||||
<p>When loading, kustomize will first look for an
|
||||
<em>executable</em> file called</p>
|
||||
<pre><code>$XDG_CONFIG_HOME/kustomize/plugin
|
||||
/${apiVersion}/LOWERCASE(${kind})/${kind}
|
||||
</code></pre><p>If this file is not found or is not executable,
|
||||
kustomize will look for a file called <code>${kind}.so</code>
|
||||
in the same directory and attempt to load it as a
|
||||
<a href="#go-plugins">Go plugin</a>.</p>
|
||||
<p>If both checks fail, the plugin load fails the overall
|
||||
<code>kustomize build</code>.</p>
|
||||
<h2 id="execution">Execution</h2>
|
||||
<p>Plugins are only used during a run of the
|
||||
<code>kustomize build</code> command.</p>
|
||||
<p>Generator plugins are run after processing the
|
||||
<code>resources</code> field (which itself can be viewed as a
|
||||
generator, simply reading objects from disk).</p>
|
||||
<p>The full set of resources is then passed into the
|
||||
transformation pipeline, wherein builtin
|
||||
transformations like <code>namePrefix</code> and
|
||||
<code>commonLabel</code> are applied (if they were specified
|
||||
in the kustomization file), followed by the
|
||||
user-specified transformers in the <code>transformers</code>
|
||||
field.</p>
|
||||
<p>The order specified in the <code>transformers</code> field is
|
||||
respected, as transformers cannot be expected to
|
||||
be commutative.</p>
|
||||
<h4 id="no-security">No Security</h4>
|
||||
<p>Kustomize plugins do not run in any kind of
|
||||
kustomize-provided sandbox. There’s no notion
|
||||
of <em>“plugin security”</em>.</p>
|
||||
<p>A <code>kustomize build</code> that tries to use plugins but
|
||||
omits the flag</p>
|
||||
<blockquote>
|
||||
<p><code>--enable_alpha_plugins</code></p>
|
||||
</blockquote>
|
||||
<p>will not load plugins and will fail with a
|
||||
warning about plugin use.</p>
|
||||
<p>The use of this flag is an opt-in acknowledging
|
||||
the unstable (alpha) plugin API, the absence of
|
||||
plugin provenance, and the fact that a plugin
|
||||
is not part of kustomize.</p>
|
||||
<p>To be clear, some kustomize plugin downloaded
|
||||
from the internet might wonderfully transform
|
||||
k8s config in a desired manner, while also
|
||||
quietly doing anything the user could do to the
|
||||
system running <code>kustomize build</code>.</p>
|
||||
<h2 id="authoring">Authoring</h2>
|
||||
<p>There are two kinds of plugins, <a href="#exec-plugins">exec</a> and <a href="#go-plugins">Go</a>.</p>
|
||||
<h3 id="exec-plugins">Exec plugins</h3>
|
||||
<p>A <em>exec plugin</em> is any executable that accepts a
|
||||
single argument on its command line - the name of
|
||||
a YAML file containing its configuration (the file name
|
||||
provided in the kustomization file).</p>
|
||||
<blockquote>
|
||||
<p>TODO: restrictions on plugin to allow the <em>same exec
|
||||
plugin</em> to be targeted by both the
|
||||
<code>generators</code> and <code>transformers</code> fields.</p>
|
||||
<ul>
|
||||
<li>first arg could be the fixed string
|
||||
<code>generate</code> or <code>transform</code>,
|
||||
(the name of the configuration file moves to
|
||||
the 2nd arg), or</li>
|
||||
<li>or by default an exec plugin behaves as a tranformer
|
||||
unless a flag <code>-g</code> is provided, switching the
|
||||
exec plugin to behave as a generator.</li>
|
||||
</ul>
|
||||
</blockquote>
|
||||
<h4 id="examples">Examples</h4>
|
||||
<ul>
|
||||
<li><a href="https://github.com/kubernetes-sigs/kustomize/tree/master/plugin/someteam.example.com/v1/chartinflator">helm chart inflator</a> - A generator that inflates a helm chart.</li>
|
||||
<li><a href="https://github.com/kubernetes-sigs/kustomize/tree/master/plugin/someteam.example.com/v1/bashedconfigmap">bashed config map</a> - Super simple configMap generation from bash.</li>
|
||||
<li><a href="https://github.com/kubernetes-sigs/kustomize/tree/master/plugin/someteam.example.com/v1/sedtransformer">sed transformer</a> - Define your unstructured edits using a
|
||||
plugin like this one.</li>
|
||||
<li><a href="https://github.com/kubernetes-sigs/kustomize/tree/master/plugin/someteam.example.com/v1/gogetter">hashicorp go-getter</a> - Download kustomize layes and build it to generate resources</li>
|
||||
</ul>
|
||||
<p>A generator plugin accepts nothing on <code>stdin</code>, but emits
|
||||
generated resources to <code>stdout</code>.</p>
|
||||
<p>A transformer plugin accepts resource YAML on <code>stdin</code>,
|
||||
and emits those resources, presumably transformed, to
|
||||
<code>stdout</code>.</p>
|
||||
<p>kustomize uses an exec plugin adapter to provide
|
||||
marshalled resources on <code>stdin</code> and capture
|
||||
<code>stdout</code> for further processing.</p>
|
||||
<h4 id="generator-options">Generator Options</h4>
|
||||
<p>A generator exec plugin can adjust the generator options for the resources it emits by setting one of the following internal annotations.</p>
|
||||
<blockquote>
|
||||
<p>NOTE: These annotations are local to kustomize and will not be included in the final output.</p>
|
||||
</blockquote>
|
||||
<p><strong><code>kustomize.config.k8s.io/needs-hash</code></strong></p>
|
||||
<p>Resources can be marked as needing to be processed by the internal hash transformer by including the <code>needs-hash</code> annotation. When set valid values for the annotation are <code>"true"</code> and <code>"false"</code> which respectively enable or disable hash suffixing for the resource. Omitting the annotation is equivalent to setting the value <code>"false"</code>.</p>
|
||||
<p>Hashes are determined as follows:</p>
|
||||
<ul>
|
||||
<li>For <code>ConfigMap</code> resources, hashes are based on the values of the <code>name</code>, <code>data</code>, and <code>binaryData</code> fields.</li>
|
||||
<li>For <code>Secret</code> resources, hashes are based on the values of the <code>name</code>, <code>type</code>, <code>data</code>, and <code>stringData</code> fields.</li>
|
||||
<li>For any other object type, hashes are based on the entire object content (i.e. all fields).</li>
|
||||
</ul>
|
||||
<p>Example:</p>
|
||||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ConfigMap</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">cm-test</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">annotations</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">kustomize.config.k8s.io/needs-hash</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">"true"</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">data</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">foo</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">bar</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span></code></pre></div><p><strong><code>kustomize.config.k8s.io/behavior</code></strong></p>
|
||||
<p>The <code>behavior</code> annotation will influence how conflicts are handled for resources emitted by the plugin. Valid values include “create”, “merge”, and “replace” with “create” being the default.</p>
|
||||
<p>Example:</p>
|
||||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ConfigMap</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">cm-test</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">annotations</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">kustomize.config.k8s.io/behavior</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">"merge"</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">data</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">foo</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">bar</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span></code></pre></div><h3 id="go-plugins">Go plugins</h3>
|
||||
<p>Be sure to read <a href="goplugincaveats/">Go plugin caveats</a>.</p>
|
||||
<p>A <code>.go</code> file can be a <a href="https://golang.org/pkg/plugin/">Go plugin</a> if it declares
|
||||
‘main’ as it’s package, and exports a symbol to
|
||||
which useful functions are attached.</p>
|
||||
<p>It can further be used as a <em>kustomize</em> plugin if
|
||||
the symbol is named ‘KustomizePlugin’ and the
|
||||
attached functions implement the <code>Configurable</code>,
|
||||
<code>Generator</code> and <code>Transformer</code> interfaces.</p>
|
||||
<p>A Go plugin for kustomize looks like this:</p>
|
||||
<blockquote>
|
||||
<pre><code>package main
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/api/resmap"
|
||||
...
|
||||
)
|
||||
|
||||
type plugin struct {...}
|
||||
|
||||
var KustomizePlugin plugin
|
||||
|
||||
func (p *plugin) Config(
|
||||
h *resmap.PluginHelpers,
|
||||
c []byte) error {...}
|
||||
|
||||
func (p *plugin) Generate() (resmap.ResMap, error) {...}
|
||||
|
||||
func (p *plugin) Transform(m resmap.ResMap) error {...}
|
||||
</code></pre></blockquote>
|
||||
<p>Use of the identifiers <code>plugin</code>, <code>KustomizePlugin</code>
|
||||
and implementation of the method signature
|
||||
<code>Config</code> is required.</p>
|
||||
<p>Implementing the <code>Generator</code> or <code>Transformer</code>
|
||||
method allows (respectively) the plugin’s config
|
||||
file to be added to the <code>generators</code> or
|
||||
<code>transformers</code> field in the kustomization file.
|
||||
Do one or the other or both as desired.</p>
|
||||
<h4 id="examples-1">Examples</h4>
|
||||
<ul>
|
||||
<li><a href="https://github.com/kubernetes-sigs/kustomize/tree/master/plugin/someteam.example.com/v1/someservicegenerator">service generator</a> - generate a service from a name and port argument.</li>
|
||||
<li><a href="https://github.com/kubernetes-sigs/kustomize/tree/master/plugin/someteam.example.com/v1/stringprefixer">string prefixer</a> - uses the value in <code>metadata/name</code> as the prefix.
|
||||
This particular example exists to show how a plugin can
|
||||
transform the behavior of a plugin. See the
|
||||
<code>TestTransformedTransformers</code> test in the <code>target</code> package.</li>
|
||||
<li><a href="https://github.com/kubernetes-sigs/kustomize/tree/master/plugin/someteam.example.com/v1/dateprefixer">date prefixer</a> - prefix the current date to resource names, a simple
|
||||
example used to modify the string prefixer plugin just mentioned.</li>
|
||||
<li><a href="https://github.com/kubernetes-sigs/kustomize/tree/master/plugin/someteam.example.com/v1/secretsfromdatabase">secret generator</a> - generate secrets from a toy database.</li>
|
||||
<li><a href="https://github.com/monopole/sopsencodedsecrets">sops encoded secrets</a> - a more complex secret generator that converts SOPS files into Kubernetes Secrets</li>
|
||||
<li><a href="https://github.com/omninonsense/kustomize-sopsgenerator">SOPSGenerator</a> - another generator that decrypts SOPS files into Secrets</li>
|
||||
<li><a href="https://github.com/kubernetes-sigs/kustomize/tree/master/plugin/builtin">All the builtin plugins</a>.
|
||||
User authored plugins are
|
||||
on the same footing as builtin operations.</li>
|
||||
</ul>
|
||||
<p>A Go plugin can be both a generator and a
|
||||
transformer. The <code>Generate</code> method will run along
|
||||
with all the other generators before the
|
||||
<code>Transform</code> method runs.</p>
|
||||
<p>Here’s a build command that sensibly assumes the
|
||||
plugin source code sits in the directory where
|
||||
kustomize expects to find <code>.so</code> files:</p>
|
||||
<pre><code>d=$XDG_CONFIG_HOME/kustomize/plugin\
|
||||
/${apiVersion}/LOWERCASE(${kind})
|
||||
|
||||
go build -buildmode plugin \
|
||||
-o $d/${kind}.so $d/${kind}.go
|
||||
</code></pre>
|
||||
<div class="section-index">
|
||||
|
||||
|
||||
@@ -927,8 +412,6 @@ go build -buildmode plugin \
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="entry">
|
||||
<h5>
|
||||
<a href="/kustomize/guides/plugins/builtins/">Builtin Plugins</a>
|
||||
@@ -938,14 +421,6 @@ go build -buildmode plugin \
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="entry">
|
||||
<h5>
|
||||
<a href="/kustomize/guides/plugins/execpluginguidedexample/">Exec plugin on linux</a>
|
||||
@@ -955,8 +430,6 @@ go build -buildmode plugin \
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="entry">
|
||||
<h5>
|
||||
<a href="/kustomize/guides/plugins/goplugincaveats/">Go plugin Caveats</a>
|
||||
@@ -976,20 +449,12 @@ go build -buildmode plugin \
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="text-muted mt-5 pt-3 border-top">Last modified November 4, 2020: <a href="https://github.com/kubernetes-sigs/kustomize/commit/0834e152b203ffeccfbbf1ddd3c1f49debdac341">Redirect kustomize docs to the new unified site. (0834e152)</a>
|
||||
<div class="text-muted mt-5 pt-3 border-top">Last modified November 11, 2020: <a href="https://github.com/kubernetes-sigs/kustomize/commit/71b763888cad614abb44b3086e291fe72d601080">Remove duplicate kustomize docs content (71b76388)</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user