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编程
226
8
}
}
这带来了我们想要实现的语义:“
foo
的默认值是
true
”。
这个使用指针的技巧对其他基础类型比如字符串类型也有效。对于
Map
数组,在无法区分
nil Map/
数组和空
Map/
数组时,很难做到双程转换。所
Kubernetes
里大多数
Map
和数组的默认值处理逻辑在两种情景下都会设
置默认值,以绕过编码和解码时的
Bug
8.4.7
双程测试
要把转换逻辑实现正确很困难。双程测试是一种有效的测试工具,通过在随
机测试中自动检测转换的结果是否符合预期(即在所有组版本之间来回转换
不丢失数据)来保证逻辑正确。
双程测试代码通常放在
install.go
文件中(例如
pkg/apis/restaurant/install/
roundtrip_test.go
)且直接在
API Machinery
中调用双程测试函数:
import (
...
"k8s.io/apimachinery/pkg/api/apitesting/roundtrip"
restaurantfuzzer "github.com/programming-kubernetes/pizza-apiserver/pkg/apis/
restaurant/fuzzer"
)
func TestRoundTripTypes(t *testing.T) {
roundtrip.RoundTripTestForAPIGroup(t, Install, restaurantfuzzer.Funcs)
}
RoundTripTestForAPIGroup ...
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