rkubectl_app/cli/command/config.rs
1use super::*;
2
3/// Modify kubeconfig files using subcommands like "kubectl config set current-context my-context".
4/// The loading order follows these rules:
5/// 1. If the --kubeconfig flag is set, then only that file is loaded.
6/// The flag may only be set once and no merging takes place.
7/// 2. If $KUBECONFIG environment variable is set, then it is used as a list of paths (normal path delimiting rules for your system).
8/// These paths are merged. When a value is modified, it is modified in the file that defines the stanza.
9/// When a value is created, it is created in the first file that exists.
10/// If no files in the chain exist, then it creates the last file in the list.
11/// 3. Otherwise, ${HOME}/.kube/config is used and no merging takes place.
12///
13
14#[derive(Clone, Debug, Subcommand)]
15pub enum Config {
16 /// Display the current-context
17 CurrentContext,
18 /// Delete the specified cluster from the kubeconfig
19 DeleteCluster,
20 /// Delete the specified context from the kubeconfig
21 DeleteContext,
22 /// Delete the specified user from the kubeconfig
23 DeleteUser,
24 /// Display clusters defined in the kubeconfig
25 GetClusters,
26 /// Describe one or many contexts
27 GetContexts,
28 /// Display users defined in the kubeconfig
29 GetUsers,
30 /// Rename a context from the kubeconfig file
31 RenameContext,
32 /// Set an individual value in a kubeconfig file
33 Set,
34 /// Set a cluster entry in kubeconfig
35 SetCluster,
36 /// Set a context entry in kubeconfig
37 SetContext,
38 /// Set a user entry in kubeconfig
39 SetCredentials,
40 /// Unset an individual value in a kubeconfig file
41 Unset,
42 /// Set the current-context in a kubeconfig file
43 UseContext,
44 /// Display merged kubeconfig settings or a specified kubeconfig file
45 View,
46}
47
48impl Config {
49 pub fn exec(self, context: &Context) -> RkResult<()> {
50 let kubeapi = context.kubeapi();
51 match self {
52 Self::CurrentContext => {
53 if let Some(ctx) = kubeapi.current_context() {
54 context.print_deprecated(ctx);
55 }
56 }
57 Self::DeleteCluster => Err(RkError::todo())?,
58 Self::DeleteContext => Err(RkError::todo())?,
59 Self::DeleteUser => Err(RkError::todo())?,
60 Self::GetClusters => {
61 kubeapi
62 .get_clusters()
63 .iter()
64 .for_each(|cluster| context.print_deprecated(&cluster.name));
65 }
66 Self::GetContexts => {
67 kubeapi
68 .get_contexts()
69 .iter()
70 .for_each(|ctx| context.print_deprecated(&ctx.name));
71 }
72 Self::GetUsers => {
73 kubeapi
74 .get_users()
75 .iter()
76 .for_each(|auth| context.print_deprecated(&auth.name));
77 }
78 Self::RenameContext => Err(RkError::todo())?,
79 Self::Set => Err(RkError::todo())?,
80 Self::SetCluster => Err(RkError::todo())?,
81 Self::SetContext => Err(RkError::todo())?,
82 Self::SetCredentials => Err(RkError::todo())?,
83 Self::Unset => Err(RkError::todo())?,
84 Self::UseContext => Err(RkError::todo())?,
85 Self::View => {
86 if let Ok(text) = kubeapi.view() {
87 context.print_deprecated(text);
88 }
89 }
90 }
91 Ok(())
92 }
93}