Openshift API part of the source learning notes (a)

Source: Internet
Author: User
Tags k8s sourcegraph

Openshift API Introduction

The Openshift API contains two parts, part Kubernetes V1 REST API, and Openshift V1 REST API, which are all accessed via HTTP (s) Openshift Container platform The master server to invoke. These APIs can be used to manage end-user applications, clusters, and clustered users.

OpenShift inside the Kubernetes API prefix is/API, and OpenShift himself developed some APIs, their prefix is/OAPI, Kubernetes Native API already has a function openshift and does not re-write interface but directly use the Kubernetes native APII, but developed some kubernetes originally did not have the function and API interface.

SOURCE Analysis

GitHub Address: Https://github.com/openshift/origin (the code in this article corresponds to version 1.3)

Sourcegraph website Address: https://sourcegraph.com/github.com/openshift/[email protected]/-/blob/cmd/openshift/ Openshift.go

Code entry

--"OpenShift/origin/cmd/openshift/openshift.go

The main method inside the Openshift.go has the start-up service logic, which can be executed by calling Commandfor to get which startup commands.

The Commandfor method determines which commands are obtained based on the incoming basename parameter, and the default is to call the Newcommandopenshift method to get all the commands

The Newcommandopenshift method first creates a command structure root and then adds commands to root. The logic will first call the Newcommandstartallinone method to get some of the main command sets.

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

The main logic for adding commands inside the Newcommandstartallinone method is as follows:

Here you will get the start command for Master,node and so on, as well as the boot of the Kubernetes related service component.

1). I'll start with the method of getting kubernetes related commands.

--"OpenShift/origin/pkg/cmd/server /start/kubernetes/kubernetes.go

The main logic inside the Newcommand method is as follows:

Here are several parts of the Kubernetes Component Start command, we focus on the API section, so is the Newapiservercommand method

--"openshift/origin/pkg/cmd/server /start/kubernetes/apiserver.go

The logic behind this is roughly the same as the logic in the API section of the Kubernetes source, first creating a new apiserver based on the default parameters

The specified Apiserver is then started by the run method inside the Server.go.

--"openshift/origin/vendor/k8s.io/kubernetes/cmd/kube-apiserver/app/ Server.go

The main logic for starting the API server inside the Run method is to create a new server based on the configuration and then start

--"openshift/origin/vendor/k8s.io/kubernetes /pkg/master/master.go

The new method in master first returns an instance of the API server based on the configuration information, and then invokes the Installapis method to initialize all the APIs

The Installapis method creates several Apigroupsinfo structures based on conditions and adds them to the middle of a apigroupsinfo group, which correspond to different version information, such as V1,V1BETA1, and so on. Added to the array well, the Installapigroups method is called to install all the APIs in the Apigroupsinfo. Here we take V1 this group, the logic will first call the Initv1resourcesstorage method to initialize V1 This group of all storage, such as Podstorage,nodestorage

The new storage will then be configured in a map, which is the equivalent of a configuration file to manage which storage are used and the corresponding path, which determines which APIs are provided later

M.v1resourcesstorage = map[string]rest. storage{"Pods": Podstorage.pod,"Pods/attach": Podstorage.attach,"Pods/status": Podstorage.status,"Pods/log": PodStorage.Log,"pods/exec": Podstorage.exec,"Pods/portforward": Podstorage.portforward,"Pods/proxy": Podstorage.proxy,"pods/binding": podstorage.binding,"Bindings": podstorage.binding,"podtemplates": Podtemplatestorage,"replicationcontrollers": Controllerstorage.controller,"Replicationcontrollers/status": Controllerstorage.status,"Services": Servicerest.service,"Services/proxy": Servicerest.proxy,"Services/status": Servicestatusstorage,"Endpoints": Endpointsstorage,"nodes": Nodestorage.node,"Nodes/status": Nodestorage.status,"Nodes/proxy": Nodestorage.proxy,"Events": Eventstorage,"limitranges": Limitrangestorage,"Resourcequotas": Resourcequotastorage,"Resourcequotas/status": Resourcequotastatusstorage,"Namespaces": Namespacestorage,"Namespaces/status": Namespacestatusstorage,"namespaces/finalize": Namespacefinalizestorage,"Secrets": Secretstorage,"serviceaccounts": Serviceaccountstorage,"securitycontextconstraints": Securitycontextconstraintsstorage,"Persistentvolumes": Persistentvolumestorage,"Persistentvolumes/status": Persistentvolumestatusstorage,"Persistentvolumeclaims": Persistentvolumeclaimstorage,"Persistentvolumeclaims/status": Persistentvolumeclaimstatusstorage,"Configmaps": Configmapstorage,"componentstatuses": Componentstatus. Newstorage (func () map[string]apiserver. Server {returnm.getserverstovalidate (c)}),}

Then create a new apigroupinfo and put the previous map in the new apigroupinfo. Call the Installapigroups method after all apigroupinfo have been placed.

--"openshift/origin/vendor/k8s.io/kubernetes/pkg/genericapiserver/ Genericapiserver.go

The Installapigroups method loops through the Installapigroup method to install each Apigroup

Installapigroup method first get the API path prefix, here we still take V1 This group example, so here get the prefix apiprefix will be/api, Then, according to the information of the APIGROUPINFO structure, get a Apigroupversion structure object, and then call Apigroupversion's Installrest method to register the rest API.

--"openshift/origin/vendor/k8s.io/kubernetes /pkg/apiserver/apiserver.go

The Installrest method creates a new webservice, which handles all requests under the specified path, and the WebService path for the group is/API/V1. Then call the Install method to initialize all of the route

--"openshift/origin/vendor/k8s.io/kubernetes/pkg/apiserver/api_installer.go

The main logic in the Install method is as follows, looping through all the paths in the previous map path and storage, and then registering each path corresponding to the handler

The Registerresourcehandlers method first obtains various action methods based on the current storage, such as the Create,get method

The action is then created based on whether the current storage corresponds to resource is namespace and placed in the actions array.

The different action methods used here are not the same API path, like the List,post method is not required in the path of the item name, and Get,put are required by the item name

Then loop the actions array to convert each action-corresponding method into a route and add it to the webservice, where the Get processing code is intercepted

After all this is done, add this webservice to the container, and the Kubernetes API Server Registration Start command is created.

Openshift API part of the source learning notes (a)

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.