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

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

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

3954b1b553954ee88141c795a9f0ef22.png

// 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, 用来对后端存储的数据层访问。

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值