k8s Source Analysis------Kube-apiserver Analysis (3)

Source: Internet
Author: User
Tags k8s
Turn from my own space, http://user.qzone.qq.com/29185807/blog/145872228

Continue to connect the Kube-apiserver analysis (2)

In the previous article, we analyzed the registration of storage. Below is an analysis of how storage is converted into restful format.


Let's start with the k8s.io\kubernetes\pkg\master\master.go.

In function func (M *master) init (c *config)


We saw Api_v1 's installrest.

Trace it in.


This selection of the default Apigroupversion,storage is a previously registered storage.

Let's follow up and look at the defaultapigroupversion.

Here returned a apiserver. Apigroupversion. For the time being, we don't care which parameters are initialized.

Code in K8s.io\kubernetes\pkg\apiserver\apiserver.go

Here's the apigroupversion structure.


We go back to the first picture and follow the apigroupversion. Installrest


We saw 128 lines of container. ADD (WS) completes the storage into RESTful's true registration from here

But we still do not see how the specific turn.

We keep tracking.


A apiinstaller is generated here. Prefix is the root+version.

Let's take a look at info.


After generating the Apiinstaller newwebservice


Some parameters are set here, and the path is the previous root+version

Followed by


On top, we see the key that traverses the storage, then generate the paths, and sort

And then registerresourcehandlers for each path.

So the real registration is in the registerresourcehandlers.

This function is relatively long


The above is not good-looking, mainly to see if there is no subresource, there is access to some kind,version and other information

The important thing is the first line in the next picture, mapping


And then there are some processing interface, now should be more familiar with, this is storage inside the


We skipped some code in the middle.

See the image directly below. The scope of which is Mapping.scope

Scope has two parameters. One of them is restscopenameroot. I'm going to go back and introduce the argument.


And then we look at the real deal encapsulation


Scope another parameter restscopenamenamespace.


Also registered a number of action


Further down, a parametric structure


And then iterate through all the actions.

From the image below, we see the familiar

411 Line route: = ws. Get (action. Path). to (handler).

425 line ws. Route (Route)


Of course there are some



Wait a minute, just a screenshot.

So far we've seen all the storage have been converted to the RESTful format and registered in the


One of the problems we have left is that scope has a type parameter.

Now, let's look at the k8s.io\kubernetes\pkg\api\install\install.go.


Here are two types of sets


The API is then invoked. Newdefaultrestmapper

K8s.io\kubernetes\pkg\api\mapper.go


Some of the types registered in Rootscope are set to Restscoperoot

The remaining types are Restscopenamespace


Hao Haohua

QQ Crescent moon Lonely Road length 29185807

March 23, 2016 (Copyright: This article is original for the author, if you need to reprint, please notify me, and indicate the source and author. Reproduced without authorization, reserve the right to pursue its infringement. )

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.