storage解读(二)-genericStore-v1.5.2

什么是genericStore

genericStore是对ETCD Helper的封装,定义了Kubernetes类型的通用操作。

阅读全文

storage解读(一)-registry-v1.5.2

什么是registry

在Kubernetes中,registry可以对ETCD中的Kubernetes各类型进行增删查改操作,并对外提供了生成apiGroupInfo的方法。这里的registry包含了两层含义,Storage和Registry,如NodeStorage和NodeRegistry。Storage提供了通用的增删查改方法,Regsitry是对Storage的封装,提供了具体类型的增删查改方法。registry定义在/pkg/registry目录下,主要包含:

阅读全文

apimachinery机制解读(二)-GroupMetaFactory-v1.5.2

什么是GroupMetaFactory

GroupMetaFactory表示一个Group,主要包含两部信息,GroupMetaFactoryArgs表示Group的信息;GroupversionFactoryArgs表示Version的信息。GroupMetaFactory还提供了向APIRegistrationManager注册的功能。

阅读全文

apimachinery机制解读(一)-APIRegistrationManager-v1.5.2

什么是apimachinery

“Package apimachinery contains the generic API machinery code that is common to both server and clients.” apimachinery是对API包及版本管理的一个抽象,主要包含registered和announced两个package:

阅读全文

Scheme机制解读(三)-Cloner-v1.5.2

什么是Cloner

Cloner是Kubernetes用来管理type对应的拷贝函数,自定义拷贝函数需要注册到Cloner中。Cloner定义在/pkg/conversion/cloner.go中:

1
2
3
4
5
6
// Cloner knows how to copy one type to another.
type Cloner struct {
// Map from the type to a function which can do the deep copy.
deepCopyFuncs map[reflect.Type]reflect.Value
generatedDeepCopyFuncs map[reflect.Type]func(in interface{}, out interface{}, c *Cloner) error
}

阅读全文

Scheme机制解读(二)-Converter-v1.5.2

什么是Converter

Converter可以完成不同结构体之间的转换。在Kubernetes中,Converter用来把一个版本的object转换成其他版本的object,转换函数需要通过注册的方式添加到Converter中。

阅读全文

Scheme机制解读(一)-Scheme-v1.5.2

什么是Scheme

如果说RESTMapper管理的是GVR和GVK的关系,那么Scheme管理的就是GVK和Type的关系。系统中所有的Type都要注册到Scheme中,当然目前系统只有一个Scheme,即api.Scheme,定义在/pkg/api/register.go中:

1
2
//***定义Scheme***//
var Scheme = runtime.NewScheme()

阅读全文

RESTMapper解读(三)-其他RESTMapper-v1.5.2

其他RESTMapper

之前的两次关于RESTMapper的分析都是和DefaultRESTMapper相关的。除了DefaultRESTMapper以外,Kubernetes还实现了PriorityRESTMapper,MuiltiRESTMaper和FirstHitRESTMapper。本次分析就来看下这些RESTMapper的实现。

阅读全文

RESTMapper解读(二)-管理DefaultRESTMapper-v1.5.2

生成DefaultRESTMapper入口

上次介绍了DefaultRESTMapper的具体实现,本次将简要分析代码何处生成了DefaultRESTMapper。生成DefaultRESTMapper的入口定义在/pkg/api/mapper.go:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
func NewDefaultRESTMapperFromScheme(defaultGroupVersions []unversioned.GroupVersion, interfacesFunc meta.VersionInterfacesFunc,
importPathPrefix string, ignoredKinds, rootScoped sets.String, scheme *runtime.Scheme) *meta.DefaultRESTMapper {
mapper := meta.NewDefaultRESTMapper(defaultGroupVersions, interfacesFunc)
// enumerate all supported versions, get the kinds, and register with the mapper how to address
// our resources.
for _, gv := range defaultGroupVersions {
for kind, oType := range scheme.KnownTypes(gv) {
gvk := gv.WithKind(kind)
// TODO: Remove import path check.
// We check the import path because we currently stuff both "api" and "extensions" objects
// into the same group within Scheme since Scheme has no notion of groups yet.
if !strings.Contains(oType.PkgPath(), importPathPrefix) || ignoredKinds.Has(kind) {
continue
}
scope := meta.RESTScopeNamespace
//***/pkg/api/install/install.go中定义***//
if rootScoped.Has(kind) {
scope = meta.RESTScopeRoot
}
mapper.Add(gvk, scope)
}
}
return mapper
}

阅读全文

RESTMapper解读(一)-DefaultRESTMapper-v1.5.2

什么是RESTMapper

先来看来什么是RESTMapper。RESTMapper是一个interface,定义在/pkg/meta/interfaces.go中:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// RESTMapper allows clients to map resources to kind, and map kind and version
// to interfaces for manipulating those objects. It is primarily intended for
// consumers of Kubernetes compatible REST APIs as defined in docs/devel/api-conventions.md.
//
// The Kubernetes API provides versioned resources and object kinds which are scoped
// to API groups. In other words, kinds and resources should not be assumed to be
// unique across groups.
//
// TODO: split into sub-interfaces
type RESTMapper interface {
// KindFor takes a partial resource and returns the single match. Returns an error if there are multiple matches
KindFor(resource unversioned.GroupVersionResource) (unversioned.GroupVersionKind, error)
// KindsFor takes a partial resource and returns the list of potential kinds in priority order
KindsFor(resource unversioned.GroupVersionResource) ([]unversioned.GroupVersionKind, error)
// ResourceFor takes a partial resource and returns the single match. Returns an error if there are multiple matches
ResourceFor(input unversioned.GroupVersionResource) (unversioned.GroupVersionResource, error)
// ResourcesFor takes a partial resource and returns the list of potential resource in priority order
ResourcesFor(input unversioned.GroupVersionResource) ([]unversioned.GroupVersionResource, error)
// RESTMapping identifies a preferred resource mapping for the provided group kind.
RESTMapping(gk unversioned.GroupKind, versions ...string) (*RESTMapping, error)
// RESTMappings returns all resource mappings for the provided group kind.
RESTMappings(gk unversioned.GroupKind) ([]*RESTMapping, error)
AliasesForResource(resource string) ([]string, bool)
ResourceSingularizer(resource string) (singular string, err error)
}

阅读全文