kube-apiserver

sourceCode

閱讀源碼

  • make generated_files 或者使用 make generated_files --debug=all 進(jìn)行debug
  • cd /Users/jomenxiao/go/src/k8s.io/kubernetes/cmd/kube-apiserver
  • go-callvis .

入口函數(shù)

  • main函數(shù) cmd/kube-apiserver/apiserver.go ,使用的時(shí)候cobra的命令管理
  • Run函數(shù)位于 cmd/kube-apiserver/app/server.go
    • Run

      1. CreateServerChain 啟動(dòng)的服務(wù)鏈
      2. 啟動(dòng)準(zhǔn)備 PrepareRun
      3. Run
    • CreateServerChain

      1. CreateNodeDialer CreateNodeDialer creates the dialer infrastructure to connect to the nodes.
      2. CreateKubeAPIServerConfig CreateKubeAPIServerConfig creates all the resources for running the API server, but runs none of them
      3. createAPIExtensionsConfig If additional API servers are added, they should be gated.
      4. createAPIExtensionsServer CustomResourceDefinitions
      5. CreateKubeAPIServer CreateKubeAPIServer creates and wires a workable kube-apiserver
      6. createAggregatorConfig aggregator comes last in the chain
      7. createAggregatorServer
    • CreateKubeAPIServerConfig

      1. buildGenericConfig BuildGenericConfig takes the master server options and produces the genericapiserver.Config associated with it
        • genericConfig = genericapiserver.NewConfig(legacyscheme.Codecs)NewConfig returns a Config struct with the default value
        • genericConfig.MergedResourceConfig = controlplane.DefaultAPIResourceConfigSource()DefaultAPIResourceConfigSource returns default configuration for an APIResource
        • s.GenericServerRunOptions.ApplyTo(genericConfig) ApplyTo applies the run options to the method receiver and returns self
        • s.SecureServing.ApplyTo(&genericConfig.SecureServing, &genericConfig.LoopbackClientConfig) ApplyTo fills up serving information in the server configuration.
        • s.Features.ApplyTo(genericConfig)
        • s.APIEnablement.ApplyTo(genericConfig, controlplane.DefaultAPIResourceConfigSource(), legacyscheme.Scheme ApplyTo override MergedResourceConfig with defaults and registry
        • s.EgressSelector.ApplyTo(genericConfig) ApplyTo adds the egress selector settings to the server configuration.
        • storageFactoryConfig := kubeapiserver.NewStorageFactoryConfig() NewStorageFactoryConfig returns a new StorageFactoryConfig set up with necessary resource overrides.
        • completedStorageFactoryConfig, err := storageFactoryConfig.Complete(s.Etcd) Complete completes the StorageFactoryConfig with provided etcdOptions returning completedStorageFactoryConfig.
        • storageFactory, lastErr = completedStorageFactoryConfig.New() New returns a new storage factory created from the completed storage factory configuration.
        • s.Etcd.ApplyWithStorageFactoryTo(storageFactory, genericConfig) 初始化緩存工程函數(shù)
        • clientgoExternalClient, err := clientgoclientset.NewForConfig(kubeClientConfig) NewForConfig creates a new Clientset for the given config.
        • versionedInformers = clientgoinformers.NewSharedInformerFactory(clientgoExternalClient, 10*time.Minute) NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
      2. capabilities.Initialize Initialize the capability set. This can only be done once per binary, subsequent calls are ignored.
      3. controlplane.Config 控制面板定義
    • CreateKubeAPIServer

      Complete New returns a new instance of Master GenericAPIServer from the given config.

      1. s, err := c.GenericConfig.New("kube-apiserver", delegationTarget)
      2. installAPI(s, c.Config)
      3. delegationTarget DelegationTarget vendor/k8s.io/apiserver/pkg/server/genericapiserver.go 的入?yún)?/li>
      4. c.ExtraConfig.APIResourceConfigSource.VersionEnabled(apiv1.SchemeGroupVersion) install legacy rest storage
      5. m.InstallLegacyAPI(&c, c.GenericConfig.RESTOptionsGetter, legacyRESTStorageProvider) InstallLegacyAPI will install the legacy APIs for the restStorageProviders if they are enabled.
        1. legacyRESTStorage, apiGroupInfo, err := legacyRESTStorageProvider.NewLegacyRESTStorage(restOptionsGetter)
        2. cacher, err := cacherstorage.NewCacherFromConfig(cacherConfig) watch緩存
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容