Skip to main content

seal/models/
context.rs

1//! Kubernetes cluster context information
2
3/// Represents the current Kubernetes cluster context
4#[derive(Debug, Clone)]
5pub struct ClusterContext {
6    /// Name of the current kubectl context
7    pub context_name: String,
8    /// Name of the cluster from kubeconfig
9    pub cluster_name: String,
10    /// Kubernetes API server URL
11    pub cluster_server: String,
12    /// Default namespace from context (if any)
13    pub namespace: Option<String>,
14    /// Username/identity from context
15    pub user: String,
16}
17
18impl ClusterContext {
19    /// Create a new ClusterContext
20    pub fn new(
21        context_name: String,
22        cluster_name: String,
23        cluster_server: String,
24        namespace: Option<String>,
25        user: String,
26    ) -> Self {
27        Self {
28            context_name,
29            cluster_name,
30            cluster_server,
31            namespace,
32            user,
33        }
34    }
35
36    /// Format context for display to user
37    pub fn display(&self) -> String {
38        format!(
39            "Current Kubernetes context: {} ({})",
40            self.context_name, self.cluster_server
41        )
42    }
43}