Realization method for cooperatively repairing ConfigMap format disorder based on cloud edge
The custom kubectl plug-in provides command line tools to format and fix ConfigMap content, which solves the problem of confusing ConfigMap resource content in the cloud-edge collaborative environment, and achieves more convenient and fast viewing and editing.
Patent Information
- Application Number
- CN202510216733.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-26
- Publication Date
- 2025-06-27
AI Technical Summary
In a cloud-edge collaborative environment, the content format of the ConfigMap resource is prone to be confused, resulting in difficulty in viewing and modifying.
Through custom kubectl plug-in, command line tools are provided to format and repair ConfigMap content, ensure the correctness of its format, and save the repaired content to etcd database.
It realizes more convenient and quick viewing and editing of ConfigMap resource content, and solves the problem of difficulty in viewing and modifying caused by format confusion.
Smart Images

Figure CN120216093A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of cloud native container technology, and in particular to an implementation method for repairing ConfigMap format disorder based on cloud-edge collaboration. Background Art
[0002] With the increasing application of container technology in public cloud, private cloud, hybrid cloud and other fields, the latest container technology has been widely used in the field of cloud computing due to its excellent performance and ease of use. Cloud computing is a computing model based on the Internet and with mass participation. It provides dynamic and scalable computing resources and provides them to demanders in the form of services. Cloud computing is mainly divided into three types of services: infrastructure as a service, platform as a service and software as a service. Edge computing is a distributed computing architecture that delegates computing tasks to devices close to the data source. The purpose of edge computing is to reduce response time, improve stability, and reduce network pressure and energy consumption on the central cloud.
[0003] Cloud-edge collaboration closely combines cloud computing and edge computing. It is responsible for real-time data collection, processing and preliminary analysis through edge nodes, while cloud data centers are responsible for large-scale computing tasks such as data analysis, machine learning and model training. In this way, cloud-edge collaboration takes advantage of the network advantages of the edge side and the elastic computing capabilities of cloud computing.
[0004] In the cloud-edge collaborative environment, ConfigMap, as an important Kubernetes resource type, stores the relevant configuration file content of the application service container. In the actual development and production process, you may need to view and modify the content in the configuration file. However, Kubernetes has strict requirements on the content format in ConfigMap. Once a tab or trailing space appears in a long paragraph, it will automatically convert it to characters such as \n and \t. The originally expected line breaks and indentation formats will all be disrupted, seriously affecting the viewing and modification of these contents.
[0005] Therefore, in order to meet the demand for more readability in scenarios where ConfigMap resource formats are disordered under cloud-edge collaboration, an implementation method for repairing ConfigMap format disorder based on cloud-edge collaboration is proposed, which aims to solve the problem of disordered ConfigMap resource content format in the cloud-edge collaboration environment, and use a custom kubectl plug-in to correct the disordered ConfigMap content in the command line with one click. Summary of the invention
[0006] In view of the requirements and deficiencies in the current technological development, the present invention provides an implementation method for repairing the disorder of the ConfigMap format based on cloud-edge collaboration, which is used to meet the more convenient viewing and modification of the content of configuration files in the cloud-edge collaboration environment.
[0007] For an implementation method for repairing the disorder of the ConfigMap format based on cloud-edge collaboration of the present invention, the technical solutions adopted to solve the above technical problems are as follows:
[0008] An implementation method for repairing the disorder of the ConfigMap format based on cloud-edge collaboration, which includes the following steps:
[0009] S1. In the cloud-edge collaboration environment, support format repair and viewing of the disordered content of the ConfigMap resource in the form of a kubectl command-line plugin.
[0010] S2. In the cloud-edge collaboration environment, support formatted viewing of the disordered content of the ConfigMap resource with a specified namespace and name.
[0011] S3. In the cloud-edge collaboration environment, support formatted repair of the ConfigMap with a specified namespace and name or all the disordered content of the ConfigMap resources in the Kubernetes cluster, and save the repaired content to the etcd database.
[0012] Optionally, the specific operations involved in step S1 are as follows:
[0013] S1.1. Implement a kubectl plugin named kubectl-format in the form of a shell script or an executable binary program file.
[0014] S1.2. Support specifying different parameters at the specific implementation level of the script or binary code according to different usage scenarios.
[0015] S1.3. Place the compiled kubectl-format executable file in the / usr / local / bin / directory on the Kubernetes cluster node, and execute chmod +x to grant executable permissions. At this time, the kubectl plugin named kubectl-format can be used in the cluster.
[0016] Further optionally, when executing step S1.2, support specifying different parameters at the specific implementation level of the script or binary code according to different usage scenarios, specifically including:
[0017] In the scenario of formatting and viewing a specified ConfigMap, use the get parameter. The specific command to execute is kubectl format get configMapName –n namespace;
[0018] In the scenario of formatting and repairing a specified ConfigMap, use the fix parameter. The specific command to execute is kubectl format fix configMapName –n namespace;
[0019] In the scenario of formatting and repairing all ConfigMaps, use the fix parameter in combination with the –all parameter. The specific command to execute is kubectl format fix –all.
[0020] Further optionally, the specific operations included in step S2 are as follows:
[0021] S2.1. In the kubectl plugin named kubectl-format, support passing in parameters when specifying a query: the ConfigMap name and the corresponding namespace name;
[0022] S2.2. Conduct a native standard query inside the kubectl plugin to obtain the native ConfigMap content in json format;
[0023] S2.3. Traverse the data field in the ConfigMap content queried in step S2.2 to obtain the key and value data in the corresponding map respectively;
[0024] S2.4. Keep the key data unchanged, use the jq tool to convert the value data to json format and ensure the correctness of its structure, and use the yq tool to convert the json format value data to yaml format;
[0025] S2.5. Combine the key data and value data obtained by querying the data field in the ConfigMap content in step S2.3, and then supplement the original fields of the ConfigMap resource except the data field to form a complete formatted ConfigMap content.
[0026] Preferably, perform step S2.4. First, use the jq tool to format the value data and output the data with the scrambled content formatted. The data is in JSON format. Use an online JSON validation tool or write a script to check whether the generated JSON data conforms to the expected structure. Subsequently, convert the JSON format data to YAML format to obtain a formatted ConfigMap content.
[0027] Optionally, perform step S3. In the cloud-edge collaboration environment, support formatting and repairing the scrambled content of the ConfigMap resources with specified namespace and name, and save the repaired content to the etcd database. The specific operations are as follows:
[0028] S3.1.1: Export all the YAML format ConfigMap resource content obtained in step S2 and save it to a temporary file named xxx.yaml in the / tmp directory.
[0029] S3.1.2: Use the sed command to replace and update the content of the temporary file, delete the trailing spaces, and replace the TAB tab characters with 4 space characters. After the replacement, still save the new content to the temporary file.
[0030] S3.1.3: Execute the kubectl apply–f / tmp / xxx.yaml command to apply the latest content back to the Kubernetes cluster, thereby updating it to the etcd database. At this time, the content directly queried using the native kubectl getconfigmap command is the already formatted content.
[0031] Further optionally, perform step S3. In the cloud-edge collaboration environment, support formatting and repairing the scrambled content of all ConfigMap resources in the cluster, and save the repaired content to the etcd database. The specific operations are as follows:
[0032] S3.2.1: Detect the specified parameter -all, indicating that all ConfigMap resources need to be formatted and repaired.
[0033] S3.2.2: Traverse and query all ConfigMap resource data in the cluster.
[0034] S3.2.3: For each ConfigMap, perform steps S3.1.1 - S3.1.3 until all ConfigMaps are processed. At this time, the content directly queried using the native kubectl get configmap command is the already formatted content.
[0035] Preferably, step S3.2.2 is executed to obtain the ConfigMap resources under all namespaces by using the command kubectl get configmaps --all-namespaces.
[0036] A method for implementing the repair of the disordered ConfigMap format based on cloud-edge collaboration in the present invention has the beneficial effects compared with the prior art as follows:
[0037] The present invention can use the kubectl command-line plugin to more conveniently view the specified ConfigMap content with a disordered format, and use the kubectl command-line plugin to perform one-key formatting repair on the specified ConfigMap with a disordered format or all ConfigMap content in the Kubernetes cluster, and permanently save it. After that, it can be viewed and edited normally, solving the problem of the disordered format of the ConfigMap resource content in the cloud-edge collaboration environment. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Attached Figure 1 is the flowchart of the method in Embodiment 1 of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0039] To make the technical solutions, the technical problems solved, and the technical effects of the present invention clearer and more understandable, the following combines specific embodiments to clearly and completely describe the technical solutions of the present invention.
[0040] Embodiment 1:
[0041] Combined with the attached Figure 1 , this embodiment proposes a method for implementing the repair of the disordered ConfigMap format based on cloud-edge collaboration, which includes the following steps:
[0042] S1. In the cloud-edge collaboration environment, support format repair and viewing of the disordered content of the ConfigMap resources in the form of a kubectl command-line plugin, specifically including the following operations:
[0043] S1.1. Implement a kubectl plugin named kubectl-format in the form of a shell script or an executable binary program file;
[0044] S1.2. Support specifying different parameters at the specific implementation level of the script or binary code according to different usage scenarios, such as:
[0045] a) In the scenario of formatting and viewing a specified ConfigMap, use the get parameter. The specific command to execute is kubectl format get configMapName –n namespace;
[0046] b) In the scenario of formatting and fixing a specified ConfigMap, use the fix parameter. The specific command to execute is kubectl format fix configMapName –n namespace;
[0047] c) In the scenario of formatting and fixing all ConfigMaps, use the fix parameter in combination with the –all parameter. The specific command to execute is kubectl format fix –all;
[0048] S1.3. Place the compiled kubectl-format executable file in the / usr / local / bin / directory on the Kubernetes cluster nodes, and execute chmod +x to grant executable permissions. At this time, the kubectl plugin named kubectl-format can be used in the cluster.
[0049] S2. In the cloud-edge collaborative environment, support formatting and viewing the content with incorrect formatting of ConfigMap resources with a specified namespace and name. The specific operations are as follows:
[0050] S2.1. The kubectl plugin named kubectl-format supports specifying parameters when querying: the ConfigMap name and the corresponding namespace name;
[0051] S2.2. Perform a native standard query inside the kubectl plugin to obtain the native ConfigMap content in json format;
[0052] S2.3. Traverse the data field in the ConfigMap content queried in step S2.2 to obtain the key and value data in the corresponding map respectively;
[0053] Keep the key data unchanged. First, use the jq tool to format the value data, output the data with the incorrect content formatted. The data is in json format. Use an online JSON validation tool or write a script to check whether the generated json data conforms to the expected structure. Subsequently, convert the json format data to yaml format to obtain a formatted ConfigMap content;
[0054] S2.5. Combine the key data and value data obtained from the data field in the ConfigMap content queried in step S2.3, and then supplement the original fields of the ConfigMap resource except the data field to form a complete and formatted ConfigMap content.
[0055] S3. In the cloud-edge collaboration environment, support formatting and repairing the content with incorrect formats of ConfigMaps with specified namespaces and names or all ConfigMap resources in the Kubernetes cluster, and save the repaired content to the etcd database.
[0056] In this step, in the cloud-edge collaboration environment, support formatting and repairing the content with incorrect formats of ConfigMap resources with specified namespaces and names, and save the repaired content to the etcd database. The specific operations are as follows:
[0057] S3.1.1. Export all the ConfigMap resource content in yaml format obtained in step S2 and save it to a temporary file named xxx.yaml in the / tmp directory.
[0058] S3.1.2. Use the sed command to replace and update the content of the temporary file, delete the trailing spaces, and replace the TAB tab characters with 4 space characters. After the replacement, still save the new content to the temporary file.
[0059] Execute the command kubectl apply –f / tmp / xxx.yaml to apply the latest content back to the Kubernetes cluster, so as to update it to the etcd database. At this time, the content queried directly using the native kubectl get configmap command is the already formatted content.
[0060] In this step, in the cloud-edge collaboration environment, support formatting and repairing the content with incorrect formats of all ConfigMap resources in the cluster, and save the repaired content to the etcd database. The specific operations are as follows:
[0061] S3.2.1. Detect the specified parameter -all, which indicates that all ConfigMap resources are to be formatted and repaired.
[0062] S3.2.2. Traverse and query all the ConfigMap resource data in the cluster. Specifically, use the command kubectl get configmaps --all-namespaces to obtain the ConfigMap resources under all namespaces.
[0063] S3.2.3. For each ConfigMap, execute steps S3.1.1 - S3.1.3 until all ConfigMaps are processed. At this time, the content queried directly using the native kubectl get configmap command is the already formatted content.
[0064] In summary, by adopting the implementation method for repairing the disordered ConfigMap format based on cloud - edge collaboration of the present invention, the disordered ConfigMap content is corrected in a command - line manner using a custom kubectl plugin, realizing more convenient, fast, and effective viewing and editing of the ConfigMap resource content.
[0065] The above application of specific examples has elaborated in detail the principle and implementation manner of the present invention. These examples are only used to help understand the core technical content of the present invention. Based on the above - mentioned specific embodiments of the present invention, any improvements and modifications made by those skilled in the art of this technical field without departing from the principle of the present invention shall fall within the patent protection scope of the present invention.
Claims
1. A method for repairing ConfigMap format disorder based on cloud-edge collaboration, characterized in that: The steps include: S1. In the cloud-edge collaborative environment, it supports format repair and viewing of ConfigMap resource format disorder content in the form of kubectl command line plug-in; S2. In the cloud-edge collaborative environment, support formatting and viewing of the ConfigMap resource format disorder content of the specified namespace and name; S3. In a cloud-edge collaborative environment, it supports formatting and repairing the ConfigMap with a specified namespace and name or the formatted content of all ConfigMap resources in the Kubernetes cluster, and saving the repaired content to the etcd database.
2. According to claim 1, a method for repairing ConfigMap format disorder based on cloud-edge collaboration is characterized in that: The step S1 specifically includes the following operations: S1.
1. Implement a kubectl plug-in named kubectl-format in the form of a shell script or executable binary program file; S1.
2. Support specifying different parameters at the specific implementation level of script or binary code according to different usage scenarios; S1.
3. Put the compiled kubectl-format executable file in the / usr / local / bin / directory on the Kubernetes cluster node and execute chmod+x to grant executable permissions. At this point, the kubectl plug-in named kubectl-format can be used in the cluster.
3. According to claim 2, a method for repairing ConfigMap format disorder based on cloud-edge collaboration is characterized in that: Execute step S1.2, and support specifying different parameters at the specific implementation level of the script or binary code according to different usage scenarios, including: To format and view a specified ConfigMap, use the get parameter. The specific command to be executed is kubectlformat get configMapName–n namespace. To format and repair a specified ConfigMap, use the fix parameter. The specific command to be executed is kubectlformat fix configMapName–n namespace. To format and fix all ConfigMaps, use the fix parameter in combination with the -all parameter. The specific command to be executed is kubectl format fix–all.
4. According to claim 3, a method for repairing ConfigMap format disorder based on cloud-edge collaboration is characterized in that: The step S2 specifically includes the following operations: S2.
1. The kubectl plug-in named kubectl-format supports passing in parameters when specifying queries: ConfigMap name and corresponding namespace name; S2.
2. Perform native standardized query inside the kubectl plug-in to obtain the native ConfigMap content in json format; S2.3, traverse the data field in the ConfigMap content queried in step S2.2, and obtain the data of the key and value in the corresponding map respectively; S2.
4. The key data remains unchanged. Use the jq tool to convert the value data into json format and ensure the correctness of its structure. Use the yq tool to convert the value data in json format into yaml format. S2.
5. Combine the key data and value data obtained by querying the data field in the ConfigMap content in step S2.3, and then add the original fields of the ConfigMap resource except the data field to form a complete formatted ConfigMap content.
5. According to claim 4, a method for repairing ConfigMap format disorder based on cloud-edge collaboration is characterized in that: Execute step S2.
4. First, use the jq tool to format the value data and output the formatted data of the disordered content. The data is in json format. Use an online JSON validation tool or write a script to check whether the generated json data conforms to the expected structure. Then, convert the json format data into yaml format to obtain a formatted ConfigMap content.
6. According to claim 4, a method for repairing ConfigMap format disorder based on cloud-edge collaboration is characterized in that: Execute step S3. In the cloud-edge collaborative environment, support formatting and repairing the ConfigMap resource format disorder content of the specified namespace and name, and save the repaired content to the etcd database. Specifically, the following operations are included: S3.1.
1. Export all the ConfigMap resource contents in the yaml format obtained in step S2 and save them to a temporary file in the xxx.yaml format in the / tmp directory; S3.1.
2. Use the sed command to replace and update the content of the temporary file, delete the trailing space, and replace the TAB character with 4 space characters. After the replacement is completed, the new content is still saved in the temporary file; S3.1.
3. Execute the kubectl apply –f / tmp / xxx.yaml command to apply the latest content back to the Kubernetes cluster and update it to the etcd database. At this time, the content queried directly using the native kubectl get configmap command is the formatted content.
7. According to claim 6, a method for repairing ConfigMap format disorder based on cloud-edge collaboration is characterized in that: Execute step S3. In the cloud-edge collaborative environment, it supports formatting and repairing the disordered content of all ConfigMap resources in the cluster, and saving the repaired content to the etcd database. The specific operations include the following: S3.2.
1. If the specified parameter -all is detected, it means that all ConfigMap resources need to be formatted and repaired; S3.2.
2. Traverse and query all ConfigMap resource data in the cluster; S3.2.
3. For each ConfigMap, execute steps S3.1.1-S3.1.3 until all ConfigMaps are processed. At this point, the content queried directly using the native kubectl get configmap command is the formatted content.
8. According to claim 7, a method for repairing ConfigMap format disorder based on cloud-edge collaboration is characterized in that: Execute step S3.2.2 and use the kubectl get configmaps --all-namespaces command to obtain the ConfigMap resources in all namespaces.