A data verification method and device based on the K8S container platform
By converting the resource configuration file in yaml format to json format and using shell scripts for verification, the problem that the K8S container platform cannot locate syntax errors is solved, and development efficiency is improved.
Patent Information
- Application Number
- CN202110744953.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-30
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2041-06-30
AI Technical Summary
The K8S container platform cannot provide specific error reasons when verifying configuration files, resulting in inefficiency of developers, especially novices who have difficulty debugging and modifying.
Convert the resource configuration file in yaml format to json format, and use the shell script file for syntax verification, locate the syntax errors in the json format file through the content mapping relationship, and convert it to the error position of the yaml format file.
Improves the verification efficiency of developers' configuration files on the K8S container platform, can quickly locate and correct syntax errors, and reduces debugging time.
Smart Images

Figure CN113626307B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to a data verification method and device based on a K8S container platform. Background Art
[0002] K8S is short for Kubernetes, which is an open-source tool for managing containerized applications on multiple hosts in a cloud platform. The K8S container platform provides a mechanism for application deployment, planning, updating, and maintenance, with the goal of making the deployment of containerized applications simple and efficient (powerful).
[0003] During the normal operation of the workload on the K8S container platform, developers need to manually write environment parameters into a Configmap resource configuration file and mount it in the form of a storage volume to a file or directory inside the container to improve the application deployment efficiency.
[0004] Although the self-mechanism of the K8S container platform performs simple data verification on the Configmap resource configuration file, it does not throw specific error reasons. Developers can only continuously modify, debug, and track problems based on experience, resulting in low development efficiency. Summary of the Invention
[0005] In view of the above problems, the present application provides a data verification method and device based on a K8S container platform to improve development efficiency.
[0006] On the one hand, an embodiment of the present application provides a data verification method based on a K8S container platform, the method including:
[0007] Obtain a resource configuration file in yaml format;
[0008] Generate a resource configuration file in json format according to the resource configuration file in yaml format, and obtain the content mapping relationship between the resource configuration file in yaml format and the resource configuration file in json format;
[0009] Use a shell script file to verify whether the syntax of the content in the resource configuration file in json format is correct. In response to the syntax of the content in the resource configuration file in json format being incorrect, obtain the position of the content with a syntax error in the resource configuration file in json format;
[0010] Determine the position of the content with a syntax error in the resource configuration file in yaml format according to the content mapping relationship and the position of the content with a syntax error in the resource configuration file in json format.
[0011] Optionally, after obtaining the position of the content with a syntax error in the resource configuration file in JSON format, the method further includes:
[0012] Performing string replacement on the content with a syntax error in the resource configuration file in JSON format to obtain a resource configuration file with correct JSON format syntax;
[0013] Converting the resource configuration file with correct JSON format syntax into a resource configuration file with correct YAML format syntax according to the content mapping relationship;
[0014] Inputting the resource configuration file with correct YAML format syntax into the K8S container platform.
[0015] Optionally, the generating a resource configuration file in JSON format according to the resource configuration file in YAML format includes:
[0016] Identifying target content that conforms to the JSON format in the resource configuration file in YAML format;
[0017] Extracting the target content from the resource configuration file in YAML format to generate a resource configuration file in JSON format.
[0018] Optionally, the generating a resource configuration file in JSON format according to the resource configuration file in YAML format includes:
[0019] Parsing the resource configuration file in YAML format into a map object;
[0020] Generating a resource configuration file in JSON format according to the map object.
[0021] Optionally, the method further includes:
[0022] Generating a resource configuration template in YAML format according to configuration items, where the configuration items include at least one of interface version, required components, source data, volume mounting location, or required environment variables;
[0023] The obtaining a resource configuration file in YAML format includes:
[0024] Generating a resource configuration file in YAML format according to the resource configuration template in YAML format and the parameters corresponding to the configuration items.
[0025] On the other hand, an embodiment of the present application further provides a data verification device based on a K8S container platform, and the device includes: an acquisition unit, a generation unit, a verification unit, and a determination unit;
[0026] The obtaining unit is configured to obtain a resource configuration file in yaml format;
[0027] The generating unit is configured to generate a resource configuration file in json format according to the resource configuration file in yaml format, and obtain the content mapping relationship between the resource configuration file in yaml format and the resource configuration file in json format;
[0028] The verification unit is configured to use a shell script file to verify whether the syntax of the content in the resource configuration file in json format is correct. In response to the incorrect syntax of the content in the resource configuration file in json format, obtain the content position where a syntax error occurs in the resource configuration file in json format;
[0029] The determining unit is configured to determine the content position where a syntax error occurs in the resource configuration file in yaml format according to the content mapping relationship and the content position where a syntax error occurs in the resource configuration file in json format.
[0030] Optionally, the device further includes a replacement unit, a conversion unit, and an input unit; after obtaining the content position where a syntax error occurs in the resource configuration file in json format,
[0031] The replacement unit is configured to perform string replacement on the content where a syntax error occurs in the resource configuration file in json format to obtain a resource configuration file with correct json format syntax;
[0032] The conversion unit is configured to convert the resource configuration file with correct json format syntax into a resource configuration file with correct yaml format syntax according to the content mapping relationship;
[0033] The input unit is configured to input the resource configuration file with correct yaml format syntax into the K8S container platform.
[0034] Optionally, the generating unit is configured to:
[0035] Identify the target content in the resource configuration file in yaml format that conforms to json format;
[0036] Extract the target content from the resource configuration file in yaml format to generate a resource configuration file in json format.
[0037] Optionally, the generating unit is configured to:
[0038] Parse the resource configuration file in yaml format into a map object;
[0039] Generate a resource configuration file in JSON format according to the described map object.
[0040] Optionally, the generating unit is further configured to:
[0041] Generate a resource configuration template in YAML format according to configuration items, where the configuration items include at least one of interface version, required components, source data, volume mounting location, or required environment variables;
[0042] The obtaining unit is configured to:
[0043] Generate a resource configuration file in YAML format according to the resource configuration template in YAML format and the parameters corresponding to the configuration items.
[0044] Compared with the prior art, the advantages of the above technical solution of the present application are as follows:
[0045] After obtaining the resource configuration file in YAML format, generate a resource configuration file in JSON format according to the resource configuration file in YAML format, and obtain the content mapping relationship between the resource configuration file in YAML format and the resource configuration file in JSON format. Use a shell script file to check whether there are syntax problems in the content of the resource configuration file in JSON format. If there are syntax problems, locate the position of the content with syntax errors in the resource configuration file in JSON format, and convert the position of the content with syntax errors located in the resource configuration file in JSON format to the position of the content with syntax errors in the resource configuration file in YAML format according to the previously determined content mapping relationship. Thus, by determining the position of the content with syntax errors in the resource configuration file in JSON format corresponding to the resource configuration file in YAML format, the position of the content with syntax errors in the resource configuration file in YAML format can be determined, solving the problem that the K8S container platform cannot locate the position of the content with syntax errors in the resource configuration file in YAML format and improving the development efficiency. Description of the Drawings
[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments recorded in the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0047] Figure 1 It is a flowchart of a data verification method based on the K8S container platform provided by the present application;
[0048] Figure 2Schematic diagram of a data verification device based on the K8S container platform provided by this application. Detailed implementation manners
[0049] In order to enable the personnel in the technical field to better understand the solution of this application, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of this application. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all the embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of this application.
[0050] The K8S container platform can run business applications in various scenarios, such as web applications, big data computing tasks, etc. The normal operation of the K8S container platform depends on the stable operation of each component, and a stable computing platform can ensure that the business application provides services normally. The container application workloads based on K8S are mainly divided into stateful and stateless workloads. During the normal operation of the workload, the Configmap resource configuration file can provide unified configuration of environment variables for the application, set command parameters for container startup, etc. After the developer writes the Configmap resource configuration file, it is mounted into the file or directory in the container in the form of a storage volume to improve the deployment efficiency of the container application.
[0051] The most common definition of the Configmap resource configuration file is a file in yaml format. One of the challenges in using yaml is that developers must strictly follow relevant rules when writing the Configmap resource configuration file. Otherwise, an error will be reported when creating the Configmap resource using the Configmap configuration file, or the application cannot normally read the relevant configuration and instructions after the resource is created.
[0052] Although the self - mechanism of the K8S container platform will perform simple data verification on the Configmap resource configuration file, it does not throw specific error reasons. Developers can only search for problems, locate problems, continuously modify, debug and track problems according to experience. Especially for developers who are new to K8S, the development efficiency is relatively low.
[0053] Based on this, the embodiments of the present application provide a data verification method and related devices based on the K8S container platform. After obtaining a resource configuration file in yaml format, a resource configuration file in json format is generated according to the resource configuration file in yaml format, and the content mapping relationship between the resource configuration file in yaml format and the resource configuration file in json format is obtained. A shell script file is used to verify whether there are syntax problems in the content of the resource configuration file in json format. If there are syntax problems, the content position where the syntax error occurs is located in the resource configuration file in json format, and according to the previously determined content mapping relationship, the content position where the syntax error occurs in the resource configuration file in json format is converted into the content position where the syntax error occurs in the resource configuration file in yaml format.
[0054] Thus, by determining the content position where the syntax error occurs in the resource configuration file in json format corresponding to the resource configuration file in yaml format, the content position where the syntax error occurs in the resource configuration file in yaml format can be determined, solving the problem that the K8S container platform cannot locate the content position where the syntax error occurs in the resource configuration file in yaml format, and improving the development efficiency.
[0055] Some terms required for the present application are described below.
[0056] Configmap resource configuration file: The configmap resource configuration file is used to save key-value pairs of configuration data and can be used to save single attributes or configuration files. Secret can provide sensitive data such as passwords, Tokens, and private keys for Pods. For some non-sensitive data, such as the configuration information of container applications, the configmap resource configuration file can be used. For the convenience of description, the configmap resource configuration file will be referred to as the resource configuration file hereinafter.
[0057] Pod: In Kubernetes, the smallest management element is the Pod. The Pod is the smallest scheduling unit for management and creation of applications, and a Pod can contain multiple containers.
[0058] Workload: The workload is an application running on Kubernetes, and the workload is used to manage a group of Pods. These resource configuration controllers ensure that the correct number of Pods of the appropriate type and in the running state is correct and consistent with the state specified by the user.
[0059] Docker: Docker is an open-source application container engine that allows developers to package their applications and dependent packages into a portable image, and then publish it to Linux or Windows machines, or to achieve virtualization.
[0060] The following will specifically describe a data verification method provided by an embodiment of the present application based on the K8S container platform in conjunction with Figure 1
[0061] Refer to Figure 1 , Figure 1 which is a flowchart of a data verification method provided by the present application based on the K8S container platform. This method may include the following steps 101-104.
[0062] S101: Obtain a resource configuration file in yaml format.
[0063] The technical solution of the present application can be executed by a server in a physical server or a virtual machine, and can also be executed by a server in the K8S container platform, for providing the data verification function of the resource configuration file. Among them, the K8S container platform can provide the container cloud platform environment required for creating the resource configuration file.
[0064] After the basic environment is deployed and configured, the user first creates a corresponding Shell script development and testing environment by selecting basic images with different CPU architectures and different operating systems; then selects different Shell script function modules for combination to implement different functions; finally, according to actual needs, sets test conditions, inputs test data, and develops and tests the script in the already created container. If the provided function modules do not meet the current needs, developers can also perform secondary development according to the modules. Thus, after the device deployment is completed, S101 can be started, that is, to obtain a resource configuration file in yaml format.
[0065] If there are syntax problems in the resource configuration file in yaml format, such as missing spaces, missing semicolons, etc., the K8S container platform can only inform that there are problems in the resource configuration file in yaml format, but cannot locate which line of code in the resource configuration file in yaml format has a syntax error, nor can it give the specific reason for the error so that developers can modify it accordingly, making developers can only find problems, locate problems, continuously modify, debug and track problems according to experience. Especially for developers who are new to K8S, the development efficiency is relatively low.
[0066] Therefore, the resource configuration file in yaml format can be converted into other formats that can perform syntax verification.
[0067] S102: Generate a resource configuration file in JSON format based on the resource configuration file in YAML format, and obtain the content mapping relationship between the resource configuration file in YAML format and the resource configuration file in JSON format.
[0068] Since the file in JSON format can parse data through shell scripts, implement the verification of data syntax, and return the position of syntax errors, the resource configuration file in YAML format can be converted into a resource configuration file in JSON format. At the same time, the content mapping relationship between the resource configuration file in YAML format and the resource configuration file in JSON format can also be obtained.
[0069] The present application does not specifically limit the conversion method, and two methods will be used as examples for illustration below.
[0070] Method 1: Identify the target content that conforms to the JSON format in the resource configuration file in YAML format, extract the target content from the resource configuration file in YAML format, and generate a resource configuration file in JSON format.
[0071] It should be noted that some codes in the resource configuration file in YAML format conform to the JSON rules. Therefore, relevant plugins can be used to parse the JSON strings (target content) included in the resource configuration file in YAML format, and then generate a resource configuration file in JSON format based on the JSON strings.
[0072] For example, the resource configuration file in YAML format includes 10 lines of code, and the 3rd to 10th lines of code conform to the JSON format. Therefore, the 3rd to 10th lines of code in the resource configuration file in YAML format can be extracted to generate a resource configuration file in JSON format. Correspondingly, the content mapping relationship between the resource configuration file in YAML format and the resource configuration file in JSON format can be obtained, that is, the 1st line of code in the resource configuration file in JSON format corresponds to the 3rd line of code in the resource configuration file in YAML format, the 2nd line of code in the resource configuration file in JSON format corresponds to the 4th line of code in the resource configuration file in YAML format, and so on.
[0073] Method 2: Parse the resource configuration file in YAML format into a map object, and generate a resource configuration file in JSON format based on the map object.
[0074] In Java, the SnakeYAML library can be used to convert the format between YAML files and JSON files. The principle is to parse the YAML file into a map object and then convert the map object into a JSON file. Therefore, the resource configuration file in YAML format can be parsed into a map object, and a JSON-formatted resource configuration file can be generated based on the map object.
[0075] Correspondingly, the first correspondence between the resource configuration file in YAML format and the map object can be obtained first, and then the second correspondence between the map object and the resource configuration file in JSON format can be obtained. The content mapping relationship can be obtained through the first and second correspondences.
[0076] S103: Use a shell script file to check whether the syntax of the content in the JSON-formatted resource configuration file is correct. In response to the incorrect syntax of the content in the JSON-formatted resource configuration file, obtain the location of the content with a syntax error in the JSON-formatted resource configuration file.
[0077] It should be noted that the shell script file includes JSON format rules. The JSON-formatted resource configuration file is identified through the JSON format rules, so as to check whether the syntax of the content in the JSON-formatted resource configuration file is correct. If there is incorrect content, the location of the content with a syntax error in the JSON-formatted resource configuration file will also be returned.
[0078] S104: Determine the location of the content with a syntax error in the YAML-formatted resource configuration file according to the content mapping relationship and the location of the content with a syntax error in the JSON-formatted resource configuration file.
[0079] After determining the location of the content with a syntax error in the JSON-formatted resource configuration file, the location of the content with a syntax error can be determined in the YAML-formatted resource configuration file according to the content mapping relationship.
[0080] As can be seen from the above technical solution, after obtaining the resource configuration file in yaml format, a resource configuration file in json format is generated according to the resource configuration file in yaml format, and the content mapping relationship between the resource configuration file in yaml format and the resource configuration file in json format is obtained. The shell script file is used to verify whether there are syntax problems in the content of the resource configuration file in json format. If there are syntax problems, the position of the content with syntax errors is located in the resource configuration file in json format, and according to the previously determined content mapping relationship, the position of the content with syntax errors located in the resource configuration file in json format is converted into the position of the content with syntax errors in the resource configuration file in yaml format. Thus, by determining the position of the content with syntax errors in the resource configuration file in json format corresponding to the resource configuration file in yaml format, the position of the content with syntax errors in the resource configuration file in yaml format can be determined, solving the problem that the K8S container platform cannot locate the position of the content with syntax errors in the resource configuration file in yaml format and improving the development efficiency.
[0081] As a possible implementation, after obtaining the position of the content with syntax errors in the resource configuration file in json format, the content with syntax errors in the resource configuration file in json format is replaced with a string, and the syntax of the content with syntax errors is corrected. For example, spaces are added to the content lacking spaces, and semicolons are added to the content lacking semicolons, so as to obtain a resource configuration file in json format with correct syntax. Then, according to the content mapping relationship, the resource configuration file in json format with correct syntax is converted into a resource configuration file in yaml format with correct syntax. Thus, the format problems caused by syntax can be basically eliminated in the resource configuration file in yaml format with correct syntax. The resource configuration file in yaml format with correct syntax is input into the K8S container platform for use, improving the accuracy of creating the resource configuration file in yaml format.
[0082] It should be noted that a Configmap resource can be created according to the resource configuration file in yaml format with correct syntax. If the resource creation fails, the error information returned by the K8S container platform is output, and the error information does not include the format problems caused by syntax errors. If the resource can be created normally, the environment variable reading verification can be performed through the busybox base image. If the reading is normal, the Configmap resource configuration file is output.
[0083] As a possible implementation, a resource configuration template in YAML format is generated according to the configuration items. The generated resource configuration template contains common configuration items in the configuration file, such as at least one of the interface version (apiVersion), required components (kind), source data (metadata), volume mounting locations (containers, volumes), parameters (spec), or required environment variables (env). According to the YAML format resource configuration template and the parameters corresponding to the configuration items, for example, users can generate a YAML format resource configuration file by writing the parameters corresponding to the configuration items into the resource configuration template. Thus, the development time of developers can be reduced through the resource configuration template, and the probability of format errors can also be reduced.
[0084] Thus, when developers need to generate a Configmap resource configuration file related to container applications based on the K8S container platform, they can first configure the corresponding environment variables in the YAML format resource configuration template according to the actual requirements of the container application to meet the basic requirements for the operation of the container application. After the configuration is completed, a YAML format resource configuration file is generated. Check whether there are syntax problems in the YAML format resource configuration file in the manner described in the foregoing S101 - S104, and correct the positions of the content with syntax problems to obtain a resource configuration file with correct YAML format syntax, and perform a second verification of the resource configuration file with correct YAML format syntax based on the K8S container platform to determine whether it can correctly read the relevant environment variables. Thus, the problem that the K8S container platform cannot locate the position of the content with syntax errors in the YAML format resource configuration file is solved, and the development efficiency is improved.
[0085] In addition to the data verification method based on the K8S container platform provided by the embodiments of the present application, a data verification device based on the K8S container platform is also provided, such as Figure 2 shown, the device includes an acquisition unit 201, a generation unit 202, a verification unit 203, and a determination unit 204;
[0086] The acquisition unit 201 is used to acquire a resource configuration file in YAML format;
[0087] The generation unit 202 is used to generate a resource configuration file in JSON format according to the YAML format resource configuration file, and obtain the content mapping relationship between the YAML format resource configuration file and the JSON format resource configuration file;
[0088] The verification unit 203 is configured to verify whether the syntax of the content in the resource configuration file in JSON format is correct by using a shell script file, and in response to incorrect syntax of the content in the resource configuration file in JSON format, obtain the position of the content with syntax errors in the resource configuration file in JSON format;
[0089] The determination unit 204 is configured to determine the position of the content with syntax errors in the resource configuration file in YAML format according to the content mapping relationship and the position of the content with syntax errors in the resource configuration file in JSON format.
[0090] As a possible implementation manner, the apparatus further includes a replacement unit, a conversion unit, and an input unit; after obtaining the position of the content with syntax errors in the resource configuration file in JSON format,
[0091] The replacement unit is configured to perform string replacement on the content with syntax errors in the resource configuration file in JSON format to obtain a resource configuration file with correct JSON format syntax;
[0092] The conversion unit is configured to convert the resource configuration file with correct JSON format syntax into a resource configuration file with correct YAML format syntax according to the content mapping relationship;
[0093] The input unit is configured to input the resource configuration file with correct YAML format syntax into the K8S container platform.
[0094] As a possible implementation manner, the generation unit 202 is configured to:
[0095] Identify the target content in the resource configuration file in YAML format that conforms to the JSON format;
[0096] Extract the target content from the resource configuration file in YAML format to generate a resource configuration file in JSON format.
[0097] As a possible implementation manner, the generation unit 202 is configured to:
[0098] Parse the resource configuration file in YAML format into a map object;
[0099] Generate a resource configuration file in JSON format according to the map object.
[0100] As a possible implementation manner, the generation unit 202 is further configured to:
[0101] Generate a resource configuration template in YAML format according to configuration items, where the configuration items include at least one of interface version, required components, source data, volume mounting location, or required environment variables;
[0102] The obtaining unit 201 is configured to:
[0103] Generate a resource configuration file in YAML format according to the resource configuration template in YAML format and the parameters corresponding to the configuration items.
[0104] According to the data verification device based on the K8S container platform provided by the embodiments of the present application, after obtaining a resource configuration file in YAML format, generate a resource configuration file in JSON format according to the resource configuration file in YAML format, and obtain the content mapping relationship between the resource configuration file in YAML format and the resource configuration file in JSON format. Use a shell script file to verify whether there are syntax problems in the content of the resource configuration file in JSON format. If there are syntax problems, locate the content position where the syntax error occurs in the resource configuration file in JSON format, and convert the content position where the syntax error occurs in the resource configuration file in JSON format to the content position where the syntax error occurs in the resource configuration file in YAML format according to the previously determined content mapping relationship. Thus, by determining the content position where the syntax error occurs in the resource configuration file in JSON format corresponding to the resource configuration file in YAML format, the content position where the syntax error occurs in the resource configuration file in YAML format can be determined, solving the problem that the K8S container platform cannot locate the content position where the syntax error occurs in the resource configuration file in YAML format and improving the development efficiency.
[0105] Each embodiment in this specification is described in a progressive manner. The same or similar parts among the embodiments can be referred to each other, and the differences emphasized in each embodiment are different from those of other embodiments. In particular, for the device embodiments, since they are basically similar to the method embodiments, they are described relatively simply, and the relevant parts can refer to the partial description of the method embodiments. The device embodiments described above are only illustrative, and the units and modules described as separate components may or may not be physically separated. In addition, some or all of the units and modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement without creative efforts.
[0106] The above is only the specific implementation manner of the present application. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present application, several improvements and refinements can be made, and these improvements and refinements should also be regarded as the protection scope of the present application.
Claims
1. A data verification method based on the K8S container platform, characterized in that The method includes: Obtain a resource configuration file in YAML format; Generate a resource configuration file in JSON format according to the resource configuration file in YAML format, and obtain the content mapping relationship between the resource configuration file in YAML format and the resource configuration file in JSON format; Among them, the generating of the resource configuration file in JSON format according to the resource configuration file in YAML format includes: identifying the target content that conforms to the JSON format in the resource configuration file in YAML format; extracting the target content from the resource configuration file in YAML format to generate a resource configuration file in JSON format; The generating of the resource configuration file in JSON format according to the resource configuration file in YAML format includes: parsing the resource configuration file in YAML format into a map object; generating a resource configuration file in JSON format according to the map object; Use a shell script file to verify whether the syntax of the content in the resource configuration file in JSON format is correct. In response to the incorrect syntax of the content in the resource configuration file in JSON format, obtain the position of the content with syntax errors in the resource configuration file in JSON format; According to the content mapping relationship and the position of the content with syntax errors in the resource configuration file in JSON format, determine the position of the content with syntax errors in the resource configuration file in YAML format; Input the resource configuration file with correct YAML format syntax into the K8S container platform to create a Configmap resource; if the resource creation fails, output the error information returned by the K8S container platform; if the resource creation is successful, verify the readability of the environment variables through the busybox base image, and output the Configmap resource configuration file after the verification passes.
2. The method according to claim 1, characterized in that, After obtaining the position of the content with syntax errors in the resource configuration file in JSON format, the method further includes: Perform string replacement on the content with syntax errors in the resource configuration file in JSON format to obtain a resource configuration file with correct JSON format syntax; According to the content mapping relationship, convert the resource configuration file with correct JSON format syntax into a resource configuration file with correct YAML format syntax; Input the resource configuration file with correct YAML format syntax into the K8S container platform.
3. The method according to claim 1, characterized in that, The method further includes: Generate a resource configuration template in YAML format according to configuration items, where the configuration items include at least one of interface version, required components, source data, volume mounting location, or required environment variables; The obtaining of the resource configuration file in YAML format includes: Generate a resource configuration file in YAML format according to the resource configuration template in YAML format and the parameters corresponding to the configuration items.
4. A data verification device based on the K8S container platform, characterized in that, The device includes: an obtaining unit, a generating unit, a verifying unit, and a determining unit; The obtaining unit is used to obtain a resource configuration file in YAML format; The generating unit is configured to generate a resource configuration file in JSON format according to the resource configuration file in YAML format, and obtain the content mapping relationship between the resource configuration file in YAML format and the resource configuration file in JSON format; The generating unit is configured to: identify target content that conforms to the JSON format in the resource configuration file in YAML format; extract the target content from the resource configuration file in YAML format to generate a resource configuration file in JSON format; The generating unit is configured to: parse the resource configuration file in YAML format into a map object; generate a resource configuration file in JSON format according to the map object The verifying unit is configured to use a shell script file to verify whether the syntax of the content in the resource configuration file in JSON format is correct. In response to the incorrect syntax of the content in the resource configuration file in JSON format, obtain the content position where a syntax error occurs in the resource configuration file in JSON format; The determining unit is configured to determine the content position where a syntax error occurs in the resource configuration file in YAML format according to the content mapping relationship and the content position where a syntax error occurs in the resource configuration file in JSON format; The device is further configured to: input a resource configuration file with correct YAML format syntax into the K8S container platform for Configmap resource creation; if the resource creation fails, output the error information returned by the K8S container platform; if the resource creation is successful, verify the readability of the environment variables through the busybox base image, and output the Configmap resource configuration file after the verification passes.
5. The device according to claim 4, characterized in that, The device further includes a replacement unit, a conversion unit, and an input unit; after obtaining the content position where a syntax error occurs in the resource configuration file in JSON format, The replacement unit is configured to perform string replacement on the content where a syntax error occurs in the resource configuration file in JSON format to obtain a resource configuration file with correct JSON format syntax; The conversion unit is configured to convert the resource configuration file with correct JSON format syntax into a resource configuration file with correct YAML format syntax according to the content mapping relationship; The input unit is configured to input the resource configuration file with correct YAML format syntax into the K8S container platform.
6. The device according to claim 4, characterized in that The generating unit is further configured to: Generate a resource configuration template in YAML format according to configuration items, where the configuration items include at least one of interface version, required components, source data, volume mounting location, or required environment variables; The obtaining unit is configured to: Generate a resource configuration file in YAML format according to the resource configuration template in YAML format and the parameters corresponding to the configuration items.
Citation Information
Patent Citations
Efficient Web form validation method and framework thereof
CN102426549A
Configuration file checking method and device based on serialization format
CN107220072A