由make
与kubebuilder一起生成的每个深度复制生成的文件都会在顶部生成一个带有// +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.
为什么要将这个特定的构建标记指令添加到这些生成的文件中?其目的是什么?
发布于 2022-08-31 15:38:26
controller-gen
使用它来标识它生成的文件,它只会覆盖这些文件。
例如,编辑生成的zz_generated.deepcopy.go
并运行make generate
=>,文件将被覆盖。
现在再次编辑该文件,还删除带有构建约束的两行( go:build
行用于go >= 1.17,+build
行用于较早版本的+build
行),并再次运行make generate
=> --这次对该文件的更改没有被覆盖。
https://stackoverflow.com/questions/73549283
复制相似问题