Skip to Content
Kubernetes编程
book

Kubernetes编程

by Michael Hausenblas, Stefan Schimanski
June 2021
Intermediate to advanced
335 pages
5h 50m
Chinese
China Electric Power Press Ltd.
Content preview from Kubernetes编程
自动代码生成
127
sample-controller
是一个模版项目,很多
Kubernetes
内置的控制器也是使
用了与其一致的模式。如果你的项目也打算选用
k8s.io/sample-controller
所定
义的模式,那首先通过下面的命令来生成代码:
$ hack/update-codegen.sh
6.2
基于
sample-controller
”中基于
sample-controller+client-go
实现的
cnat
示例就是按这个模式来做的。
通常情况下,代码仓库里除了
hack/update-codegen.sh
脚本以外,还有一
个名为
hack/verify-codegen.sh
的脚本。
这个脚本会调用
hack/update-codegen.sh
脚本并检查是否有什么东西发生
了变化,如果已经生成的代码不是最新的,这个脚本会中断运行并返回一个
非零值。
这在持续集成(
Continuous Integration
CI
)的脚本中非常有用,如果开发
者不小心修改了文件或者文件没有及时更新,
CI
就能发现这个问题并及时
发出通知。
5.3
通过标签控制代码生成器行为
除了可以通过先前提到过的命令行参数来控制代码生成器的行为(尤其是用
于指定要处理的包名),还可以通过在
Go
语言源代码中使用标签来控制代码
生成时所使用的属性。在
Go
语言中,“标签”是一段以指定的格式编写的注释:
// +some-tag
// +some-other-tag=value
标签分为两种:
doc.go
文件中
package
行前面的全局标签。 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

解密金融数据

解密金融数据

Justin Pauley
Python机器学习案例精解

Python机器学习案例精解

Posts & Telecom Press, Yuxi (Hayden) Liu
软件开发实践:项目驱动式的Java开发指南

软件开发实践:项目驱动式的Java开发指南

Raoul-Gabriel Urma, Richard Warburton

Publisher Resources

ISBN: 9787519854799