### Install mise and Setup kftray Development Environment Source: https://github.com/hcavarsan/kftray/blob/main/README.md Installs mise, clones the kftray repository, installs development tools, sets up dependencies, and starts the development server. ```bash # Install mise curl https://mise.run | sh # Clone and setup git clone https://github.com/hcavarsan/kftray.git cd kftray mise install # Install all tools mise run setup # Setup dependencies mise run dev # Start development ``` -------------------------------- ### Quick Start kftray Development Source: https://github.com/hcavarsan/kftray/blob/main/DEVELOPMENT.md Clone the repository, install mise-managed tools, set up system dependencies, and start the development server. ```bash # Clone the repository git clone https://github.com/hcavarsan/kftray.git cd kftray # Install tools defined in .mise.toml mise install # Setup system dependencies and install project dependencies mise run setup # Start development mise run dev ``` -------------------------------- ### Run Setup Script Source: https://github.com/hcavarsan/kftray/blob/main/DEVELOPMENT.md Execute the setup script to automatically detect your OS and install any missing system dependencies. ```bash mise run setup ``` -------------------------------- ### First Time Project Setup Source: https://github.com/hcavarsan/kftray/blob/main/DEVELOPMENT.md Install mise-managed tools like Node.js and Rust, and then set up system dependencies required for the project. ```bash # Install mise-managed tools (Node, Rust, pnpm, etc.) mise install # Install system dependencies (webkit, build tools, etc.) # This detects your OS and installs the right packages mise run setup ``` -------------------------------- ### Setup Development Environment Manually Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftray/BUILD.md Install pnpm globally and then install project dependencies using pnpm. ```bash npm install -g pnpm pnpm install ``` -------------------------------- ### Setup Development Environment with mise Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftray/BUILD.md Use mise to install all necessary tools defined in .mise.toml and then set up system and project dependencies. ```bash mise install # Install all tools defined in .mise.toml mise run setup # Install system dependencies and project deps ``` -------------------------------- ### Example of Getting and Using Config Directory Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/configuration-utilities.md Demonstrates how to obtain the configuration directory path and then construct a path to a specific configuration file, such as 'config.json'. ```rust use kftray_commons::utils::config_dir::get_config_dir; let config_dir = get_config_dir()?; let config_file = config_dir.join("config.json"); ``` -------------------------------- ### Clone and Setup KFtray Environment Source: https://github.com/hcavarsan/kftray/blob/main/CONTRIBUTING.md Clones the KFtray repository and installs required tools and system dependencies using mise. This prepares the local environment for development. ```bash git clone https://github.com/hcavarsan/kftray.git cd kftray mise install # Install all required tools mise run setup # Setup system dependencies ``` -------------------------------- ### Basic Port Forwarding Setup Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/README.md Demonstrates how to configure and start a TCP port forward to a Kubernetes service. Ensure the necessary configuration details like service name, namespace, ports, and cluster context are provided. ```rust use kftray_commons::models::config_model::Config; use kftray_portforward::start_port_forward; #[tokio::main] async fn main() -> Result<(), Box> { // Create a port forward configuration let mut config = Config::default(); config.service = Some("my-service".to_string()); config.namespace = "production".to_string(); config.local_port = Some(8080); config.remote_port = Some(80); config.protocol = "tcp".to_string(); config.context = Some("prod-cluster".to_string()); // Start the port forward let responses = start_port_forward(vec![config], "tcp").await?; for response in responses { println!("Forward started: {} -> {}:{}", response.local_port, response.service, response.remote_port); } // Port forward is now active // Traffic on localhost:8080 goes to the service Ok(()) } ``` -------------------------------- ### Install kftui using wget (Fish) Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftui/INSTALL.md Install kftui on Unix-like systems using wget to download and execute the installer script in a Fish shell. ```fish wget -qO- https://raw.githubusercontent.com/hcavarsan/kftray/main/hacks/kftui_installer.sh | bash ``` -------------------------------- ### Launch kftui with a Configuration File Source: https://github.com/hcavarsan/kftray/blob/main/crates/kftui/README.md Start the kftui interface by specifying the path to a JSON configuration file. ```bash kftui --configs-path config.json ``` -------------------------------- ### Install kftui using wget (Bash) Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftui/INSTALL.md Install kftui on Unix-like systems using wget to download and execute the installer script in a Bash shell. ```sh bash <(wget -qO- https://raw.githubusercontent.com/hcavarsan/kftray/main/hacks/kftui_installer.sh) ``` -------------------------------- ### Install kftray on Linux using Homebrew Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftray/INSTALL.md Installs the Linux version of kftray by first tapping the repository and then installing the specific Linux package. ```bash brew tap hcavarsan/kftray brew install kftray-linux ``` -------------------------------- ### Install kftui on Windows using PowerShell Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftui/INSTALL.md Install kftui on Windows by running this PowerShell command to download and execute the installer script. ```powershell Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/hcavarsan/kftray/main/hacks/kftui_installer.ps1')) ``` -------------------------------- ### Install kftui using curl (Fish) Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftui/INSTALL.md Install kftui on Unix-like systems using curl to download and execute the installer script in a Fish shell. ```fish curl -s https://raw.githubusercontent.com/hcavarsan/kftray/main/hacks/kftui_installer.sh | bash ``` -------------------------------- ### Install kftui using Homebrew Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftui/INSTALL.md Install kftui on macOS or Linux systems with Homebrew by tapping the repository and installing the package. ```sh brew tap hcavarsan/kftray brew install kftui ``` -------------------------------- ### Install kftui using curl (Bash) Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftui/INSTALL.md Install kftui on Unix-like systems using curl to download and execute the installer script in a Bash shell. ```sh bash <(curl -s https://raw.githubusercontent.com/hcavarsan/kftray/main/hacks/kftui_installer.sh) ``` -------------------------------- ### Install kftray on macOS using Homebrew Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftray/INSTALL.md Installs kftray on macOS by first tapping the repository and then installing the cask. ```bash brew tap hcavarsan/kftray brew install --cask kftray ``` -------------------------------- ### Start Public Service Exposure Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/errors-expose.md Example of starting a public exposure for a local service. This configuration includes settings for TLS certificate generation. ```rust let mut config = Config::default(); config.workload_type = Some("expose".to_string()); config.exposure_type = Some("public".to_string()); config.alias = Some("myapp.example.com".to_string()); config.local_port = Some(3000); config.local_address = Some("localhost".to_string()); config.namespace = "production".to_string(); config.context = Some("prod-cluster".to_string()); config.cert_manager_enabled = Some(true); config.cert_issuer = Some("letsencrypt-prod".to_string()); config.cert_issuer_kind = Some("ClusterIssuer".to_string()); let response = start_expose(config).await?; println!("Exposed at: https://myapp.example.com"); ``` -------------------------------- ### Start Development Server with mise Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftray/BUILD.md Launch the kftray application in development mode using the 'dev' task in mise. ```bash mise run dev # Launch app in development mode (tauri dev) ``` -------------------------------- ### Minimal kftray Configuration Example Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/README.md This is a minimal example of a kftray configuration file, stored as a JSON array of Config objects. It specifies parameters for forwarding traffic to a Kubernetes service. ```json [ { "service": "api-server", "namespace": "production", "local_port": 8080, "remote_port": 80, "context": "prod-cluster", "workload_type": "service", "protocol": "tcp" } ] ``` -------------------------------- ### Install kftui using Cargo Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftui/INSTALL.md Use this command to install kftui if you have the Rust toolchain and Cargo installed. ```sh cargo install kftui ``` -------------------------------- ### Verify kftui installation Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftui/INSTALL.md After installation, run this command in your terminal to verify that kftui has been installed correctly. ```sh kftui ``` -------------------------------- ### Install mise Source: https://github.com/hcavarsan/kftray/blob/main/DEVELOPMENT.md Install mise, the unified task runner for the project. After installation, restart your terminal or source your shell configuration file. ```bash curl https://mise.run | sh ``` ```bash source ~/.bashrc # or ~/.zshrc ``` -------------------------------- ### Rust - Initialize and Use CompositeStore Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/http-logging-ssl.md Demonstrates initializing a CompositeStore with KeyringStore and FileStore, then retrieving a certificate. The CompositeStore will attempt to get the certificate from the keyring first, then the file store. ```rust use kftray_portforward::ssl::CertificateStore; let keyring = KeyringStore::new(); let file = FileStore::new("/etc/kftray/certs"); let composite = CompositeStore::new(vec![ Arc::new(keyring), Arc::new(file), ]); // Tries keyring first, then file store let cert = composite.get("myapp.local").await?; ``` -------------------------------- ### Install mise Source: https://github.com/hcavarsan/kftray/blob/main/CONTRIBUTING.md Installs the mise version manager using a curl script. This is the first step to setting up the development environment. ```bash curl https://mise.run | sh ``` -------------------------------- ### kftray Configuration Example Source: https://github.com/hcavarsan/kftray/blob/main/README.md This is a sample kftray configuration for forwarding a Kubernetes service. It specifies details like alias, context, ports, and protocol. ```json [ { "alias": "argocd", "context": "kind-kftray-cluster", "kubeconfig": "/Users/henrique/.kube/kind-config-kftray-cluster", "local_port": 16080, "namespace": "argocd", "protocol": "tcp", "remote_port": 8080, "service": "argocd-server", "workload_type": "service", "http_logs_enabled": true } ] ``` -------------------------------- ### Start Expose Tunnel Configuration Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/portforward-operations.md Configure kftray to start a reverse tunnel for exposing local services. Set the workload type to 'expose' and specify exposure type, certificate manager, issuer, and alias. ```rust let mut config = Config::default(); config.workload_type = Some("expose".to_string()); config.exposure_type = Some("public".to_string()); config.cert_manager_enabled = Some(true); config.cert_issuer = Some("letsencrypt-prod".to_string()); config.alias = Some("myapp.example.com".to_string()); ``` -------------------------------- ### Run Development Mode Manually Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftray/BUILD.md Start the kftray application in development mode using pnpm and tauri. ```bash pnpm tauri dev ``` -------------------------------- ### Start KFtray Development Mode Source: https://github.com/hcavarsan/kftray/blob/main/CONTRIBUTING.md Launches the KFtray application in development mode using mise. This command is used after the environment is set up. ```bash mise run dev # Launch development mode ``` -------------------------------- ### Example of Validating Configurations Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/configuration-utilities.md Shows how to use the `validate_configs` function with a vector of configurations. Ensure necessary imports are included before calling. ```rust use kftray_commons::utils::validate_configs::validate_configs; let configs = vec![my_config]; validate_configs(&configs).await?; ``` -------------------------------- ### Example kftui JSON Configuration Source: https://github.com/hcavarsan/kftray/blob/main/crates/kftui/README.md A sample JSON configuration for kftui, defining a port-forward for a Kubernetes service. ```json [ { "alias": "my-api", "context": "minikube", "namespace": "default", "service": "api-service", "local_port": 8080, "remote_port": 80, "protocol": "tcp", "workload_type": "service" } ] ``` -------------------------------- ### Example kftray Configuration File Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/configuration-utilities.md Illustrates the structure of the kftray configuration file, which is a JSON array of Config objects. This file defines services, namespaces, ports, and other connection details. ```json [ { "id": 1, "service": "api-server", "namespace": "production", "local_port": 8080, "remote_port": 80, "context": "prod-cluster", "workload_type": "service", "protocol": "tcp", "alias": "prod-api", "kubeconfig": "/home/user/.kube/config" }, { "id": 2, "namespace": "staging", "local_port": 3000, "context": "staging-cluster", "workload_type": "pod", "protocol": "tcp", "target": "app=backend", "alias": "staging-backend", "http_logs_enabled": true, "http_logs_max_file_size": 5242880 } ] ``` -------------------------------- ### Check Installed Versions Source: https://github.com/hcavarsan/kftray/blob/main/DEVELOPMENT.md List all the tool versions currently managed and installed by mise. ```bash # Check installed versions mise ls ``` -------------------------------- ### Headless Auto-Discovery with Auto-Start Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftui/USAGE.md Run kftui non-interactively to automatically discover annotated services, start port-forwards, and keep them running. This is ideal for scripted or CI environments. ```bash kftui --auto-discover --context my-cluster --auto-start --non-interactive ``` -------------------------------- ### Start UDP Port Forward Command Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/tauri-commands.md Starts UDP port forwards for given configurations. Deploys UDP relay pods and uses kftray-server proxy for relay. ```rust #[tauri::command] pub async fn start_port_forward_udp_cmd( configs: Vec, _app_handle: tauri::AppHandle ) -> Result, String> ``` ```javascript await invoke('start_port_forward_udp_cmd', { configs: [{ service: 'dns-service', namespace: 'kube-system', local_port: 5353, remote_port: 53, context: 'my-cluster', protocol: 'udp' }] }) ``` -------------------------------- ### Create Client with Specific Kubeconfig Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/errors-expose.md This code example shows how to create a Kubernetes client by specifying a particular kubeconfig file path. It's useful when you need to connect to a cluster using a non-default configuration. ```rust let client = create_client_with_specific_context( Some("/path/to/kubeconfig".to_string()), None ).await?; ``` -------------------------------- ### Start Port Forward Function Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/module-architecture.md Initiates a port forwarding process with a list of configurations and a specified protocol. ```rust pub async fn start_port_forward( configs: Vec, protocol: &str ) -> Result, String> ``` -------------------------------- ### Usage Examples for Database Modes Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/configuration-utilities.md Demonstrates how to instantiate the DatabaseMode enum for different storage requirements. SQLite is recommended for production environments, while Memory is suitable for testing. ```rust use kftray_commons::utils::db_mode::DatabaseMode; // Use SQLite for production let mode = DatabaseMode::SQLite; // Use in-memory for testing let mode = DatabaseMode::Memory; ``` -------------------------------- ### Start Deploy and Forward Pod Command Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/tauri-commands.md Deploys and forwards a proxy pod, used for UDP and proxy forwarding. Returns the deployment response or an error. ```rust #[tauri::command] pub async fn start_deploy_and_forward_pod_cmd( config: Config, _app_handle: tauri::AppHandle ) -> Result ``` ```javascript await invoke('start_deploy_and_forward_pod_cmd', { config: { /* proxy config */ } }) ``` -------------------------------- ### Example JSON Configuration File for Kftray Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftray/USAGE.md This JSON file contains various Kftray configurations, including service port forwards, pod port forwards, and proxy configurations. It can be exported and imported to manage settings. ```json [ { "alias": "service-tcp-8080", "context": "kind", "kubeconfig": "/Users/henrique/.kube/config.bkp", "local_port": 8080, "namespace": "argocd", "protocol": "tcp", "remote_port": 8080, "service": "argocd-server", "workload_type": "service" }, { "alias": "pod-tcp-8083", "context": "kind", "kubeconfig": "/Users/henrique/.kube/config.bkp", "local_port": 8083, "namespace": "argocd", "protocol": "tcp", "remote_port": 8083, "target": "app.kubernetes.io/component=server", "workload_type": "pod" }, { "alias": "proxy-udp-5353", "context": "kind", "kubeconfig": "/Users/henrique/.kube/config.bkp", "local_port": 5353, "namespace": "argocd", "protocol": "udp", "remote_address": "coredns.cluster.local.internal", "remote_port": 5353, "workload_type": "proxy" }, { "alias": "proxy-tcp-6443", "context": "kind", "kubeconfig": "/Users/henrique/.kube/config.bkp", "local_port": 8777, "namespace": "argocd", "protocol": "tcp", "remote_address": "test.homelab.cluster.internal", "remote_port": 80, "workload_type": "proxy" } ] ``` -------------------------------- ### Daily Development Tasks Source: https://github.com/hcavarsan/kftray/blob/main/DEVELOPMENT.md Start the development server with hot reload enabled, run backend tests in a separate terminal, and format/lint code before committing. ```bash # Start development mode (hot reload enabled) mise run dev # In another terminal, run tests mise run test:back # Format and lint before committing mise run format mise run lint ``` -------------------------------- ### Get Application Settings Frontend Call (JavaScript) Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/tauri-commands.md Invokes the `get_app_settings_cmd` Tauri command from the frontend to fetch application settings and logs the theme. ```javascript const settings = await invoke('get_app_settings_cmd') console.log(`Theme: ${settings.theme}`) ``` -------------------------------- ### start_port_forward_udp_cmd Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/tauri-commands.md Starts UDP port forwards for given configurations. This command deploys UDP relay pods in Kubernetes, establishes UDP port forwards, and uses the kftray-server proxy for relay. ```APIDOC ## start_port_forward_udp_cmd ### Description Starts UDP port forwards for given configurations. This command deploys UDP relay pods in Kubernetes, establishes UDP port forwards, and uses the kftray-server proxy for relay. ### Method POST ### Endpoint /start_port_forward_udp_cmd ### Parameters #### Request Body - **configs** (Vec) - Required - List of UDP port forward configurations ### Request Example ```json { "configs": [ { "service": "dns-service", "namespace": "kube-system", "local_port": 5353, "remote_port": 53, "context": "my-cluster", "protocol": "udp" } ] } ``` ### Response #### Success Response (200) - **Vec** - Response for each config #### Response Example ```json { "example": "[ { \"id\": \"456\", \"status\": \"success\" } ]" } ``` ``` -------------------------------- ### Start Internal Service Exposure Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/errors-expose.md Example of starting an internal exposure for a local service. This configuration is suitable for cluster-internal access only. ```rust let mut config = Config::default(); config.workload_type = Some("expose".to_string()); config.exposure_type = Some("internal".to_string()); config.alias = Some("myapp.local".to_string()); config.local_port = Some(8080); config.namespace = "development".to_string(); config.context = Some("dev-cluster".to_string()); let response = start_expose(config).await?; println!("Exposed internally at: http://myapp.local"); ``` -------------------------------- ### Start, Stop, and Manage Port Forwarding Configurations Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/INDEX.md These functions handle the core port forwarding operations. Use `start_port_forward` to initiate forwarding, `stop_port_forward` to terminate it, and `get_configs`/`save_config` to manage your configuration profiles. ```rust pub async fn start_port_forward( configs: Vec, protocol: &str ) -> Result, String> pub async fn stop_port_forward(config_id: String) -> Result<(), String> pub async fn get_configs() -> Result, String> pub async fn save_config(config: Config) -> Result ``` -------------------------------- ### Get Application Settings Command (Rust) Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/tauri-commands.md Retrieves the current application settings. This command returns a `AppSettings` struct which includes theme preference, window dimensions, and UI settings. ```rust #[tauri::command] pub async fn get_app_settings_cmd() -> Result ``` -------------------------------- ### Import kftray Configuration via CLI Source: https://github.com/hcavarsan/kftray/blob/main/examples/README.md Demonstrates how to import kftray configurations using the kftui CLI. Supports local files and GitHub URLs. ```bash kftui --config /path/to/example.json ``` ```bash kftui --github-url https://raw.githubusercontent.com/hcavarsan/kftray/main/examples/service-tcp.json ``` -------------------------------- ### Load Configurations from Local File Source: https://github.com/hcavarsan/kftray/blob/main/crates/kftui/README.md Specify a local JSON file as the source for kftui configurations. ```bash kftui --configs-path /path/to/config.json ``` -------------------------------- ### keyring_init::init_keyring_for_platform Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/http-logging-ssl.md Initializes the appropriate keyring based on the current operating system platform. ```APIDOC ## keyring_init::init_keyring_for_platform ### Description Initializes the appropriate keyring based on the current operating system platform. Supports macOS, Linux, and Windows with platform-specific features. ### Method `init_keyring_for_platform() -> Result<()>` ### Parameters This function does not take any parameters. ### Response #### Success Response - `()` - Indicates successful initialization. ### Usage Example ```rust use kftray_portforward::ssl::keyring_init; keyring_init::init_keyring_for_platform()?; ``` ``` -------------------------------- ### Build Production App Manually Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftray/BUILD.md Build the production-ready kftray application using pnpm and tauri. ```bash pnpm tauri build ``` -------------------------------- ### Start TCP Port Forward Command Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/tauri-commands.md Starts TCP port forwards for given configurations. Emits 'config_state_changed' event and updates database state. ```rust #[tauri::command] pub async fn start_port_forward_tcp_cmd( configs: Vec, _app_handle: tauri::AppHandle ) -> Result, String> ``` ```javascript await invoke('start_port_forward_tcp_cmd', { configs: [{ service: 'api-server', namespace: 'production', local_port: 8080, remote_port: 80, context: 'prod-cluster', protocol: 'tcp' }] }) ``` -------------------------------- ### Build Production App with mise Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftray/BUILD.md Build the production-ready kftray application using the 'build' task in mise. ```bash mise run build # Build production app (tauri build) ``` -------------------------------- ### kftray Required RBAC Permissions Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/README.md This YAML defines the ClusterRole required for kftray to interact with Kubernetes resources. It grants permissions to get, list, and watch pods, get and list services, and create/get/list pods/portforward. ```yaml apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: kftray-user rules: - apiGroups: [""] resources: ["pods"] verbs: ["get", "list", "watch"] - apiGroups: [""] resources: ["services"] verbs: ["get", "list"] - apiGroups: [""] resources: ["pods/portforward"] verbs: ["create", "get", "list"] ``` -------------------------------- ### Build Production Application Source: https://github.com/hcavarsan/kftray/blob/main/DEVELOPMENT.md Build the production version of the application, with options to build only the UI or include bundle analysis. ```bash # Build production app mise run build # Build only the UI mise run build:ui # Build with bundle analysis mise run build:analyze ``` -------------------------------- ### Reinstall All Tools Source: https://github.com/hcavarsan/kftray/blob/main/DEVELOPMENT.md Use this command to ensure you have the latest versions of all managed tools installed. ```bash mise install # Reinstall all tools ``` -------------------------------- ### Rust - Generate and Use Certificate with CertificateManager Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/http-logging-ssl.md Demonstrates creating a CertificateManager, generating a certificate for a domain, and accessing its fingerprint. Ensure AppSettings is properly configured. ```rust use kftray_portforward::ssl::CertificateManager; let manager = CertificateManager::new(&settings)?; let cert = manager.generate_certificate("myapp.local").await?; println!("Generated cert: {}", cert.fingerprint); ``` -------------------------------- ### start_deploy_and_forward_pod_cmd Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/tauri-commands.md Deploys and forwards a proxy pod. This command is used for UDP and proxy forwarding, deploying a kftray-server relay pod and establishing a port forward to it. ```APIDOC ## start_deploy_and_forward_pod_cmd ### Description Deploys and forwards a proxy pod. This command is used for UDP and proxy forwarding, deploying a kftray-server relay pod and establishing a port forward to it. ### Method POST ### Endpoint /start_deploy_and_forward_pod_cmd ### Parameters #### Request Body - **config** (Config) - Required - Proxy deployment configuration ### Request Example ```json { "config": { "service": "my-proxy-service", "namespace": "default", "local_port": 9000, "remote_port": 8080, "context": "my-cluster", "protocol": "udp" } } ``` ### Response #### Success Response (200) - **CustomResponse** - Deployment response #### Response Example ```json { "example": "{ \"id\": \"789\", \"status\": \"deployed_and_forwarded\" }" } ``` ``` -------------------------------- ### Get Log Directory Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/utilities-reference.md Returns the designated directory for application logs, providing a platform-specific default path. ```rust pub fn get_log_dir() -> Result ``` -------------------------------- ### Get Configurations Command (Rust) Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/tauri-commands.md Retrieves all saved configurations. Used to fetch a list of all stored configurations. ```rust #[tauri::command] pub async fn get_configs_cmd() -> Result, String> ``` ```javascript const configs = await invoke('get_configs_cmd') for (const config of configs) { console.log(`${config.alias}: ${config.namespace}`) } ``` -------------------------------- ### get_config_dir Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/configuration-utilities.md Gets the platform-specific configuration directory for Kftray. It creates the directory if it doesn't exist and returns its path. ```APIDOC ## get_config_dir ### Description Gets the platform-specific configuration directory for Kftray. It creates the directory if it doesn't exist and returns its path. ### Function Signature ```rust pub fn get_config_dir() -> Result ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Returns `Result` - Path to config directory or error ### Platform-specific paths: - Linux: `~/.config/kftray` - macOS: `~/Library/Application Support/kftray` - Windows: `%APPDATA%\kftray` ### Behavior: - Creates directory if not exists - Returns error if directory cannot be created ### Example ```rust use kftray_commons::utils::config_dir::get_config_dir; let config_dir = get_config_dir()?; let config_file = config_dir.join("config.json"); ``` ``` -------------------------------- ### initialize_database() Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/SUMMARY.txt Initializes the database schema. ```APIDOC ## initialize_database() ### Description Initializes the database schema. ### Method N/A (Function) ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response - **bool**: True if initialization was successful, False otherwise. #### Response Example N/A ``` -------------------------------- ### NameSpace Struct Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/types.md Wrapper for an optional namespace name. Provides a method to get the namespace name or 'default' if None. ```rust pub struct NameSpace(pub Option); ``` -------------------------------- ### Build and Use TlsAcceptor Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/http-logging-ssl.md Demonstrates how to build a TLS acceptor and use it to accept TLS connections from incoming TCP streams. Ensure you have the necessary configuration and settings. ```rust use kftray_portforward::ssl::build_tls_acceptor; let acceptor = build_tls_acceptor(&config, &settings).await?; let listener = TcpListener::bind("127.0.0.1:8443").await?; loop { let (stream, _) = listener.accept().await?; let tls_stream = acceptor.accept(stream).await?; // Handle TLS stream } ``` -------------------------------- ### Load Application Settings Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/utilities-reference.md Loads application settings from storage. Returns settings or default values if none are found. Settings include theme, window position, kubeconfig path, and auto-start preferences. ```rust pub async fn load_settings() -> Result ``` -------------------------------- ### Source Environment Variables Source: https://github.com/hcavarsan/kftray/blob/main/DEVELOPMENT.md If 'mise' command is not found after installation, source your shell's configuration file to load environment variables. ```bash source ~/.bashrc # or ~/.zshrc ``` -------------------------------- ### Import kftray Libraries Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/README.md Import necessary modules for core port forwarding, configuration, HTTP logging, and Kubernetes client operations. ```rust // Core port forwarding use kftray_portforward:: start_port_forward, stop_port_forward, deploy_and_forward_pod, ; // Configuration and utilities use kftray_commons:: models::config_model::Config, utils::config::{get_configs, save_config}, ; // HTTP logging use kftray_http_logs::{HttpLogger, LogConfig}; // Kubernetes client use kftray_portforward::kube:: list_kube_contexts, list_all_namespaces, ; ``` -------------------------------- ### Port Forwarding Operations API Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/README.md API for managing port forwarding operations, including starting, stopping, and deploying proxy pods. ```APIDOC ## Port Forwarding Operations API ### Description This section details the API for managing port forwarding operations within kftray. It covers starting and stopping individual or all port forwards, as well as deploying proxy pods and discovering services. ### Operations - `start_port_forward()`: Initiates TCP or UDP port forwards. - `stop_port_forward()`: Stops a specific port forward. - `stop_all_port_forward()`: Stops all active port forwards. - `deploy_and_forward_pod()`: Deploys a proxy pod to facilitate port forwarding. - `retrieve_service_configs()`: Discovers and retrieves configurations for available services. ### Additional Features - HTTP logging configuration - Expose operations ``` -------------------------------- ### Build Frontend UI with mise Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftray/BUILD.md Build only the frontend UI of the kftray application using the 'build:ui' task. ```bash mise run build:ui ``` -------------------------------- ### Get Configuration Directory Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/utilities-reference.md Retrieves the platform-specific configuration directory for kftray. Creates the directory if it doesn't exist and returns an absolute path. ```rust pub fn get_config_dir() -> Result ``` ```rust use kftray_commons::utils::config_dir::get_config_dir; let config_dir = get_config_dir()?; let config_file = config_dir.join("config.json"); println!("Config at: {:?}", config_file); ``` -------------------------------- ### Invoke Get Configuration State Command Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/tauri-commands.md Frontend JavaScript code to invoke the `get_configs_state_cmd` Tauri command and process the returned configuration states. ```javascript const states = await invoke('get_configs_state_cmd') for (const state of states) { if (state.is_running) { console.log(`${state.config_id}: pod=${state.active_pod_name}`) } } ``` -------------------------------- ### launch_helper() Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/SUMMARY.txt Launches a privileged helper process. ```APIDOC ## launch_helper() ### Description Launches a privileged helper process. ### Method N/A (Function) ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response - **bool**: True if the helper was launched successfully, False otherwise. #### Response Example N/A ``` -------------------------------- ### Retrieve a Specific Kubernetes Service Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/kubernetes-client.md Use this function to get details of a specific service by its name and namespace. Requires a Kubernetes client instance. ```rust pub async fn get_service( client: Client, namespace: &str, service_name: &str ) -> KubeResult ``` ```rust let service = get_service(client, "production", "api-service").await?; for port in service.spec.unwrap().ports.unwrap() { println!("Port: {:?}", port.name); } ``` -------------------------------- ### Get a Specific Pod Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/kubernetes-client.md Retrieves a specific pod by its name within a given namespace. Requires the Kubernetes client, namespace, and pod name. ```rust pub async fn get_pod( client: Client, namespace: &str, pod_name: &str ) -> KubeResult ``` ```rust use kftray_portforward::get_pod; let pod = get_pod(client, "production", "api-server-abc123").await?; println!("Pod status: {:?}", pod.status); ``` -------------------------------- ### Basic kftui Configuration Source: https://github.com/hcavarsan/kftray/blob/main/crates/kftui/README.md Create a simple configuration file named 'config.json' to define your port-forwarding settings for kftui. ```json { "port": 8080, "host": "localhost", "target": "localhost:3000" } ``` -------------------------------- ### Retrieve Service Configurations Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/portforward-operations.md Discovers service configurations from Kubernetes auto-import annotations. It scans Kubernetes services for specific annotations to enable automatic setup. ```rust use kftray_portforward::retrieve_service_configs; let configs = retrieve_service_configs( None, Some("production".to_string()), None ).await?; for config in configs { println!("Discovered: {:?}", config.service); } ``` -------------------------------- ### Load Configurations from GitHub Repository Source: https://github.com/hcavarsan/kftray/blob/main/crates/kftui/README.md Import configurations from a JSON file located within a GitHub repository. Useful for team-shared environment configurations. ```bash kftui --github-url https://github.com/your-team/k8s-configs --configs-path environments/dev.json ``` -------------------------------- ### Running KFtray Server with Docker Source: https://github.com/hcavarsan/kftray/blob/main/crates/kftray-server/README.md This command launches the KFtray Server in a Docker container, setting the necessary environment variables and mapping ports. Ensure the environment variables match your desired configuration. ```bash docker run -e REMOTE_ADDRESS=target.host \ -e REMOTE_PORT=8080 \ -e LOCAL_PORT=8080 \ -e PROXY_TYPE=tcp \ -p 8080:8080 \ kftray-server ``` -------------------------------- ### Stop Expose Tunnel Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/errors-expose.md Example of stopping an existing expose tunnel using its configuration ID. This action removes the associated ingress and tunnel resources. ```rust use kftray_portforward::stop_expose; stop_expose("42".to_string()).await?; println!("Expose tunnel stopped"); ``` -------------------------------- ### Get Configuration State Command Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/tauri-commands.md Retrieves the runtime state of all configurations. This command returns a Result containing a vector of ConfigState objects or an error string. ```rust #[tauri::command] pub async fn get_configs_state_cmd() -> Result, String> ``` -------------------------------- ### init_logger() Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/SUMMARY.txt Initializes the logging system. ```APIDOC ## init_logger() ### Description Initializes the logging system. ### Method N/A (Function) ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response - **bool**: True if logging was initialized successfully, False otherwise. #### Response Example N/A ``` -------------------------------- ### Open Configuration Directory Command (Rust) Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/tauri-commands.md Opens the application's configuration directory in the system's default file explorer. Returns a `Result` indicating success or error. ```rust #[tauri::command] pub async fn open_config_directory_cmd() -> Result<(), String> ``` -------------------------------- ### Get Pod Container Logs Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/kubernetes-client.md Retrieves the log contents from a specific container within a pod. If no container name is provided, logs from the first container are returned. ```rust pub async fn get_pod_logs( client: Client, namespace: &str, pod_name: &str, container_name: Option<&str> ) -> KubeResult ``` ```rust let logs = get_pod_logs( client, "production", "api-server-abc123", Some("api") ).await?; println!("Pod logs:\n{}", logs); ``` -------------------------------- ### Build with Bundle Analysis with mise Source: https://github.com/hcavarsan/kftray/blob/main/docs/kftray/BUILD.md Build the kftray application with bundle analysis enabled using the 'build:analyze' task. ```bash mise run build:analyze ``` -------------------------------- ### Get Services with Annotation Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/portforward-operations.md Retrieves Kubernetes services that have a specific annotation, typically used for auto-discovery. Filters services by the annotation `kftray.app/enabled: "true"`. ```rust use kube::Client; use kftray_portforward::get_services_with_annotation; let client = Client::try_default().await?; let services = get_services_with_annotation(client, "default", "kftray.app/enabled").await?; ``` -------------------------------- ### Start Reverse Tunneling (Expose) Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/INDEX.md Initiate a reverse tunnel to expose a local service to the Kubernetes cluster. This function requires a `Config` object specifying the service details. ```rust pub async fn start_expose(config: Config) -> Result ``` -------------------------------- ### Invoke Get HTTP Logs Command (JavaScript) Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/tauri-commands.md Frontend JavaScript code to invoke the 'get_http_logs_cmd' Tauri command with a configuration ID and log the returned HTTP logs. ```javascript const logs = await invoke('get_http_logs_cmd', { configId: 42 }) console.log(logs) ``` -------------------------------- ### List Kubernetes Contexts Command Source: https://github.com/hcavarsan/kftray/blob/main/_autodocs/tauri-commands.md Lists available Kubernetes contexts. Accepts an optional path to a kubeconfig file. Returns a list of KubeContextInfo or an error string. ```rust #[tauri::command] pub async fn list_kube_contexts_cmd( kubeconfig: Option ) -> Result, String> ``` ```javascript const contexts = await invoke('list_kube_contexts_cmd') for (const ctx of contexts) { console.log(ctx.name) } ```