前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >K8s源码分析(14)-资源的服务层接口实现

K8s源码分析(14)-资源的服务层接口实现

作者头像
TA码字
发布2022-02-25 09:32:27
4510
发布2022-02-25 09:32:27
举报
文章被收录于专栏:TA码字TA码字

上一篇文章中,我们主要介绍了 kubernetes 中资源的服务层接口定义,包括增删改查类接口,以及操作的策略类接口。在本篇文章里, 我们主要来介绍资源增删改查类接口的实现。

对于增删改查类接口实现,图解和源码如下:

代码语言:javascript
复制
// k8s.io/apiserver/pkg/registry/generic/registry/store.go
type GenericStore interface {
  GetCreateStrategy() rest.RESTCreateStrategy
  GetUpdateStrategy() rest.RESTUpdateStrategy
  GetDeleteStrategy() rest.RESTDeleteStrategy
}

type Store struct {
  NewFunc func() runtime.Object
  NewListFunc func() runtime.Object
  CreateStrategy rest.RESTCreateStrategy
  UpdateStrategy rest.RESTUpdateStrategy
  DeleteStrategy rest.RESTDeleteStrategy
  Storage DryRunnableStorage
  KeyRootFunc func(ctx context.Context) string
  KeyFunc func(ctx context.Context, name string) (string, error)
  ObjectNameFunc func(obj runtime.Object) (string, error)
  ......
}

func (e *Store) New() runtime.Object{...} ==>Storage
func (e *Store) NewList() runtime.Object{...}==>Lister
func (e *Store) List(ctx context.Context, options *metainternalversion.ListOptions) (runtime.Object, error) {...}
func (e *Store) NamespaceScoped() bool {...}==>Scoper
func (e *Store) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error){...}==>Getter
func (e *Store) Watch(ctx context.Context, options *metainternalversion.ListOptions) (watch.Interface, error)==>{...}Watcher
func (e *Store) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error)==>{...}Creater
func (e *Store) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error){...}==>Updater
func (e *Store) Delete(ctx context.Context, name string, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions) (runtime.Object, bool, error){...} ==>GracefulDeleter
func (e *Store) DeleteCollection(ctx context.Context, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions, listOptions *metainternalversion.ListOptions) (runtime.Object, error){...}==>CollectionDeleter

func (e *Store) GetCreateStrategy() rest.RESTCreateStrategy{...} ==>GenericStore
func (e *Store) GetUpdateStrategy() rest.RESTUpdateStrategy{...} 
func (e *Store) GetDeleteStrategy() rest.RESTDeleteStrategy{...}
  • registry.store.Store 结构体实现了增删改查类型接口定义的函数。
  • registry.store.Store 结构体中,以组合的方式封装了上一篇文章中介绍的对于资源操作策略类型的一系列相关属性,例如RESTCreateStrategy/RESTUpdateStrategy/RESTDeleteStrategy 等,用来完成不同操作的逻辑。
  • registry.store.Store 结构体中,以组合的方式封装以前文章中介绍的数据访问层属性 DryRunnableStorage, 用来对后端存储的数据层访问。

目前先我们写到这里,在下一篇文章中我们继续来介绍资源数据服务层策略类型接口的实现。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-01-21,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 TA码字 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档