5932 lines
438 KiB
HTML
5932 lines
438 KiB
HTML
|
|
|||
|
<!DOCTYPE HTML>
|
|||
|
<html lang="zh-hans" >
|
|||
|
<head>
|
|||
|
<meta charset="UTF-8">
|
|||
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
|||
|
<title>client-go 中的 informer 源码分析 · Kubernetes Handbook - Kubernetes 中文指南/云原生应用架构实践手册 · Jimmy Song</title>
|
|||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|||
|
<meta name="description" content="">
|
|||
|
<meta name="generator" content="GitBook 3.2.3">
|
|||
|
<meta name="author" content="Jimmy Song(宋净超)">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/style.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/gitbook-plugin-page-toc-button/plugin.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/gitbook-plugin-image-captions/image-captions.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search-plus/search.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-ghcolors.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/gitbook-plugin-lightbox/css/lightbox.min.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<meta name="HandheldFriendly" content="true"/>
|
|||
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
|||
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
|||
|
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
|||
|
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
|
|||
|
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
|
|||
|
|
|||
|
|
|||
|
<link rel="next" href="operator.html" />
|
|||
|
|
|||
|
|
|||
|
<link rel="prev" href="client-go-sample.html" />
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="shortcut icon" href='../favicon.ico' type="image/x-icon">
|
|||
|
|
|||
|
|
|||
|
<link rel="bookmark" href='../favicon.ico' type="image/x-icon">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<style>
|
|||
|
@media only screen and (max-width: 640px) {
|
|||
|
.book-header .hidden-mobile {
|
|||
|
display: none;
|
|||
|
}
|
|||
|
}
|
|||
|
</style>
|
|||
|
<script>
|
|||
|
window["gitbook-plugin-github-buttons"] = {"repo":"rootsongjc/kubernetes-handbook","types":["star"],"size":"small"};
|
|||
|
</script>
|
|||
|
|
|||
|
</head>
|
|||
|
<body>
|
|||
|
|
|||
|
<div class="book">
|
|||
|
<div class="book-summary">
|
|||
|
|
|||
|
|
|||
|
<div id="book-search-input" role="search">
|
|||
|
<input type="text" placeholder="输入并搜索" />
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
<nav role="navigation">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="summary">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li>
|
|||
|
<a href="https://jimmysong.io" target="_blank" class="custom-link">回到主页</a>
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
<li>
|
|||
|
<a href="https://jimmysong.io/awesome-cloud-native" target="_blank" class="custom-link">云原生开源项目大全</a>
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
<li>
|
|||
|
<a href="https://cloudnative.to" target="_blank" class="custom-link">云原生社区</a>
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="divider"></li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="header">前言</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.1" data-path="../">
|
|||
|
|
|||
|
<a href="../">
|
|||
|
|
|||
|
|
|||
|
<b>1.1.</b>
|
|||
|
|
|||
|
序言
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="header">云原生</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="2.1" data-path="../cloud-native/cloud-native-definition.html">
|
|||
|
|
|||
|
<a href="../cloud-native/cloud-native-definition.html">
|
|||
|
|
|||
|
|
|||
|
<b>2.1.</b>
|
|||
|
|
|||
|
云原生(Cloud Native)的定义
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="2.2" data-path="../cloud-native/cloud-native-philosophy.html">
|
|||
|
|
|||
|
<a href="../cloud-native/cloud-native-philosophy.html">
|
|||
|
|
|||
|
|
|||
|
<b>2.2.</b>
|
|||
|
|
|||
|
云原生的设计哲学
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="2.3" data-path="../cloud-native/kubernetes-history.html">
|
|||
|
|
|||
|
<a href="../cloud-native/kubernetes-history.html">
|
|||
|
|
|||
|
|
|||
|
<b>2.3.</b>
|
|||
|
|
|||
|
Kubernetes 的诞生
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="2.4" data-path="../cloud-native/kubernetes-and-cloud-native-app-overview.html">
|
|||
|
|
|||
|
<a href="../cloud-native/kubernetes-and-cloud-native-app-overview.html">
|
|||
|
|
|||
|
|
|||
|
<b>2.4.</b>
|
|||
|
|
|||
|
Kubernetes 与云原生应用概览
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="2.5" data-path="../cloud-native/from-kubernetes-to-cloud-native.html">
|
|||
|
|
|||
|
<a href="../cloud-native/from-kubernetes-to-cloud-native.html">
|
|||
|
|
|||
|
|
|||
|
<b>2.5.</b>
|
|||
|
|
|||
|
云原生应用之路 —— 从 Kubernetes 到 Cloud Native
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="2.6" data-path="../cloud-native/define-cloud-native-app.html">
|
|||
|
|
|||
|
<a href="../cloud-native/define-cloud-native-app.html">
|
|||
|
|
|||
|
|
|||
|
<b>2.6.</b>
|
|||
|
|
|||
|
定义云原生应用
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="2.6.1" data-path="../cloud-native/oam.html">
|
|||
|
|
|||
|
<a href="../cloud-native/oam.html">
|
|||
|
|
|||
|
|
|||
|
<b>2.6.1.</b>
|
|||
|
|
|||
|
OAM
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="2.6.1.1" data-path="../cloud-native/workload.html">
|
|||
|
|
|||
|
<a href="../cloud-native/workload.html">
|
|||
|
|
|||
|
|
|||
|
<b>2.6.1.1.</b>
|
|||
|
|
|||
|
Workload
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="2.6.1.2" data-path="../cloud-native/component.html">
|
|||
|
|
|||
|
<a href="../cloud-native/component.html">
|
|||
|
|
|||
|
|
|||
|
<b>2.6.1.2.</b>
|
|||
|
|
|||
|
Component
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="2.6.1.3" data-path="../cloud-native/trait.html">
|
|||
|
|
|||
|
<a href="../cloud-native/trait.html">
|
|||
|
|
|||
|
|
|||
|
<b>2.6.1.3.</b>
|
|||
|
|
|||
|
Trait
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="2.6.1.4" data-path="../cloud-native/application-scope.html">
|
|||
|
|
|||
|
<a href="../cloud-native/application-scope.html">
|
|||
|
|
|||
|
|
|||
|
<b>2.6.1.4.</b>
|
|||
|
|
|||
|
Application Scope
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="2.6.1.5" data-path="../cloud-native/application-configuration.html">
|
|||
|
|
|||
|
<a href="../cloud-native/application-configuration.html">
|
|||
|
|
|||
|
|
|||
|
<b>2.6.1.5.</b>
|
|||
|
|
|||
|
Application Configuration
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="2.6.2" data-path="../cloud-native/crossplane.html">
|
|||
|
|
|||
|
<a href="../cloud-native/crossplane.html">
|
|||
|
|
|||
|
|
|||
|
<b>2.6.2.</b>
|
|||
|
|
|||
|
Crossplane
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="2.7" data-path="../cloud-native/cloud-native-programming-languages.html">
|
|||
|
|
|||
|
<a href="../cloud-native/cloud-native-programming-languages.html">
|
|||
|
|
|||
|
|
|||
|
<b>2.7.</b>
|
|||
|
|
|||
|
云原生编程语言
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="2.7.1" data-path="../cloud-native/cloud-native-programming-language-ballerina.html">
|
|||
|
|
|||
|
<a href="../cloud-native/cloud-native-programming-language-ballerina.html">
|
|||
|
|
|||
|
|
|||
|
<b>2.7.1.</b>
|
|||
|
|
|||
|
云原生编程语言 Ballerina
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="2.7.2" data-path="../cloud-native/cloud-native-programming-language-pulumi.html">
|
|||
|
|
|||
|
<a href="../cloud-native/cloud-native-programming-language-pulumi.html">
|
|||
|
|
|||
|
|
|||
|
<b>2.7.2.</b>
|
|||
|
|
|||
|
云原生编程语言 Pulumi
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="2.8" data-path="../cloud-native/the-future-of-cloud-native.html">
|
|||
|
|
|||
|
<a href="../cloud-native/the-future-of-cloud-native.html">
|
|||
|
|
|||
|
|
|||
|
<b>2.8.</b>
|
|||
|
|
|||
|
云原生的未来
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="header">快速入门</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="3.1" data-path="../cloud-native/quick-start.html">
|
|||
|
|
|||
|
<a href="../cloud-native/quick-start.html">
|
|||
|
|
|||
|
|
|||
|
<b>3.1.</b>
|
|||
|
|
|||
|
云原生新手入门指南
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="3.2" data-path="../cloud-native/play-with-kubernetes.html">
|
|||
|
|
|||
|
<a href="../cloud-native/play-with-kubernetes.html">
|
|||
|
|
|||
|
|
|||
|
<b>3.2.</b>
|
|||
|
|
|||
|
Play with Kubernetes
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="3.3" data-path="../cloud-native/cloud-native-local-quick-start.html">
|
|||
|
|
|||
|
<a href="../cloud-native/cloud-native-local-quick-start.html">
|
|||
|
|
|||
|
|
|||
|
<b>3.3.</b>
|
|||
|
|
|||
|
快速部署一个云原生本地实验环境
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="3.4" data-path="../cloud-native/setup-kubernetes-with-rancher-and-aliyun.html">
|
|||
|
|
|||
|
<a href="../cloud-native/setup-kubernetes-with-rancher-and-aliyun.html">
|
|||
|
|
|||
|
|
|||
|
<b>3.4.</b>
|
|||
|
|
|||
|
使用 Rancher 在阿里云上部署 Kubenretes 集群
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="header">概念与原理</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="4.1" data-path="../concepts/">
|
|||
|
|
|||
|
<a href="../concepts/">
|
|||
|
|
|||
|
|
|||
|
<b>4.1.</b>
|
|||
|
|
|||
|
Kubernetes 架构
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="4.1.1" data-path="../concepts/concepts.html">
|
|||
|
|
|||
|
<a href="../concepts/concepts.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.1.1.</b>
|
|||
|
|
|||
|
设计理念
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.1.2" data-path="../concepts/etcd.html">
|
|||
|
|
|||
|
<a href="../concepts/etcd.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.1.2.</b>
|
|||
|
|
|||
|
Etcd 解析
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.1.3" data-path="../concepts/open-interfaces.html">
|
|||
|
|
|||
|
<a href="../concepts/open-interfaces.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.1.3.</b>
|
|||
|
|
|||
|
开放接口
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="4.1.3.1" data-path="../concepts/cri.html">
|
|||
|
|
|||
|
<a href="../concepts/cri.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.1.3.1.</b>
|
|||
|
|
|||
|
CRI - Container Runtime Interface(容器运行时接口)
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.1.3.2" data-path="../concepts/cni.html">
|
|||
|
|
|||
|
<a href="../concepts/cni.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.1.3.2.</b>
|
|||
|
|
|||
|
CNI - Container Network Interface(容器网络接口)
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.1.3.3" data-path="../concepts/csi.html">
|
|||
|
|
|||
|
<a href="../concepts/csi.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.1.3.3.</b>
|
|||
|
|
|||
|
CSI - Container Storage Interface(容器存储接口)
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.2" data-path="../concepts/networking.html">
|
|||
|
|
|||
|
<a href="../concepts/networking.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.2.</b>
|
|||
|
|
|||
|
Kubernetes 中的网络
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="4.2.1" data-path="../concepts/flannel.html">
|
|||
|
|
|||
|
<a href="../concepts/flannel.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.2.1.</b>
|
|||
|
|
|||
|
Kubernetes 中的网络解析 —— 以 flannel 为例
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.2.2" data-path="../concepts/calico.html">
|
|||
|
|
|||
|
<a href="../concepts/calico.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.2.2.</b>
|
|||
|
|
|||
|
Kubernetes 中的网络解析 —— 以 calico 为例
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.2.3" data-path="../concepts/cilium.html">
|
|||
|
|
|||
|
<a href="../concepts/cilium.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.2.3.</b>
|
|||
|
|
|||
|
具备 API 感知的网络和安全性管理开源软件 Cilium
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="4.2.3.1" data-path="../concepts/cilium-concepts.html">
|
|||
|
|
|||
|
<a href="../concepts/cilium-concepts.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.2.3.1.</b>
|
|||
|
|
|||
|
Cilium 架构设计与概念解析
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.3" data-path="../concepts/objects.html">
|
|||
|
|
|||
|
<a href="../concepts/objects.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.3.</b>
|
|||
|
|
|||
|
资源对象与基本概念解析
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.4" data-path="../concepts/pod-state-and-lifecycle.html">
|
|||
|
|
|||
|
<a href="../concepts/pod-state-and-lifecycle.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.4.</b>
|
|||
|
|
|||
|
Pod 状态与生命周期管理
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="4.4.1" data-path="../concepts/pod-overview.html">
|
|||
|
|
|||
|
<a href="../concepts/pod-overview.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.4.1.</b>
|
|||
|
|
|||
|
Pod 概览
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.4.2" data-path="../concepts/pod.html">
|
|||
|
|
|||
|
<a href="../concepts/pod.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.4.2.</b>
|
|||
|
|
|||
|
Pod 解析
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.4.3" data-path="../concepts/init-containers.html">
|
|||
|
|
|||
|
<a href="../concepts/init-containers.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.4.3.</b>
|
|||
|
|
|||
|
Init 容器
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.4.4" data-path="../concepts/pause-container.html">
|
|||
|
|
|||
|
<a href="../concepts/pause-container.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.4.4.</b>
|
|||
|
|
|||
|
Pause 容器
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.4.5" data-path="../concepts/pod-security-policy.html">
|
|||
|
|
|||
|
<a href="../concepts/pod-security-policy.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.4.5.</b>
|
|||
|
|
|||
|
Pod 安全策略
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.4.6" data-path="../concepts/pod-lifecycle.html">
|
|||
|
|
|||
|
<a href="../concepts/pod-lifecycle.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.4.6.</b>
|
|||
|
|
|||
|
Pod 的生命周期
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.4.7" data-path="../concepts/pod-hook.html">
|
|||
|
|
|||
|
<a href="../concepts/pod-hook.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.4.7.</b>
|
|||
|
|
|||
|
Pod Hook
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.4.8" data-path="../concepts/pod-preset.html">
|
|||
|
|
|||
|
<a href="../concepts/pod-preset.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.4.8.</b>
|
|||
|
|
|||
|
Pod Preset
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.4.9" data-path="../concepts/pod-disruption-budget.html">
|
|||
|
|
|||
|
<a href="../concepts/pod-disruption-budget.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.4.9.</b>
|
|||
|
|
|||
|
Pod 中断与 PDB(Pod 中断预算)
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.5" data-path="../concepts/cluster.html">
|
|||
|
|
|||
|
<a href="../concepts/cluster.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.5.</b>
|
|||
|
|
|||
|
集群资源管理
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="4.5.1" data-path="../concepts/node.html">
|
|||
|
|
|||
|
<a href="../concepts/node.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.5.1.</b>
|
|||
|
|
|||
|
Node
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.5.2" data-path="../concepts/namespace.html">
|
|||
|
|
|||
|
<a href="../concepts/namespace.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.5.2.</b>
|
|||
|
|
|||
|
Namespace
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.5.3" data-path="../concepts/label.html">
|
|||
|
|
|||
|
<a href="../concepts/label.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.5.3.</b>
|
|||
|
|
|||
|
Label
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.5.4" data-path="../concepts/annotation.html">
|
|||
|
|
|||
|
<a href="../concepts/annotation.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.5.4.</b>
|
|||
|
|
|||
|
Annotation
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.5.5" data-path="../concepts/taint-and-toleration.html">
|
|||
|
|
|||
|
<a href="../concepts/taint-and-toleration.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.5.5.</b>
|
|||
|
|
|||
|
Taint 和 Toleration(污点和容忍)
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.5.6" data-path="../concepts/garbage-collection.html">
|
|||
|
|
|||
|
<a href="../concepts/garbage-collection.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.5.6.</b>
|
|||
|
|
|||
|
垃圾收集
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.6" data-path="../concepts/controllers.html">
|
|||
|
|
|||
|
<a href="../concepts/controllers.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.6.</b>
|
|||
|
|
|||
|
控制器
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="4.6.1" data-path="../concepts/deployment.html">
|
|||
|
|
|||
|
<a href="../concepts/deployment.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.6.1.</b>
|
|||
|
|
|||
|
Deployment
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.6.2" data-path="../concepts/statefulset.html">
|
|||
|
|
|||
|
<a href="../concepts/statefulset.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.6.2.</b>
|
|||
|
|
|||
|
StatefulSet
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.6.3" data-path="../concepts/daemonset.html">
|
|||
|
|
|||
|
<a href="../concepts/daemonset.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.6.3.</b>
|
|||
|
|
|||
|
DaemonSet
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.6.4" data-path="../concepts/replicaset.html">
|
|||
|
|
|||
|
<a href="../concepts/replicaset.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.6.4.</b>
|
|||
|
|
|||
|
ReplicationController 和 ReplicaSet
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.6.5" data-path="../concepts/job.html">
|
|||
|
|
|||
|
<a href="../concepts/job.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.6.5.</b>
|
|||
|
|
|||
|
Job
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.6.6" data-path="../concepts/cronjob.html">
|
|||
|
|
|||
|
<a href="../concepts/cronjob.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.6.6.</b>
|
|||
|
|
|||
|
CronJob
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.6.7" data-path="../concepts/horizontal-pod-autoscaling.html">
|
|||
|
|
|||
|
<a href="../concepts/horizontal-pod-autoscaling.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.6.7.</b>
|
|||
|
|
|||
|
Horizontal Pod Autoscaling
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="4.6.7.1" data-path="../concepts/custom-metrics-hpa.html">
|
|||
|
|
|||
|
<a href="../concepts/custom-metrics-hpa.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.6.7.1.</b>
|
|||
|
|
|||
|
自定义指标 HPA
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.6.8" data-path="../concepts/admission-controller.html">
|
|||
|
|
|||
|
<a href="../concepts/admission-controller.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.6.8.</b>
|
|||
|
|
|||
|
准入控制器(Admission Controller)
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.7" data-path="../concepts/service-discovery.html">
|
|||
|
|
|||
|
<a href="../concepts/service-discovery.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.7.</b>
|
|||
|
|
|||
|
服务发现
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="4.7.1" data-path="../concepts/service.html">
|
|||
|
|
|||
|
<a href="../concepts/service.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.7.1.</b>
|
|||
|
|
|||
|
Service
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.7.2" data-path="../concepts/ingress.html">
|
|||
|
|
|||
|
<a href="../concepts/ingress.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.7.2.</b>
|
|||
|
|
|||
|
Ingress
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="4.7.2.1" data-path="../concepts/traefik-ingress-controller.html">
|
|||
|
|
|||
|
<a href="../concepts/traefik-ingress-controller.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.7.2.1.</b>
|
|||
|
|
|||
|
Traefik Ingress Controller
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.7.3" data-path="../concepts/kubernetes-service-api.html">
|
|||
|
|
|||
|
<a href="../concepts/kubernetes-service-api.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.7.3.</b>
|
|||
|
|
|||
|
Kubernetes Service API
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="4.7.3.1" data-path="../concepts/service-api-overview.html">
|
|||
|
|
|||
|
<a href="../concepts/service-api-overview.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.7.3.1.</b>
|
|||
|
|
|||
|
Service API 简介
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.8" data-path="../concepts/authentication-and-permission.html">
|
|||
|
|
|||
|
<a href="../concepts/authentication-and-permission.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.8.</b>
|
|||
|
|
|||
|
身份与权限控制
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="4.8.1" data-path="../concepts/serviceaccount.html">
|
|||
|
|
|||
|
<a href="../concepts/serviceaccount.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.8.1.</b>
|
|||
|
|
|||
|
ServiceAccount
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.8.2" data-path="../concepts/rbac.html">
|
|||
|
|
|||
|
<a href="../concepts/rbac.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.8.2.</b>
|
|||
|
|
|||
|
RBAC—— 基于角色的访问控制
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.8.3" data-path="../concepts/network-policy.html">
|
|||
|
|
|||
|
<a href="../concepts/network-policy.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.8.3.</b>
|
|||
|
|
|||
|
NetworkPolicy
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.9" data-path="../concepts/storage.html">
|
|||
|
|
|||
|
<a href="../concepts/storage.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.9.</b>
|
|||
|
|
|||
|
存储
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="4.9.1" data-path="../concepts/secret.html">
|
|||
|
|
|||
|
<a href="../concepts/secret.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.9.1.</b>
|
|||
|
|
|||
|
Secret
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.9.2" data-path="../concepts/configmap.html">
|
|||
|
|
|||
|
<a href="../concepts/configmap.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.9.2.</b>
|
|||
|
|
|||
|
ConfigMap
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="4.9.2.1" data-path="../concepts/configmap-hot-update.html">
|
|||
|
|
|||
|
<a href="../concepts/configmap-hot-update.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.9.2.1.</b>
|
|||
|
|
|||
|
ConfigMap 的热更新
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.9.3" data-path="../concepts/volume.html">
|
|||
|
|
|||
|
<a href="../concepts/volume.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.9.3.</b>
|
|||
|
|
|||
|
Volume
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.9.4" data-path="../concepts/persistent-volume.html">
|
|||
|
|
|||
|
<a href="../concepts/persistent-volume.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.9.4.</b>
|
|||
|
|
|||
|
Persistent Volume(持久化卷)
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.9.5" data-path="../concepts/storageclass.html">
|
|||
|
|
|||
|
<a href="../concepts/storageclass.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.9.5.</b>
|
|||
|
|
|||
|
Storage Class
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.9.6" data-path="../concepts/local-persistent-storage.html">
|
|||
|
|
|||
|
<a href="../concepts/local-persistent-storage.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.9.6.</b>
|
|||
|
|
|||
|
本地持久化存储
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.10" data-path="../concepts/extension.html">
|
|||
|
|
|||
|
<a href="../concepts/extension.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.10.</b>
|
|||
|
|
|||
|
集群扩展
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="4.10.1" data-path="../concepts/custom-resource.html">
|
|||
|
|
|||
|
<a href="../concepts/custom-resource.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.10.1.</b>
|
|||
|
|
|||
|
使用自定义资源扩展 API
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.10.2" data-path="../concepts/crd.html">
|
|||
|
|
|||
|
<a href="../concepts/crd.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.10.2.</b>
|
|||
|
|
|||
|
使用 CRD 扩展 Kubernetes API
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.10.3" data-path="../concepts/aggregated-api-server.html">
|
|||
|
|
|||
|
<a href="../concepts/aggregated-api-server.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.10.3.</b>
|
|||
|
|
|||
|
Aggregated API Server
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.10.4" data-path="../concepts/apiservice.html">
|
|||
|
|
|||
|
<a href="../concepts/apiservice.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.10.4.</b>
|
|||
|
|
|||
|
APIService
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.10.5" data-path="../concepts/service-catalog.html">
|
|||
|
|
|||
|
<a href="../concepts/service-catalog.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.10.5.</b>
|
|||
|
|
|||
|
Service Catalog
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.10.6" data-path="../concepts/multicluster.html">
|
|||
|
|
|||
|
<a href="../concepts/multicluster.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.10.6.</b>
|
|||
|
|
|||
|
多集群管理
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="4.11" data-path="../concepts/scheduling.html">
|
|||
|
|
|||
|
<a href="../concepts/scheduling.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.11.</b>
|
|||
|
|
|||
|
资源调度
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="4.11.1" data-path="../concepts/qos.html">
|
|||
|
|
|||
|
<a href="../concepts/qos.html">
|
|||
|
|
|||
|
|
|||
|
<b>4.11.1.</b>
|
|||
|
|
|||
|
QoS(服务质量等级)
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="header">用户指南</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="5.1" data-path="../guide/">
|
|||
|
|
|||
|
<a href="../guide/">
|
|||
|
|
|||
|
|
|||
|
<b>5.1.</b>
|
|||
|
|
|||
|
用户指南概览
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.2" data-path="../guide/resource-configuration.html">
|
|||
|
|
|||
|
<a href="../guide/resource-configuration.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.2.</b>
|
|||
|
|
|||
|
资源对象配置
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="5.2.1" data-path="../guide/configure-liveness-readiness-probes.html">
|
|||
|
|
|||
|
<a href="../guide/configure-liveness-readiness-probes.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.2.1.</b>
|
|||
|
|
|||
|
配置 Pod 的 liveness 和 readiness 探针
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.2.2" data-path="../guide/configure-pod-service-account.html">
|
|||
|
|
|||
|
<a href="../guide/configure-pod-service-account.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.2.2.</b>
|
|||
|
|
|||
|
配置 Pod 的 Service Account
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.2.3" data-path="../guide/secret-configuration.html">
|
|||
|
|
|||
|
<a href="../guide/secret-configuration.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.2.3.</b>
|
|||
|
|
|||
|
Secret 配置
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.2.4" data-path="../guide/resource-quota-management.html">
|
|||
|
|
|||
|
<a href="../guide/resource-quota-management.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.2.4.</b>
|
|||
|
|
|||
|
管理 namespace 中的资源配额
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.3" data-path="../guide/command-usage.html">
|
|||
|
|
|||
|
<a href="../guide/command-usage.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.3.</b>
|
|||
|
|
|||
|
命令使用
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="5.3.1" data-path="../guide/docker-cli-to-kubectl.html">
|
|||
|
|
|||
|
<a href="../guide/docker-cli-to-kubectl.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.3.1.</b>
|
|||
|
|
|||
|
Docker 用户过渡到 kubectl 命令行指南
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.3.2" data-path="../guide/using-kubectl.html">
|
|||
|
|
|||
|
<a href="../guide/using-kubectl.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.3.2.</b>
|
|||
|
|
|||
|
kubectl 命令概览
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.3.3" data-path="../guide/kubectl-cheatsheet.html">
|
|||
|
|
|||
|
<a href="../guide/kubectl-cheatsheet.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.3.3.</b>
|
|||
|
|
|||
|
kubectl 命令技巧大全
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.3.4" data-path="../guide/using-etcdctl-to-access-kubernetes-data.html">
|
|||
|
|
|||
|
<a href="../guide/using-etcdctl-to-access-kubernetes-data.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.3.4.</b>
|
|||
|
|
|||
|
使用 etcdctl 访问 kubernetes 数据
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.4" data-path="../guide/cluster-security-management.html">
|
|||
|
|
|||
|
<a href="../guide/cluster-security-management.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.4.</b>
|
|||
|
|
|||
|
集群安全性管理
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="5.4.1" data-path="../guide/managing-tls-in-a-cluster.html">
|
|||
|
|
|||
|
<a href="../guide/managing-tls-in-a-cluster.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.4.1.</b>
|
|||
|
|
|||
|
管理集群中的 TLS
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.4.2" data-path="../guide/kubelet-authentication-authorization.html">
|
|||
|
|
|||
|
<a href="../guide/kubelet-authentication-authorization.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.4.2.</b>
|
|||
|
|
|||
|
kubelet 的认证授权
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.4.3" data-path="../guide/tls-bootstrapping.html">
|
|||
|
|
|||
|
<a href="../guide/tls-bootstrapping.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.4.3.</b>
|
|||
|
|
|||
|
TLS Bootstrap
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.4.4" data-path="../guide/kubectl-user-authentication-authorization.html">
|
|||
|
|
|||
|
<a href="../guide/kubectl-user-authentication-authorization.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.4.4.</b>
|
|||
|
|
|||
|
创建用户认证授权的 kubeconfig 文件
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.4.5" data-path="../guide/ip-masq-agent.html">
|
|||
|
|
|||
|
<a href="../guide/ip-masq-agent.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.4.5.</b>
|
|||
|
|
|||
|
IP 伪装代理
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.4.6" data-path="../guide/auth-with-kubeconfig-or-token.html">
|
|||
|
|
|||
|
<a href="../guide/auth-with-kubeconfig-or-token.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.4.6.</b>
|
|||
|
|
|||
|
使用 kubeconfig 或 token 进行用户身份认证
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.4.7" data-path="../guide/authentication.html">
|
|||
|
|
|||
|
<a href="../guide/authentication.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.4.7.</b>
|
|||
|
|
|||
|
Kubernetes 中的用户与身份认证授权
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.4.8" data-path="../guide/kubernetes-security-best-practice.html">
|
|||
|
|
|||
|
<a href="../guide/kubernetes-security-best-practice.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.4.8.</b>
|
|||
|
|
|||
|
Kubernetes 集群安全性配置最佳实践
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.5" data-path="../guide/access-kubernetes-cluster.html">
|
|||
|
|
|||
|
<a href="../guide/access-kubernetes-cluster.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.5.</b>
|
|||
|
|
|||
|
访问 Kubernetes 集群
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="5.5.1" data-path="../guide/access-cluster.html">
|
|||
|
|
|||
|
<a href="../guide/access-cluster.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.5.1.</b>
|
|||
|
|
|||
|
访问集群
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.5.2" data-path="../guide/authenticate-across-clusters-kubeconfig.html">
|
|||
|
|
|||
|
<a href="../guide/authenticate-across-clusters-kubeconfig.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.5.2.</b>
|
|||
|
|
|||
|
使用 kubeconfig 文件配置跨集群认证
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.5.3" data-path="../guide/connecting-to-applications-port-forward.html">
|
|||
|
|
|||
|
<a href="../guide/connecting-to-applications-port-forward.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.5.3.</b>
|
|||
|
|
|||
|
通过端口转发访问集群中的应用程序
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.5.4" data-path="../guide/service-access-application-cluster.html">
|
|||
|
|
|||
|
<a href="../guide/service-access-application-cluster.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.5.4.</b>
|
|||
|
|
|||
|
使用 service 访问群集中的应用程序
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.5.5" data-path="../guide/accessing-kubernetes-pods-from-outside-of-the-cluster.html">
|
|||
|
|
|||
|
<a href="../guide/accessing-kubernetes-pods-from-outside-of-the-cluster.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.5.5.</b>
|
|||
|
|
|||
|
从外部访问 Kubernetes 中的 Pod
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.5.6" data-path="../guide/cabin-mobile-dashboard-for-kubernetes.html">
|
|||
|
|
|||
|
<a href="../guide/cabin-mobile-dashboard-for-kubernetes.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.5.6.</b>
|
|||
|
|
|||
|
Cabin - Kubernetes 手机客户端
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.5.7" data-path="../guide/kubernetes-desktop-client.html">
|
|||
|
|
|||
|
<a href="../guide/kubernetes-desktop-client.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.5.7.</b>
|
|||
|
|
|||
|
Lens - Kubernetes IDE/桌面客户端
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.5.8" data-path="../guide/kubernator-kubernetes-ui.html">
|
|||
|
|
|||
|
<a href="../guide/kubernator-kubernetes-ui.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.5.8.</b>
|
|||
|
|
|||
|
Kubernator - 更底层的 Kubernetes UI
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.6" data-path="../guide/application-development-deployment-flow.html">
|
|||
|
|
|||
|
<a href="../guide/application-development-deployment-flow.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.6.</b>
|
|||
|
|
|||
|
在 Kubernetes 中开发部署应用
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="5.6.1" data-path="../guide/deploy-applications-in-kubernetes.html">
|
|||
|
|
|||
|
<a href="../guide/deploy-applications-in-kubernetes.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.6.1.</b>
|
|||
|
|
|||
|
适用于 kubernetes 的应用开发部署流程
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.6.2" data-path="../guide/migrating-hadoop-yarn-to-kubernetes.html">
|
|||
|
|
|||
|
<a href="../guide/migrating-hadoop-yarn-to-kubernetes.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.6.2.</b>
|
|||
|
|
|||
|
迁移传统应用到 Kubernetes 中 —— 以 Hadoop YARN 为例
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="5.6.3" data-path="../guide/using-statefulset.html">
|
|||
|
|
|||
|
<a href="../guide/using-statefulset.html">
|
|||
|
|
|||
|
|
|||
|
<b>5.6.3.</b>
|
|||
|
|
|||
|
使用 StatefulSet 部署用状态应用
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="header">最佳实践</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.1" data-path="../practice/">
|
|||
|
|
|||
|
<a href="../practice/">
|
|||
|
|
|||
|
|
|||
|
<b>6.1.</b>
|
|||
|
|
|||
|
最佳实践概览
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.2" data-path="../practice/install-kubernetes-on-centos.html">
|
|||
|
|
|||
|
<a href="../practice/install-kubernetes-on-centos.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.2.</b>
|
|||
|
|
|||
|
在 CentOS 上部署 Kubernetes 集群
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.2.1" data-path="../practice/create-tls-and-secret-key.html">
|
|||
|
|
|||
|
<a href="../practice/create-tls-and-secret-key.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.2.1.</b>
|
|||
|
|
|||
|
创建 TLS 证书和秘钥
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.2.2" data-path="../practice/create-kubeconfig.html">
|
|||
|
|
|||
|
<a href="../practice/create-kubeconfig.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.2.2.</b>
|
|||
|
|
|||
|
创建 kubeconfig 文件
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.2.3" data-path="../practice/etcd-cluster-installation.html">
|
|||
|
|
|||
|
<a href="../practice/etcd-cluster-installation.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.2.3.</b>
|
|||
|
|
|||
|
创建高可用 etcd 集群
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.2.4" data-path="../practice/kubectl-installation.html">
|
|||
|
|
|||
|
<a href="../practice/kubectl-installation.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.2.4.</b>
|
|||
|
|
|||
|
安装 kubectl 命令行工具
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.2.5" data-path="../practice/master-installation.html">
|
|||
|
|
|||
|
<a href="../practice/master-installation.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.2.5.</b>
|
|||
|
|
|||
|
部署 master 节点
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.2.6" data-path="../practice/flannel-installation.html">
|
|||
|
|
|||
|
<a href="../practice/flannel-installation.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.2.6.</b>
|
|||
|
|
|||
|
安装 flannel 网络插件
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.2.7" data-path="../practice/node-installation.html">
|
|||
|
|
|||
|
<a href="../practice/node-installation.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.2.7.</b>
|
|||
|
|
|||
|
部署 node 节点
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.2.8" data-path="../practice/kubedns-addon-installation.html">
|
|||
|
|
|||
|
<a href="../practice/kubedns-addon-installation.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.2.8.</b>
|
|||
|
|
|||
|
安装 kubedns 插件
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.2.9" data-path="../practice/dashboard-addon-installation.html">
|
|||
|
|
|||
|
<a href="../practice/dashboard-addon-installation.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.2.9.</b>
|
|||
|
|
|||
|
安装 dashboard 插件
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.2.10" data-path="../practice/heapster-addon-installation.html">
|
|||
|
|
|||
|
<a href="../practice/heapster-addon-installation.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.2.10.</b>
|
|||
|
|
|||
|
安装 heapster 插件
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.2.11" data-path="../practice/efk-addon-installation.html">
|
|||
|
|
|||
|
<a href="../practice/efk-addon-installation.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.2.11.</b>
|
|||
|
|
|||
|
安装 EFK 插件
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.3" data-path="../practice/install-kubernetes-with-kubeadm.html">
|
|||
|
|
|||
|
<a href="../practice/install-kubernetes-with-kubeadm.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.3.</b>
|
|||
|
|
|||
|
生产级的 Kubernetes 简化管理工具 kubeadm
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.3.1" data-path="../practice/install-kubernetes-on-ubuntu-server-16.04-with-kubeadm.html">
|
|||
|
|
|||
|
<a href="../practice/install-kubernetes-on-ubuntu-server-16.04-with-kubeadm.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.3.1.</b>
|
|||
|
|
|||
|
使用 kubeadm 在 Ubuntu Server 16.04 上快速构建测试集群
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.4" data-path="../practice/service-discovery-and-loadbalancing.html">
|
|||
|
|
|||
|
<a href="../practice/service-discovery-and-loadbalancing.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.4.</b>
|
|||
|
|
|||
|
服务发现与负载均衡
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.4.1" data-path="../practice/traefik-ingress-installation.html">
|
|||
|
|
|||
|
<a href="../practice/traefik-ingress-installation.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.4.1.</b>
|
|||
|
|
|||
|
安装 Traefik ingress
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.4.2" data-path="../practice/distributed-load-test.html">
|
|||
|
|
|||
|
<a href="../practice/distributed-load-test.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.4.2.</b>
|
|||
|
|
|||
|
分布式负载测试
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.4.3" data-path="../practice/network-and-cluster-perfermance-test.html">
|
|||
|
|
|||
|
<a href="../practice/network-and-cluster-perfermance-test.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.4.3.</b>
|
|||
|
|
|||
|
网络和集群性能测试
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.4.4" data-path="../practice/edge-node-configuration.html">
|
|||
|
|
|||
|
<a href="../practice/edge-node-configuration.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.4.4.</b>
|
|||
|
|
|||
|
边缘节点配置
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.4.5" data-path="../practice/nginx-ingress-installation.html">
|
|||
|
|
|||
|
<a href="../practice/nginx-ingress-installation.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.4.5.</b>
|
|||
|
|
|||
|
安装 Nginx ingress
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.4.6" data-path="../practice/dns-installation.html">
|
|||
|
|
|||
|
<a href="../practice/dns-installation.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.4.6.</b>
|
|||
|
|
|||
|
安装配置 DNS
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.4.6.1" data-path="../practice/configuring-dns.html">
|
|||
|
|
|||
|
<a href="../practice/configuring-dns.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.4.6.1.</b>
|
|||
|
|
|||
|
安装配置 Kube-dns
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.4.6.2" data-path="../practice/coredns.html">
|
|||
|
|
|||
|
<a href="../practice/coredns.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.4.6.2.</b>
|
|||
|
|
|||
|
安装配置 CoreDNS
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.5" data-path="../practice/operation.html">
|
|||
|
|
|||
|
<a href="../practice/operation.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.5.</b>
|
|||
|
|
|||
|
运维管理
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.5.1" data-path="../practice/master-ha.html">
|
|||
|
|
|||
|
<a href="../practice/master-ha.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.5.1.</b>
|
|||
|
|
|||
|
Master 节点高可用
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.5.2" data-path="../practice/service-rolling-update.html">
|
|||
|
|
|||
|
<a href="../practice/service-rolling-update.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.5.2.</b>
|
|||
|
|
|||
|
服务滚动升级
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.5.3" data-path="../practice/app-log-collection.html">
|
|||
|
|
|||
|
<a href="../practice/app-log-collection.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.5.3.</b>
|
|||
|
|
|||
|
应用日志收集
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.5.4" data-path="../practice/configuration-best-practice.html">
|
|||
|
|
|||
|
<a href="../practice/configuration-best-practice.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.5.4.</b>
|
|||
|
|
|||
|
配置最佳实践
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.5.5" data-path="../practice/monitor.html">
|
|||
|
|
|||
|
<a href="../practice/monitor.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.5.5.</b>
|
|||
|
|
|||
|
集群及应用监控
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.5.6" data-path="../practice/data-persistence-problem.html">
|
|||
|
|
|||
|
<a href="../practice/data-persistence-problem.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.5.6.</b>
|
|||
|
|
|||
|
数据持久化问题
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.5.7" data-path="../practice/manage-compute-resources-container.html">
|
|||
|
|
|||
|
<a href="../practice/manage-compute-resources-container.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.5.7.</b>
|
|||
|
|
|||
|
管理容器的计算资源
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.5.8" data-path="../practice/federation.html">
|
|||
|
|
|||
|
<a href="../practice/federation.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.5.8.</b>
|
|||
|
|
|||
|
集群联邦(Cluster Federation)
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.6" data-path="../practice/storage.html">
|
|||
|
|
|||
|
<a href="../practice/storage.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.6.</b>
|
|||
|
|
|||
|
存储管理
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.6.1" data-path="../practice/glusterfs.html">
|
|||
|
|
|||
|
<a href="../practice/glusterfs.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.6.1.</b>
|
|||
|
|
|||
|
GlusterFS
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.6.1.1" data-path="../practice/using-glusterfs-for-persistent-storage.html">
|
|||
|
|
|||
|
<a href="../practice/using-glusterfs-for-persistent-storage.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.6.1.1.</b>
|
|||
|
|
|||
|
使用 GlusterFS 做持久化存储
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.6.1.2" data-path="../practice/using-heketi-gluster-for-persistent-storage.html">
|
|||
|
|
|||
|
<a href="../practice/using-heketi-gluster-for-persistent-storage.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.6.1.2.</b>
|
|||
|
|
|||
|
使用 Heketi 作为 Kubernetes 的持久存储 GlusterFS 的 external provisioner
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.6.1.3" data-path="../practice/storage-for-containers-using-glusterfs-with-openshift.html">
|
|||
|
|
|||
|
<a href="../practice/storage-for-containers-using-glusterfs-with-openshift.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.6.1.3.</b>
|
|||
|
|
|||
|
在 OpenShift 中使用 GlusterFS 做持久化存储
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.6.2" data-path="../practice/glusterd-2.0.html">
|
|||
|
|
|||
|
<a href="../practice/glusterd-2.0.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.6.2.</b>
|
|||
|
|
|||
|
GlusterD-2.0
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.6.3" data-path="../practice/ceph.html">
|
|||
|
|
|||
|
<a href="../practice/ceph.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.6.3.</b>
|
|||
|
|
|||
|
Ceph
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.6.3.1" data-path="../practice/ceph-helm-install-guide-zh.html">
|
|||
|
|
|||
|
<a href="../practice/ceph-helm-install-guide-zh.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.6.3.1.</b>
|
|||
|
|
|||
|
用 Helm 托管安装 Ceph 集群并提供后端存储
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.6.3.2" data-path="../practice/using-ceph-for-persistent-storage.html">
|
|||
|
|
|||
|
<a href="../practice/using-ceph-for-persistent-storage.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.6.3.2.</b>
|
|||
|
|
|||
|
使用 Ceph 做持久化存储
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.6.3.3" data-path="../practice/rbd-provisioner.html">
|
|||
|
|
|||
|
<a href="../practice/rbd-provisioner.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.6.3.3.</b>
|
|||
|
|
|||
|
使用 rbd-provisioner 提供 rbd 持久化存储
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.6.4" data-path="../practice/openebs.html">
|
|||
|
|
|||
|
<a href="../practice/openebs.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.6.4.</b>
|
|||
|
|
|||
|
OpenEBS
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.6.4.1" data-path="../practice/using-openebs-for-persistent-storage.html">
|
|||
|
|
|||
|
<a href="../practice/using-openebs-for-persistent-storage.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.6.4.1.</b>
|
|||
|
|
|||
|
使用 OpenEBS 做持久化存储
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.6.5" data-path="../practice/rook.html">
|
|||
|
|
|||
|
<a href="../practice/rook.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.6.5.</b>
|
|||
|
|
|||
|
Rook
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.6.6" data-path="../practice/nfs.html">
|
|||
|
|
|||
|
<a href="../practice/nfs.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.6.6.</b>
|
|||
|
|
|||
|
NFS
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.6.6.1" data-path="../practice/using-nfs-for-persistent-storage.html">
|
|||
|
|
|||
|
<a href="../practice/using-nfs-for-persistent-storage.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.6.6.1.</b>
|
|||
|
|
|||
|
利用 NFS 动态提供 Kubernetes 后端存储卷
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.7" data-path="../practice/monitoring.html">
|
|||
|
|
|||
|
<a href="../practice/monitoring.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.7.</b>
|
|||
|
|
|||
|
集群与应用监控
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.7.1" data-path="../practice/heapster.html">
|
|||
|
|
|||
|
<a href="../practice/heapster.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.7.1.</b>
|
|||
|
|
|||
|
Heapster
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.7.1.1" data-path="../practice/using-heapster-to-get-object-metrics.html">
|
|||
|
|
|||
|
<a href="../practice/using-heapster-to-get-object-metrics.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.7.1.1.</b>
|
|||
|
|
|||
|
使用 Heapster 获取集群和对象的 metric 数据
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.7.2" data-path="../practice/prometheus.html">
|
|||
|
|
|||
|
<a href="../practice/prometheus.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.7.2.</b>
|
|||
|
|
|||
|
Prometheus
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.7.2.1" data-path="../practice/using-prometheus-to-monitor-kuberentes-cluster.html">
|
|||
|
|
|||
|
<a href="../practice/using-prometheus-to-monitor-kuberentes-cluster.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.7.2.1.</b>
|
|||
|
|
|||
|
使用 Prometheus 监控 kubernetes 集群
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.7.2.2" data-path="../practice/promql.html">
|
|||
|
|
|||
|
<a href="../practice/promql.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.7.2.2.</b>
|
|||
|
|
|||
|
Prometheus 查询语言 PromQL 使用说明
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.7.3" data-path="../practice/vistio-visualize-your-istio-mesh.html">
|
|||
|
|
|||
|
<a href="../practice/vistio-visualize-your-istio-mesh.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.7.3.</b>
|
|||
|
|
|||
|
使用 Vistio 监控 Istio 服务网格中的流量
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.8" data-path="../practice/distributed-tracing.html">
|
|||
|
|
|||
|
<a href="../practice/distributed-tracing.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.8.</b>
|
|||
|
|
|||
|
分布式追踪
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.8.1" data-path="../practice/opentracing.html">
|
|||
|
|
|||
|
<a href="../practice/opentracing.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.8.1.</b>
|
|||
|
|
|||
|
OpenTracing
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.9" data-path="../practice/services-management-tool.html">
|
|||
|
|
|||
|
<a href="../practice/services-management-tool.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.9.</b>
|
|||
|
|
|||
|
服务编排管理
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.9.1" data-path="../practice/helm.html">
|
|||
|
|
|||
|
<a href="../practice/helm.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.9.1.</b>
|
|||
|
|
|||
|
使用 Helm 管理 Kubernetes 应用
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.9.2" data-path="../practice/create-private-charts-repo.html">
|
|||
|
|
|||
|
<a href="../practice/create-private-charts-repo.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.9.2.</b>
|
|||
|
|
|||
|
构建私有 Chart 仓库
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.10" data-path="../practice/ci-cd.html">
|
|||
|
|
|||
|
<a href="../practice/ci-cd.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.10.</b>
|
|||
|
|
|||
|
持续集成与发布
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.10.1" data-path="../practice/jenkins-ci-cd.html">
|
|||
|
|
|||
|
<a href="../practice/jenkins-ci-cd.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.10.1.</b>
|
|||
|
|
|||
|
使用 Jenkins 进行持续集成与发布
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.10.2" data-path="../practice/drone-ci-cd.html">
|
|||
|
|
|||
|
<a href="../practice/drone-ci-cd.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.10.2.</b>
|
|||
|
|
|||
|
使用 Drone 进行持续集成与发布
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.11" data-path="../practice/update-and-upgrade.html">
|
|||
|
|
|||
|
<a href="../practice/update-and-upgrade.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.11.</b>
|
|||
|
|
|||
|
更新与升级
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.11.1" data-path="../practice/manually-upgrade.html">
|
|||
|
|
|||
|
<a href="../practice/manually-upgrade.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.11.1.</b>
|
|||
|
|
|||
|
手动升级 Kubernetes 集群
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.11.2" data-path="../practice/dashboard-upgrade.html">
|
|||
|
|
|||
|
<a href="../practice/dashboard-upgrade.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.11.2.</b>
|
|||
|
|
|||
|
升级 dashboard
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.12" data-path="../practice/controller-extended.html">
|
|||
|
|
|||
|
<a href="../practice/controller-extended.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.12.</b>
|
|||
|
|
|||
|
扩展控制器
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.12.1" data-path="../practice/openkruise.html">
|
|||
|
|
|||
|
<a href="../practice/openkruise.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.12.1.</b>
|
|||
|
|
|||
|
OpenKruise
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.12.1.1" data-path="../practice/in-place-update.html">
|
|||
|
|
|||
|
<a href="../practice/in-place-update.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.12.1.1.</b>
|
|||
|
|
|||
|
原地升级
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="6.13" data-path="../practice/security-policy.html">
|
|||
|
|
|||
|
<a href="../practice/security-policy.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.13.</b>
|
|||
|
|
|||
|
安全策略
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="6.13.1" data-path="../practice/open-policy-agent.html">
|
|||
|
|
|||
|
<a href="../practice/open-policy-agent.html">
|
|||
|
|
|||
|
|
|||
|
<b>6.13.1.</b>
|
|||
|
|
|||
|
OPA(开放策略代理)
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="header">服务网格</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="7.1" data-path="../usecases/service-mesh.html">
|
|||
|
|
|||
|
<a href="../usecases/service-mesh.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.1.</b>
|
|||
|
|
|||
|
服务网格(Service Mesh)
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.2" data-path="../usecases/the-enterprise-path-to-service-mesh-architectures.html">
|
|||
|
|
|||
|
<a href="../usecases/the-enterprise-path-to-service-mesh-architectures.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.2.</b>
|
|||
|
|
|||
|
企业级服务网格架构
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="7.2.1" data-path="../usecases/service-mesh-fundamental.html">
|
|||
|
|
|||
|
<a href="../usecases/service-mesh-fundamental.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.2.1.</b>
|
|||
|
|
|||
|
服务网格基础
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.2.2" data-path="../usecases/comparing-service-mesh-technologies.html">
|
|||
|
|
|||
|
<a href="../usecases/comparing-service-mesh-technologies.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.2.2.</b>
|
|||
|
|
|||
|
服务网格技术对比
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.2.3" data-path="../usecases/service-mesh-vs-api-gateway.html">
|
|||
|
|
|||
|
<a href="../usecases/service-mesh-vs-api-gateway.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.2.3.</b>
|
|||
|
|
|||
|
服务网格对比 API 网关
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.2.4" data-path="../usecases/service-mesh-adoption-and-evolution.html">
|
|||
|
|
|||
|
<a href="../usecases/service-mesh-adoption-and-evolution.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.2.4.</b>
|
|||
|
|
|||
|
采纳和演进
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.2.5" data-path="../usecases/service-mesh-customization-and-integration.html">
|
|||
|
|
|||
|
<a href="../usecases/service-mesh-customization-and-integration.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.2.5.</b>
|
|||
|
|
|||
|
定制和集成
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.2.6" data-path="../usecases/service-mesh-conclusion.html">
|
|||
|
|
|||
|
<a href="../usecases/service-mesh-conclusion.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.2.6.</b>
|
|||
|
|
|||
|
总结
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.3" data-path="../usecases/istio.html">
|
|||
|
|
|||
|
<a href="../usecases/istio.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.3.</b>
|
|||
|
|
|||
|
Istio
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="7.3.1" data-path="../usecases/before-using-istio.html">
|
|||
|
|
|||
|
<a href="../usecases/before-using-istio.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.3.1.</b>
|
|||
|
|
|||
|
使用 Istio 前需要考虑的问题
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.3.2" data-path="../usecases/istio-installation.html">
|
|||
|
|
|||
|
<a href="../usecases/istio-installation.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.3.2.</b>
|
|||
|
|
|||
|
安装并试用 Istio
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.3.3" data-path="../usecases/sidecar-spec-in-istio.html">
|
|||
|
|
|||
|
<a href="../usecases/sidecar-spec-in-istio.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.3.3.</b>
|
|||
|
|
|||
|
Istio 中 sidecar 的注入规范及示例
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.3.4" data-path="../usecases/istio-community-tips.html">
|
|||
|
|
|||
|
<a href="../usecases/istio-community-tips.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.3.4.</b>
|
|||
|
|
|||
|
如何参与 Istio 社区及注意事项
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.3.5" data-path="../usecases/istio-tutorials-collection.html">
|
|||
|
|
|||
|
<a href="../usecases/istio-tutorials-collection.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.3.5.</b>
|
|||
|
|
|||
|
Istio 免费学习资源汇总
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.3.6" data-path="../usecases/understand-sidecar-injection-and-traffic-hijack-in-istio-service-mesh.html">
|
|||
|
|
|||
|
<a href="../usecases/understand-sidecar-injection-and-traffic-hijack-in-istio-service-mesh.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.3.6.</b>
|
|||
|
|
|||
|
Sidecar 的注入与流量劫持
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.3.7" data-path="../usecases/envoy-sidecar-routing-of-istio-service-mesh-deep-dive.html">
|
|||
|
|
|||
|
<a href="../usecases/envoy-sidecar-routing-of-istio-service-mesh-deep-dive.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.3.7.</b>
|
|||
|
|
|||
|
Envoy Sidecar 代理的路由转发
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.3.8" data-path="../usecases/how-to-integrate-istio-with-vm.html">
|
|||
|
|
|||
|
<a href="../usecases/how-to-integrate-istio-with-vm.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.3.8.</b>
|
|||
|
|
|||
|
Istio 如何支持虚拟机
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.3.9" data-path="../usecases/istio-vm-support.html">
|
|||
|
|
|||
|
<a href="../usecases/istio-vm-support.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.3.9.</b>
|
|||
|
|
|||
|
Istio 支持虚拟机的历史
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.4" data-path="../usecases/envoy.html">
|
|||
|
|
|||
|
<a href="../usecases/envoy.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.4.</b>
|
|||
|
|
|||
|
Envoy
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="7.4.1" data-path="../usecases/envoy-terminology.html">
|
|||
|
|
|||
|
<a href="../usecases/envoy-terminology.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.4.1.</b>
|
|||
|
|
|||
|
Envoy 的架构与基本术语
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.4.2" data-path="../usecases/envoy-front-proxy.html">
|
|||
|
|
|||
|
<a href="../usecases/envoy-front-proxy.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.4.2.</b>
|
|||
|
|
|||
|
Envoy 作为前端代理
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="7.4.3" data-path="../usecases/envoy-mesh-in-kubernetes-tutorial.html">
|
|||
|
|
|||
|
<a href="../usecases/envoy-mesh-in-kubernetes-tutorial.html">
|
|||
|
|
|||
|
|
|||
|
<b>7.4.3.</b>
|
|||
|
|
|||
|
Envoy mesh 教程
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="header">领域应用</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="8.1" data-path="../usecases/">
|
|||
|
|
|||
|
<a href="../usecases/">
|
|||
|
|
|||
|
|
|||
|
<b>8.1.</b>
|
|||
|
|
|||
|
领域应用概览
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="8.2" data-path="../usecases/microservices.html">
|
|||
|
|
|||
|
<a href="../usecases/microservices.html">
|
|||
|
|
|||
|
|
|||
|
<b>8.2.</b>
|
|||
|
|
|||
|
微服务架构
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="8.2.1" data-path="../usecases/service-discovery-in-microservices.html">
|
|||
|
|
|||
|
<a href="../usecases/service-discovery-in-microservices.html">
|
|||
|
|
|||
|
|
|||
|
<b>8.2.1.</b>
|
|||
|
|
|||
|
微服务中的服务发现
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="8.2.2" data-path="../usecases/microservices-for-java-developers.html">
|
|||
|
|
|||
|
<a href="../usecases/microservices-for-java-developers.html">
|
|||
|
|
|||
|
|
|||
|
<b>8.2.2.</b>
|
|||
|
|
|||
|
使用 Java 构建微服务并发布到 Kubernetes 平台
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="8.2.2.1" data-path="../usecases/spring-boot-quick-start-guide.html">
|
|||
|
|
|||
|
<a href="../usecases/spring-boot-quick-start-guide.html">
|
|||
|
|
|||
|
|
|||
|
<b>8.2.2.1.</b>
|
|||
|
|
|||
|
Spring Boot 快速开始指南
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="8.3" data-path="../usecases/big-data.html">
|
|||
|
|
|||
|
<a href="../usecases/big-data.html">
|
|||
|
|
|||
|
|
|||
|
<b>8.3.</b>
|
|||
|
|
|||
|
大数据
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="8.3.1" data-path="../usecases/spark-standalone-on-kubernetes.html">
|
|||
|
|
|||
|
<a href="../usecases/spark-standalone-on-kubernetes.html">
|
|||
|
|
|||
|
|
|||
|
<b>8.3.1.</b>
|
|||
|
|
|||
|
Spark standalone on Kubernetes
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="8.3.2" data-path="../usecases/running-spark-with-kubernetes-native-scheduler.html">
|
|||
|
|
|||
|
<a href="../usecases/running-spark-with-kubernetes-native-scheduler.html">
|
|||
|
|
|||
|
|
|||
|
<b>8.3.2.</b>
|
|||
|
|
|||
|
运行支持 Kubernetes 原生调度的 Spark 程序
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="8.4" data-path="../usecases/serverless.html">
|
|||
|
|
|||
|
<a href="../usecases/serverless.html">
|
|||
|
|
|||
|
|
|||
|
<b>8.4.</b>
|
|||
|
|
|||
|
Serverless 架构
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="8.4.1" data-path="../usecases/understanding-serverless.html">
|
|||
|
|
|||
|
<a href="../usecases/understanding-serverless.html">
|
|||
|
|
|||
|
|
|||
|
<b>8.4.1.</b>
|
|||
|
|
|||
|
理解 Serverless
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="8.4.2" data-path="../usecases/faas.html">
|
|||
|
|
|||
|
<a href="../usecases/faas.html">
|
|||
|
|
|||
|
|
|||
|
<b>8.4.2.</b>
|
|||
|
|
|||
|
FaaS(函数即服务)
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="8.4.2.1" data-path="../usecases/openfaas-quick-start.html">
|
|||
|
|
|||
|
<a href="../usecases/openfaas-quick-start.html">
|
|||
|
|
|||
|
|
|||
|
<b>8.4.2.1.</b>
|
|||
|
|
|||
|
OpenFaaS 快速入门指南
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="8.4.3" data-path="../usecases/knative.html">
|
|||
|
|
|||
|
<a href="../usecases/knative.html">
|
|||
|
|
|||
|
|
|||
|
<b>8.4.3.</b>
|
|||
|
|
|||
|
Knative
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="8.5" data-path="../usecases/edge-computing.html">
|
|||
|
|
|||
|
<a href="../usecases/edge-computing.html">
|
|||
|
|
|||
|
|
|||
|
<b>8.5.</b>
|
|||
|
|
|||
|
边缘计算
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="8.6" data-path="../usecases/ai.html">
|
|||
|
|
|||
|
<a href="../usecases/ai.html">
|
|||
|
|
|||
|
|
|||
|
<b>8.6.</b>
|
|||
|
|
|||
|
人工智能
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="8.7" data-path="../usecases/observability.html">
|
|||
|
|
|||
|
<a href="../usecases/observability.html">
|
|||
|
|
|||
|
|
|||
|
<b>8.7.</b>
|
|||
|
|
|||
|
可观察性
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="header">开发指南</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="9.1" data-path="./">
|
|||
|
|
|||
|
<a href="./">
|
|||
|
|
|||
|
|
|||
|
<b>9.1.</b>
|
|||
|
|
|||
|
开发指南概览
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="9.2" data-path="sigs-and-working-group.html">
|
|||
|
|
|||
|
<a href="sigs-and-working-group.html">
|
|||
|
|
|||
|
|
|||
|
<b>9.2.</b>
|
|||
|
|
|||
|
SIG 和工作组
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="9.3" data-path="developing-environment.html">
|
|||
|
|
|||
|
<a href="developing-environment.html">
|
|||
|
|
|||
|
|
|||
|
<b>9.3.</b>
|
|||
|
|
|||
|
开发环境搭建
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="9.3.1" data-path="using-vagrant-and-virtualbox-for-development.html">
|
|||
|
|
|||
|
<a href="using-vagrant-and-virtualbox-for-development.html">
|
|||
|
|
|||
|
|
|||
|
<b>9.3.1.</b>
|
|||
|
|
|||
|
本地分布式开发环境搭建(使用 Vagrant 和 Virtualbox)
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="9.4" data-path="testing.html">
|
|||
|
|
|||
|
<a href="testing.html">
|
|||
|
|
|||
|
|
|||
|
<b>9.4.</b>
|
|||
|
|
|||
|
单元测试和集成测试
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="9.5" data-path="client-go-sample.html">
|
|||
|
|
|||
|
<a href="client-go-sample.html">
|
|||
|
|
|||
|
|
|||
|
<b>9.5.</b>
|
|||
|
|
|||
|
client-go 示例
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter active" data-level="9.5.1" data-path="client-go-informer-sourcecode-analyse.html">
|
|||
|
|
|||
|
<a href="client-go-informer-sourcecode-analyse.html">
|
|||
|
|
|||
|
|
|||
|
<b>9.5.1.</b>
|
|||
|
|
|||
|
client-go 中的 informer 源码分析
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="9.6" data-path="operator.html">
|
|||
|
|
|||
|
<a href="operator.html">
|
|||
|
|
|||
|
|
|||
|
<b>9.6.</b>
|
|||
|
|
|||
|
Operator
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="9.6.1" data-path="operator-sdk.html">
|
|||
|
|
|||
|
<a href="operator-sdk.html">
|
|||
|
|
|||
|
|
|||
|
<b>9.6.1.</b>
|
|||
|
|
|||
|
operator-sdk
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="9.7" data-path="kubebuilder.html">
|
|||
|
|
|||
|
<a href="kubebuilder.html">
|
|||
|
|
|||
|
|
|||
|
<b>9.7.</b>
|
|||
|
|
|||
|
kubebuilder
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="9.7.1" data-path="kubebuilder-example.html">
|
|||
|
|
|||
|
<a href="kubebuilder-example.html">
|
|||
|
|
|||
|
|
|||
|
<b>9.7.1.</b>
|
|||
|
|
|||
|
使用 kubebuilder 创建 operator 示例
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="9.8" data-path="advance-developer.html">
|
|||
|
|
|||
|
<a href="advance-developer.html">
|
|||
|
|
|||
|
|
|||
|
<b>9.8.</b>
|
|||
|
|
|||
|
高级开发指南
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="9.9" data-path="contribute.html">
|
|||
|
|
|||
|
<a href="contribute.html">
|
|||
|
|
|||
|
|
|||
|
<b>9.9.</b>
|
|||
|
|
|||
|
社区贡献
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="9.10" data-path="minikube.html">
|
|||
|
|
|||
|
<a href="minikube.html">
|
|||
|
|
|||
|
|
|||
|
<b>9.10.</b>
|
|||
|
|
|||
|
Minikube
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="header">社区及生态</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="10.1" data-path="../cloud-native/cncf.html">
|
|||
|
|
|||
|
<a href="../cloud-native/cncf.html">
|
|||
|
|
|||
|
|
|||
|
<b>10.1.</b>
|
|||
|
|
|||
|
云原生计算基金会(CNCF)
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="10.1.1" data-path="../cloud-native/cncf-charter.html">
|
|||
|
|
|||
|
<a href="../cloud-native/cncf-charter.html">
|
|||
|
|
|||
|
|
|||
|
<b>10.1.1.</b>
|
|||
|
|
|||
|
CNCF 章程
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="10.1.2" data-path="../cloud-native/cncf-sig.html">
|
|||
|
|
|||
|
<a href="../cloud-native/cncf-sig.html">
|
|||
|
|
|||
|
|
|||
|
<b>10.1.2.</b>
|
|||
|
|
|||
|
CNCF 特别兴趣小组(SIG)说明
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="10.1.3" data-path="../cloud-native/cncf-sandbox-criteria.html">
|
|||
|
|
|||
|
<a href="../cloud-native/cncf-sandbox-criteria.html">
|
|||
|
|
|||
|
|
|||
|
<b>10.1.3.</b>
|
|||
|
|
|||
|
开源项目加入 CNCF Sandbox 的要求
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="10.1.4" data-path="../cloud-native/cncf-project-governing.html">
|
|||
|
|
|||
|
<a href="../cloud-native/cncf-project-governing.html">
|
|||
|
|
|||
|
|
|||
|
<b>10.1.4.</b>
|
|||
|
|
|||
|
CNCF 中的项目治理
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="10.1.5" data-path="../cloud-native/cncf-ambassador.html">
|
|||
|
|
|||
|
<a href="../cloud-native/cncf-ambassador.html">
|
|||
|
|
|||
|
|
|||
|
<b>10.1.5.</b>
|
|||
|
|
|||
|
CNCF Ambassador
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="10.2" data-path="../cloud-native/cnc.html">
|
|||
|
|
|||
|
<a href="../cloud-native/cnc.html">
|
|||
|
|
|||
|
|
|||
|
<b>10.2.</b>
|
|||
|
|
|||
|
云原生社区
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="10.3" data-path="../cloud-native/certification.html">
|
|||
|
|
|||
|
<a href="../cloud-native/certification.html">
|
|||
|
|
|||
|
|
|||
|
<b>10.3.</b>
|
|||
|
|
|||
|
认证及培训
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="10.3.1" data-path="../appendix/about-kcsp.html">
|
|||
|
|
|||
|
<a href="../appendix/about-kcsp.html">
|
|||
|
|
|||
|
|
|||
|
<b>10.3.1.</b>
|
|||
|
|
|||
|
认证 Kubernetes 服务提供商(KCSP)说明
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="10.3.2" data-path="../appendix/about-cka-candidate.html">
|
|||
|
|
|||
|
<a href="../appendix/about-cka-candidate.html">
|
|||
|
|
|||
|
|
|||
|
<b>10.3.2.</b>
|
|||
|
|
|||
|
认证 Kubernetes 管理员(CKA)说明
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="header">附录</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="11.1" data-path="../appendix/">
|
|||
|
|
|||
|
<a href="../appendix/">
|
|||
|
|
|||
|
|
|||
|
<b>11.1.</b>
|
|||
|
|
|||
|
附录说明
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="11.2" data-path="../appendix/debug-kubernetes-services.html">
|
|||
|
|
|||
|
<a href="../appendix/debug-kubernetes-services.html">
|
|||
|
|
|||
|
|
|||
|
<b>11.2.</b>
|
|||
|
|
|||
|
Kubernetes 中的应用故障排查
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="11.3" data-path="../appendix/material-share.html">
|
|||
|
|
|||
|
<a href="../appendix/material-share.html">
|
|||
|
|
|||
|
|
|||
|
<b>11.3.</b>
|
|||
|
|
|||
|
Kubernetes 相关资讯和情报链接
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="11.4" data-path="../appendix/docker-best-practice.html">
|
|||
|
|
|||
|
<a href="../appendix/docker-best-practice.html">
|
|||
|
|
|||
|
|
|||
|
<b>11.4.</b>
|
|||
|
|
|||
|
Docker 最佳实践
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="11.5" data-path="../appendix/tricks.html">
|
|||
|
|
|||
|
<a href="../appendix/tricks.html">
|
|||
|
|
|||
|
|
|||
|
<b>11.5.</b>
|
|||
|
|
|||
|
使用技巧
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="11.6" data-path="../appendix/issues.html">
|
|||
|
|
|||
|
<a href="../appendix/issues.html">
|
|||
|
|
|||
|
|
|||
|
<b>11.6.</b>
|
|||
|
|
|||
|
问题记录
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="11.7" data-path="../appendix/kubernetes-changelog.html">
|
|||
|
|
|||
|
<a href="../appendix/kubernetes-changelog.html">
|
|||
|
|
|||
|
|
|||
|
<b>11.7.</b>
|
|||
|
|
|||
|
Kubernetes 版本更新日志
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="11.8" data-path="../appendix/summary-and-outlook.html">
|
|||
|
|
|||
|
<a href="../appendix/summary-and-outlook.html">
|
|||
|
|
|||
|
|
|||
|
<b>11.8.</b>
|
|||
|
|
|||
|
Kubernetes 及云原生年度总结及展望
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="11.8.1" data-path="../appendix/kubernetes-and-cloud-native-summary-in-2017-and-outlook-for-2018.html">
|
|||
|
|
|||
|
<a href="../appendix/kubernetes-and-cloud-native-summary-in-2017-and-outlook-for-2018.html">
|
|||
|
|
|||
|
|
|||
|
<b>11.8.1.</b>
|
|||
|
|
|||
|
Kubernetes 与云原生 2017 年年终总结及 2018 年展望
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="11.8.2" data-path="../appendix/kubernetes-and-cloud-native-summary-in-2018-and-outlook-for-2019.html">
|
|||
|
|
|||
|
<a href="../appendix/kubernetes-and-cloud-native-summary-in-2018-and-outlook-for-2019.html">
|
|||
|
|
|||
|
|
|||
|
<b>11.8.2.</b>
|
|||
|
|
|||
|
Kubernetes 与云原生 2018 年年终总结及 2019 年展望
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="11.9" data-path="../appendix/cncf-annual-report.html">
|
|||
|
|
|||
|
<a href="../appendix/cncf-annual-report.html">
|
|||
|
|
|||
|
|
|||
|
<b>11.9.</b>
|
|||
|
|
|||
|
CNCF 年度报告解读
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="11.9.1" data-path="../appendix/cncf-annual-report-2018.html">
|
|||
|
|
|||
|
<a href="../appendix/cncf-annual-report-2018.html">
|
|||
|
|
|||
|
|
|||
|
<b>11.9.1.</b>
|
|||
|
|
|||
|
CNCF 2018 年年度报告解读
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="11.9.2" data-path="../appendix/cncf-annual-report-2020.html">
|
|||
|
|
|||
|
<a href="../appendix/cncf-annual-report-2020.html">
|
|||
|
|
|||
|
|
|||
|
<b>11.9.2.</b>
|
|||
|
|
|||
|
CNCF 2020 年年度报告解读
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="divider"></li>
|
|||
|
|
|||
|
<li>
|
|||
|
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
|
|||
|
本书使用 GitBook 发布
|
|||
|
</a>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
|
|||
|
</nav>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="book-body">
|
|||
|
|
|||
|
<div class="body-inner">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<div class="book-header" role="navigation">
|
|||
|
|
|||
|
|
|||
|
<!-- Title -->
|
|||
|
<h1>
|
|||
|
<i class="fa fa-circle-o-notch fa-spin"></i>
|
|||
|
<a href=".." >client-go 中的 informer 源码分析</a>
|
|||
|
</h1>
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<div class="page-wrapper" tabindex="-1" role="main">
|
|||
|
<div class="page-inner">
|
|||
|
|
|||
|
<div class="search-plus" id="book-search-results">
|
|||
|
<div class="search-noresults">
|
|||
|
|
|||
|
<section class="normal markdown-section">
|
|||
|
|
|||
|
<h1 id="client-go-中的-informer-源码分析">client-go 中的 informer 源码分析</h1>
|
|||
|
<figure id="fig9.5.1.1"><a href="https://user-images.githubusercontent.com/41672087/116676748-efbbed00-a9d9-11eb-88ff-2b25120b59b3.png" data-lightbox="2d3fa501-d4c1-4e88-b367-acab7665dd2e" data-title="image" target="_blank"><img src="https://user-images.githubusercontent.com/41672087/116676748-efbbed00-a9d9-11eb-88ff-2b25120b59b3.png" alt="image"></a><figcaption>图 9.5.1.1:image</figcaption></figure>
|
|||
|
<h2 id="以deployment-controller为例分析其中client-go-informer的用法">以deployment controller为例分析其中client-go informer的用法</h2>
|
|||
|
<pre class="language-"><code class="lang-go">kubeInformerFactory <span class="token operator">:=</span> kubeinformers<span class="token punctuation">.</span><span class="token function">NewSharedInformerFactory</span><span class="token punctuation">(</span>kubeClient<span class="token punctuation">,</span> time<span class="token punctuation">.</span>Second<span class="token operator">*</span><span class="token number">30</span><span class="token punctuation">)</span>
|
|||
|
controller <span class="token operator">:=</span> <span class="token function">NewController</span><span class="token punctuation">(</span>
|
|||
|
kubeClient<span class="token punctuation">,</span> exampleClient<span class="token punctuation">,</span>
|
|||
|
kubeInformerFactory<span class="token punctuation">.</span><span class="token function">Apps</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">V1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Deployments</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
|
|||
|
|
|||
|
kubeInformerFactory<span class="token punctuation">.</span><span class="token function">Start</span><span class="token punctuation">(</span>stopCh<span class="token punctuation">)</span>
|
|||
|
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">=</span> controller<span class="token punctuation">.</span><span class="token function">Run</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> stopCh<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
klog<span class="token punctuation">.</span><span class="token function">Fatalf</span><span class="token punctuation">(</span><span class="token string">"Error running controller: %s"</span><span class="token punctuation">,</span> err<span class="token punctuation">.</span><span class="token function">Error</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h3 id="sharedinformerfactory结构">SharedInformerFactory结构</h3>
|
|||
|
<p>使用sharedInformerFactory的好处:比如很多个模块都需要使用pod对象,没必要都创建一个pod informer,用factor存储每种资源的一个informer,这里的informer实现是shareIndexInformer
|
|||
|
NewSharedInformerFactory调用了NewSharedInformerFactoryWithOptions,将返回一个sharedInformerFactory对象</p>
|
|||
|
<blockquote>
|
|||
|
<p>kubeClient:clientset
|
|||
|
defaultResync:30s,用于初始化持有的shareIndexInformer的resyncCheckPeriod和defaultEventHandlerResyncPeriod字段</p>
|
|||
|
</blockquote>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">type</span> sharedInformerFactory <span class="token keyword">struct</span> <span class="token punctuation">{</span>
|
|||
|
client kubernetes<span class="token punctuation">.</span>Interface <span class="token comment">//clientset</span>
|
|||
|
namespace <span class="token builtin">string</span> <span class="token comment">//关注的namepace,可以通过WithNamespace Option配置</span>
|
|||
|
tweakListOptions internalinterfaces<span class="token punctuation">.</span>TweakListOptionsFunc
|
|||
|
lock sync<span class="token punctuation">.</span>Mutex
|
|||
|
defaultResync time<span class="token punctuation">.</span>Duration <span class="token comment">//前面传过来的时间,如30s</span>
|
|||
|
customResync <span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span>time<span class="token punctuation">.</span>Duration <span class="token comment">//针对每一个informer,用户配置的resync时间,通过WithCustomResyncConfig这个Option配置,否则就用指定的defaultResync</span>
|
|||
|
|
|||
|
informers <span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span>cache<span class="token punctuation">.</span>SharedIndexInformer <span class="token comment">//针对每种类型资源存储一个informer,informer的类型是ShareIndexInformer</span>
|
|||
|
<span class="token comment">// startedInformers is used for tracking which informers have been started.</span>
|
|||
|
<span class="token comment">// This allows Start() to be called multiple times safely.</span>
|
|||
|
startedInformers <span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span><span class="token builtin">bool</span> <span class="token comment">//每个informer是否都启动了</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<p>sharedInformerFactory对象的关键方法:</p>
|
|||
|
<h4 id="创建一个sharedinformerfactory">创建一个sharedInformerFactory</h4>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token function">NewSharedInformerFactoryWithOptions</span><span class="token punctuation">(</span>client kubernetes<span class="token punctuation">.</span>Interface<span class="token punctuation">,</span> defaultResync time<span class="token punctuation">.</span>Duration<span class="token punctuation">,</span> options <span class="token operator">...</span>SharedInformerOption<span class="token punctuation">)</span> SharedInformerFactory <span class="token punctuation">{</span>
|
|||
|
factory <span class="token operator">:=</span> <span class="token operator">&</span>sharedInformerFactory<span class="token punctuation">{</span>
|
|||
|
client<span class="token punctuation">:</span> client<span class="token punctuation">,</span> <span class="token comment">//clientset,对deployment资源来说,这里就可以直接使用kube clientset</span>
|
|||
|
namespace<span class="token punctuation">:</span> v1<span class="token punctuation">.</span>NamespaceAll<span class="token punctuation">,</span> <span class="token comment">//可以看到默认是监听所有ns下的指定资源</span>
|
|||
|
defaultResync<span class="token punctuation">:</span> defaultResync<span class="token punctuation">,</span> <span class="token comment">//30s</span>
|
|||
|
<span class="token comment">//以下初始化map结构</span>
|
|||
|
informers<span class="token punctuation">:</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span>cache<span class="token punctuation">.</span>SharedIndexInformer<span class="token punctuation">)</span><span class="token punctuation">,</span>
|
|||
|
startedInformers<span class="token punctuation">:</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span><span class="token builtin">bool</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
|
|||
|
customResync<span class="token punctuation">:</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span>time<span class="token punctuation">.</span>Duration<span class="token punctuation">)</span><span class="token punctuation">,</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> factory
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="启动factory下的所有informer">启动factory下的所有informer</h4>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>sharedInformerFactory<span class="token punctuation">)</span> <span class="token function">Start</span><span class="token punctuation">(</span>stopCh <span class="token operator"><-</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
|
|||
|
<span class="token keyword">for</span> informerType<span class="token punctuation">,</span> informer <span class="token operator">:=</span> <span class="token keyword">range</span> f<span class="token punctuation">.</span>informers <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">if</span> <span class="token operator">!</span>f<span class="token punctuation">.</span>startedInformers<span class="token punctuation">[</span>informerType<span class="token punctuation">]</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">//直接起gorouting调用informer的Run方法,并且标记对应的informer已经启动</span>
|
|||
|
<span class="token keyword">go</span> informer<span class="token punctuation">.</span><span class="token function">Run</span><span class="token punctuation">(</span>stopCh<span class="token punctuation">)</span>
|
|||
|
f<span class="token punctuation">.</span>startedInformers<span class="token punctuation">[</span>informerType<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token boolean">true</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="等待shareindexinformer的cache被同步">等待ShareIndexInformer的cache被同步</h4>
|
|||
|
<p>等待每一个ShareIndexInformer的cache被同步,具体怎么算同步完成呢?</p>
|
|||
|
<ul>
|
|||
|
<li><p>sharedInformerFactory的WaitForCacheSync将会不断调用factory持有的所有informer的HasSynced方法,直到返回true</p>
|
|||
|
</li>
|
|||
|
<li><p>而informer的HasSynced方法调用的自己持有的controller的HasSynced方法(informer结构体包含controller对象,下文会分析informer的结构)</p>
|
|||
|
</li>
|
|||
|
<li><p>informer中的controller的HasSynced方法则调用的是controller持有的deltaFIFO对象的HasSynced方法</p>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
<p>也就说sharedInformerFactory的WaitForCacheSync方法判断informer的cache是否同步,看的是informer中的deltaFIFO是否同步了,deltaFIFO的结构下文将会分析</p>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>sharedInformerFactory<span class="token punctuation">)</span> <span class="token function">WaitForCacheSync</span><span class="token punctuation">(</span>stopCh <span class="token operator"><-</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span><span class="token builtin">bool</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">//获取每一个已经启动的informer</span>
|
|||
|
informers <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span>cache<span class="token punctuation">.</span>SharedIndexInformer <span class="token punctuation">{</span>
|
|||
|
f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
|
|||
|
informers <span class="token operator">:=</span> <span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span>cache<span class="token punctuation">.</span>SharedIndexInformer<span class="token punctuation">{</span><span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">for</span> informerType<span class="token punctuation">,</span> informer <span class="token operator">:=</span> <span class="token keyword">range</span> f<span class="token punctuation">.</span>informers <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">if</span> f<span class="token punctuation">.</span>startedInformers<span class="token punctuation">[</span>informerType<span class="token punctuation">]</span> <span class="token punctuation">{</span>
|
|||
|
informers<span class="token punctuation">[</span>informerType<span class="token punctuation">]</span> <span class="token operator">=</span> informer
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> informers
|
|||
|
<span class="token punctuation">}</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
|
|||
|
res <span class="token operator">:=</span> <span class="token keyword">map</span><span class="token punctuation">[</span>reflect<span class="token punctuation">.</span>Type<span class="token punctuation">]</span><span class="token builtin">bool</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
|
|||
|
<span class="token comment">// 等待他们的cache被同步,调用的是informer的HasSynced方法</span>
|
|||
|
<span class="token keyword">for</span> informType<span class="token punctuation">,</span> informer <span class="token operator">:=</span> <span class="token keyword">range</span> informers <span class="token punctuation">{</span>
|
|||
|
res<span class="token punctuation">[</span>informType<span class="token punctuation">]</span> <span class="token operator">=</span> cache<span class="token punctuation">.</span><span class="token function">WaitForCacheSync</span><span class="token punctuation">(</span>stopCh<span class="token punctuation">,</span> informer<span class="token punctuation">.</span>HasSynced<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> res
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="factory为自己添加informer">factory为自己添加informer</h4>
|
|||
|
<p>只有向factory中添加informer,factory才有意义,添加完成之后,上面factory的start方法就可以启动了</p>
|
|||
|
<blockquote>
|
|||
|
<p>obj:如deployment{}
|
|||
|
newFunc:一个可以用来创建指定informer的方法,k8s为每一个内置的对象都实现了这个方法,比如创建deployment的ShareIndexInformer的方法</p>
|
|||
|
</blockquote>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>sharedInformerFactory<span class="token punctuation">)</span> <span class="token function">InformerFor</span><span class="token punctuation">(</span>obj runtime<span class="token punctuation">.</span>Object<span class="token punctuation">,</span> newFunc internalinterfaces<span class="token punctuation">.</span>NewInformerFunc<span class="token punctuation">)</span> cache<span class="token punctuation">.</span>SharedIndexInformer <span class="token punctuation">{</span>
|
|||
|
f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token comment">//根据对象类型判断factory中是否已经有对应informer</span>
|
|||
|
informerType <span class="token operator">:=</span> reflect<span class="token punctuation">.</span><span class="token function">TypeOf</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span>
|
|||
|
informer<span class="token punctuation">,</span> exists <span class="token operator">:=</span> f<span class="token punctuation">.</span>informers<span class="token punctuation">[</span>informerType<span class="token punctuation">]</span>
|
|||
|
<span class="token keyword">if</span> exists <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> informer
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">//如果factory中已经有这个对象类型的informer,就不创建了</span>
|
|||
|
resyncPeriod<span class="token punctuation">,</span> exists <span class="token operator">:=</span> f<span class="token punctuation">.</span>customResync<span class="token punctuation">[</span>informerType<span class="token punctuation">]</span>
|
|||
|
<span class="token keyword">if</span> <span class="token operator">!</span>exists <span class="token punctuation">{</span>
|
|||
|
resyncPeriod <span class="token operator">=</span> f<span class="token punctuation">.</span>defaultResync
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">//没有就根据newFunc创建一个,并存在map中</span>
|
|||
|
informer <span class="token operator">=</span> <span class="token function">newFunc</span><span class="token punctuation">(</span>f<span class="token punctuation">.</span>client<span class="token punctuation">,</span> resyncPeriod<span class="token punctuation">)</span>
|
|||
|
f<span class="token punctuation">.</span>informers<span class="token punctuation">[</span>informerType<span class="token punctuation">]</span> <span class="token operator">=</span> informer
|
|||
|
|
|||
|
<span class="token keyword">return</span> informer
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h5 id="deployment的shareindexinformer对应的newfunc的实现">deployment的shareIndexInformer对应的newFunc的实现</h5>
|
|||
|
<p>client-go中已经为所有内置对象都提供了NewInformerFunc</p>
|
|||
|
<p>以deployment为例,通过调用factory.Apps().V1().Deployments()即可为factory添加一个deployment对应的shareIndexInformer的实现,具体过程如下:</p>
|
|||
|
<ul>
|
|||
|
<li>调用factory.Apps().V1().Deployments()即会调用以下Deployments方法创建deploymentInformer对象</li>
|
|||
|
</ul>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>v <span class="token operator">*</span>version<span class="token punctuation">)</span> <span class="token function">Deployments</span><span class="token punctuation">(</span><span class="token punctuation">)</span> DeploymentInformer <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> <span class="token operator">&</span>deploymentInformer<span class="token punctuation">{</span>factory<span class="token punctuation">:</span> v<span class="token punctuation">.</span>factory<span class="token punctuation">,</span> namespace<span class="token punctuation">:</span> v<span class="token punctuation">.</span>namespace<span class="token punctuation">,</span> tweakListOptions<span class="token punctuation">:</span> v<span class="token punctuation">.</span>tweakListOptions<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<ul>
|
|||
|
<li>只要调用了factory.Apps().V1().Deployments()返回的deploymentInformer的Informer或Lister方法,就完成了向factory中添加deployment informer</li>
|
|||
|
</ul>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token comment">//即会调用以下Deployments方法创建deploymentInformer对象具有defaultInformer、Informer、Lister方法</span>
|
|||
|
<span class="token comment">//可以看到创建deploymentInformer时传递了一个带索引的缓存,附带了一个namespace索引,后面可以了解带索引的缓存实现,比如可以支持查询:某个namespace下的所有pod</span>
|
|||
|
<span class="token comment">//用于创建对应的shareIndexInformer,该方法提供给factory的InformerFor方法</span>
|
|||
|
<span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>deploymentInformer<span class="token punctuation">)</span> <span class="token function">defaultInformer</span><span class="token punctuation">(</span>client kubernetes<span class="token punctuation">.</span>Interface<span class="token punctuation">,</span> resyncPeriod time<span class="token punctuation">.</span>Duration<span class="token punctuation">)</span> cache<span class="token punctuation">.</span>SharedIndexInformer <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> <span class="token function">NewFilteredDeploymentInformer</span><span class="token punctuation">(</span>client<span class="token punctuation">,</span> f<span class="token punctuation">.</span>namespace<span class="token punctuation">,</span> resyncPeriod<span class="token punctuation">,</span> cache<span class="token punctuation">.</span>Indexers<span class="token punctuation">{</span>cache<span class="token punctuation">.</span>NamespaceIndex<span class="token punctuation">:</span> cache<span class="token punctuation">.</span>MetaNamespaceIndexFunc<span class="token punctuation">}</span><span class="token punctuation">,</span> f<span class="token punctuation">.</span>tweakListOptions<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">//向factor中添加dpeloyment的shareIndexInformer并返回</span>
|
|||
|
<span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>deploymentInformer<span class="token punctuation">)</span> <span class="token function">Informer</span><span class="token punctuation">(</span><span class="token punctuation">)</span> cache<span class="token punctuation">.</span>SharedIndexInformer <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> f<span class="token punctuation">.</span>factory<span class="token punctuation">.</span><span class="token function">InformerFor</span><span class="token punctuation">(</span><span class="token operator">&</span>appsv1<span class="token punctuation">.</span>Deployment<span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> f<span class="token punctuation">.</span>defaultInformer<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">//返回dpeloyment的lister对象,该lister中持有上面创建出的shareIndexInformer的cache的引用,方便通过缓存获取对象</span>
|
|||
|
<span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>deploymentInformer<span class="token punctuation">)</span> <span class="token function">Lister</span><span class="token punctuation">(</span><span class="token punctuation">)</span> v1<span class="token punctuation">.</span>DeploymentLister <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> v1<span class="token punctuation">.</span><span class="token function">NewDeploymentLister</span><span class="token punctuation">(</span>f<span class="token punctuation">.</span><span class="token function">Informer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">GetIndexer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<ul>
|
|||
|
<li>deploymentInformer的defaultInformer方法将会创建出一个shareIndexInformer</li>
|
|||
|
</ul>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token comment">// 可先看看下面的shareIndexInformer结构</span>
|
|||
|
<span class="token keyword">func</span> <span class="token function">NewFilteredDeploymentInformer</span><span class="token punctuation">(</span>client kubernetes<span class="token punctuation">.</span>Interface<span class="token punctuation">,</span> namespace <span class="token builtin">string</span><span class="token punctuation">,</span> resyncPeriod time<span class="token punctuation">.</span>Duration<span class="token punctuation">,</span> indexers cache<span class="token punctuation">.</span>Indexers<span class="token punctuation">,</span> tweakListOptions internalinterfaces<span class="token punctuation">.</span>TweakListOptionsFunc<span class="token punctuation">)</span> cache<span class="token punctuation">.</span>SharedIndexInformer <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> cache<span class="token punctuation">.</span><span class="token function">NewSharedIndexInformer</span><span class="token punctuation">(</span>
|
|||
|
<span class="token comment">//定义对象的ListWatch方法,这里直接用的是clientset中的方法</span>
|
|||
|
<span class="token operator">&</span>cache<span class="token punctuation">.</span>ListWatch<span class="token punctuation">{</span>
|
|||
|
ListFunc<span class="token punctuation">:</span> <span class="token keyword">func</span><span class="token punctuation">(</span>options v1<span class="token punctuation">.</span>ListOptions<span class="token punctuation">)</span> <span class="token punctuation">(</span>runtime<span class="token punctuation">.</span>Object<span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">if</span> tweakListOptions <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token function">tweakListOptions</span><span class="token punctuation">(</span><span class="token operator">&</span>options<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> client<span class="token punctuation">.</span><span class="token function">AppsV1beta1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Deployments</span><span class="token punctuation">(</span>namespace<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">List</span><span class="token punctuation">(</span>options<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
|||
|
WatchFunc<span class="token punctuation">:</span> <span class="token keyword">func</span><span class="token punctuation">(</span>options v1<span class="token punctuation">.</span>ListOptions<span class="token punctuation">)</span> <span class="token punctuation">(</span>watch<span class="token punctuation">.</span>Interface<span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">if</span> tweakListOptions <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token function">tweakListOptions</span><span class="token punctuation">(</span><span class="token operator">&</span>options<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> client<span class="token punctuation">.</span><span class="token function">AppsV1beta1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Deployments</span><span class="token punctuation">(</span>namespace<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Watch</span><span class="token punctuation">(</span>options<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
|||
|
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
|||
|
<span class="token operator">&</span>appsv1beta1<span class="token punctuation">.</span>Deployment<span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
|
|||
|
resyncPeriod<span class="token punctuation">,</span> <span class="token comment">//创建factory是制定的时间,30s</span>
|
|||
|
indexers<span class="token punctuation">,</span>
|
|||
|
<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h3 id="shareindexinformer结构">shareIndexInformer结构</h3>
|
|||
|
<blockquote>
|
|||
|
<p>indexer:底层缓存,其实就是一个map记录对象,再通过一些其他map在插入删除对象是根据索引函数维护索引key如ns与对象pod的关系
|
|||
|
controller:informer内部的一个controller,这个controller包含reflector:根据用户定义的ListWatch方法获取对象并更新增量队列DeltaFIFO
|
|||
|
processor:知道如何处理DeltaFIFO队列中的对象,实现是sharedProcessor{}
|
|||
|
listerWatcher:知道如何list对象和watch对象的方法
|
|||
|
objectType:deployment{}
|
|||
|
resyncCheckPeriod: 给自己的controller的reflector每隔多少s<尝试>调用listener的shouldResync方法
|
|||
|
defaultEventHandlerResyncPeriod:通过AddEventHandler方法给informer配置回调时如果没有配置的默认值,这个值用在processor的listener中判断是否需要进行resync,最小1s</p>
|
|||
|
</blockquote>
|
|||
|
<p>两个字段的默认值都是来自创建factory时指定的defaultResync,当resyncPeriod < s.resyncCheckPeriod时,如果informer已经启动了才添加的EventHandler,那么调整resyncPeriod为resyncCheckPeriod,否则调整resyncCheckPeriod为resyncPeriod</p>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">type</span> sharedIndexInformer <span class="token keyword">struct</span> <span class="token punctuation">{</span>
|
|||
|
indexer Indexer <span class="token comment">//informer中的底层缓存cache</span>
|
|||
|
controller Controller <span class="token comment">//持有reflector和deltaFIFO对象,reflector对象将会listWatch对象添加到deltaFIFO,同时更新indexer cahce,更新成功则通过sharedProcessor触发用户配置的Eventhandler</span>
|
|||
|
|
|||
|
processor <span class="token operator">*</span>sharedProcessor <span class="token comment">//持有一系列的listener,每个listener对应用户的EventHandler</span>
|
|||
|
cacheMutationDetector MutationDetector <span class="token comment">//可以先忽略,这个对象可以用来监测local cache是否被外部直接修改</span>
|
|||
|
|
|||
|
<span class="token comment">// This block is tracked to handle late initialization of the controller</span>
|
|||
|
listerWatcher ListerWatcher <span class="token comment">//deployment的listWatch方法</span>
|
|||
|
objectType runtime<span class="token punctuation">.</span>Object
|
|||
|
|
|||
|
<span class="token comment">// resyncCheckPeriod is how often we want the reflector's resync timer to fire so it can call</span>
|
|||
|
<span class="token comment">// shouldResync to check if any of our listeners need a resync.</span>
|
|||
|
resyncCheckPeriod time<span class="token punctuation">.</span>Duration
|
|||
|
<span class="token comment">// defaultEventHandlerResyncPeriod is the default resync period for any handlers added via</span>
|
|||
|
<span class="token comment">// AddEventHandler (i.e. they don't specify one and just want to use the shared informer's default</span>
|
|||
|
<span class="token comment">// value).</span>
|
|||
|
defaultEventHandlerResyncPeriod time<span class="token punctuation">.</span>Duration
|
|||
|
<span class="token comment">// clock allows for testability</span>
|
|||
|
clock clock<span class="token punctuation">.</span>Clock
|
|||
|
|
|||
|
started<span class="token punctuation">,</span> stopped <span class="token builtin">bool</span>
|
|||
|
startedLock sync<span class="token punctuation">.</span>Mutex
|
|||
|
|
|||
|
<span class="token comment">// blockDeltas gives a way to stop all event distribution so that a late event handler</span>
|
|||
|
<span class="token comment">// can safely join the shared informer.</span>
|
|||
|
blockDeltas sync<span class="token punctuation">.</span>Mutex
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<p>sharedIndexInformer对象的关键方法:</p>
|
|||
|
<h4 id="sharedindexinformer的run方法">sharedIndexInformer的Run方法</h4>
|
|||
|
<p>前面factory的start方法就是调用了这个Run方法</p>
|
|||
|
<p>该方法初始化了controller对象并启动,同时调用processor.run启动所有的listener,用于回调用户配置的EventHandler</p>
|
|||
|
<p>具体sharedIndexInformer中的processor中的listener是怎么添加的,看下文shareProcessor的分析</p>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>s <span class="token operator">*</span>sharedIndexInformer<span class="token punctuation">)</span> <span class="token function">Run</span><span class="token punctuation">(</span>stopCh <span class="token operator"><-</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">defer</span> utilruntime<span class="token punctuation">.</span><span class="token function">HandleCrash</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token comment">//创建一个DeltaFIFO,用于shareIndexInformer.controller.reflector</span>
|
|||
|
<span class="token comment">//可以看到这里把indexer即本地缓存传入,用来初始化deltaFIFO的knownObject字段</span>
|
|||
|
fifo <span class="token operator">:=</span> <span class="token function">NewDeltaFIFO</span><span class="token punctuation">(</span>MetaNamespaceKeyFunc<span class="token punctuation">,</span> s<span class="token punctuation">.</span>indexer<span class="token punctuation">)</span>
|
|||
|
<span class="token comment">//shareIndexInformer中的controller的配置</span>
|
|||
|
cfg <span class="token operator">:=</span> <span class="token operator">&</span>Config<span class="token punctuation">{</span>
|
|||
|
Queue<span class="token punctuation">:</span> fifo<span class="token punctuation">,</span>
|
|||
|
ListerWatcher<span class="token punctuation">:</span> s<span class="token punctuation">.</span>listerWatcher<span class="token punctuation">,</span>
|
|||
|
ObjectType<span class="token punctuation">:</span> s<span class="token punctuation">.</span>objectType<span class="token punctuation">,</span>
|
|||
|
FullResyncPeriod<span class="token punctuation">:</span> s<span class="token punctuation">.</span>resyncCheckPeriod<span class="token punctuation">,</span>
|
|||
|
RetryOnError<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
|
|||
|
ShouldResync<span class="token punctuation">:</span> s<span class="token punctuation">.</span>processor<span class="token punctuation">.</span>shouldResync<span class="token punctuation">,</span> <span class="token comment">// 这个shouldResync方法将被用在reflector ListAndWatch方法中判断定时时间resyncCheckPeriod到了之后该不该进行resync动作</span>
|
|||
|
<span class="token comment">//一个知道如何处理从informer中的controller中的deltaFIFO pop出来的对象的方法</span>
|
|||
|
Process<span class="token punctuation">:</span> s<span class="token punctuation">.</span>HandleDeltas<span class="token punctuation">,</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
<span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
s<span class="token punctuation">.</span>startedLock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> s<span class="token punctuation">.</span>startedLock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token comment">// 这里New一个具体的controller</span>
|
|||
|
s<span class="token punctuation">.</span>controller <span class="token operator">=</span> <span class="token function">New</span><span class="token punctuation">(</span>cfg<span class="token punctuation">)</span>
|
|||
|
s<span class="token punctuation">.</span>controller<span class="token punctuation">.</span><span class="token punctuation">(</span><span class="token operator">*</span>controller<span class="token punctuation">)</span><span class="token punctuation">.</span>clock <span class="token operator">=</span> s<span class="token punctuation">.</span>clock
|
|||
|
s<span class="token punctuation">.</span>started <span class="token operator">=</span> <span class="token boolean">true</span>
|
|||
|
<span class="token punctuation">}</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
|
|||
|
<span class="token comment">// Separate stop channel because Processor should be stopped strictly after controller</span>
|
|||
|
processorStopCh <span class="token operator">:=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">var</span> wg wait<span class="token punctuation">.</span>Group
|
|||
|
<span class="token keyword">defer</span> wg<span class="token punctuation">.</span><span class="token function">Wait</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// Wait for Processor to stop</span>
|
|||
|
<span class="token keyword">defer</span> <span class="token function">close</span><span class="token punctuation">(</span>processorStopCh<span class="token punctuation">)</span> <span class="token comment">// Tell Processor to stop</span>
|
|||
|
<span class="token comment">// 调用processor.run启动所有的listener,回调用户配置的EventHandler</span>
|
|||
|
wg<span class="token punctuation">.</span><span class="token function">StartWithChannel</span><span class="token punctuation">(</span>processorStopCh<span class="token punctuation">,</span> s<span class="token punctuation">.</span>processor<span class="token punctuation">.</span>run<span class="token punctuation">)</span>
|
|||
|
|
|||
|
<span class="token comment">// 启动controller</span>
|
|||
|
s<span class="token punctuation">.</span>controller<span class="token punctuation">.</span><span class="token function">Run</span><span class="token punctuation">(</span>stopCh<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="为shareindexinformer创建controller">为shareIndexInformer创建controller</h4>
|
|||
|
<p>创建Controller的New方法会生成一个controller对象,只初始化controller的config成员,controller的reflector成员是在Run的时候初始化:</p>
|
|||
|
<ul>
|
|||
|
<li><p>通过执行reflector.Run方法启动reflector,开启对指定对象的listAndWatch过程,获取的对象将添加到reflector的deltaFIFO中</p>
|
|||
|
</li>
|
|||
|
<li><p>通过不断执行processLoop方法,从DeltaFIFO pop出对象,再调用reflector的Process(就是shareIndexInformer的HandleDeltas方法)处理</p>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token function">New</span><span class="token punctuation">(</span>c <span class="token operator">*</span>Config<span class="token punctuation">)</span> Controller <span class="token punctuation">{</span>
|
|||
|
ctlr <span class="token operator">:=</span> <span class="token operator">&</span>controller<span class="token punctuation">{</span>
|
|||
|
config<span class="token punctuation">:</span> <span class="token operator">*</span>c<span class="token punctuation">,</span>
|
|||
|
clock<span class="token punctuation">:</span> <span class="token operator">&</span>clock<span class="token punctuation">.</span>RealClock<span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> ctlr
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">//更多字段的配置是在Run的时候</span>
|
|||
|
<span class="token keyword">func</span> <span class="token punctuation">(</span>c <span class="token operator">*</span>controller<span class="token punctuation">)</span> <span class="token function">Run</span><span class="token punctuation">(</span>stopCh <span class="token operator"><-</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">// 使用config创建一个Reflector</span>
|
|||
|
r <span class="token operator">:=</span> <span class="token function">NewReflector</span><span class="token punctuation">(</span>
|
|||
|
c<span class="token punctuation">.</span>config<span class="token punctuation">.</span>ListerWatcher<span class="token punctuation">,</span> <span class="token comment">// deployment的listWatch方法</span>
|
|||
|
c<span class="token punctuation">.</span>config<span class="token punctuation">.</span>ObjectType<span class="token punctuation">,</span> <span class="token comment">// deployment{}</span>
|
|||
|
c<span class="token punctuation">.</span>config<span class="token punctuation">.</span>Queue<span class="token punctuation">,</span> <span class="token comment">//DeltaFIFO</span>
|
|||
|
c<span class="token punctuation">.</span>config<span class="token punctuation">.</span>FullResyncPeriod<span class="token punctuation">,</span> <span class="token comment">//30s</span>
|
|||
|
<span class="token punctuation">)</span>
|
|||
|
r<span class="token punctuation">.</span>ShouldResync <span class="token operator">=</span> c<span class="token punctuation">.</span>config<span class="token punctuation">.</span>ShouldResync <span class="token comment">//来自sharedProcessor的方法</span>
|
|||
|
r<span class="token punctuation">.</span>clock <span class="token operator">=</span> c<span class="token punctuation">.</span>clock
|
|||
|
|
|||
|
c<span class="token punctuation">.</span>reflectorMutex<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
c<span class="token punctuation">.</span>reflector <span class="token operator">=</span> r
|
|||
|
c<span class="token punctuation">.</span>reflectorMutex<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
|
|||
|
<span class="token keyword">var</span> wg wait<span class="token punctuation">.</span>Group
|
|||
|
<span class="token keyword">defer</span> wg<span class="token punctuation">.</span><span class="token function">Wait</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token comment">// 启动reflector,执行ListWatch方法</span>
|
|||
|
wg<span class="token punctuation">.</span><span class="token function">StartWithChannel</span><span class="token punctuation">(</span>stopCh<span class="token punctuation">,</span> r<span class="token punctuation">.</span>Run<span class="token punctuation">)</span>
|
|||
|
<span class="token comment">// 不断执行processLoop,这个方法其实就是从DeltaFIFO pop出对象,再调用reflector的Process(其实是shareIndexInformer的HandleDeltas方法)处理</span>
|
|||
|
wait<span class="token punctuation">.</span><span class="token function">Until</span><span class="token punctuation">(</span>c<span class="token punctuation">.</span>processLoop<span class="token punctuation">,</span> time<span class="token punctuation">.</span>Second<span class="token punctuation">,</span> stopCh<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="controller的processloop方法">controller的processLoop方法</h4>
|
|||
|
<p>不断执行processLoop,这个方法其实就是从DeltaFIFO pop出对象,再调用reflector的Process(其实是shareIndexInformer的HandleDeltas方法)处理</p>
|
|||
|
<pre class="language-"><code>func (c *controller) processLoop() {
|
|||
|
for {
|
|||
|
obj, err := c.config.Queue.Pop(PopProcessFunc(c.config.Process))
|
|||
|
if err != nil {
|
|||
|
if err == ErrFIFOClosed {
|
|||
|
return
|
|||
|
}
|
|||
|
if c.config.RetryOnError {
|
|||
|
// This is the safe way to re-enqueue.
|
|||
|
c.config.Queue.AddIfNotPresent(obj)
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
</code></pre><h4 id="deltafifo-pop出来的对象处理逻辑">deltaFIFO pop出来的对象处理逻辑</h4>
|
|||
|
<p>先看看controller怎么处理DeltaFIFO中的对象,需要注意DeltaFIFO中的Deltas的结构,是一个slice,保存同一个对象的所有增量事件
|
|||
|
<a href="https://user-images.githubusercontent.com/41672087/116666059-19224c00-a9cd-11eb-945c-955cce9eacd1.png" data-lightbox="7e9594c8-450e-479d-9f6a-8f434967ef9d" data-title="image" target="_blank"><img src="https://user-images.githubusercontent.com/41672087/116666059-19224c00-a9cd-11eb-945c-955cce9eacd1.png" alt="image"></a></p>
|
|||
|
<p>sharedIndexInformer的HandleDeltas处理从deltaFIFO pod出来的增量时,先尝试更新到本地缓存cache,更新成功的话会调用processor.distribute方法向processor中的listener添加notification,listener启动之后会不断获取notification回调用户的EventHandler方法</p>
|
|||
|
<ul>
|
|||
|
<li>Sync: reflector list到对象时Replace到deltaFIFO时daltaType为Sync或者resync把localstrore中的对象加回到deltaFIFO</li>
|
|||
|
<li>Added、Updated: reflector watch到对象时根据watch event type是Add还是Modify对应deltaType为Added或者Updated</li>
|
|||
|
<li><p>Deleted: reflector watch到对象的watch event type是Delete或者re-list Replace到deltaFIFO时local store多出的对象以Delete的方式加入deltaFIFO</p>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>s <span class="token operator">*</span>sharedIndexInformer<span class="token punctuation">)</span> <span class="token function">HandleDeltas</span><span class="token punctuation">(</span>obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
|
|||
|
s<span class="token punctuation">.</span>blockDeltas<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> s<span class="token punctuation">.</span>blockDeltas<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
|
|||
|
<span class="token comment">// from oldest to newest</span>
|
|||
|
<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> d <span class="token operator">:=</span> <span class="token keyword">range</span> obj<span class="token punctuation">.</span><span class="token punctuation">(</span>Deltas<span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">switch</span> d<span class="token punctuation">.</span>Type <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">case</span> Sync<span class="token punctuation">,</span> Added<span class="token punctuation">,</span> Updated<span class="token punctuation">:</span>
|
|||
|
isSync <span class="token operator">:=</span> d<span class="token punctuation">.</span>Type <span class="token operator">==</span> Sync
|
|||
|
<span class="token comment">// 对象先通过shareIndexInformer中的indexer更新到缓存</span>
|
|||
|
<span class="token keyword">if</span> old<span class="token punctuation">,</span> exists<span class="token punctuation">,</span> err <span class="token operator">:=</span> s<span class="token punctuation">.</span>indexer<span class="token punctuation">.</span><span class="token function">Get</span><span class="token punctuation">(</span>d<span class="token punctuation">.</span>Object<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token operator">&&</span> exists <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">:=</span> s<span class="token punctuation">.</span>indexer<span class="token punctuation">.</span><span class="token function">Update</span><span class="token punctuation">(</span>d<span class="token punctuation">.</span>Object<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> err
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">// 如果informer的本地缓存更新成功,那么就调用shareProcess分发对象给用户自定义controller处理</span>
|
|||
|
<span class="token comment">// 可以看到,对EventHandler来说,本地缓存已经存在该对象就认为是update</span>
|
|||
|
s<span class="token punctuation">.</span>processor<span class="token punctuation">.</span><span class="token function">distribute</span><span class="token punctuation">(</span>updateNotification<span class="token punctuation">{</span>oldObj<span class="token punctuation">:</span> old<span class="token punctuation">,</span> newObj<span class="token punctuation">:</span> d<span class="token punctuation">.</span>Object<span class="token punctuation">}</span><span class="token punctuation">,</span> isSync<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">:=</span> s<span class="token punctuation">.</span>indexer<span class="token punctuation">.</span><span class="token function">Add</span><span class="token punctuation">(</span>d<span class="token punctuation">.</span>Object<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> err
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
s<span class="token punctuation">.</span>processor<span class="token punctuation">.</span><span class="token function">distribute</span><span class="token punctuation">(</span>addNotification<span class="token punctuation">{</span>newObj<span class="token punctuation">:</span> d<span class="token punctuation">.</span>Object<span class="token punctuation">}</span><span class="token punctuation">,</span> isSync<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">case</span> Deleted<span class="token punctuation">:</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">:=</span> s<span class="token punctuation">.</span>indexer<span class="token punctuation">.</span><span class="token function">Delete</span><span class="token punctuation">(</span>d<span class="token punctuation">.</span>Object<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> err
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
s<span class="token punctuation">.</span>processor<span class="token punctuation">.</span><span class="token function">distribute</span><span class="token punctuation">(</span>deleteNotification<span class="token punctuation">{</span>oldObj<span class="token punctuation">:</span> d<span class="token punctuation">.</span>Object<span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
<p>前面描述了shareIndexInformer内部如何从deltaFIFO取出对象更新缓存并通过processor回调用户的EventHandler,那deltaFIFO中的增量事件是怎么加进入的呢?先看看shareIndexInformer中controller中的reflector实现</p>
|
|||
|
<h4 id="reflectorrun发起listwatch">reflector.run发起ListWatch</h4>
|
|||
|
<p>reflector.run将会调用指定资源的ListAndWatch方法,注意这里什么时候可能发生re-list或者re-watch:因为是通过wait.Util不断调用ListAndWatch方法,所以只要该方法return了,那么就会发生re-list,watch过程则被嵌套在for循环中</p>
|
|||
|
<ul>
|
|||
|
<li>以ResourceVersion=0开始首次的List操作获取指定资源的全量对象,并通过reflector的syncWith方法将所有对象批量插入deltaFIFO</li>
|
|||
|
<li>List完成之后将会更新ResourceVersion用户Watch操作,通过reflector的watchHandler方法把watch到的增量对象加入到deltaFIFO</li>
|
|||
|
</ul>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>r <span class="token operator">*</span>Reflector<span class="token punctuation">)</span> <span class="token function">ListAndWatch</span><span class="token punctuation">(</span>stopCh <span class="token operator"><-</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">// 以版本号ResourceVersion=0开始首次list</span>
|
|||
|
options <span class="token operator">:=</span> metav1<span class="token punctuation">.</span>ListOptions<span class="token punctuation">{</span>ResourceVersion<span class="token punctuation">:</span> <span class="token string">"0"</span><span class="token punctuation">}</span>
|
|||
|
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">:=</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
|
|||
|
initTrace <span class="token operator">:=</span> trace<span class="token punctuation">.</span><span class="token function">New</span><span class="token punctuation">(</span><span class="token string">"Reflector ListAndWatch"</span><span class="token punctuation">,</span> trace<span class="token punctuation">.</span>Field<span class="token punctuation">{</span><span class="token string">"name"</span><span class="token punctuation">,</span> r<span class="token punctuation">.</span>name<span class="token punctuation">}</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">var</span> list runtime<span class="token punctuation">.</span>Object
|
|||
|
<span class="token keyword">go</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">// 获取list的结果</span>
|
|||
|
list<span class="token punctuation">,</span> err <span class="token operator">=</span> pager<span class="token punctuation">.</span><span class="token function">List</span><span class="token punctuation">(</span>context<span class="token punctuation">.</span><span class="token function">Background</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> options<span class="token punctuation">)</span>
|
|||
|
<span class="token function">close</span><span class="token punctuation">(</span>listCh<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
listMetaInterface<span class="token punctuation">,</span> err <span class="token operator">:=</span> meta<span class="token punctuation">.</span><span class="token function">ListAccessor</span><span class="token punctuation">(</span>list<span class="token punctuation">)</span>
|
|||
|
<span class="token comment">// 根据结果更新版本号,用于接下来的watch</span>
|
|||
|
resourceVersion <span class="token operator">=</span> listMetaInterface<span class="token punctuation">.</span><span class="token function">GetResourceVersion</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
items<span class="token punctuation">,</span> err <span class="token operator">:=</span> meta<span class="token punctuation">.</span><span class="token function">ExtractList</span><span class="token punctuation">(</span>list<span class="token punctuation">)</span>
|
|||
|
<span class="token comment">// 这里的syncWith是把首次list到的结果通过DeltaFIFO的Replce方法批量添加到队列</span>
|
|||
|
<span class="token comment">// 队列提供了Resync方法用于判断Replace批量插入的对象是否都pop出去了,factory/informer的WaitForCacheSync就是调用了DeltaFIFO的的Resync方法</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">:=</span> r<span class="token punctuation">.</span><span class="token function">syncWith</span><span class="token punctuation">(</span>items<span class="token punctuation">,</span> resourceVersion<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">"%s: Unable to sync list result: %v"</span><span class="token punctuation">,</span> r<span class="token punctuation">.</span>name<span class="token punctuation">,</span> err<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
r<span class="token punctuation">.</span><span class="token function">setLastSyncResourceVersion</span><span class="token punctuation">(</span>resourceVersion<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> err
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
|
|||
|
<span class="token comment">// 以list对象中获取的ResourceVersion不断watch</span>
|
|||
|
<span class="token keyword">for</span> <span class="token punctuation">{</span>
|
|||
|
start <span class="token operator">:=</span> r<span class="token punctuation">.</span>clock<span class="token punctuation">.</span><span class="token function">Now</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
w<span class="token punctuation">,</span> err <span class="token operator">:=</span> r<span class="token punctuation">.</span>listerWatcher<span class="token punctuation">.</span><span class="token function">Watch</span><span class="token punctuation">(</span>options<span class="token punctuation">)</span>
|
|||
|
<span class="token comment">// watchhandler处理watch到的数据,即把对象根据watch.type增加到DeltaFIFO中</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">:=</span> r<span class="token punctuation">.</span><span class="token function">watchHandler</span><span class="token punctuation">(</span>start<span class="token punctuation">,</span> w<span class="token punctuation">,</span> <span class="token operator">&</span>resourceVersion<span class="token punctuation">,</span> resyncerrc<span class="token punctuation">,</span> stopCh<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">!=</span> errorStopRequested <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">switch</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">case</span> apierrs<span class="token punctuation">.</span><span class="token function">IsResourceExpired</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span><span class="token punctuation">:</span>
|
|||
|
klog<span class="token punctuation">.</span><span class="token function">V</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Infof</span><span class="token punctuation">(</span><span class="token string">"%s: watch of %v ended with: %v"</span><span class="token punctuation">,</span> r<span class="token punctuation">.</span>name<span class="token punctuation">,</span> r<span class="token punctuation">.</span>expectedType<span class="token punctuation">,</span> err<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">default</span><span class="token punctuation">:</span>
|
|||
|
klog<span class="token punctuation">.</span><span class="token function">Warningf</span><span class="token punctuation">(</span><span class="token string">"%s: watch of %v ended with: %v"</span><span class="token punctuation">,</span> r<span class="token punctuation">.</span>name<span class="token punctuation">,</span> r<span class="token punctuation">.</span>expectedType<span class="token punctuation">,</span> err<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h5 id="list出的对象批量插入deltafifo">list出的对象批量插入deltaFIFO</h5>
|
|||
|
<blockquote>
|
|||
|
<p>可以看到是syncWith方法是通过调用deltaFIFO的Replace实现批量插入,具体实现见下文中deltaFIFO的实现描述</p>
|
|||
|
</blockquote>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>r <span class="token operator">*</span>Reflector<span class="token punctuation">)</span> <span class="token function">syncWith</span><span class="token punctuation">(</span>items <span class="token punctuation">[</span><span class="token punctuation">]</span>runtime<span class="token punctuation">.</span>Object<span class="token punctuation">,</span> resourceVersion <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
|
|||
|
found <span class="token operator">:=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token function">len</span><span class="token punctuation">(</span>items<span class="token punctuation">)</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> item <span class="token operator">:=</span> <span class="token keyword">range</span> items <span class="token punctuation">{</span>
|
|||
|
found <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>found<span class="token punctuation">,</span> item<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> r<span class="token punctuation">.</span>store<span class="token punctuation">.</span><span class="token function">Replace</span><span class="token punctuation">(</span>found<span class="token punctuation">,</span> resourceVersion<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h5 id="watch出的增量对象插入到deltafifo">watch出的增量对象插入到deltaFIFO</h5>
|
|||
|
<blockquote>
|
|||
|
<p>watch到的对象直接根据watch到的事件类型eventType更新store(即deltaFIFO),注意这个event是api直接返回的,watch event type可能是Added、Modifyed、Deleted</p>
|
|||
|
</blockquote>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token comment">// watchHandler watches w and keeps *resourceVersion up to date.</span>
|
|||
|
<span class="token keyword">func</span> <span class="token punctuation">(</span>r <span class="token operator">*</span>Reflector<span class="token punctuation">)</span> <span class="token function">watchHandler</span><span class="token punctuation">(</span>start time<span class="token punctuation">.</span>Time<span class="token punctuation">,</span> w watch<span class="token punctuation">.</span>Interface<span class="token punctuation">,</span> resourceVersion <span class="token operator">*</span><span class="token builtin">string</span><span class="token punctuation">,</span> errc <span class="token keyword">chan</span> <span class="token builtin">error</span><span class="token punctuation">,</span> stopCh <span class="token operator"><-</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">for</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">select</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">case</span> <span class="token operator"><-</span>stopCh<span class="token punctuation">:</span>
|
|||
|
<span class="token keyword">return</span> errorStopRequested
|
|||
|
<span class="token keyword">case</span> err <span class="token operator">:=</span> <span class="token operator"><-</span>errc<span class="token punctuation">:</span>
|
|||
|
<span class="token keyword">return</span> err
|
|||
|
<span class="token keyword">case</span> event<span class="token punctuation">,</span> ok <span class="token operator">:=</span> <span class="token operator"><-</span>w<span class="token punctuation">.</span><span class="token function">ResultChan</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
|
|||
|
<span class="token keyword">switch</span> event<span class="token punctuation">.</span>Type <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">case</span> watch<span class="token punctuation">.</span>Added<span class="token punctuation">:</span>
|
|||
|
err <span class="token operator">:=</span> r<span class="token punctuation">.</span>store<span class="token punctuation">.</span><span class="token function">Add</span><span class="token punctuation">(</span>event<span class="token punctuation">.</span>Object<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">case</span> watch<span class="token punctuation">.</span>Modified<span class="token punctuation">:</span>
|
|||
|
err <span class="token operator">:=</span> r<span class="token punctuation">.</span>store<span class="token punctuation">.</span><span class="token function">Update</span><span class="token punctuation">(</span>event<span class="token punctuation">.</span>Object<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">case</span> watch<span class="token punctuation">.</span>Deleted<span class="token punctuation">:</span>
|
|||
|
err <span class="token operator">:=</span> r<span class="token punctuation">.</span>store<span class="token punctuation">.</span><span class="token function">Delete</span><span class="token punctuation">(</span>event<span class="token punctuation">.</span>Object<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">case</span> watch<span class="token punctuation">.</span>Bookmark<span class="token punctuation">:</span>
|
|||
|
<span class="token comment">// A `Bookmark` means watch has synced here, just update the resourceVersion</span>
|
|||
|
<span class="token keyword">default</span><span class="token punctuation">:</span>
|
|||
|
utilruntime<span class="token punctuation">.</span><span class="token function">HandleError</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">"%s: unable to understand watch event %#v"</span><span class="token punctuation">,</span> r<span class="token punctuation">.</span>name<span class="token punctuation">,</span> event<span class="token punctuation">)</span><span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token operator">*</span>resourceVersion <span class="token operator">=</span> newResourceVersion
|
|||
|
r<span class="token punctuation">.</span><span class="token function">setLastSyncResourceVersion</span><span class="token punctuation">(</span>newResourceVersion<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h5 id="定时触发resync">定时触发resync</h5>
|
|||
|
<p>在ListAndWatch中还起了一个gorouting定时的进行resync动作</p>
|
|||
|
<pre class="language-"><code class="lang-go"> resyncerrc <span class="token operator">:=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword">chan</span> <span class="token builtin">error</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span>
|
|||
|
cancelCh <span class="token operator">:=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> <span class="token function">close</span><span class="token punctuation">(</span>cancelCh<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">go</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">//获取一个定时channel,定时的时间是创建informer factory时传入的resyncPeriod</span>
|
|||
|
resyncCh<span class="token punctuation">,</span> cleanup <span class="token operator">:=</span> r<span class="token punctuation">.</span><span class="token function">resyncChan</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token function">cleanup</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// Call the last one written into cleanup</span>
|
|||
|
<span class="token punctuation">}</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">for</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">select</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">case</span> <span class="token operator"><-</span>resyncCh<span class="token punctuation">:</span>
|
|||
|
<span class="token keyword">case</span> <span class="token operator"><-</span>stopCh<span class="token punctuation">:</span>
|
|||
|
<span class="token keyword">return</span>
|
|||
|
<span class="token keyword">case</span> <span class="token operator"><-</span>cancelCh<span class="token punctuation">:</span>
|
|||
|
<span class="token keyword">return</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">if</span> r<span class="token punctuation">.</span>ShouldResync <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token operator">||</span> r<span class="token punctuation">.</span><span class="token function">ShouldResync</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
klog<span class="token punctuation">.</span><span class="token function">V</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">Infof</span><span class="token punctuation">(</span><span class="token string">"%s: forcing resync"</span><span class="token punctuation">,</span> r<span class="token punctuation">.</span>name<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">:=</span> r<span class="token punctuation">.</span>store<span class="token punctuation">.</span><span class="token function">Resync</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
resyncerrc <span class="token operator"><-</span> err
|
|||
|
<span class="token keyword">return</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token function">cleanup</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
resyncCh<span class="token punctuation">,</span> cleanup <span class="token operator">=</span> r<span class="token punctuation">.</span><span class="token function">resyncChan</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
</code></pre>
|
|||
|
<p>调用deltaFIFO的Resync方法,把底层缓存的对象全部重新添加到deltaFIFO中</p>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>DeltaFIFO<span class="token punctuation">)</span> <span class="token function">Resync</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
|
|||
|
f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
|
|||
|
<span class="token keyword">if</span> f<span class="token punctuation">.</span>knownObjects <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
keys <span class="token operator">:=</span> f<span class="token punctuation">.</span>knownObjects<span class="token punctuation">.</span><span class="token function">ListKeys</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> k <span class="token operator">:=</span> <span class="token keyword">range</span> keys <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">:=</span> f<span class="token punctuation">.</span><span class="token function">syncKeyLocked</span><span class="token punctuation">(</span>k<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> err
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<p>需要注意的是,在添加对象到deltaFIFO时会检查该队列中有没有增量没有处理完的,如果有则忽略这个对象的此次resync</p>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>DeltaFIFO<span class="token punctuation">)</span> <span class="token function">syncKeyLocked</span><span class="token punctuation">(</span>key <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
|
|||
|
obj<span class="token punctuation">,</span> exists<span class="token punctuation">,</span> err <span class="token operator">:=</span> f<span class="token punctuation">.</span>knownObjects<span class="token punctuation">.</span><span class="token function">GetByKey</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
klog<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">"Unexpected error %v during lookup of key %v, unable to queue object for sync"</span><span class="token punctuation">,</span> err<span class="token punctuation">,</span> key<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token operator">!</span>exists <span class="token punctuation">{</span>
|
|||
|
klog<span class="token punctuation">.</span><span class="token function">Infof</span><span class="token punctuation">(</span><span class="token string">"Key %v does not exist in known objects store, unable to queue object for sync"</span><span class="token punctuation">,</span> key<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
<span class="token comment">// If we are doing Resync() and there is already an event queued for that object,</span>
|
|||
|
<span class="token comment">// we ignore the Resync for it. This is to avoid the race, in which the resync</span>
|
|||
|
<span class="token comment">// comes with the previous value of object (since queueing an event for the object</span>
|
|||
|
<span class="token comment">// doesn't trigger changing the underlying store <knownObjects>.</span>
|
|||
|
id<span class="token punctuation">,</span> err <span class="token operator">:=</span> f<span class="token punctuation">.</span><span class="token function">KeyOf</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> KeyError<span class="token punctuation">{</span>obj<span class="token punctuation">,</span> err<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">// 如果deltaFIFO中该对象还有增量没有处理,则忽略以避免冲突,原因如上面注释:在同一个对象的增量列表中,排在后面的增量的object相比前面的增量应该更新才是合理的</span>
|
|||
|
<span class="token keyword">if</span> <span class="token function">len</span><span class="token punctuation">(</span>f<span class="token punctuation">.</span>items<span class="token punctuation">[</span>id<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token operator">></span> <span class="token number">0</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">// 跟deltaFIFO的Replace方法一样,都是添加一个Sync类型的增量</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">:=</span> f<span class="token punctuation">.</span><span class="token function">queueActionLocked</span><span class="token punctuation">(</span>Sync<span class="token punctuation">,</span> obj<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">"couldn't queue object: %v"</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h3 id="底层缓存的实现">底层缓存的实现</h3>
|
|||
|
<p>shareIndexInformer中带有一个缓存indexer,是一个支持索引的map,优点是支持快速查询,参考类图,我们可以知道:</p>
|
|||
|
<ul>
|
|||
|
<li>Indexer、Queue接口和cache结构体都实现了顶层的Store接口</li>
|
|||
|
<li>cache结构体持有threadSafeStore对象,该结构体是线程安全的,具备索引查找能力的map</li>
|
|||
|
</ul>
|
|||
|
<p>threadSafeMap的结构如下:</p>
|
|||
|
<blockquote>
|
|||
|
<p>items:存储具体的对象,比如key为ns/podName,value为pod{}
|
|||
|
Indexers:一个map[string]IndexFunc结构,其中key为索引的名称,如’namespace’字符串,value则是一个具体的索引函数
|
|||
|
Indices:一个map[string]Index结构,其中key也是索引的名称,value是一个map[string]sets.String结构,其中key是具体的namespace,如default这个ns,vlaue则是这个ns下的按照索引函数求出来的值的集合,比如default这个ns下的所有pod对象名称</p>
|
|||
|
</blockquote>
|
|||
|
<p>通过在向items插入对象的过程中,遍历所有的Indexers中的索引函数,根据索引函数存储索引key到value的集合关系,以下图式结构可以很好的说明</p>
|
|||
|
<figure id="fig9.5.1.2"><a href="https://user-images.githubusercontent.com/41672087/116666278-5981ca00-a9cd-11eb-9570-8ee6eb447d05.png" data-lightbox="046508be-f5bd-4be0-a63f-d1863d17a180" data-title="image" target="_blank"><img src="https://user-images.githubusercontent.com/41672087/116666278-5981ca00-a9cd-11eb-9570-8ee6eb447d05.png" alt="image"></a><figcaption>图 9.5.1.2:image</figcaption></figure>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">type</span> threadSafeMap <span class="token keyword">struct</span> <span class="token punctuation">{</span>
|
|||
|
lock sync<span class="token punctuation">.</span>RWMutex
|
|||
|
items <span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">string</span><span class="token punctuation">]</span><span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
|
|||
|
|
|||
|
<span class="token comment">// indexers maps a name to an IndexFunc</span>
|
|||
|
indexers Indexers
|
|||
|
<span class="token comment">// indices maps a name to an Index</span>
|
|||
|
indices Indices
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
<span class="token comment">// Indexers maps a name to a IndexFunc</span>
|
|||
|
<span class="token keyword">type</span> Indexers <span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">string</span><span class="token punctuation">]</span>IndexFunc
|
|||
|
|
|||
|
<span class="token comment">// Indices maps a name to an Index</span>
|
|||
|
<span class="token keyword">type</span> Indices <span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">string</span><span class="token punctuation">]</span>Index
|
|||
|
<span class="token keyword">type</span> Index <span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">string</span><span class="token punctuation">]</span>sets<span class="token punctuation">.</span>String
|
|||
|
</code></pre>
|
|||
|
<h4 id="缓存中增加对象">缓存中增加对象</h4>
|
|||
|
<p>以向上面的结构中增加一个对象为例</p>
|
|||
|
<blockquote>
|
|||
|
<p>所谓带索引的缓存,其实就是在crud对象的时候,维护对应的索引结构</p>
|
|||
|
</blockquote>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>c <span class="token operator">*</span>threadSafeMap<span class="token punctuation">)</span> <span class="token function">Add</span><span class="token punctuation">(</span>key <span class="token builtin">string</span><span class="token punctuation">,</span> obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
c<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> c<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
oldObject <span class="token operator">:=</span> c<span class="token punctuation">.</span>items<span class="token punctuation">[</span>key<span class="token punctuation">]</span>
|
|||
|
<span class="token comment">//存储对象</span>
|
|||
|
c<span class="token punctuation">.</span>items<span class="token punctuation">[</span>key<span class="token punctuation">]</span> <span class="token operator">=</span> obj
|
|||
|
<span class="token comment">//更新索引</span>
|
|||
|
c<span class="token punctuation">.</span><span class="token function">updateIndices</span><span class="token punctuation">(</span>oldObject<span class="token punctuation">,</span> obj<span class="token punctuation">,</span> key<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
<span class="token comment">// updateIndices modifies the objects location in the managed indexes, if this is an update, you must provide an oldObj</span>
|
|||
|
<span class="token comment">// updateIndices must be called from a function that already has a lock on the cache</span>
|
|||
|
<span class="token keyword">func</span> <span class="token punctuation">(</span>c <span class="token operator">*</span>threadSafeMap<span class="token punctuation">)</span> <span class="token function">updateIndices</span><span class="token punctuation">(</span>oldObj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> newObj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> key <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">// if we got an old object, we need to remove it before we add it again</span>
|
|||
|
<span class="token keyword">if</span> oldObj <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">// 这是一个更新操作,先删除原对象的索引记录</span>
|
|||
|
c<span class="token punctuation">.</span><span class="token function">deleteFromIndices</span><span class="token punctuation">(</span>oldObj<span class="token punctuation">,</span> key<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">// 枚举所有添加的索引函数</span>
|
|||
|
<span class="token keyword">for</span> name<span class="token punctuation">,</span> indexFunc <span class="token operator">:=</span> <span class="token keyword">range</span> c<span class="token punctuation">.</span>indexers <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">//根据索引函数计算obj对应的</span>
|
|||
|
indexValues<span class="token punctuation">,</span> err <span class="token operator">:=</span> <span class="token function">indexFunc</span><span class="token punctuation">(</span>newObj<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token function">panic</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">"unable to calculate an index entry for key %q on index %q: %v"</span><span class="token punctuation">,</span> key<span class="token punctuation">,</span> name<span class="token punctuation">,</span> err<span class="token punctuation">)</span><span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
index <span class="token operator">:=</span> c<span class="token punctuation">.</span>indices<span class="token punctuation">[</span>name<span class="token punctuation">]</span>
|
|||
|
<span class="token keyword">if</span> index <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
index <span class="token operator">=</span> Index<span class="token punctuation">{</span><span class="token punctuation">}</span>
|
|||
|
c<span class="token punctuation">.</span>indices<span class="token punctuation">[</span>name<span class="token punctuation">]</span> <span class="token operator">=</span> index
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">//索引函数计算出多个value,也可能是一个,比如pod的ns就只有一个值,pod的label可能就有多个值</span>
|
|||
|
<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> indexValue <span class="token operator">:=</span> <span class="token keyword">range</span> indexValues <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">//比如namespace索引,根据indexValue=default,获取default对应的ji he再把当前对象插入</span>
|
|||
|
set <span class="token operator">:=</span> index<span class="token punctuation">[</span>indexValue<span class="token punctuation">]</span>
|
|||
|
<span class="token keyword">if</span> set <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
set <span class="token operator">=</span> sets<span class="token punctuation">.</span>String<span class="token punctuation">{</span><span class="token punctuation">}</span>
|
|||
|
index<span class="token punctuation">[</span>indexValue<span class="token punctuation">]</span> <span class="token operator">=</span> set
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
set<span class="token punctuation">.</span><span class="token function">Insert</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="metanamespaceindexfunc索引函数">MetaNamespaceIndexFunc索引函数</h4>
|
|||
|
<p>一个典型的索引函数MetaNamespaceIndexFunc,方便查询时可以根据namespace获取该namespace下的所有对象</p>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token comment">// MetaNamespaceIndexFunc is a default index function that indexes based on an object's namespace</span>
|
|||
|
<span class="token keyword">func</span> <span class="token function">MetaNamespaceIndexFunc</span><span class="token punctuation">(</span>obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
meta<span class="token punctuation">,</span> err <span class="token operator">:=</span> meta<span class="token punctuation">.</span><span class="token function">Accessor</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">{</span><span class="token string">""</span><span class="token punctuation">}</span><span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">"object has no meta: %v"</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">{</span>meta<span class="token punctuation">.</span><span class="token function">GetNamespace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="index方法利用索引查找对象">Index方法利用索引查找对象</h4>
|
|||
|
<p>提供利用索引来查询的能力,Index方法可以根据索引名称和对象,查询所有的关联对象</p>
|
|||
|
<blockquote>
|
|||
|
<p>例如通过</p>
|
|||
|
<p>Index(“namespace”, &metav1.ObjectMeta{Namespace: namespace})</p>
|
|||
|
<p>获取指定ns下的所有对象,具体可以参考tools/cache/listers.go#ListAllByNamespace</p>
|
|||
|
</blockquote>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>c <span class="token operator">*</span>threadSafeMap<span class="token punctuation">)</span> <span class="token function">Index</span><span class="token punctuation">(</span>indexName <span class="token builtin">string</span><span class="token punctuation">,</span> obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
c<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">RLock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> c<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">RUnlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
|
|||
|
indexFunc <span class="token operator">:=</span> c<span class="token punctuation">.</span>indexers<span class="token punctuation">[</span>indexName<span class="token punctuation">]</span>
|
|||
|
<span class="token keyword">if</span> indexFunc <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span><span class="token punctuation">,</span> fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">"Index with name %s does not exist"</span><span class="token punctuation">,</span> indexName<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
indexKeys<span class="token punctuation">,</span> err <span class="token operator">:=</span> <span class="token function">indexFunc</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span><span class="token punctuation">,</span> err
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
index <span class="token operator">:=</span> c<span class="token punctuation">.</span>indices<span class="token punctuation">[</span>indexName<span class="token punctuation">]</span>
|
|||
|
|
|||
|
<span class="token keyword">var</span> returnKeySet sets<span class="token punctuation">.</span>String
|
|||
|
<span class="token comment">//例如namespace索引</span>
|
|||
|
<span class="token keyword">if</span> <span class="token function">len</span><span class="token punctuation">(</span>indexKeys<span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">1</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">// In majority of cases, there is exactly one value matching.</span>
|
|||
|
<span class="token comment">// Optimize the most common path - deduping is not needed here.</span>
|
|||
|
returnKeySet <span class="token operator">=</span> index<span class="token punctuation">[</span>indexKeys<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
|
|||
|
<span class="token comment">//例如label索引</span>
|
|||
|
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">// Need to de-dupe the return list.</span>
|
|||
|
<span class="token comment">// Since multiple keys are allowed, this can happen.</span>
|
|||
|
returnKeySet <span class="token operator">=</span> sets<span class="token punctuation">.</span>String<span class="token punctuation">{</span><span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> indexKey <span class="token operator">:=</span> <span class="token keyword">range</span> indexKeys <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">for</span> key <span class="token operator">:=</span> <span class="token keyword">range</span> index<span class="token punctuation">[</span>indexKey<span class="token punctuation">]</span> <span class="token punctuation">{</span>
|
|||
|
returnKeySet<span class="token punctuation">.</span><span class="token function">Insert</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
list <span class="token operator">:=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> returnKeySet<span class="token punctuation">.</span><span class="token function">Len</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">for</span> absoluteKey <span class="token operator">:=</span> <span class="token keyword">range</span> returnKeySet <span class="token punctuation">{</span>
|
|||
|
list <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>list<span class="token punctuation">,</span> c<span class="token punctuation">.</span>items<span class="token punctuation">[</span>absoluteKey<span class="token punctuation">]</span><span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> list<span class="token punctuation">,</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h3 id="deltafifo实现">deltaFIFO实现</h3>
|
|||
|
<p>shareIndexInformer.controller.reflector中的deltaFIFO实现</p>
|
|||
|
<blockquote>
|
|||
|
<p>items:记录deltaFIFO中的对象,注意map的value是一个Delta slice
|
|||
|
queue:记录上面items中的key
|
|||
|
populated:队列中是否填充过数据,LIST时调用Replace或调用Delete/Add/Update都会置为true
|
|||
|
initialPopulationCount:前面首次List的时候获取到的数据就会调用Replace批量增加到队列,同时设置initialPopulationCount为List到的对象数量,每次Pop出来会减一,由于判断是否把首次批量插入的数据都POP出去了
|
|||
|
keyFunc:知道怎么从对象中解析出对应key的函数
|
|||
|
knownObjects:这个其实就是shareIndexInformer中的indexer底层缓存的引用,可以认为和etcd中的数据一致</p>
|
|||
|
</blockquote>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">type</span> DeltaFIFO <span class="token keyword">struct</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">// lock/cond protects access to 'items' and 'queue'.</span>
|
|||
|
lock sync<span class="token punctuation">.</span>RWMutex
|
|||
|
cond sync<span class="token punctuation">.</span>Cond
|
|||
|
|
|||
|
<span class="token comment">// We depend on the property that items in the set are in</span>
|
|||
|
<span class="token comment">// the queue and vice versa, and that all Deltas in this</span>
|
|||
|
<span class="token comment">// map have at least one Delta.</span>
|
|||
|
<span class="token comment">// 这里的Deltas是[]Delta类型</span>
|
|||
|
items <span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">string</span><span class="token punctuation">]</span>Deltas
|
|||
|
queue <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">string</span>
|
|||
|
|
|||
|
<span class="token comment">// populated is true if the first batch of items inserted by Replace() has been populated</span>
|
|||
|
<span class="token comment">// or Delete/Add/Update was called first.</span>
|
|||
|
populated <span class="token builtin">bool</span>
|
|||
|
<span class="token comment">// initialPopulationCount is the number of items inserted by the first call of Replace()</span>
|
|||
|
initialPopulationCount <span class="token builtin">int</span>
|
|||
|
|
|||
|
<span class="token comment">// keyFunc is used to make the key used for queued item</span>
|
|||
|
<span class="token comment">// insertion and retrieval, and should be deterministic.</span>
|
|||
|
keyFunc KeyFunc
|
|||
|
|
|||
|
<span class="token comment">// knownObjects list keys that are "known", for the</span>
|
|||
|
<span class="token comment">// purpose of figuring out which items have been deleted</span>
|
|||
|
<span class="token comment">// when Replace() or Delete() is called.</span>
|
|||
|
<span class="token comment">// 这个其实就是shareIndexInformer中的indexer底层缓存的引用</span>
|
|||
|
knownObjects KeyListerGetter
|
|||
|
|
|||
|
<span class="token comment">// Indication the queue is closed.</span>
|
|||
|
<span class="token comment">// Used to indicate a queue is closed so a control loop can exit when a queue is empty.</span>
|
|||
|
<span class="token comment">// Currently, not used to gate any of CRED operations.</span>
|
|||
|
closed <span class="token builtin">bool</span>
|
|||
|
closedLock sync<span class="token punctuation">.</span>Mutex
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
<span class="token keyword">type</span> Delta <span class="token keyword">struct</span> <span class="token punctuation">{</span>
|
|||
|
Type DeltaType
|
|||
|
Object <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
<span class="token comment">// Deltas is a list of one or more 'Delta's to an individual object.</span>
|
|||
|
<span class="token comment">// The oldest delta is at index 0, the newest delta is the last one.</span>
|
|||
|
<span class="token keyword">type</span> Deltas <span class="token punctuation">[</span><span class="token punctuation">]</span>Delta
|
|||
|
</code></pre>
|
|||
|
<p>DeltaFIFO关键的方法:</p>
|
|||
|
<h4 id="向deltafifo批量插入对象">向deltaFIFO批量插入对象</h4>
|
|||
|
<p>批量向队列插入数据的方法,注意knownObjects是本地缓存indexer的引用</p>
|
|||
|
<p>这里会更新deltaFIFO的initialPopulationCount为Replace list的对象总数加上list中相比knownObjects多出的对象数量。
|
|||
|
因为Replace方法可能是reflector发生re-list的时候再次调用,这个时候就会出现knownObjects中存在的对象不在Replace list的情况(比如watch的delete事件丢失了),这个时候是把这些对象筛选出来,封装成DeletedFinalStateUnknown对象以Delete type类型再次加入到deltaFIFO中,这样最终从detaFIFO处理这个DeletedFinalStateUnknown 增量时就可以更新本地缓存并且触发reconcile。
|
|||
|
因为这个对象最终的结构确实找不到了,所以只能用knownObjects里面的记录来封装,所以叫做FinalStateUnknown。</p>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>DeltaFIFO<span class="token punctuation">)</span> <span class="token function">Replace</span><span class="token punctuation">(</span>list <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> resourceVersion <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
|
|||
|
f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
keys <span class="token operator">:=</span> <span class="token function">make</span><span class="token punctuation">(</span>sets<span class="token punctuation">.</span>String<span class="token punctuation">,</span> <span class="token function">len</span><span class="token punctuation">(</span>list<span class="token punctuation">)</span><span class="token punctuation">)</span>
|
|||
|
|
|||
|
<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> item <span class="token operator">:=</span> <span class="token keyword">range</span> list <span class="token punctuation">{</span>
|
|||
|
key<span class="token punctuation">,</span> err <span class="token operator">:=</span> f<span class="token punctuation">.</span><span class="token function">KeyOf</span><span class="token punctuation">(</span>item<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> KeyError<span class="token punctuation">{</span>item<span class="token punctuation">,</span> err<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
keys<span class="token punctuation">.</span><span class="token function">Insert</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span>
|
|||
|
<span class="token comment">// 通过Replace添加到队列的Delta type都是Sync</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">:=</span> f<span class="token punctuation">.</span><span class="token function">queueActionLocked</span><span class="token punctuation">(</span>Sync<span class="token punctuation">,</span> item<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">"couldn't enqueue object: %v"</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
<span class="token comment">// 底层的缓存不应该会是nil</span>
|
|||
|
<span class="token keyword">if</span> f<span class="token punctuation">.</span>knownObjects <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">// Do deletion detection against our own list.</span>
|
|||
|
queuedDeletions <span class="token operator">:=</span> <span class="token number">0</span>
|
|||
|
<span class="token keyword">for</span> k<span class="token punctuation">,</span> oldItem <span class="token operator">:=</span> <span class="token keyword">range</span> f<span class="token punctuation">.</span>items <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">if</span> keys<span class="token punctuation">.</span><span class="token function">Has</span><span class="token punctuation">(</span>k<span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">continue</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">// 当knownObjects为空时,如果item中存在对象不在新来的list中,那么该对象被认为要被删除</span>
|
|||
|
<span class="token keyword">var</span> deletedObj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">if</span> n <span class="token operator">:=</span> oldItem<span class="token punctuation">.</span><span class="token function">Newest</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> n <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
deletedObj <span class="token operator">=</span> n<span class="token punctuation">.</span>Object
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
queuedDeletions<span class="token operator">++</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">:=</span> f<span class="token punctuation">.</span><span class="token function">queueActionLocked</span><span class="token punctuation">(</span>Deleted<span class="token punctuation">,</span> DeletedFinalStateUnknown<span class="token punctuation">{</span>k<span class="token punctuation">,</span> deletedObj<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> err
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
<span class="token keyword">if</span> <span class="token operator">!</span>f<span class="token punctuation">.</span>populated <span class="token punctuation">{</span>
|
|||
|
f<span class="token punctuation">.</span>populated <span class="token operator">=</span> <span class="token boolean">true</span>
|
|||
|
<span class="token comment">// While there shouldn't be any queued deletions in the initial</span>
|
|||
|
<span class="token comment">// population of the queue, it's better to be on the safe side.</span>
|
|||
|
f<span class="token punctuation">.</span>initialPopulationCount <span class="token operator">=</span> <span class="token function">len</span><span class="token punctuation">(</span>list<span class="token punctuation">)</span> <span class="token operator">+</span> queuedDeletions
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
<span class="token comment">// Detect deletions not already in the queue.</span>
|
|||
|
knownKeys <span class="token operator">:=</span> f<span class="token punctuation">.</span>knownObjects<span class="token punctuation">.</span><span class="token function">ListKeys</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token comment">// 记录这次替换相当于在缓存中删除多少对象</span>
|
|||
|
queuedDeletions <span class="token operator">:=</span> <span class="token number">0</span>
|
|||
|
<span class="token comment">// 枚举每一个缓存对象的key,看看在不在即将用来替换delta队列的list中</span>
|
|||
|
<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> k <span class="token operator">:=</span> <span class="token keyword">range</span> knownKeys <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">if</span> keys<span class="token punctuation">.</span><span class="token function">Has</span><span class="token punctuation">(</span>k<span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">continue</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">// 对象在缓存,但不在list中,说明替换操作完成后,这个对象相当于被删除了</span>
|
|||
|
<span class="token comment">// 注意这里的所谓替换,对deltaFIFO来说,是给队列中的对应对象增加一个delete增量queueActionLocked(Deleted, DeletedFinalStateUnknown{k, deletedObj})</span>
|
|||
|
<span class="token comment">// 真正删除缓存是在shareIndexInformer中的HandleDeltas中</span>
|
|||
|
deletedObj<span class="token punctuation">,</span> exists<span class="token punctuation">,</span> err <span class="token operator">:=</span> f<span class="token punctuation">.</span>knownObjects<span class="token punctuation">.</span><span class="token function">GetByKey</span><span class="token punctuation">(</span>k<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
deletedObj <span class="token operator">=</span> <span class="token boolean">nil</span>
|
|||
|
klog<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">"Unexpected error %v during lookup of key %v, placing DeleteFinalStateUnknown marker without object"</span><span class="token punctuation">,</span> err<span class="token punctuation">,</span> k<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token operator">!</span>exists <span class="token punctuation">{</span>
|
|||
|
deletedObj <span class="token operator">=</span> <span class="token boolean">nil</span>
|
|||
|
klog<span class="token punctuation">.</span><span class="token function">Infof</span><span class="token punctuation">(</span><span class="token string">"Key %v does not exist in known objects store, placing DeleteFinalStateUnknown marker without object"</span><span class="token punctuation">,</span> k<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
queuedDeletions<span class="token operator">++</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">:=</span> f<span class="token punctuation">.</span><span class="token function">queueActionLocked</span><span class="token punctuation">(</span>Deleted<span class="token punctuation">,</span> DeletedFinalStateUnknown<span class="token punctuation">{</span>k<span class="token punctuation">,</span> deletedObj<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> err
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">// 设置f.initialPopulationCount,大于0表示首次插入的对象还没有全部pop出去</span>
|
|||
|
<span class="token keyword">if</span> <span class="token operator">!</span>f<span class="token punctuation">.</span>populated <span class="token punctuation">{</span>
|
|||
|
f<span class="token punctuation">.</span>populated <span class="token operator">=</span> <span class="token boolean">true</span>
|
|||
|
f<span class="token punctuation">.</span>initialPopulationCount <span class="token operator">=</span> <span class="token function">len</span><span class="token punctuation">(</span>list<span class="token punctuation">)</span> <span class="token operator">+</span> queuedDeletions
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="从deltafifo-pop出对象">从deltaFIFO pop出对象</h4>
|
|||
|
<p>从队列中Pop出一个方法,并由函数process来处理,就是shareIndexInformer的HandleDeltas</p>
|
|||
|
<blockquote>
|
|||
|
<p>每次从DeltaFIFO Pop出一个对象,f.initialPopulationCount会减一,初始值为List时的对象数量
|
|||
|
前面的Informer的WaitForCacheSync最终就是调用了这个HasSynced方法</p>
|
|||
|
<p>因为前面Pop出对象的处理方法HandleDeltas中,会先调用indexder把对象存起来,所以这个HasSynced相当于判断本地缓存是否首次同步完成</p>
|
|||
|
</blockquote>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>DeltaFIFO<span class="token punctuation">)</span> <span class="token function">Pop</span><span class="token punctuation">(</span>process PopProcessFunc<span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">for</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">for</span> <span class="token function">len</span><span class="token punctuation">(</span>f<span class="token punctuation">.</span>queue<span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">0</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">// When the queue is empty, invocation of Pop() is blocked until new item is enqueued.</span>
|
|||
|
<span class="token comment">// When Close() is called, the f.closed is set and the condition is broadcasted.</span>
|
|||
|
<span class="token comment">// Which causes this loop to continue and return from the Pop().</span>
|
|||
|
<span class="token keyword">if</span> f<span class="token punctuation">.</span><span class="token function">IsClosed</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span><span class="token punctuation">,</span> ErrFIFOClosed
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
f<span class="token punctuation">.</span>cond<span class="token punctuation">.</span><span class="token function">Wait</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">//取出队首元素</span>
|
|||
|
id <span class="token operator">:=</span> f<span class="token punctuation">.</span>queue<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span>
|
|||
|
<span class="token comment">//去掉队首元素</span>
|
|||
|
f<span class="token punctuation">.</span>queue <span class="token operator">=</span> f<span class="token punctuation">.</span>queue<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">:</span><span class="token punctuation">]</span>
|
|||
|
<span class="token comment">//首次填充的对象数减一</span>
|
|||
|
<span class="token keyword">if</span> f<span class="token punctuation">.</span>initialPopulationCount <span class="token operator">></span> <span class="token number">0</span> <span class="token punctuation">{</span>
|
|||
|
f<span class="token punctuation">.</span>initialPopulationCount<span class="token operator">--</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
item<span class="token punctuation">,</span> ok <span class="token operator">:=</span> f<span class="token punctuation">.</span>items<span class="token punctuation">[</span>id<span class="token punctuation">]</span>
|
|||
|
<span class="token keyword">if</span> <span class="token operator">!</span>ok <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">// Item may have been deleted subsequently.</span>
|
|||
|
<span class="token keyword">continue</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token function">delete</span><span class="token punctuation">(</span>f<span class="token punctuation">.</span>items<span class="token punctuation">,</span> id<span class="token punctuation">)</span>
|
|||
|
<span class="token comment">//处理增量对象</span>
|
|||
|
err <span class="token operator">:=</span> <span class="token function">process</span><span class="token punctuation">(</span>item<span class="token punctuation">)</span>
|
|||
|
<span class="token comment">// 如果没有处理成功,那么就会重新加到deltaFIFO队列中</span>
|
|||
|
<span class="token keyword">if</span> e<span class="token punctuation">,</span> ok <span class="token operator">:=</span> err<span class="token punctuation">.</span><span class="token punctuation">(</span>ErrRequeue<span class="token punctuation">)</span><span class="token punctuation">;</span> ok <span class="token punctuation">{</span>
|
|||
|
f<span class="token punctuation">.</span><span class="token function">addIfNotPresent</span><span class="token punctuation">(</span>id<span class="token punctuation">,</span> item<span class="token punctuation">)</span>
|
|||
|
err <span class="token operator">=</span> e<span class="token punctuation">.</span>Err
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">// Don't need to copyDeltas here, because we're transferring</span>
|
|||
|
<span class="token comment">// ownership to the caller.</span>
|
|||
|
<span class="token keyword">return</span> item<span class="token punctuation">,</span> err
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="deltafifo是否同步完成">deltaFIFO是否同步完成</h4>
|
|||
|
<p>对应到前面遗留的没有串起来的问题:factory的WaitForCacheSync是如何等待缓存同步完成:</p>
|
|||
|
<blockquote>
|
|||
|
<p>factory的WaitForCacheSync方法调用informer的HasSync方法,继而调用deltaFIFO的HasSync方法,也就是判断从reflector list到的数据是否pop完</p>
|
|||
|
</blockquote>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>DeltaFIFO<span class="token punctuation">)</span> <span class="token function">HasSynced</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">bool</span> <span class="token punctuation">{</span>
|
|||
|
f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">return</span> f<span class="token punctuation">.</span>populated <span class="token operator">&&</span> f<span class="token punctuation">.</span>initialPopulationCount <span class="token operator">==</span> <span class="token number">0</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="deltafifo增加一个对象">deltaFIFO增加一个对象</h4>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token comment">//在队列中给指定的对象append一个Delta</span>
|
|||
|
<span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>DeltaFIFO<span class="token punctuation">)</span> <span class="token function">queueActionLocked</span><span class="token punctuation">(</span>actionType DeltaType<span class="token punctuation">,</span> obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
|
|||
|
id<span class="token punctuation">,</span> err <span class="token operator">:=</span> f<span class="token punctuation">.</span><span class="token function">KeyOf</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> KeyError<span class="token punctuation">{</span>obj<span class="token punctuation">,</span> err<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
newDeltas <span class="token operator">:=</span> <span class="token function">append</span><span class="token punctuation">(</span>f<span class="token punctuation">.</span>items<span class="token punctuation">[</span>id<span class="token punctuation">]</span><span class="token punctuation">,</span> Delta<span class="token punctuation">{</span>actionType<span class="token punctuation">,</span> obj<span class="token punctuation">}</span><span class="token punctuation">)</span>
|
|||
|
newDeltas <span class="token operator">=</span> <span class="token function">dedupDeltas</span><span class="token punctuation">(</span>newDeltas<span class="token punctuation">)</span>
|
|||
|
|
|||
|
<span class="token keyword">if</span> <span class="token function">len</span><span class="token punctuation">(</span>newDeltas<span class="token punctuation">)</span> <span class="token operator">></span> <span class="token number">0</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">if</span> <span class="token boolean">_</span><span class="token punctuation">,</span> exists <span class="token operator">:=</span> f<span class="token punctuation">.</span>items<span class="token punctuation">[</span>id<span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token operator">!</span>exists <span class="token punctuation">{</span>
|
|||
|
f<span class="token punctuation">.</span>queue <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>f<span class="token punctuation">.</span>queue<span class="token punctuation">,</span> id<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
f<span class="token punctuation">.</span>items<span class="token punctuation">[</span>id<span class="token punctuation">]</span> <span class="token operator">=</span> newDeltas
|
|||
|
f<span class="token punctuation">.</span>cond<span class="token punctuation">.</span><span class="token function">Broadcast</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">// We need to remove this from our map (extra items in the queue are</span>
|
|||
|
<span class="token comment">// ignored if they are not in the map).</span>
|
|||
|
<span class="token function">delete</span><span class="token punctuation">(</span>f<span class="token punctuation">.</span>items<span class="token punctuation">,</span> id<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="resync方法">Resync方法</h4>
|
|||
|
<blockquote>
|
|||
|
<p>所谓的resync,其实就是把knownObjects即缓存中的对象全部再通过queueActionLocked(Sync, obj)加到队列</p>
|
|||
|
</blockquote>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>DeltaFIFO<span class="token punctuation">)</span> <span class="token function">Resync</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
|
|||
|
f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> f<span class="token punctuation">.</span>lock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
|
|||
|
<span class="token keyword">if</span> f<span class="token punctuation">.</span>knownObjects <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
keys <span class="token operator">:=</span> f<span class="token punctuation">.</span>knownObjects<span class="token punctuation">.</span><span class="token function">ListKeys</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> k <span class="token operator">:=</span> <span class="token keyword">range</span> keys <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">:=</span> f<span class="token punctuation">.</span><span class="token function">syncKeyLocked</span><span class="token punctuation">(</span>k<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> err
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
<span class="token keyword">func</span> <span class="token punctuation">(</span>f <span class="token operator">*</span>DeltaFIFO<span class="token punctuation">)</span> <span class="token function">syncKeyLocked</span><span class="token punctuation">(</span>key <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token builtin">error</span> <span class="token punctuation">{</span>
|
|||
|
obj<span class="token punctuation">,</span> exists<span class="token punctuation">,</span> err <span class="token operator">:=</span> f<span class="token punctuation">.</span>knownObjects<span class="token punctuation">.</span><span class="token function">GetByKey</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span>
|
|||
|
|
|||
|
<span class="token comment">// If we are doing Resync() and there is already an event queued for that object,</span>
|
|||
|
<span class="token comment">// we ignore the Resync for it. This is to avoid the race, in which the resync</span>
|
|||
|
<span class="token comment">// comes with the previous value of object (since queueing an event for the object</span>
|
|||
|
<span class="token comment">// doesn't trigger changing the underlying store <knownObjects>.</span>
|
|||
|
id<span class="token punctuation">,</span> err <span class="token operator">:=</span> f<span class="token punctuation">.</span><span class="token function">KeyOf</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> KeyError<span class="token punctuation">{</span>obj<span class="token punctuation">,</span> err<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">// 如上述注释,在resync时,如果deltaFIFO中该对象还存在其他delta没处理,那么忽略这次的resync</span>
|
|||
|
<span class="token comment">// 因为调用queueActionLocked是增加delta是通过append的,且处理对象的增量delta时,是从oldest到newdest的</span>
|
|||
|
<span class="token comment">// 所以如果某个对象还存在增量没处理,再append就可能导致后处理的delta是旧的对象</span>
|
|||
|
<span class="token keyword">if</span> <span class="token function">len</span><span class="token punctuation">(</span>f<span class="token punctuation">.</span>items<span class="token punctuation">[</span>id<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token operator">></span> <span class="token number">0</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">:=</span> f<span class="token punctuation">.</span><span class="token function">queueActionLocked</span><span class="token punctuation">(</span>Sync<span class="token punctuation">,</span> obj<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span> fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">"couldn't queue object: %v"</span><span class="token punctuation">,</span> err<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h3 id=""> </h3>
|
|||
|
<h3 id="shareprocess的实现">shareProcess的实现</h3>
|
|||
|
<p>shareIndexInformer中具有一个shareProcess结构,用于分发deltaFIFO的对象,调用用户配置的EventHandler处理</p>
|
|||
|
<p>可以看到shareIndexInformer中的process直接通过&sharedProcessor{clock: realClock}初始化
|
|||
|
如下为sharedProcessor结构:</p>
|
|||
|
<blockquote>
|
|||
|
<p>listenersStarted:listeners中包含的listener是否都已经启动了
|
|||
|
listeners:已添加的listener列表,用来处理watch到的数据
|
|||
|
syncingListeners:已添加的listener列表,用来处理list到的数据</p>
|
|||
|
</blockquote>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token comment">// NewSharedIndexInformer creates a new instance for the listwatcher.</span>
|
|||
|
<span class="token keyword">func</span> <span class="token function">NewSharedIndexInformer</span><span class="token punctuation">(</span>lw ListerWatcher<span class="token punctuation">,</span> objType runtime<span class="token punctuation">.</span>Object<span class="token punctuation">,</span> defaultEventHandlerResyncPeriod time<span class="token punctuation">.</span>Duration<span class="token punctuation">,</span> indexers Indexers<span class="token punctuation">)</span> SharedIndexInformer <span class="token punctuation">{</span>
|
|||
|
realClock <span class="token operator">:=</span> <span class="token operator">&</span>clock<span class="token punctuation">.</span>RealClock<span class="token punctuation">{</span><span class="token punctuation">}</span>
|
|||
|
sharedIndexInformer <span class="token operator">:=</span> <span class="token operator">&</span>sharedIndexInformer<span class="token punctuation">{</span>
|
|||
|
processor<span class="token punctuation">:</span> <span class="token operator">&</span>sharedProcessor<span class="token punctuation">{</span>clock<span class="token punctuation">:</span> realClock<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
|||
|
indexer<span class="token punctuation">:</span> <span class="token function">NewIndexer</span><span class="token punctuation">(</span>DeletionHandlingMetaNamespaceKeyFunc<span class="token punctuation">,</span> indexers<span class="token punctuation">)</span><span class="token punctuation">,</span>
|
|||
|
listerWatcher<span class="token punctuation">:</span> lw<span class="token punctuation">,</span>
|
|||
|
objectType<span class="token punctuation">:</span> objType<span class="token punctuation">,</span>
|
|||
|
resyncCheckPeriod<span class="token punctuation">:</span> defaultEventHandlerResyncPeriod<span class="token punctuation">,</span>
|
|||
|
defaultEventHandlerResyncPeriod<span class="token punctuation">:</span> defaultEventHandlerResyncPeriod<span class="token punctuation">,</span>
|
|||
|
cacheMutationDetector<span class="token punctuation">:</span> <span class="token function">NewCacheMutationDetector</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">"%T"</span><span class="token punctuation">,</span> objType<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
|
|||
|
clock<span class="token punctuation">:</span> realClock<span class="token punctuation">,</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> sharedIndexInformer
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
|
|||
|
<span class="token keyword">type</span> sharedProcessor <span class="token keyword">struct</span> <span class="token punctuation">{</span>
|
|||
|
listenersStarted <span class="token builtin">bool</span>
|
|||
|
listenersLock sync<span class="token punctuation">.</span>RWMutex
|
|||
|
listeners <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">*</span>processorListener
|
|||
|
syncingListeners <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">*</span>processorListener
|
|||
|
clock clock<span class="token punctuation">.</span>Clock
|
|||
|
wg wait<span class="token punctuation">.</span>Group
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="为sharedprocessor添加listener">为sharedProcessor添加listener</h4>
|
|||
|
<p>在sharedProcessor中添加一个listener</p>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>p <span class="token operator">*</span>sharedProcessor<span class="token punctuation">)</span> <span class="token function">addListenerLocked</span><span class="token punctuation">(</span>listener <span class="token operator">*</span>processorListener<span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">// 同时添加到listeners和syncingListeners列表,但其实添加的是同一个对象的引用</span>
|
|||
|
p<span class="token punctuation">.</span>listeners <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>p<span class="token punctuation">.</span>listeners<span class="token punctuation">,</span> listener<span class="token punctuation">)</span>
|
|||
|
p<span class="token punctuation">.</span>syncingListeners <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>p<span class="token punctuation">.</span>syncingListeners<span class="token punctuation">,</span> listener<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="启动sharedprocessor中的的listener">启动sharedProcessor中的的listener</h4>
|
|||
|
<p>sharedProcessor启动所有的listener
|
|||
|
是通过调用listener.run和listener.pop来启动一个listener,两个方法具体作用看下文processorListener说明</p>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>p <span class="token operator">*</span>sharedProcessor<span class="token punctuation">)</span> <span class="token function">run</span><span class="token punctuation">(</span>stopCh <span class="token operator"><-</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
p<span class="token punctuation">.</span>listenersLock<span class="token punctuation">.</span><span class="token function">RLock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> p<span class="token punctuation">.</span>listenersLock<span class="token punctuation">.</span><span class="token function">RUnlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> listener <span class="token operator">:=</span> <span class="token keyword">range</span> p<span class="token punctuation">.</span>listeners <span class="token punctuation">{</span>
|
|||
|
p<span class="token punctuation">.</span>wg<span class="token punctuation">.</span><span class="token function">Start</span><span class="token punctuation">(</span>listener<span class="token punctuation">.</span>run<span class="token punctuation">)</span>
|
|||
|
p<span class="token punctuation">.</span>wg<span class="token punctuation">.</span><span class="token function">Start</span><span class="token punctuation">(</span>listener<span class="token punctuation">.</span>pop<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
p<span class="token punctuation">.</span>listenersStarted <span class="token operator">=</span> <span class="token boolean">true</span>
|
|||
|
<span class="token punctuation">}</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token operator"><-</span>stopCh
|
|||
|
p<span class="token punctuation">.</span>listenersLock<span class="token punctuation">.</span><span class="token function">RLock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> p<span class="token punctuation">.</span>listenersLock<span class="token punctuation">.</span><span class="token function">RUnlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> listener <span class="token operator">:=</span> <span class="token keyword">range</span> p<span class="token punctuation">.</span>listeners <span class="token punctuation">{</span>
|
|||
|
<span class="token function">close</span><span class="token punctuation">(</span>listener<span class="token punctuation">.</span>addCh<span class="token punctuation">)</span> <span class="token comment">// Tell .pop() to stop. .pop() will tell .run() to stop</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
p<span class="token punctuation">.</span>wg<span class="token punctuation">.</span><span class="token function">Wait</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// Wait for all .pop() and .run() to stop</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="sharedprocessor分发对象">sharedProcessor分发对象</h4>
|
|||
|
<p>distribute方法是在前面介绍[deltaFIFO pop出来的对象处理逻辑]时提到的,把notification事件添加到listener中,listener如何pop出notification回调EventHandler见下文listener分析</p>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>p <span class="token operator">*</span>sharedProcessor<span class="token punctuation">)</span> <span class="token function">distribute</span><span class="token punctuation">(</span>obj <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> sync <span class="token builtin">bool</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
p<span class="token punctuation">.</span>listenersLock<span class="token punctuation">.</span><span class="token function">RLock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> p<span class="token punctuation">.</span>listenersLock<span class="token punctuation">.</span><span class="token function">RUnlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token comment">// 如果是通过reflector list Replace到deltaFIFO的对象,那么distribute到syncingListeners</span>
|
|||
|
<span class="token keyword">if</span> sync <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> listener <span class="token operator">:=</span> <span class="token keyword">range</span> p<span class="token punctuation">.</span>syncingListeners <span class="token punctuation">{</span>
|
|||
|
listener<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> listener <span class="token operator">:=</span> <span class="token keyword">range</span> p<span class="token punctuation">.</span>listeners <span class="token punctuation">{</span>
|
|||
|
listener<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h3 id="processorlistener结构">processorListener结构</h3>
|
|||
|
<p>sharedProcessor中的listener具体的类型:运转逻辑就是把用户通过addCh增加的事件发送到nextCh供run方法取出回调Eventhandler,因为addCh和nectCh都是无缓冲channel,所以中间引入ringBuffer做缓存</p>
|
|||
|
<blockquote>
|
|||
|
<p>processorListener是sharedIndexInformer调用AddEventHandler时创建并添加到sharedProcess
|
|||
|
对于一个Informer,可以多次调用AddEventHandler来添加多个listener,但我们的一般的使用场景应该都只会添加一个,作用都是类似enqueue到workQueue
|
|||
|
addCh和nextCh:都将被初始化为无缓冲的chan
|
|||
|
pendingNotifications:一个无容量限制的环形缓冲区,可以理解为可以无限存储的队列,用来存储deltaFIFO分发过来的消息</p>
|
|||
|
</blockquote>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">type</span> processorListener <span class="token keyword">struct</span> <span class="token punctuation">{</span>
|
|||
|
nextCh <span class="token keyword">chan</span> <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
|
|||
|
addCh <span class="token keyword">chan</span> <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
|
|||
|
|
|||
|
handler ResourceEventHandler
|
|||
|
|
|||
|
<span class="token comment">// pendingNotifications is an unbounded ring buffer that holds all notifications not yet distributed.</span>
|
|||
|
<span class="token comment">// There is one per listener, but a failing/stalled listener will have infinite pendingNotifications</span>
|
|||
|
<span class="token comment">// added until we OOM.</span>
|
|||
|
<span class="token comment">// TODO: This is no worse than before, since reflectors were backed by unbounded DeltaFIFOs, but</span>
|
|||
|
<span class="token comment">// we should try to do something better.</span>
|
|||
|
pendingNotifications buffer<span class="token punctuation">.</span>RingGrowing
|
|||
|
|
|||
|
<span class="token comment">// requestedResyncPeriod is how frequently the listener wants a full resync from the shared informer</span>
|
|||
|
requestedResyncPeriod time<span class="token punctuation">.</span>Duration
|
|||
|
<span class="token comment">// resyncPeriod is how frequently the listener wants a full resync from the shared informer. This</span>
|
|||
|
<span class="token comment">// value may differ from requestedResyncPeriod if the shared informer adjusts it to align with the</span>
|
|||
|
<span class="token comment">// informer's overall resync check period.</span>
|
|||
|
resyncPeriod time<span class="token punctuation">.</span>Duration
|
|||
|
<span class="token comment">// nextResync is the earliest time the listener should get a full resync</span>
|
|||
|
nextResync time<span class="token punctuation">.</span>Time
|
|||
|
<span class="token comment">// resyncLock guards access to resyncPeriod and nextResync</span>
|
|||
|
resyncLock sync<span class="token punctuation">.</span>Mutex
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="在listener中添加事件">在listener中添加事件</h4>
|
|||
|
<p>shareProcessor中的distribute方法调用的是listener的add来向addCh增加消息,注意addCh是无缓冲的chan,依赖pop不断从addCh取出数据</p>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>p <span class="token operator">*</span>processorListener<span class="token punctuation">)</span> <span class="token function">add</span><span class="token punctuation">(</span>notification <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
p<span class="token punctuation">.</span>addCh <span class="token operator"><-</span> notification
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="判断是否需要resync">判断是否需要resync</h4>
|
|||
|
<p>前面reflector中会调用这个shouldResync方法根据每个listener的resyncPeriod判断是否需要resync</p>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token comment">// shouldResync queries every listener to determine if any of them need a resync, based on each</span>
|
|||
|
<span class="token comment">// listener's resyncPeriod.</span>
|
|||
|
<span class="token keyword">func</span> <span class="token punctuation">(</span>p <span class="token operator">*</span>sharedProcessor<span class="token punctuation">)</span> <span class="token function">shouldResync</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">bool</span> <span class="token punctuation">{</span>
|
|||
|
p<span class="token punctuation">.</span>listenersLock<span class="token punctuation">.</span><span class="token function">Lock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> p<span class="token punctuation">.</span>listenersLock<span class="token punctuation">.</span><span class="token function">Unlock</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
|
|||
|
p<span class="token punctuation">.</span>syncingListeners <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">*</span>processorListener<span class="token punctuation">{</span><span class="token punctuation">}</span>
|
|||
|
|
|||
|
resyncNeeded <span class="token operator">:=</span> <span class="token boolean">false</span>
|
|||
|
now <span class="token operator">:=</span> p<span class="token punctuation">.</span>clock<span class="token punctuation">.</span><span class="token function">Now</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> listener <span class="token operator">:=</span> <span class="token keyword">range</span> p<span class="token punctuation">.</span>listeners <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">// need to loop through all the listeners to see if they need to resync so we can prepare any</span>
|
|||
|
<span class="token comment">// listeners that are going to be resyncing.</span>
|
|||
|
<span class="token keyword">if</span> listener<span class="token punctuation">.</span><span class="token function">shouldResync</span><span class="token punctuation">(</span>now<span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
resyncNeeded <span class="token operator">=</span> <span class="token boolean">true</span>
|
|||
|
p<span class="token punctuation">.</span>syncingListeners <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>p<span class="token punctuation">.</span>syncingListeners<span class="token punctuation">,</span> listener<span class="token punctuation">)</span>
|
|||
|
listener<span class="token punctuation">.</span><span class="token function">determineNextResync</span><span class="token punctuation">(</span>now<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">return</span> resyncNeeded
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="listener的run方法回调eventhandler">listener的run方法回调EventHandler</h4>
|
|||
|
<p>listener的run方法不断的从nextCh中获取notification,并根据notification的类型来调用用户自定的EventHandler</p>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>p <span class="token operator">*</span>processorListener<span class="token punctuation">)</span> <span class="token function">run</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">// this call blocks until the channel is closed. When a panic happens during the notification</span>
|
|||
|
<span class="token comment">// we will catch it, **the offending item will be skipped!**, and after a short delay (one second)</span>
|
|||
|
<span class="token comment">// the next notification will be attempted. This is usually better than the alternative of never</span>
|
|||
|
<span class="token comment">// delivering again.</span>
|
|||
|
stopCh <span class="token operator">:=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword">chan</span> <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
|
|||
|
wait<span class="token punctuation">.</span><span class="token function">Until</span><span class="token punctuation">(</span><span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">// this gives us a few quick retries before a long pause and then a few more quick retries</span>
|
|||
|
err <span class="token operator">:=</span> wait<span class="token punctuation">.</span><span class="token function">ExponentialBackoff</span><span class="token punctuation">(</span>retry<span class="token punctuation">.</span>DefaultRetry<span class="token punctuation">,</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token builtin">bool</span><span class="token punctuation">,</span> <span class="token builtin">error</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">for</span> next <span class="token operator">:=</span> <span class="token keyword">range</span> p<span class="token punctuation">.</span>nextCh <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">switch</span> notification <span class="token operator">:=</span> next<span class="token punctuation">.</span><span class="token punctuation">(</span><span class="token keyword">type</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">case</span> updateNotification<span class="token punctuation">:</span>
|
|||
|
p<span class="token punctuation">.</span>handler<span class="token punctuation">.</span><span class="token function">OnUpdate</span><span class="token punctuation">(</span>notification<span class="token punctuation">.</span>oldObj<span class="token punctuation">,</span> notification<span class="token punctuation">.</span>newObj<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">case</span> addNotification<span class="token punctuation">:</span>
|
|||
|
p<span class="token punctuation">.</span>handler<span class="token punctuation">.</span><span class="token function">OnAdd</span><span class="token punctuation">(</span>notification<span class="token punctuation">.</span>newObj<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">case</span> deleteNotification<span class="token punctuation">:</span>
|
|||
|
p<span class="token punctuation">.</span>handler<span class="token punctuation">.</span><span class="token function">OnDelete</span><span class="token punctuation">(</span>notification<span class="token punctuation">.</span>oldObj<span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">default</span><span class="token punctuation">:</span>
|
|||
|
utilruntime<span class="token punctuation">.</span><span class="token function">HandleError</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Errorf</span><span class="token punctuation">(</span><span class="token string">"unrecognized notification: %T"</span><span class="token punctuation">,</span> next<span class="token punctuation">)</span><span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">// the only way to get here is if the p.nextCh is empty and closed</span>
|
|||
|
<span class="token keyword">return</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token boolean">nil</span>
|
|||
|
<span class="token punctuation">}</span><span class="token punctuation">)</span>
|
|||
|
|
|||
|
<span class="token comment">// the only way to get here is if the p.nextCh is empty and closed</span>
|
|||
|
<span class="token keyword">if</span> err <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token function">close</span><span class="token punctuation">(</span>stopCh<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token operator">*</span>time<span class="token punctuation">.</span>Minute<span class="token punctuation">,</span> stopCh<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<h4 id="addch到nextch的对象传递">addCh到nextCh的对象传递</h4>
|
|||
|
<p>listener中pop方法的逻辑相对比较绕,最终目的就是把分发到addCh的数据从nextCh或者pendingNotifications取出来</p>
|
|||
|
<blockquote>
|
|||
|
<p>notification变量记录下一次要被放到p.nextCh供pop方法取出的对象
|
|||
|
开始seletct时必然只有case2可能ready
|
|||
|
Case2做的事可以描述为:从p.addCh获取对象,如果临时变量notification还是nil,说明需要往notification赋值,供case1推送到p.nextCh
|
|||
|
如果notification已经有值了,那个当前从p.addCh取出的值要先放到环形缓冲区中</p>
|
|||
|
<p>Case1做的事可以描述为:看看能不能把临时变量notification推送到nextCh(nil chan会阻塞在读写操作上),可以写的话,说明这个nextCh是p.nextCh,写成功之后,需要从缓存中取出一个对象放到notification为下次执行这个case做准备,如果缓存是空的,通过把nextCh chan设置为nil来禁用case1,以便case2位notification赋值</p>
|
|||
|
</blockquote>
|
|||
|
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token punctuation">(</span>p <span class="token operator">*</span>processorListener<span class="token punctuation">)</span> <span class="token function">pop</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">defer</span> utilruntime<span class="token punctuation">.</span><span class="token function">HandleCrash</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">defer</span> <span class="token function">close</span><span class="token punctuation">(</span>p<span class="token punctuation">.</span>nextCh<span class="token punctuation">)</span> <span class="token comment">// Tell .run() to stop</span>
|
|||
|
|
|||
|
<span class="token comment">//nextCh没有利用make初始化,将阻塞在读和写上</span>
|
|||
|
<span class="token keyword">var</span> nextCh <span class="token keyword">chan</span><span class="token operator"><-</span> <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
|
|||
|
<span class="token comment">//notification初始值为nil</span>
|
|||
|
<span class="token keyword">var</span> notification <span class="token keyword">interface</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">for</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">select</span> <span class="token punctuation">{</span>
|
|||
|
<span class="token comment">// 执行这个case,相当于给p.nextCh添加来自p.addCh的内容</span>
|
|||
|
<span class="token keyword">case</span> nextCh <span class="token operator"><-</span> notification<span class="token punctuation">:</span>
|
|||
|
<span class="token comment">// Notification dispatched</span>
|
|||
|
<span class="token keyword">var</span> ok <span class="token builtin">bool</span>
|
|||
|
<span class="token comment">//前面的notification已经加到p.nextCh了, 为下一次这个case再次ready做准备</span>
|
|||
|
notification<span class="token punctuation">,</span> ok <span class="token operator">=</span> p<span class="token punctuation">.</span>pendingNotifications<span class="token punctuation">.</span><span class="token function">ReadOne</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
|||
|
<span class="token keyword">if</span> <span class="token operator">!</span>ok <span class="token punctuation">{</span> <span class="token comment">// Nothing to pop</span>
|
|||
|
nextCh <span class="token operator">=</span> <span class="token boolean">nil</span> <span class="token comment">// Disable this select case</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token comment">//第一次select只有这个case ready</span>
|
|||
|
<span class="token keyword">case</span> notificationToAdd<span class="token punctuation">,</span> ok <span class="token operator">:=</span> <span class="token operator"><-</span>p<span class="token punctuation">.</span>addCh<span class="token punctuation">:</span>
|
|||
|
<span class="token keyword">if</span> <span class="token operator">!</span>ok <span class="token punctuation">{</span>
|
|||
|
<span class="token keyword">return</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token keyword">if</span> notification <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span> <span class="token comment">// No notification to pop (and pendingNotifications is empty)</span>
|
|||
|
<span class="token comment">// Optimize the case - skip adding to pendingNotifications</span>
|
|||
|
<span class="token comment">//为notification赋值</span>
|
|||
|
notification <span class="token operator">=</span> notificationToAdd
|
|||
|
<span class="token comment">//唤醒第一个case</span>
|
|||
|
nextCh <span class="token operator">=</span> p<span class="token punctuation">.</span>nextCh
|
|||
|
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> <span class="token comment">// There is already a notification waiting to be dispatched</span>
|
|||
|
<span class="token comment">//select没有命中第一个case,那么notification就没有被消耗,那么把从p.addCh获取的对象加到缓存中</span>
|
|||
|
p<span class="token punctuation">.</span>pendingNotifications<span class="token punctuation">.</span><span class="token function">WriteOne</span><span class="token punctuation">(</span>notificationToAdd<span class="token punctuation">)</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
<span class="token punctuation">}</span>
|
|||
|
</code></pre>
|
|||
|
<footer class="page-footer"><span class="copyright"><a href="https://mp.weixin.qq.com/s/vWlSdzz2MNdXRr0sd2-LFg" target="_blank">加入云原生社区</a><p></p>Copyright © 2017-2021 | Distributed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" target="_blank">CC BY 4.0</a> | <a href="https://jimmysong.io" target="_blank">jimmysong.io</a> all right reserved,powered by Gitbook</span><span class="footer-modification"> Updated at
|
|||
|
2021-07-01 01:57:47
|
|||
|
</span></footer>
|
|||
|
|
|||
|
</section>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="search-results">
|
|||
|
<div class="has-results">
|
|||
|
|
|||
|
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
|
|||
|
<ul class="search-results-list"></ul>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="no-results">
|
|||
|
|
|||
|
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<a href="client-go-sample.html" class="navigation navigation-prev " aria-label="Previous page: client-go 示例">
|
|||
|
<i class="fa fa-angle-left"></i>
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
<a href="operator.html" class="navigation navigation-next " aria-label="Next page: Operator">
|
|||
|
<i class="fa fa-angle-right"></i>
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
|
|||
|
<script>
|
|||
|
var gitbook = gitbook || [];
|
|||
|
gitbook.push(function() {
|
|||
|
gitbook.page.hasChanged({"page":{"title":"client-go 中的 informer 源码分析","level":"9.5.1","depth":2,"next":{"title":"Operator","level":"9.6","depth":1,"path":"develop/operator.md","ref":"develop/operator.md","articles":[{"title":"operator-sdk","level":"9.6.1","depth":2,"path":"develop/operator-sdk.md","ref":"develop/operator-sdk.md","articles":[]}]},"previous":{"title":"client-go 示例","level":"9.5","depth":1,"path":"develop/client-go-sample.md","ref":"develop/client-go-sample.md","articles":[{"title":"client-go 中的 informer 源码分析","level":"9.5.1","depth":2,"path":"develop/client-go-informer-sourcecode-analyse.md","ref":"develop/client-go-informer-sourcecode-analyse.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["github","codesnippet","splitter","page-toc-button","image-captions","editlink","back-to-top-button","-lunr","-search","search-plus","github-buttons@2.1.0","favicon@^0.0.2","tbfed-pagefooter@^0.0.1","3-ba","theme-default","-highlight","prism","prism-themes","lightbox","ga","sitemap-general"],"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"<a href=https://mp.weixin.qq.com/s/vWlSdzz2MNdXRr0sd2-LFg>加入云原生社区</a></p>Copyright © 2017-2021 | Distributed under <a href=https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh>CC BY 4.0</a> | <a href=https://jimmysong.io>jimmysong.io</a>","modify_label":" Updated at ","modify_format":"YYYY-MM-DD HH:mm:ss"},"prism":{"css":["prism-themes/themes/prism-ghcolors.css"]},"github":{"url":"https://github.com/rootsongjc/kubernetes-handbook"},"editlink":{"label":"编辑本页","multilingual":false,"base":"https://github.com/rootsongjc/kubernetes-handbook/blob/master/"},"splitter":{},"codesnippet":{},"sitemap-general":{"prefix":"https://jimmysong.io/kubernetes-handbook/"},"fontsettings":{"theme":"white","family":"sans","size":2},"favicon":{"shortcut":"favicon.ico","bookmark":"favicon.ico"},"lightbox":{"jquery":true,"sameUuid":false},"page-toc-button":{},"back-to-top-button":{},"prism-themes":{},"github-buttons":{"repo":"rootsongjc/kubernetes-handbook","types":["star"],"size":"small"},"3-ba":{"configuration":"auto","token":"11f7d254cfa4e0ca44b175c66d379ecc"},"ga":{"configuration":"auto","token":"UA-93485976-1"},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"showLevel":true,"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"}},"search-plus":{},"image-captions":{"caption":"图 _PAGE_LEVEL_._PAGE_IMAGE_NUMBER_:_CAPTION_","variable_name":"_pictures"}},"theme":"default","author":"Jimmy Song(宋净超)","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{"_pictures":[{"backlink":"cloud-native/kubernetes-and-cloud-native-app-overview.html#fig2.4.1","level":"2.4","list_caption":"Figure: 云计算演进历程","alt":"云计算演进历程","nro":1,"url":"../images/cloud-computing-evolution-road.jpg","index":1,"caption_template":"图 _PAGE_LEVEL_._PAGE_IMAGE_NUMBER_:_CAPTION_","label":"云计算演进历程","attributes":{},"skip":false,"key":"2.4.1"},{"backlink":"cloud-native/kubernetes-and-cloud-native-app-overview.html#fig2.4.2","level":"2.4","list_caption":"Figure: 来自Twitter @MarcWilczek","alt":"来自Twitter @MarcWilczek","nro":2,"url":"../images/cloud-native-comes-of-age.jpg","index":2,"caption_template":"图 _PAGE_LEVEL_._PAGE_IMAGE_NUMBER_:_CAPTION_","label":"来自Twitter @MarcWilczek","attributes":{},"skip":false,"key":"2.4.2"},{"backlink":"cloud-native/kubernetes-and
|
|||
|
});
|
|||
|
</script>
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook.js"></script>
|
|||
|
<script src="../gitbook/theme.js"></script>
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-editlink/plugin.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-search-plus/search.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-3-ba/plugin.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-lightbox/js/lightbox.min.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-ga/plugin.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</body>
|
|||
|
</html>
|
|||
|
|