简体   繁体   English

为什么 kubebuilder 在 zz_generated.deepcopy?go 文件中包含 // +build.ignore_autogenerated?

[英]Why does kubebuilder include // +build !ignore_autogenerated in zz_generated.deepcopy.go files?

Every deepcopy generated file that is produced by make with kubebuilder produces a file with a // +build !ignore_autogenerated build tag directive at the top.使用 kubebuilder 生成的每个 deepcopy 生成的文件make在顶部生成一个带有// +build !ignore_autogenerated构建标签指令的文件。

//go:build !ignore_autogenerated
// +build !ignore_autogenerated

/*
Licensed under the Apache License, Version 2.0 (the "License");
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 "AS IS" 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.

Why is this specific build tag directive added to these generated files?为什么将这个特定的构建标签指令添加到这些生成的文件中? What's its purpose?它的目的是什么?

It's used by controller-gen to identify files it generated, it will only overwrite those. controller-gen使用它来识别它生成的文件,它只会覆盖那些文件。

Eg edit a generated zz_generated.deepcopy.go and run make generate => the file is overwritten.例如编辑生成的zz_generated.deepcopy.go并运行make generate => 文件被覆盖。

Now edit the file again, also remove the two lines with the build constraints (the go:build line is for go >= 1.17, the +build line for older versions IIRC) and run make generate again => your changes to the file have not been overwritten this time.现在再次编辑文件,同时删除带有构建约束的两行( go:build行适用于 go >= 1.17, +build行适用于旧版本 IIRC)并再次运行make generate => 您对文件的更改有这次没有被覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM