sourceCode
閱讀源碼
-
make generated_files或者使用make generated_files --debug=all進(jìn)行debug cd /Users/jomenxiao/go/src/k8s.io/kubernetes/cmd/kube-apiservergo-callvis .
入口函數(shù)
- main函數(shù)
cmd/kube-apiserver/apiserver.go,使用的時(shí)候cobra的命令管理 - Run函數(shù)位于
cmd/kube-apiserver/app/server.go-
Run
-
CreateServerChain啟動(dòng)的服務(wù)鏈 - 啟動(dòng)準(zhǔn)備
PrepareRun Run
-
-
CreateServerChain
-
CreateNodeDialerCreateNodeDialer creates the dialer infrastructure to connect to the nodes. -
CreateKubeAPIServerConfigCreateKubeAPIServerConfig creates all the resources for running the API server, but runs none of them -
createAPIExtensionsConfigIf additional API servers are added, they should be gated. -
createAPIExtensionsServerCustomResourceDefinitions -
CreateKubeAPIServerCreateKubeAPIServer creates and wires a workable kube-apiserver -
createAggregatorConfigaggregator comes last in the chain createAggregatorServer
-
-
CreateKubeAPIServerConfig
-
buildGenericConfigBuildGenericConfig 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.SchemeApplyTo 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.
-
-
capabilities.InitializeInitialize the capability set. This can only be done once per binary, subsequent calls are ignored. -
controlplane.Config控制面板定義
-
-
CreateKubeAPIServer
CompleteNewreturns a new instance of MasterGenericAPIServerfrom the given config.s, err := c.GenericConfig.New("kube-apiserver", delegationTarget)installAPI(s, c.Config)-
delegationTarget DelegationTargetvendor/k8s.io/apiserver/pkg/server/genericapiserver.go的入?yún)?/li> -
c.ExtraConfig.APIResourceConfigSource.VersionEnabled(apiv1.SchemeGroupVersion)install legacy rest storage -
m.InstallLegacyAPI(&c, c.GenericConfig.RESTOptionsGetter, legacyRESTStorageProvider)InstallLegacyAPI will install the legacy APIs for the restStorageProviders if they are enabled.legacyRESTStorage, apiGroupInfo, err := legacyRESTStorageProvider.NewLegacyRESTStorage(restOptionsGetter)-
cacher, err := cacherstorage.NewCacherFromConfig(cacherConfig)watch緩存
-