Openshift API部分源码学习笔记(二)

前面一篇文章将openshift里面启动kubernetes组件部分解析了一下,本文将对openshift启动master服务的代码解析一下

上一篇文章链接:http://www.cnblogs.com/zard/p/7767112.html

源码分析

前面将kubernetes的API Server注册启动命令创建好了之后回到NewCommandStartAllInOne方法中,这次看下NewCommandStartMaster方法,此方法即为获取启动openshift master的命令

--》openshift/origin/pkg/cmd/server/start/start_allinone.go

 

--》openshift/origin/pkg/cmd/server/start/start_master.go

NewCommandStartMaster方法中添加命令的逻辑如下,即为添加了controller和API的两个启动命令

这里我们主要看下API相关的即NewCommandStartMasterAPI方法

--》openshift/origin/pkg/cmd/server/start/start_api.go

 NewCommandStartMasterAPI方法里面主要逻辑如下,即调用StartMaster方法来启动master服务

后面在RunMaster方法里面根据配置信息生产一个master结构对象并调用start方法启动

--》openshift/origin/pkg/cmd/server/start/start_master.go

 start方法里面先根据给定选项来创建openshift和kubernetes的配置信息

然后判断此master server是否有api服务,若有则根据刚刚创建的两个配置文件调用StartAPI方法来启动master上的api部分组件

StartAPI方法会启动那些在master上被认为是API一部分的组件,比如一开始就会根据配置信息来判断是否启动etcd

后面会调用openshiftConfig的run方法来加载组件

--》openshift/origin/pkg/cmd/server/origin/master.go

run方法里面会处理两种API,一种是访问受保护的api(通常这类调用是需要验证的),另一种是不受保护的api,我们这里主要关注那些受保护的api,因为大部分api都是这种

InstallProtectedAPI方法即为安装注册受保护的api,逻辑里首先初始化所有openshift的api

GetRestStorage方法会获取openshift所用到的所有storage,例如projectStorage

然后将所有storage放到一个map中,此map相当于一个openshift的配置文件,记录了所有api路径和此路径所用到的storage

storage := map[string]rest.Storage{
        "images":               imageStorage,
        "imagesignatures":      imageSignatureStorage,
        "imageStreams/secrets": imageStreamSecretsStorage,
        "imageStreams":         imageStreamStorage,
        "imageStreams/status":  imageStreamStatusStorage,
        "imageStreamImports":   imageStreamImportStorage,
        "imageStreamImages":    imageStreamImageStorage,
        "imageStreamMappings":  imageStreamMappingStorage,
        "imageStreamTags":      imageStreamTagStorage,

        "deploymentConfigs":          deployConfigStorage,
        "deploymentConfigs/scale":    deployConfigScaleStorage,
        "deploymentConfigs/status":   deployConfigStatusStorage,
        "deploymentConfigs/rollback": deployConfigRollbackStorage,
        "deploymentConfigs/log":      deploylogregistry.NewREST(configClient, kclient, c.DeploymentLogClient(), kubeletClient),

        // TODO: Deprecate these
        "generateDeploymentConfigs": deployconfiggenerator.NewREST(deployConfigGenerator, c.EtcdHelper.Codec()),
        "deploymentConfigRollbacks": deployrollback.NewDeprecatedREST(deployRollbackClient, c.EtcdHelper.Codec()),

        "processedTemplates": templateregistry.NewREST(),
        "templates":          templateStorage,

        "routes":        routeStorage,
        "routes/status": routeStatusStorage,

        "projects":        projectStorage,
        "projectRequests": projectRequestStorage,

        "hostSubnets":           hostSubnetStorage,
        "netNamespaces":         netNamespaceStorage,
        "clusterNetworks":       clusterNetworkStorage,
        "egressNetworkPolicies": egressNetworkPolicyStorage,

        "users":                userStorage,
        "groups":               groupStorage,
        "identities":           identityStorage,
        "userIdentityMappings": userIdentityMappingStorage,

        "oAuthAuthorizeTokens":      authorizeTokenStorage,
        "oAuthAccessTokens":         accessTokenStorage,
        "oAuthClients":              clientStorage,
        "oAuthClientAuthorizations": clientAuthorizationStorage,

        "resourceAccessReviews":      resourceAccessReviewStorage,
        "subjectAccessReviews":       subjectAccessReviewStorage,
        "localSubjectAccessReviews":  localSubjectAccessReviewStorage,
        "localResourceAccessReviews": localResourceAccessReviewStorage,
        "selfSubjectRulesReviews":    selfSubjectRulesReviewStorage,

        "policies":       policyStorage,
        "policyBindings": policyBindingStorage,
        "roles":          roleStorage,
        "roleBindings":   roleBindingStorage,

        "clusterPolicies":       clusterPolicyStorage,
        "clusterPolicyBindings": clusterPolicyBindingStorage,
        "clusterRoleBindings":   clusterRoleBindingStorage,
        "clusterRoles":          clusterRoleStorage,

        "clusterResourceQuotas":        restInPeace(clusterresourcequotaregistry.NewStorage(c.RESTOptionsGetter)),
        "clusterResourceQuotas/status": updateInPeace(clusterresourcequotaregistry.NewStatusStorage(c.RESTOptionsGetter)),
        "appliedClusterResourceQuotas": appliedclusterresourcequotaregistry.NewREST(
            c.ClusterQuotaMappingController.GetClusterQuotaMapper(), c.Informers.ClusterResourceQuotas().Lister(), c.Informers.Namespaces().Lister()),
    }

拿到了所有storage后便判断是否是v1版本的,若是则安装注册这些api

这里会先调用apiLegacyV1方法通过刚刚得到的storage map得到一个APIGroupVersion结构对象,此对象即为kubernetes的结构对象,然后调用APIGroupVersion的InstallREST方法去安装api

InstallREST方法逻辑很前一篇文章kubernetes里面的一样,这里就不再重复分析,此方法代码如下:

这样openshift master上的api组件就启动成功了

 

转载于:https://www.cnblogs.com/zard/p/7772472.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值