<p>Every deepcopy generated file that is produced by <code>make</code> with kubebuilder produces a file with a <code>// +build !ignore_autogenerated</code> build tag directive at the top.</p>
<pre><code>//go:build !ignore_autogenerated
// +build !ignore_autogenerated

/*
Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Code generated by controller-gen. DO NOT EDIT.
</code></pre>
<p>Why is this specific build tag directive added to these generated files? What's its purpose?</p>

Jonathan Innis
<p>It's used by <code>controller-gen</code> to identify files it generated, it will only overwrite those.</p>
<p>E.g. edit a generated <code>zz_generated.deepcopy.go</code> and run <code>make generate</code> =&gt; the file is overwritten.</p>
<p>Now edit the file again, also remove the two lines with the build constraints (the <code>go:build</code> line is for go &gt;= 1.17, the <code>+build</code>line for older versions IIRC) and run <code>make generate</code> again =&gt; your changes to the file have not been overwritten this time.</p>
