remotefs_kube/
lib.rs

1#![crate_name = "remotefs_kube"]
2#![crate_type = "lib"]
3#![cfg_attr(docsrs, feature(doc_cfg))]
4
5//! # remotefs-kube
6//!
7//! remotefs-kube is a client implementation for [remotefs](https://github.com/remotefs-rs/remotefs-rs), providing support for the Kube API protocol.
8//!
9//! ## Get started
10//!
11//! First of all you need to add **remotefs** and the client to your project dependencies:
12//!
13//! ```toml
14//! remotefs = "^0.3"
15//! remotefs-kube = "^0.4"
16//! ```
17//!
18//! these features are supported:
19//!
20//! - `find`: enable `find()` method for RemoteFs. (*enabled by default*)
21//! - `no-log`: disable logging. By default, this library will log via the `log` crate.
22//!
23//!
24//! ### Kube multi pod client
25//!
26//! The MultiPod client gives access to all the pods with their own containers in a namespace.
27//!
28//! This client creates an abstract file system with the following structure
29//!
30//! - / (root)
31//!   - pod-a
32//!     - container-a
33//!       - / (container-a root)
34//!         - /bin
35//!         - /home
36//!         - ...
37//!     - container-b
38//!       - / (container-b root)
39//!         - ...
40//!   - pod-b
41//!     - container-c
42//!       - / (container-c root)
43//!         - ...
44//!
45//! So paths have the following structure: `/pod-name/container-name/path/to/file`.
46//!
47//! ```rust,ignore
48//!
49//! // import remotefs trait and client
50//! use remotefs::RemoteFs;
51//! use remotefs_kube::KubeMultiPodFs;
52//! use std::path::Path;
53//!
54//! let rt = Arc::new(
55//!     tokio::runtime::Builder::new_current_thread()
56//!     .enable_all()
57//!     .build()
58//!     .unwrap(),
59//! );
60//! let mut client: KubeMultiPodFs = KubeMultiPodFs::new(&rt);
61//!
62//! // connect
63//! assert!(client.connect().is_ok());
64//! // get working directory
65//! println!("Wrkdir: {}", client.pwd().ok().unwrap().display());
66//! // change working directory
67//! assert!(client.change_dir(Path::new("/my-pod/alpine/tmp")).is_ok());
68//! // disconnect
69//! assert!(client.disconnect().is_ok());
70//! ```
71//!
72//! ### Kube container client
73//!
74//! Here is a basic usage example, with the `KubeContainerFs` client, which is used to connect and interact with a single container on a certain pod. This client gives the entire access to the container file system.
75//!
76//! ```rust,ignore
77//!
78//! // import remotefs trait and client
79//! use remotefs::RemoteFs;
80//! use remotefs_kube::KubeContainerFs;
81//! use std::path::Path;
82//!
83//! let rt = Arc::new(
84//!     tokio::runtime::Builder::new_current_thread()
85//!     .enable_all()
86//!     .build()
87//!     .unwrap(),
88//! );
89//! let mut client: KubeContainerFs = KubeContainerFs::new("my-pod", "container-name", &rt);
90//!
91//! // connect
92//! assert!(client.connect().is_ok());
93//! // get working directory
94//! println!("Wrkdir: {}", client.pwd().ok().unwrap().display());
95//! // change working directory
96//! assert!(client.change_dir(Path::new("/tmp")).is_ok());
97//! // disconnect
98//! assert!(client.disconnect().is_ok());
99//! ```
100//!
101
102#![doc(html_playground_url = "https://play.rust-lang.org")]
103#![doc(
104    html_favicon_url = "https://raw.githubusercontent.com/remotefs-rs/remotefs-rs/main/assets/logo-128.png"
105)]
106#![doc(
107    html_logo_url = "https://raw.githubusercontent.com/remotefs-rs/remotefs-rs/main/assets/logo.png"
108)]
109
110// -- common deps
111#[macro_use]
112extern crate lazy_regex;
113#[macro_use]
114extern crate log;
115
116mod kube_container_fs;
117mod kube_multipod_fs;
118mod utils;
119
120pub use kube::Config;
121pub use kube_container_fs::KubeContainerFs;
122pub use kube_multipod_fs::KubeMultiPodFs;
123
124// -- test logging
125#[cfg(test)]
126pub fn log_init() {
127    let _ = env_logger::builder()
128        .is_test(true)
129        .filter_module("remotefs_kube", log::LevelFilter::Debug)
130        .try_init();
131}