In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Today, I will talk to you about how to understand the implementation of api multi-version mechanism in kubernetes, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
In web development, with the update and iteration of the version, it is usually necessary to maintain multiple versions of api in the system, and multiple versions of api often have different data structures. Today, let's learn how the Scheme mechanism in kubernetes solves this problem and how to deserialize with the help of the data in the HTTP request.
1. Web request processing flow 1.1 HTTP request processing flow
Usually, webServer first processes the Http protocol, and then parses it into a Http request object within the basic webServer. Usually, the object holds the request header of the corresponding request and the underlying corresponding byte sequence (read from the socket stream). Then it is usually deserialized according to the corresponding encoding format to complete the mapping from the byte sequence to the business model of the current interface, and then handed over to the business logic for processing. As a result, persistent storage is finally carried out, and the focus of this article is on the deserialization part.
two。 Implementation 2.1 of model mapping describes resource version information / api/ {version} / {resource} / {action}
The above is a basic web url. Usually we register a corresponding URL for each version, which contains two key pieces of information, namely version and resource. Through these two messages, we can usually know that this may be the version of a resource. If we package the later action, we can usually know the specific operation of the corresponding resource.
2.2 Group group information
Today, when micro-services are popular, we usually split micro-services according to business functions. In essence, a micro-service may be a collection of functions that implement a specific business scenario. For example, the user system usually contains all the related operations of the user. In kubernetes, there is a similar concept called Group.
POST / apis/batch/v1beta1/namespaces/ {namespace} / cronjobs
POST / apis/apps/v1/namespaces/ {namespace} / daemonsets
Let's take a look at an example. This is a url that creates daemonsets and cronjobs. If you split it according to Group, resource, and version, you can split it into the following: batch, v1beta1, cronjobs and apps, v1, daemonsets, that is, the GroupVersionKind you try, where kind corresponds to resource.
2.3 implementation of model mapping
We get the GroupVersionKind information of the resource through url. How can we map it to a specific type? This seems to be very simple, just combine reflection and map to do it. We get the corresponding GVK information through url, and then through our mapping table, we know which model the corresponding model is, and then we just need to transform it.
GvkToType map[schema.GroupVersionKind] reflect.Type
3. Implementation of 3.1 Decoding Mechanism by deserialization
Then how to deserialize the data flow in the corresponding Http into an internal object? don't forget that it is the Http protocol, which must be the information in the header header. We can know the corresponding encoding format through the serialization in the header header. We only need to call the decoding of the corresponding format.
Content-Type: "application/json"
3.2 default object
If we want to decode a byte array in json format, we usually do the following. We need to pass in a pointer to the target object, and then the json parses the corresponding byte data into the target object. We also need an object to store the deserialized result.
Func Unmarshal (data [] byte, v interface {}) error {}
Is it OK if I provide another object constructor corresponding to the current version? The answer is yes.
Func () Object {return target object}
4. Design summary
First of all, when registering with url, we construct the version information of the resources mapped by url, that is, GroupVersionKind. For many subsequent operations, we can obtain the corresponding target operation or object through the corresponding version mapping, then obtain the corresponding decoder through the fields in Header, and decode the byte sequence in Body to the target object, thus realizing the mapping and deserialization of multi-version resources.
After reading the above, do you have any further understanding of how to understand the implementation of the api multi-version mechanism in kubernetes? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.