Environment variable configuration method and device, electronic equipment and storage medium

By customizing the access controller to intercept and verify the resource configuration files of the container hosting platform, the problem of environmental variable injection failure is solved, and the correct injection of environment variables and stable management of the container hosting platform is realized.

CN119473434APending Publication Date: 2025-02-18CHINA PING AN LIFE INSURANCE CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411711932.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-26
Publication Date
2025-02-18

AI Technical Summary

Technical Problem

When using the configuration file management tool of the container hosting platform, environment variable injection is prone to failure, making it difficult to troubleshoot problems and lacks effective solutions.

Method used

Intercept the writes of resource configuration files through a custom admission controller, verify the differences in environment variables, and replace the target environment variables after the write is completed, ensuring that the environment variable values ​​are correctly injected into the container.

Benefits of technology

It effectively solves the problem of environment variable configuration failure and improves the management stability and reliability of container hosting platforms in cloud-native environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119473434A_ABST
    Figure CN119473434A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an environment variable configuration method and device, electronic equipment and a storage medium, and belongs to the technical field of cloud computing. The method comprises the steps that under the condition that it is detected that a first resource configuration file is written into a storage of a container hosting platform, the first resource configuration file is intercepted, the first resource configuration file is used for conducting resource configuration updating on the container hosting platform, and the first resource configuration file comprises multiple first environment variables; if a plurality of second environment variables included in a second resource configuration file configured by the container hosting platform are different from the plurality of first environment variables, obtaining target environment variables with differences; copying the target environment variable to obtain a temporary environment variable; and after the first resource configuration file is written into the memory of the container hosting platform, replacing the target environment variable in the first resource configuration file by adopting the temporary environment variable. According to the embodiment of the invention, the problem of environment variable configuration failure can be solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of cloud computing technology, and in particular to an environment variable configuration method, device, electronic device and storage medium. Background Art

[0002] With the development of cloud computing technology, cloud native has become the new standard for IT infrastructure. The cloud native environment based on the container hosting platform provides users with comprehensive computing power, network, storage and other services. In order to simplify the management of the container hosting platform, a corresponding configuration file management tool has been developed. The configuration file management tool reduces the difficulty of using the container hosting platform by providing standard software resource templates, and has become a common tool for large container hosting platform clusters. However, in the process of using the configuration file management tool, there is still the problem of invalid environment variable injection. That is, after modifying the resource configuration file of the container hosting platform, the environment variables injected through the configuration file during the container generation process may disappear, resulting in difficult to troubleshoot problems, and there is currently no effective solution. Summary of the invention

[0003] The main purpose of the embodiments of the present application is to propose an environment variable configuration method, device, electronic device and storage medium, aiming to solve the problem of environment variable configuration failure.

[0004] To achieve the above purpose, a first aspect of an embodiment of the present application proposes an environment variable configuration method, the method comprising:

[0005] When it is detected that a first resource configuration file is written into a storage of the container hosting platform, intercepting the first resource configuration file, where the first resource configuration file is used to update resource configuration of the container hosting platform, and the first resource configuration file includes a plurality of first environment variables;

[0006] If the plurality of second environment variables included in the second resource configuration file configured by the container hosting platform are different from the plurality of first environment variables, obtaining the target environment variables with the difference;

[0007] Copying the target environment variable to obtain a temporary environment variable;

[0008] After the first resource configuration file is written into the storage of the container hosting platform, the target environment variable in the first resource configuration file is replaced by the temporary environment variable.

[0009] In some embodiments, the first resource configuration file further includes a plurality of first configuration parameters, a parameter value of each of the first configuration parameters, and a parameter value of each of the first environment variables;

[0010] The method of intercepting the first resource configuration file when it is detected that the first resource configuration file is written into the storage of the container hosting platform includes:

[0011] In a case where it is detected that the first resource configuration file is written to the storage of the container hosting platform, if the second resource configuration file includes a first parameter, and the parameter value of the first parameter included in the second resource configuration file is different from the parameter value of the first parameter included in the first resource configuration file, intercepting the first resource configuration file, wherein the first parameter is the first configuration parameter or the first environment variable;

[0012] In a case where it is detected that the first resource configuration file is written to the memory of the container hosting platform, if the second resource configuration file does not include the first parameter, the first resource configuration file is intercepted.

[0013] In some embodiments, the target environment variable satisfies one of the following:

[0014] The plurality of first environment variables include the target environment variable, and the plurality of second environment variables do not include the target environment variable;

[0015] The variable values ​​of the target environment variables included in the plurality of first environment variables are different from the variable values ​​of the target environment variables included in the plurality of second environment variables.

[0016] In some embodiments, when detecting that the first resource configuration file is written to the memory of the container hosting platform, before intercepting the first resource configuration file, the method further includes:

[0017] If the first resource configuration file is verified according to a preset rule, the first resource configuration file is written into the memory.

[0018] In some embodiments, when it is detected that the first resource configuration file is written to the memory of the container hosting platform, after intercepting the first resource configuration file, if a plurality of second environment variables included in a second resource configuration file configured by the container hosting platform differ from the plurality of first environment variables, before obtaining the target environment variables with the difference, the method further includes:

[0019] The multiple environment variable files in the first resource configuration file are traversed in sequence to obtain the multiple first environment variables.

[0020] In some embodiments, copying the target environment variable to obtain a temporary environment variable includes:

[0021] The target environment variable is copied, and the copied target environment variable is renamed to obtain the temporary environment variable.

[0022] In some embodiments, after writing the first resource configuration file into the storage of the container hosting platform, replacing the target environment variable in the first resource configuration file with the temporary environment variable includes:

[0023] After the first resource configuration file is written into the storage of the container hosting platform, if the variable value of the target environment variable is a preset value, the target environment variable in the first resource configuration file is replaced by the temporary environment variable.

[0024] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application provides an environment variable configuration device, the device comprising:

[0025] an interception module, configured to intercept a first resource configuration file when detecting that the first resource configuration file is written into a storage of the container hosting platform, wherein the first resource configuration file is used to update resource configuration of the container hosting platform, and the first resource configuration file includes a plurality of first environment variables;

[0026] A detection module, configured to obtain a target environment variable with a difference if a plurality of second environment variables included in a second resource configuration file configured on the container hosting platform differ from the plurality of first environment variables;

[0027] A copy module, used for copying the target environment variable to obtain a temporary environment variable;

[0028] A replacement module is used to replace the target environment variable in the first resource configuration file with the temporary environment variable after the first resource configuration file is written into the storage of the container hosting platform.

[0029] To achieve the above objectives, a third aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method described in the first aspect is implemented.

[0030] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect is implemented.

[0031] The environment variable configuration method, device, electronic device and storage medium proposed in the present application intercept the resource configuration file before it is written to the storage through a customized access controller, and verify the resource configuration file; according to the verification result, if the environment variables in the resource configuration file are consistent with the environment variables being applied, the resource configuration file is directly written to the storage system; if the environment variables change, the environment variables with differences are copied, and the copied environment variables are renamed to obtain temporary environment variables; after the resource configuration file is written to the storage and before the container is configured, the written environment variables are replaced with temporary environment variables through the prestart resource, thereby ensuring that the environment variable values ​​can be correctly injected into the container, solving the problem of invalid environment variable configuration, and improving the stability and reliability of container hosting platform management in a cloud-native environment. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 This is one of the flow charts of the environment variable configuration method provided in the embodiment of the present application;

[0033] Figure 2 yes Figure 1 A schematic flow chart of step S100 in FIG.

[0034] Figure 3 This is the second flow chart of the environment variable configuration method provided in the embodiment of the present application;

[0035] Figure 4 This is the third flow chart of the environment variable configuration method provided in the embodiment of the present application;

[0036] Figure 5 This is the fourth flow chart of the environment variable configuration method provided in the embodiment of the present application;

[0037] Figure 6 This is the fifth flow chart of the environment variable configuration method provided in the embodiment of the present application;

[0038] Figure 7 is a schematic diagram of the structure of the environment variable configuration device provided in an embodiment of the present application;

[0039] Figure 8 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION

[0040] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0041] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0042] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0043] First, some nouns involved in this application are analyzed:

[0044] Container hosting platform: It is a containerized application used to manage multiple hosts in a cloud platform, making the deployment of containerized applications simple and efficient. The traditional way to deploy applications is to install applications through plug-ins or scripts. The disadvantage of this is that the operation, configuration, management, and all life cycles of the application will be bound to the current operating system, which is not conducive to the upgrade, update, rollback, and other operations of the application. Of course, some functions can be implemented by creating virtual machines, but virtual machines are very heavy and inconvenient to transplant. The new way is to implement it by deploying containers. Each container is isolated from each other, each container has its own file system, and the processes between containers will not affect each other, and computing resources can be distinguished. Compared with virtual machines, containers can be deployed quickly. Since containers are decoupled from the underlying facilities and machine file systems, they can be migrated between different clouds and different versions of operating systems. At the same time, containers occupy less resources and are deployed quickly. Each application can be packaged into a container image. The one-to-one relationship between each application and the container also makes containers have greater advantages. Using containers, container images can be created for applications during the creation or release stage, because each application does not need to be combined with the rest of the application stack, nor does it rely on the production environment infrastructure, which enables a consistent environment from R&D to testing and production. At the same time, containers are lighter than virtual machines, which makes them easier to monitor and manage.

[0045] Admission controller: It is a plug-in in the container hosting platform, responsible for processing API requests from the outside. They ensure that only requests that meet specific conditions can access cluster resources. The admission controller intercepts requests to the API server after the request is authenticated and authorized and before the object is persisted. The admission controller is provided based on the plug-in mechanism of the container hosting platform itself, and related functions can be customized according to the admission controller framework. By using the admission controller, fine-grained control of cluster resources can be achieved, thereby improving the security and reliability of the cluster.

[0046] Environment variables: a way to set and pass configuration information in a container, mainly used to dynamically modify the behavior of an application and implement flexible deployment and configuration management. They can be accessed in the container to configure the behavior and properties of the application at runtime. Environment variables can be used to store various types of configuration information, such as database connection strings, API keys, log levels, etc. Environment variables allow the configuration of an application to be adjusted dynamically without rebuilding the image.

[0047] Prestart resources: These are some necessary initialization operations that are performed before the container is started. They are mainly used to initialize settings, prepare data, configure environment variables, set network parameters, etc. By using prestart, you can ensure that the container has all the resources and environment it needs before starting, thereby improving the reliability and stability of the application and avoiding startup failures or abnormal operations caused by configuration errors or missing data.

[0048] As the concept of cloud computing matures, the cloud computing of current IT architecture has become the de facto standard of current IT infrastructure. After incorporating the experience of practical feedback, cloud computing itself has evolved from simple cloud computing to the current cloud native, becoming a more mature infrastructure ecosystem, providing more complete infrastructure services including computing power, network, storage, etc. The current cloud native environment is mainly built on the container hosting platform, and operators manage the platform by managing the resource configuration files of the container hosting platform. In order to simplify the use of the container hosting platform, the concept of templates has been introduced into the container hosting platform system. Based on the container hosting platform, Ping An has developed its own container management platform PKS (Pingan Kubernetes Service), introducing the container-based cloud into Ping An's IT infrastructure.

[0049] The combination of PKS and template tools reduces the difficulty of managing applications hosted on PKS. The template tool greatly simplifies the use of PKS by providing a standard software resource template on PKS (built from a directory and a series of resource templates under it). However, when using the template management tool in a PKS environment, there is a problem of invalid environment variable injection. That is, after the PKS resource configuration file is modified in the template, the environment variables injected through the configuration file during the container generation process will disappear. Even if the relevant environment variables have not been modified, the deployment process will not prompt, making it difficult to troubleshoot the problem. After the environment variable injection fails, it is usually necessary to delete the problematic resources in the PKS environment and then try to recover by rebuilding the template. However, after evaluation and practice, it was found that deleting the configuration and then rebuilding it will cause the corresponding PKS resources of the configuration, that is, the PKS yaml resources used to describe the software build will also be deleted and rebuilt accordingly, which will cause service interruption during the period. Not only can the problem of invalid environment variable injection not be solved, but it will also cause more problems.

[0050] Based on this, the embodiments of the present application provide an environment variable configuration method, device, electronic device and storage medium, aiming to solve the problem of environment variable configuration failure.

[0051] The environmental variable configuration method, device, electronic device and storage medium provided in the embodiments of the present application are specifically illustrated through the following embodiments. First, the recommended method in the embodiments of the present application is described.

[0052] The environment variable configuration method provided in the embodiment of the present application relates to the field of cloud computing technology. The environment variable configuration method provided in the embodiment of the present application can be applied to a terminal, can also be applied to a server side, and can also be software running in a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or can be configured as a server cluster or a distributed system composed of multiple physical servers, and can also be configured as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the environment variable configuration method, etc., but is not limited to the above forms.

[0053] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.

[0054] It should be noted that in each specific implementation of the present application, when it comes to the need to perform relevant processing based on data related to user identity or characteristics such as user information, user behavior data, user historical data, and user location information, the user's permission or consent will be obtained first, and the collection, use, and processing of these data will comply with relevant laws, regulations, and standards. In addition, when the embodiment of the present application needs to obtain the user's sensitive personal information, the user's separate permission or consent will be obtained through a pop-up window or by jumping to a confirmation page. After clearly obtaining the user's separate permission or consent, the necessary user-related data for the normal operation of the embodiment of the present application will be obtained.

[0055] Figure 1 This is one of the flow charts of the environment variable configuration method provided in the embodiment of the present application. Figure 1 The method may include but is not limited to steps S100 to S400.

[0056] Step S100, when it is detected that a first resource configuration file is written into the memory of the container hosting platform, the first resource configuration file is intercepted, the first resource configuration file is used to update the resource configuration of the container hosting platform, and the first resource configuration file includes multiple first environment variables.

[0057] The PKS template management function uses the merge (merge difference) mechanism to manage resource configuration, that is, compare the difference between the current operation and the latest modification, and update by identifying the difference. When the environment variable name changes, the merge mechanism will identify the difference, merge the new configuration with the old configuration, and only update the difference to achieve the update. By using the PKS merge mechanism, by creating a new variable name with a difference, or creating an alias for the current variable to force the template tool to identify the difference and update, the problem of abnormal environment variable injection in the template management environment under the PKS environment can be effectively solved.

[0058] The admission controller is an important component in PKS, responsible for intercepting and verifying API requests before they reach the API Server. In this embodiment, according to the PKS specification, a custom admission controller env-patch is developed. The admission controller env-patch can intercept all resource configuration files written to PKS storage, verify and modify the resource configuration files, and compare the differences in environment variables. If there are differences, the environment variables are copied and renamed to ensure that the environment variables will not be overwritten; the admission controller env-patch assigns the renamed environment variables to the original environment variables before configuring after the resource configuration is written to the storage, so as to automatically repair the environment variables.

[0059] Specifically, the first resource configuration file is used to update the resource configuration of the container hosting platform, and the first resource configuration file includes a plurality of first environment variables.

[0060] Step S200: If the second environment variables included in the second resource configuration file configured in the container hosting platform are different from the first environment variables, the target environment variables with the difference are obtained.

[0061] Before all resource configuration files are written to PKS storage and take effect, the admission controller env-patch intercepts the write request. Then, the admission controller env-patch checks the resource configuration files. If there are differences between the environment variables in the currently applied resource configuration files and the intercepted resource configuration files, the admission controller env-patch repairs the target environment variables with differences; if there are no differences, the write request is released.

[0062] Specifically, the target environment variable satisfies one of the following: the multiple first environment variables include the target environment variable, and the multiple second environment variables do not include the target environment variable; the variable value of the target environment variable included in the multiple first environment variables is different from the variable value of the target environment variable included in the multiple second environment variables.

[0063] Step S300, copy the target environment variable to obtain a temporary environment variable.

[0064] In order to avoid losing the original environment variable value during the container creation process, the original value needs to be temporarily stored. By copying the target environment variable with differences, temporarily storing the value of the original environment variable, a temporary environment variable is obtained. This operation does not require modifying the application. The application still reads the original environment variable according to the original configuration or code, ensuring that the application can read the environment variable normally.

[0065] Step S400: After the first resource configuration file is written into the storage of the container hosting platform, the target environment variable in the first resource configuration file is replaced by the temporary environment variable.

[0066] After writing the modified resource configuration file to the storage of the container hosting platform, before resource configuration begins, the value of the original environment variable is restored through the temporary environment variable. Since the value of the original environment variable may disappear for some reason during the container creation process, the value of the environment variable is restored before the program starts through the prestart hook mechanism of PKS to ensure that the original environment variable has the correct value when the program starts.

[0067] In this embodiment, after the first resource configuration file is written into the storage of the container hosting platform, a temporary environment variable is used to replace the target environment variable in the first resource configuration file, so as to replace the resource configuration file of the container hosting platform from the second resource configuration file to the first resource configuration file, thereby realizing the update of resource configuration.

[0068] This embodiment develops an access controller plug-in to automatically identify and repair environmental variable anomalies without the need for manual operation by the user, greatly reducing the user's workload and operational risks; based on the PKS's own mechanism management and control plug-in, it has good compatibility with the existing cloud native ecological environment and can be seamlessly integrated into the existing PKS platform without modifying existing processes or applications, and existing users are basically unaware; it adopts a non-invasive repair method, without the need to delete resources or rebuild templates, and has basically no impact on services, ensuring business continuity; it adopts a plug-in architecture with strong scalability, and can add new functions or adjust repair strategies as needed, facilitating subsequent maintenance and upgrades. This embodiment effectively solves the problem of environmental variable injection anomalies in template management under the PKS environment in an automated and non-invasive manner, which can effectively improve the stability and reliability of the system.

[0069] See also Figure 2 In some embodiments, step S100 may include but is not limited to steps S110 to S120:

[0070] Step S110, when it is detected that the first resource configuration file is written into the storage of the container hosting platform, if the second resource configuration file includes a first parameter, and the parameter value of the first parameter included in the second resource configuration file is different from the parameter value of the first parameter included in the first resource configuration file, intercepting the first resource configuration file, wherein the first parameter is the first configuration parameter or the first environment variable;

[0071] Step S120: When it is detected that the first resource configuration file is written into the memory of the container hosting platform, if the second resource configuration file does not include the first parameter, the first resource configuration file is intercepted.

[0072] Specifically, the first resource configuration file includes not only a plurality of first environment variables, but also a plurality of first configuration parameters, a parameter value of each first configuration parameter, and a parameter value of each first environment variable.

[0073] In this embodiment, when the admission controller env-patch detects that a resource configuration file is to be written to the storage, it detects the resource configuration file being written, and intercepts the resource configuration file being written if the parameters of the resource configuration file being written are different from the parameters of the resource configuration file being applied.

[0074] Specifically, when it is detected that the first resource configuration file is written to the memory of the container hosting platform, if the second resource configuration file includes a first parameter, and the parameter value of the first parameter included in the second resource configuration file is different from the parameter value of the first parameter included in the first resource configuration file, the first resource configuration file is intercepted, wherein the first parameter is the first configuration parameter or the first environment variable; when it is detected that the first resource configuration file is written to the memory of the container hosting platform, if the second resource configuration file does not include the first parameter, the first resource configuration file is intercepted.

[0075] In this embodiment, by intercepting the write request of the resource configuration file, the admission controller env-patch can repair the environment variable injection exception before the resource configuration file takes effect, thereby avoiding the problem.

[0076] Figure 3 This is the second flow chart of the environment variable configuration method provided in the embodiment of the present application, such as Figure 3 As shown, the environment variable configuration method provided in the embodiment of the present application may include but is not limited to the following steps:

[0077] Step S500, if the first resource configuration file is verified according to a preset rule, the first resource configuration file is written into the memory;

[0078] Step S100, when it is detected that a first resource configuration file is written into a memory of a container hosting platform, intercepting the first resource configuration file, where the first resource configuration file is used to update resource configuration of the container hosting platform, and the first resource configuration file includes a plurality of first environment variables;

[0079] Step S200, if the second environment variables included in the second resource configuration file configured by the container hosting platform are different from the first environment variables, then obtaining the target environment variables with the difference;

[0080] Step S300, copying the target environment variable to obtain a temporary environment variable;

[0081] Step S400: After the first resource configuration file is written into the storage of the container hosting platform, the target environment variable in the first resource configuration file is replaced by the temporary environment variable.

[0082] When the admission controller env-patch detects that a resource configuration file is to be written to the storage, it verifies the resource configuration file according to the preset rules. Only resource configuration files that pass the verification can be written to the storage. The admission controller first parses the configuration file in the API request. These configuration files are usually provided in YAML or JSON format and contain the definition of the PKS object that the user wants to create or update. Then, the admission controller checks the file structure, legality, and permissions of the resource configuration file according to the preset rules. If all contents are verified, the request will be allowed to pass; if the verification fails, the request will be rejected and an error message will be returned to the user.

[0083] Specifically, the admission controller verifies the structure of the resource configuration file, such as whether the necessary fields exist, whether the field types are correct, and whether there are any format errors. The admission controller performs legitimacy checks, such as ensuring that all required fields are filled in, checking whether the field values ​​are within the allowed range (memory and CPU requests and limits), and verifying whether the field values ​​conform to the expected format (email address, URL, or string in a specific format). The admission controller performs business logic validation, such as ensuring that the requested resources do not exceed the quota of the namespace or cluster, checking whether the object name conforms to the organization's naming conventions, and ensuring that the object has the necessary labels and annotations. The admission controller can also check whether the user or service account that initiates the request has permission to create or modify the object. In addition, a custom admission controller can execute specific business logic, such as verifying whether the environment variables in the configuration file contain sensitive information.

[0084] In one implementation of this embodiment, the admission controller env-patch needs to verify whether the file name of the resource configuration file is legal, whether the creation time is within the validity period, whether the environment variable name included in the resource configuration file is correct, whether the environment variables match the container hosting platform, check whether the variable value of the environment variable is within the corresponding value range, and verify whether the field value conforms to the expected format.

[0085] This embodiment verifies resource configuration files through the admission controller, which can avoid service interruptions or security issues caused by incorrect configuration, check whether the configuration files contain sensitive information, and intercept them before they are deployed to the cluster. The admission controller can automatically modify resources when they are created, such as adding default settings or configurations to reduce manual operations; or you can write a custom admission controller according to specific needs to implement personalized verification logic. This ensures that the configuration of resources meets security, compliance, and operating standards, and improves the stability and reliability of the entire cluster.

[0086] Figure 4 This is the third flow chart of the environment variable configuration method provided in the embodiment of the present application, such as Figure 4 As shown, the environment variable configuration method provided in the embodiment of the present application may include but is not limited to the following steps:

[0087] Step S100, when it is detected that a first resource configuration file is written into a memory of a container hosting platform, intercepting the first resource configuration file, where the first resource configuration file is used to update resource configuration of the container hosting platform, and the first resource configuration file includes a plurality of first environment variables;

[0088] Step S600, traversing the multiple environment variable files in the first resource configuration file in sequence to obtain the multiple first environment variables;

[0089] Step S200, if the second environment variables included in the second resource configuration file configured by the container hosting platform are different from the first environment variables, then obtaining the target environment variables with the difference;

[0090] Step S300, copying the target environment variable to obtain a temporary environment variable;

[0091] Step S400: After the first resource configuration file is written into the storage of the container hosting platform, the target environment variable in the first resource configuration file is replaced by the temporary environment variable.

[0092] The admission controller env-patch needs to determine the storage location of the environment variables in the configuration file. The environment variables are the contents of the env part in the PKS software resource definition file, that is, the system environment variables that take effect in the container. The admission controller scans the first resource configuration file, traverses each environment variable file in the first resource configuration file, and obtains all the environment variables contained in the first resource configuration file.

[0093] This embodiment traverses all environment variables to obtain information of all environment variables in the resource configuration file, ensuring that all environment variables are identified and extracted, thereby providing a data basis for subsequent difference detection and copying of target environment variables.

[0094] Figure 5 This is the fourth flow chart of the environment variable configuration method provided in the embodiment of the present application, such as Figure 5 As shown, the environment variable configuration method provided in the embodiment of the present application may include but is not limited to the following steps:

[0095] Step S100, when it is detected that a first resource configuration file is written into a memory of a container hosting platform, intercepting the first resource configuration file, where the first resource configuration file is used to update resource configuration of the container hosting platform, and the first resource configuration file includes a plurality of first environment variables;

[0096] Step S200, if the second environment variables included in the second resource configuration file configured by the container hosting platform are different from the first environment variables, then obtaining the target environment variables with the difference;

[0097] Step S310, copying the target environment variable and renaming the copied target environment variable to obtain the temporary environment variable;

[0098] Step S310 is a specific implementation of step S300.

[0099] Step S400: After the first resource configuration file is written into the storage of the container hosting platform, the target environment variable in the first resource configuration file is replaced by the temporary environment variable.

[0100] In this embodiment, the target environment variable is copied and renamed, and the renamed temporary environment variable is used to temporarily store the original environment variable value. The purpose of renaming the copied target environment variable is to temporarily store and restore the value of the original environment variable safely, ensuring that the application can read the environment variable normally. Because the solution does not modify the application, the application still reads the original environment variable according to the original configuration or code, but at this time the value of the original environment variable has been saved through the temporary environment variable, and there will be no problems due to the loss of value when creating the container.

[0101] In one implementation of this embodiment, a PATCH_ prefix is ​​added to the target environment variable name to obtain a temporary environment variable. Then, through the prestart hook mechanism, the value of the target environment variable is restored before the program starts to ensure that the application can read the correct environment variable normally. The prestart resource is a PKS resource definition, corresponding to the PKSprestart hook mechanism. After PKS creates the container according to the software resource definition but before starting the program, the script or program defined in prestart is executed first. It is generally used to make some custom modifications before the software starts.

[0102] Specifically, this embodiment adds an export command in the prestart resource to assign the variable value prefixed with PATCH_ to the original variable name: export original variable name = $PATCH_original variable name, thereby ensuring that the original variable has a value when the resource is configured.

[0103] This embodiment can temporarily store the value of the target environment variable in a temporary environment variable by copying the target environment variable and renaming it. By adding a script to the prestart resource, the value of the temporary environment variable can be assigned to the target environment variable before the program starts, ensuring that the correct environment variable value can be obtained when the program starts, thereby avoiding the program from failing to run normally due to failed environment variable injection.

[0104] Figure 6 This is the fifth flow chart of the environment variable configuration method provided in the embodiment of the present application, such as Figure 6 As shown, the environment variable configuration method provided in the embodiment of the present application may include but is not limited to the following steps:

[0105] Step S100, when it is detected that a first resource configuration file is written into a memory of a container hosting platform, intercepting the first resource configuration file, where the first resource configuration file is used to update resource configuration of the container hosting platform, and the first resource configuration file includes a plurality of first environment variables;

[0106] Step S200, if the second environment variables included in the second resource configuration file configured by the container hosting platform are different from the first environment variables, then obtaining the target environment variables with the difference;

[0107] Step S300, copying the target environment variable to obtain a temporary environment variable;

[0108] Step S410, after writing the first resource configuration file into the storage of the container hosting platform, if the variable value of the target environment variable is a preset value, the target environment variable in the first resource configuration file is replaced by the temporary environment variable.

[0109] Step S410 is a specific implementation of step S400.

[0110] In one implementation of this embodiment, after the first resource configuration file is written into the storage of the container hosting platform, if the variable value of the target environment variable is a preset value, a temporary environment variable is used to replace the target environment variable in the first resource configuration file. Specifically, the preset value is 0, that is, when the value of the target environment variable becomes 0, it means that the injection of the target environment variable fails. By replacing the target environment variable with the temporary environment variable, the environment variable can obtain the correct value during resource configuration, effectively solving the problem of injection failure of environment variables in the template management environment under the PKS environment.

[0111] The embodiment of the present application uses a custom admission controller to intercept the resource configuration file before it is written to the storage and verify the resource configuration file; according to the verification result, if the environment variables in the resource configuration file are consistent with the environment variables being applied, the resource configuration file is directly written to the storage system; if the environment variables change, the environment variables with differences are copied, and the copied environment variables are renamed to obtain temporary environment variables; after the resource configuration file is written to the storage and before the container is configured, the written environment variables are replaced with temporary environment variables through the prestart resource, thereby ensuring that the environment variable values ​​can be correctly injected into the container and solving the problem of invalid environment variable configuration. The embodiment of the present application utilizes the PKS's own mechanism to manage and control plug-ins, develops an access controller plug-in, automatically identifies and repairs abnormal environment variables, and does not require manual operation by the user, greatly reducing the user's workload and operational risks; based on the PKS's own mechanism to manage and control plug-ins, it has good compatibility with the existing cloud native ecological environment and can be seamlessly integrated into the existing PKS platform without modifying existing processes or applications, and existing users are basically unaware; it adopts a non-invasive repair method, does not require deleting resources or rebuilding templates, and has basically no impact on services, ensuring business continuity; it adopts a plug-in architecture with strong scalability, and can add new functions or adjust repair strategies as needed, facilitating subsequent maintenance and upgrades. This embodiment effectively solves the problem of abnormal environment variable injection in template management under the PKS environment in an automated and non-invasive manner, and can effectively improve the stability and reliability of the system.

[0112] See also Figure 7 The embodiment of the present application also provides an environment variable configuration device, which can implement the above-mentioned environment variable configuration method, and the device includes:

[0113] An interception module 10 is used to intercept the first resource configuration file when it is detected that the first resource configuration file is written into the storage of the container hosting platform, wherein the first resource configuration file is used to update the resource configuration of the container hosting platform, and the first resource configuration file includes a plurality of first environment variables;

[0114] A detection module 20 is configured to obtain a target environment variable with a difference if a plurality of second environment variables included in a second resource configuration file configured by the container hosting platform differ from the plurality of first environment variables; wherein the plurality of first environment variables include the target environment variable, and the plurality of second environment variables do not include the target environment variable; and a variable value of the target environment variable included in the plurality of first environment variables is different from a variable value of the target environment variable included in the plurality of second environment variables;

[0115] A copy module 30, used for copying the target environment variable to obtain a temporary environment variable;

[0116] The replacement module 40 is used to replace the target environment variables in the first resource configuration file with the temporary environment variables after the first resource configuration file is written into the storage of the container hosting platform.

[0117] In some embodiments, the interception module 10 may include:

[0118] A first interception unit is configured to intercept the first resource configuration file if it is detected that the first resource configuration file is written to the memory of the container hosting platform, if the second resource configuration file includes a first parameter, and the parameter value of the first parameter included in the second resource configuration file is different from the parameter value of the first parameter included in the first resource configuration file, wherein the first parameter is the first configuration parameter or the first environment variable; wherein the first resource configuration file further includes multiple first configuration parameters, the parameter value of each of the first configuration parameters, and the parameter value of each of the first environment variables;

[0119] The second interception unit is used to intercept the first resource configuration file if it is detected that the first resource configuration file is written into the memory of the container hosting platform and if the second resource configuration file does not include the first parameter.

[0120] In some embodiments, the interception module 10 may further include:

[0121] The third interception unit is configured to write the first resource configuration file into the memory if the first resource configuration file is verified according to a preset rule.

[0122] In some embodiments, the interception module 10 may further include:

[0123] The traversal unit is used to traverse the multiple environment variable files in the first resource configuration file in sequence to obtain multiple first environment variables.

[0124] In some embodiments, the replication module 30 may include:

[0125] The renaming unit is used to copy the target environment variable and rename the copied target environment variable to obtain the temporary environment variable.

[0126] In some embodiments, the replacement module 40 may include:

[0127] A replacement unit is used to replace the target environment variable in the first resource configuration file with the temporary environment variable after writing the first resource configuration file into the storage of the container hosting platform if the variable value of the target environment variable is a preset value.

[0128] The specific implementation of the environment variable configuration device is basically the same as the specific implementation of the above-mentioned environment variable configuration method, and will not be repeated here.

[0129] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above-mentioned environment variable configuration method when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.

[0130] See also Figure 8 , Figure 8 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:

[0131] The processor 801 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;

[0132] The memory 802 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 802 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 802, and the processor 801 calls and executes the environment variable configuration method of the embodiment of this application;

[0133] Input / output interface 803, used to implement information input and output;

[0134] The communication interface 804 is used to realize the communication interaction between the device and other devices. The communication can be realized through a wired manner (such as USB, network cable, etc.) or a wireless manner (such as mobile network, WI FI, Bluetooth, etc.);

[0135] A bus 805 that transmits information between the various components of the device (e.g., the processor 801, the memory 802, the input / output interface 803, and the communication interface 804);

[0136] The processor 801 , the memory 802 , the input / output interface 803 and the communication interface 804 are connected to each other in communication within the device via a bus 805 .

[0137] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the above-mentioned environment variable configuration method is implemented.

[0138] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0139] The environment variable configuration method, environment variable configuration device, electronic device and storage medium provided by the embodiment of the present application divide the area and configure the corresponding function management interface and administrator for each area; the administrator can set different functions for different areas and control the switch through the background interface; the administrator can also group functions according to business needs and adjust the overall or individual listing status of the function; when the configuration changes, the system will synchronize and push the new configuration to the client, and the front end will dynamically display or hide the function according to the configuration; in addition, the system records the function configuration and usage through logs and monitoring, which is convenient for the administrator to view and analyze, and handle abnormal situations in a timely manner. The present application simplifies the function launch and management process, improves work efficiency, and can perform differentiated configuration of functions according to the needs of users in different areas to meet the personalized needs of users.

[0140] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0141] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.

[0142] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0143] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.

[0144] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0145] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0146] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0147] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0148] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0149] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.

[0150] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.

Claims

1. A method for configuring an environment variable, characterized in that: The method comprises: When it is detected that a first resource configuration file is written into a storage of the container hosting platform, intercepting the first resource configuration file, where the first resource configuration file is used to update resource configuration of the container hosting platform, and the first resource configuration file includes a plurality of first environment variables; If the plurality of second environment variables included in the second resource configuration file configured by the container hosting platform are different from the plurality of first environment variables, obtaining the target environment variables with the difference; Copying the target environment variable to obtain a temporary environment variable; After the first resource configuration file is written into the storage of the container hosting platform, the target environment variable in the first resource configuration file is replaced by the temporary environment variable.

2. The method according to claim 1, characterized in that The first resource configuration file further includes a plurality of first configuration parameters, a parameter value of each of the first configuration parameters, and a parameter value of each of the first environment variables; The method of intercepting the first resource configuration file when it is detected that the first resource configuration file is written into the storage of the container hosting platform includes: In a case where it is detected that the first resource configuration file is written to the storage of the container hosting platform, if the second resource configuration file includes a first parameter, and the parameter value of the first parameter included in the second resource configuration file is different from the parameter value of the first parameter included in the first resource configuration file, intercepting the first resource configuration file, wherein the first parameter is the first configuration parameter or the first environment variable; In a case where it is detected that the first resource configuration file is written to the memory of the container hosting platform, if the second resource configuration file does not include the first parameter, the first resource configuration file is intercepted.

3. The method according to claim 1, characterized in that The target environment variable satisfies one of the following: The plurality of first environment variables include the target environment variable, and the plurality of second environment variables do not include the target environment variable; The variable values ​​of the target environment variables included in the plurality of first environment variables are different from the variable values ​​of the target environment variables included in the plurality of second environment variables.

4. The method according to claim 1, characterized in that: In the case where it is detected that the first resource configuration file is written into the memory of the container hosting platform, before intercepting the first resource configuration file, the method further includes: If the first resource configuration file is verified according to a preset rule, the first resource configuration file is written into the memory.

5. The method according to claim 1, characterized in that In the case where it is detected that the first resource configuration file is written to the memory of the container hosting platform, after intercepting the first resource configuration file, if a plurality of second environment variables included in a second resource configuration file configured by the container hosting platform differ from the plurality of first environment variables, before obtaining the target environment variables with the difference, the method further includes: The multiple environment variable files in the first resource configuration file are traversed in sequence to obtain the multiple first environment variables.

6. The method according to claim 1, characterized in that The step of copying the target environment variable to obtain a temporary environment variable includes: The target environment variable is copied, and the copied target environment variable is renamed to obtain the temporary environment variable.

7. The method according to claim 1, characterized in that After writing the first resource configuration file into the storage of the container hosting platform, replacing the target environment variable in the first resource configuration file with the temporary environment variable includes: After the first resource configuration file is written into the storage of the container hosting platform, if the variable value of the target environment variable is a preset value, the target environment variable in the first resource configuration file is replaced by the temporary environment variable.

8. An environment variable configuration device, characterized in that: The device comprises: an interception module, configured to intercept a first resource configuration file when detecting that the first resource configuration file is written into a storage of the container hosting platform, wherein the first resource configuration file is used to update resource configuration of the container hosting platform, and the first resource configuration file includes a plurality of first environment variables; A detection module, configured to obtain a target environment variable with a difference if a plurality of second environment variables included in a second resource configuration file configured on the container hosting platform differ from the plurality of first environment variables; A copy module, used for copying the target environment variable to obtain a temporary environment variable; A replacement module is used to replace the target environment variable in the first resource configuration file with the temporary environment variable after the first resource configuration file is written into the storage of the container hosting platform.

9. An electronic device, characterized in that: The electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the environmental variable configuration method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the environment variable configuration method according to any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Multi-domain environment construction method and device based on PKS and storage medium

    CN120315780A

  • PKS-based multi-domain environment construction method, device and storage medium

    CN120315780B