CN115048187A - Operator-based pvc file importing method, device and storage medium - Google Patents

Operator-based pvc file importing method, device and storage medium Download PDF

Info

Publication number
CN115048187A
CN115048187A CN202210743830.8A CN202210743830A CN115048187A CN 115048187 A CN115048187 A CN 115048187A CN 202210743830 A CN202210743830 A CN 202210743830A CN 115048187 A CN115048187 A CN 115048187A
Authority
CN
China
Prior art keywords
import
file
pod
pvc
operator
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210743830.8A
Other languages
Chinese (zh)
Inventor
黄芳凤
尹大力
赵凯麟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Asean Information Harbor Co ltd
Original Assignee
China Asean Information Harbor Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Asean Information Harbor Co ltd filed Critical China Asean Information Harbor Co ltd
Priority to CN202210743830.8A priority Critical patent/CN115048187A/en
Publication of CN115048187A publication Critical patent/CN115048187A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/955Retrieval from the web using information identifiers, e.g. uniform resource locators [URL]
    • G06F16/9566URL specific, e.g. using aliases, detecting broken or misspelled links

Abstract

The invention discloses a method, equipment and a storage medium for importing a pvc file based on Operator, which belong to the technical field of computers and solve the technical problem that data cannot be automatically imported into the pvc which is not mounted at present, wherein the method comprises the following steps: initializing an application cluster, creating cr resources, operating the cr in an Operator rotation training environment, detecting the current cr, creating an import pod for mounting a pvc, binding the import pod to a corresponding node of the pvc, checking the import pod, executing a file transmission operation after the import pod state is Running, converting a file into a data stream, transmitting the data stream to a pvc path relative path mounted in the import pod, setting the resource state as success and deleting the import pod after the file transmission is finished.

Description

Operator-based pvc file importing method, device and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to an Operator-based pvc file importing method, device and storage medium.
Background
kubernets (k8s) is a distributed architecture solution based on container technology for managing containerized workloads and services. Persistentvolume (PV) is a block of storage space in an external storage system, has persistence and has a life cycle independent of Pod. PersistentVolumeClaim (pvc) is an application for PV (Claim). When a storage resource needs to be allocated to a Pod, a user may create a pvc indicating information such as the size of the storage resource and the access mode, and k8s may search for and provide a PV satisfying the condition. In most application scenarios, a user needs to apply for pvc first and then mount the pvc to a k8s container for use, and the user is likely to face a problem during use. However, in the existing scheme, there is no method for importing data into the uninstalled pvc in an automatic and general way.
Disclosure of Invention
The present invention is directed to solve the foregoing problems of the prior art, and an object of the present invention is to provide an Operator-based pvc file importing method, which can automatically import data into an unmounted pvc.
The invention also aims to provide computer equipment.
The invention also provides a computer readable storage medium.
In order to achieve the first purpose, the invention provides an Operator-based pvc file importing method, which comprises the following steps:
s1, initializing an application cluster, and creating a related custom resource CRD and a custom Controller in an Operator expansion mode for providing a pvc file import function;
s2, creating cr resources, wherein cr is a custom resource instance corresponding to crd, one instance corresponds to a file import task, and file import requirement parameters are defined in the cr specification and comprise: importing an object pvc name, a name space, a file source and a path parameter, wherein the file source can be a file server path url or a local file path;
s3, operator rounds cr in the environment, monitoring the change of the user-defined resource and triggering coordination logic;
s4, detecting the current cr, and checking the correctness of the imported object pvc name, the name space, the file source and the path parameter; creating an import pod for mounting the pvc; transmitting the source import file to the pvc mounted on the pod in a k8s apiserver manner;
s5, checking whether an import pod exists, wherein the import pod is a container named as a container with pvc identification under a specified name space; if the import pod exists, checking whether the import pod state is normal, if the import pod state is abnormal, setting the resource state as Failed, recording the failure reason, and deleting the import pod; if the import pod exists and is normal, but the import time is overtime, setting the resource state as Failed, recording the failure reason, and deleting the import pod;
step S6, if the import pod does not exist, creating a container with a pvc identifier under a specified name space, mounting the pvc to the import pod for use, and waiting for the import pod to be created and have a Running state;
s7, if the import pod is Failed to be created or the state is overtime, setting the resource state as Failed, recording the reason of the failure and deleting the import pod;
s8, if the local path file is the local path file, mounting the local path to an import pod in a hostpath mode, and if the local path file is the url mode, downloading the file to an operator controller pod;
s9, after waiting for the import pod state to be Running, if the source address is url, executing a file transmission operation, wherein the file transmission operation accesses the container through the kube-api server, the file is converted into a data stream, the data stream contains file attributes and authority contents, and the data stream is transmitted from the pod of the operator controller to a pvc path relative path mounted in the import pod; if the source address is in the mode of the native path, copying a source file of the mounted native path into a pvc path relative path in the import pod by sending a copy command;
step S10, in order to adapt to the mounted pvc condition, if the mounted pvc has a file, the import pod is also bound to the node bound with the pvc, if there are a plurality of pods bound by the pvc, one of the pods is selected to determine the bound node; if the pvc is not mounted with the file, preferentially selecting the node where the controller pod is located as a binding node;
and S11, after the file is transmitted, setting the resource state as success, and deleting the import pod.
As a further improvement, the method further comprises a step S12 of setting a cleaning operation for the completed and successful cr instance according to operator configuration; and for the failed cr instance, the cleaning operation is not executed, so that the user can conveniently confirm the failure reason after the failure, and the user can clean the failed instance by self.
Further, in step S12, three cleaning operations may be selected: cleaning is carried out immediately after a certain time, and cleaning is not carried out forever.
Further, step S13 is included, which is to establish an association in the Operator, and delete crd resources when deleting the corresponding import pod.
Further, in step S1, the imported object is any pvc with read-write rights, and the imported file originates from any file server providing a file download service or from the host path file; the import path is the opposite path within the pvc.
Further, in step S4, the parameter check passes through creating an admission control webhook, including changing the admission control mutatingdissionwebhook, and verifying the admission control validatingaddissionwebhook.
Further, in step S6, the wait timeout time is set to 60S.
In order to achieve the second objective, the invention provides a computer device, comprising a memory, a processor; the memory is used for storing a computer program; the processor is used for executing the computer program to realize the above Operator-based pvc file import method.
In order to achieve the third objective, the present invention provides a computer-readable storage medium, which stores thereon a computer program, which when executed by a processor is configured to implement an Operator-based pvc file import method as described above.
Advantageous effects
Compared with the prior art, the invention has the advantages that:
according to the invention, a series of operations for importing the pvc file are encapsulated in an Operator expansion mode, complex operations and states are managed, the cloud native mode is better met, data is automatically imported into the unmounted pvc in an Operator CRD self-defined resource expansion mode, the CRD object can be deployed in a k8s cluster, and adaptation work is not required to be added.
Drawings
FIG. 1 is a flow chart of a method of the present invention;
FIG. 2 is a flow chart of the cleaning operation of the present invention.
Detailed Description
The invention will be further described with reference to specific embodiments shown in the drawings.
Referring to fig. 1 and 2, an Operator-based pvc file import method includes:
s1, initializing an application cluster, and creating a related custom resource CRD (custom resource definition) and a custom Controller in an Operator extension mode for providing a pvc file import function; the imported object is any pvc with read-write authority, and the imported file is from any file server providing file downloading service or from host path file; the import path is a relative path within the pvc; the custom controller runs in k8s in a Deployment manner;
step S2. the user creates cr resources in the Kubernetes cluster,
Figure BDA0003716333270000051
cr is a self-defined resource instance corresponding to crd, one instance corresponds to a file import task, and the cr specification defines file import requirement parameters, wherein the requirement parameters include: importing the name and the name space of an object pvc, a file source and path parameters, wherein the file source can be a file server path url, such as http://127.0.0.1/package/test.tar, or a local file path, such as/package/test.tar;
s3, operator rounds cr in the environment, monitoring the change of the user-defined resource and triggering coordination logic;
s4, detecting the current cr, and checking the correctness of the imported object pvc name, the name space, the file source and the path parameter; creating an import pod for mounting the pvc; transmitting the source import file to the pvc mounted on the pod in a k8s apiserver manner; the parameter verification is realized by creating an admission control webhook, including changing the admission control mutatingdissionwebhook and verifying the admission control validatingwebhook;
step S5, checking whether an import pod exists, wherein the import pod is a container named as a container with pvc identification under a specified namespace, such as tmp-import- { namespace } - { pvcname }; if the import pod exists, checking whether the import pod state is normal, if the import pod state is abnormal, setting the resource state as Failed, recording the failure reason, and deleting the import pod; if the import pod exists and is normal, but the import time is overtime (preset for 30min), setting the resource state as Failed, recording the failure reason, and deleting the import pod;
step S6, if the import pod does not exist, creating a container with a pvc identifier under a specified namespace, and mounting the pvc identifier to the import pod for use, wherein the mounting path is as follows: the/tmp-upload-target waits for the import pod to be created and has a Running state; setting the waiting timeout time to be 60 s;
s7, if the import pod is Failed to be created or the state is overtime, setting the resource state as Failed, recording the reason of the failure and deleting the import pod;
s8, if the path file is the local path file, mounting the local path into the import pod in a hostpath mode, wherein the mounting path is as follows: if the/tmp-upload-source is in the url mode, downloading the file to the operator controller pod first, wherein the path is as follows: tmp-upload-source;
step S9, after waiting for the import pod status to Running, if the source address is url, executing a file transmission operation, wherein the file transmission operation accesses the container through the kube-api server, the file is converted into a data stream, the data stream contains file attributes and authority content (realized by referring to kutectlcp), and the data stream is transmitted from the pod of the operator controller to the pvc path relative path mounted in the import pod: tmp-upload-target/{ destPath }; if the source address is in the mode of the native path, copying a source file of the mounted native path into the pvc path relative path in the import pod by sending a copy command: a/tmp-upload-source to/tmp-upload-target/{ destPath };
s10, in order to adapt to the mounted pvc condition, if the mounted pvc has a file, an import pod is also bound to the node bound with the pvc, and if there are a plurality of pods bound by the pvc, one of the pods is selected to determine the bound node; if the pvc is not mounted with the file, preferentially selecting the node where the controller pod is located as a binding node;
s11, setting the resource state as success and deleting the import pod after the file transmission is finished;
s12, setting cleaning operation on the completed and successful cr instances according to operator configuration; for the failed cr instance, the cleaning operation is not executed, so that a user can conveniently confirm the reason of the failure after the failure, and the user can clean the failed instance by himself; three cleaning operations can be selected: cleaning is carried out for a certain time, and cleaning is carried out immediately after the cleaning is successful and never carried out;
and S13, establishing association in the Operator, and deleting corresponding import pod when crd resources are deleted. The automatic import of data into the unmounted pvc is completed.
A computer device comprising a memory, a processor; the memory is used for storing a computer program; the processor is used for executing the computer program to realize the Operator-based pvc file import method.
A computer-readable storage medium, on which a computer program is stored, the computer program, when executed by a processor, is configured to implement an Operator-based pvc file import method as described above.
The above is only a preferred embodiment of the present invention, and it should be noted that it is obvious to those skilled in the art that several variations and modifications can be made without departing from the structure of the present invention, which will not affect the effect of the implementation of the present invention and the utility of the patent.

Claims (9)

1. An Operator-based pvc file import method, comprising:
s1, initializing an application cluster, and creating a related custom resource CRD and a custom Controller in an Operator expansion mode for providing a pvc file import function;
s2, creating cr resources, wherein cr is a custom resource instance corresponding to crd, one instance corresponds to a file import task, and file import requirement parameters are defined in the cr specification and comprise: importing an object pvc name, a name space, a file source and a path parameter, wherein the file source can be a file server path url or a local file path;
s3, operator rounds cr in the environment, monitoring the change of the user-defined resource and triggering coordination logic;
s4, detecting the current cr, and checking the correctness of the imported object pvc name, the name space, the file source and the path parameter; creating an import pod for mounting the pvc; transmitting the source import file to the pvc mounted on the pod in a k8s apiserver manner;
s5, checking whether an import pod exists, wherein the import pod is a container named as a container with pvc identification under a specified name space; if the import pod exists, checking whether the import pod state is normal, if the import pod state is abnormal, setting the resource state as Failed, recording the failure reason, and deleting the import pod; if the import pod exists and is normal, but the import time is overtime, setting the resource state as Failed, recording the failure reason, and deleting the import pod;
step S6, if the import pod does not exist, creating a container with a pvc identifier under a specified name space, mounting the pvc to the import pod for use, and waiting for the import pod to be created and have a Running state;
s7, if the import pod is Failed to be created or the state is overtime, setting the resource state as Failed, recording the reason of the failure and deleting the import pod;
s8, if the local path file is the local path file, mounting the local path to an import pod in a hostpath mode, and if the local path file is the url mode, downloading the file to an operator controller pod;
s9, after waiting for the import pod state to be Running, if the source address is url, executing a file transmission operation, wherein the file transmission operation accesses the container through the kube-api server, the file is converted into a data stream, the data stream contains file attributes and authority contents, and the data stream is transmitted from the pod of the operator controller to a pvc path relative path mounted in the import pod; if the source address is in the mode of the native path, copying a source file of the mounted native path into a pvc path relative path in the import pod by sending a copy command;
step S10, in order to adapt to the mounted pvc condition, if the mounted pvc has a file, the import pod is also bound to the node bound with the pvc, if there are a plurality of pods bound by the pvc, one of the pods is selected to determine the bound node; if the pvc is not mounted with the file, preferentially selecting the node where the controller pod is located as a binding node;
and S11, after the file is transmitted, setting the resource state as success, and deleting the import pod.
2. The Operator-based pvc file import method according to claim 1, further comprising step S12, setting a clean-up operation for the completed and successful cr instance according to Operator configuration; and for the failed cr instance, the cleaning operation is not executed, so that the user can conveniently confirm the failure reason after the failure, and the user can clean the failed instance by self.
3. The Operator-based pvc file import method according to claim 2, wherein in step S12, three clean-up operations can be selected: cleaning is carried out immediately after a certain time, and cleaning is not carried out forever.
4. The Operator-based pvc file import method according to claim 1, further comprising step S13, establishing association in Operator, and deleting crd resource, which deletes corresponding import pod.
5. The Operator-based pvc file import method according to claim 1, wherein in step S1, the imported object is any pvc file with read-write right, and the imported file originates from any file server providing file download service or from host path file; the import path is a relative path within the pvc.
6. The Operator-based pvc file importing method according to claim 1, wherein in step S4, the parameter check passes creating an admission control webhook, including changing the admission control mutatingdissionwebhook and verifying the admission control validatingwebhook.
7. The Operator-based pvc file import method according to claim 1, wherein in step S6, the waiting timeout period is set to 60S.
8. A computer device comprising a memory, a processor; the memory is used for storing a computer program; the processor is configured to execute the computer program to implement an Operator-based pvc file import method according to any one of claims 1 to 7.
9. A computer-readable storage medium, on which a computer program is stored, the computer program, when being executed by a processor, is configured to implement an Operator-based pvc file import method according to any one of claims 1 to 7.
CN202210743830.8A 2022-06-27 2022-06-27 Operator-based pvc file importing method, device and storage medium Pending CN115048187A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210743830.8A CN115048187A (en) 2022-06-27 2022-06-27 Operator-based pvc file importing method, device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210743830.8A CN115048187A (en) 2022-06-27 2022-06-27 Operator-based pvc file importing method, device and storage medium

Publications (1)

Publication Number Publication Date
CN115048187A true CN115048187A (en) 2022-09-13

Family

ID=83163753

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210743830.8A Pending CN115048187A (en) 2022-06-27 2022-06-27 Operator-based pvc file importing method, device and storage medium

Country Status (1)

Country Link
CN (1) CN115048187A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115357198A (en) * 2022-10-19 2022-11-18 苏州浪潮智能科技有限公司 Mounting method and device of storage volume, storage medium and electronic equipment

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115357198A (en) * 2022-10-19 2022-11-18 苏州浪潮智能科技有限公司 Mounting method and device of storage volume, storage medium and electronic equipment

Similar Documents

Publication Publication Date Title
US11481244B2 (en) Methods and systems that verify endpoints and external tasks in release-pipeline prior to execution
US20220078092A1 (en) Provisioning a service
CN110162345B (en) Application program access method and device and storage medium
EP2989543B1 (en) Method and device for updating client
US10002054B2 (en) Method and system for performing automatic system recovery
CN107896162B (en) Deployment method and device of monitoring system, computer equipment and storage medium
US11363117B2 (en) Software-specific auto scaling
CN112333096A (en) Micro-service traffic scheduling method and related components
CN110673923A (en) XWIKI system configuration method, system and computer equipment
CN109558260A (en) Kubernetes troubleshooting system, method, equipment and medium
CN114553960A (en) Data caching method, device, equipment and storage medium
US20050108704A1 (en) Software distribution application supporting verification of external installation programs
CN115048187A (en) Operator-based pvc file importing method, device and storage medium
CN115357198B (en) Mounting method and device of storage volume, storage medium and electronic equipment
CN117041111A (en) Vehicle cloud function test method and device, electronic equipment and storage medium
CN109495298B (en) Method and device for managing nodes in OpenStack system
CN110502238A (en) A kind of method and device of front and back end joint debugging
CN114860203A (en) Project creation method, project creation device, server and storage medium
JP3543683B2 (en) Automatic document creation system, automatic document creation method, and recording medium recording automatic document creation program
CN110968888B (en) Data processing method and device
CN105843881A (en) Picture processing url mapping method and apparatus
CN113741912A (en) Model management system, method, device and equipment
US20110023018A1 (en) Software platform and method of managing application individuals in the software platform
CN114661256B (en) Data acquisition method, device, equipment and storage medium
US20220109630A1 (en) Check-In Monitoring For Workflows

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination