Skip to content

Commit

Permalink
rename config -> kubeconfig for clearity
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramilito committed Aug 27, 2023
1 parent 2b60281 commit 041859a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::model::Config;
use crate::model::KubeConfig;
use crate::config;

use std::process;
Expand Down Expand Up @@ -86,12 +86,12 @@ pub fn selectable_list(input: Vec<String>) -> String {
selected_items[0].output().to_string()
}

pub fn set_namespace(ctx: &str, selection: &str, temp_dir: &str, config: &Config) {
pub fn set_namespace(ctx: &str, selection: &str, temp_dir: &str, config: &KubeConfig) {
let choice = config.contexts.iter().find(|x| x.name == ctx);
config::write(choice.unwrap(), Some(selection), temp_dir)
}

pub fn set_context(ctx: &str, temp_dir: &str, config: &Config) {
pub fn set_context(ctx: &str, temp_dir: &str, config: &KubeConfig) {
let choice = config.contexts.iter().find(|x| x.name == ctx);
config::write(choice.unwrap(), None, temp_dir);
}
20 changes: 10 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::model::{Config, Context, Contexts};
use crate::model::{KubeConfig, Context, Contexts};
use crate::{KUBECONFIG, KUBESESSCONFIG};
use std::fs::{self, File};
use std::io::{BufReader, BufWriter, Read};
use std::path::Path;

fn build(ctx: &Contexts, ns: Option<&str>, strbuf: &str) -> Config {
let mut config: Config = serde_yaml::from_str(&strbuf).unwrap();
fn build(ctx: &Contexts, ns: Option<&str>, strbuf: &str) -> KubeConfig {
let mut config: KubeConfig = serde_yaml::from_str(&strbuf).unwrap();
config.api_version = "v1".to_string();
config.kind = "Config".to_string();
config.current_context = format!("{}", ctx.name);
Expand Down Expand Up @@ -71,14 +71,14 @@ pub fn write(ctx: &Contexts, namespace: Option<&str>, dest: &str) {
serde_yaml::to_writer(writer, &config).unwrap();
}

pub fn get() -> Config {
let mut configs = Config::default();
pub fn get() -> KubeConfig {
let mut configs = KubeConfig::default();

for s in KUBECONFIG.rsplit(":") {
if s.contains("/kubesess/cache") {
continue;
}
let config: Config = get_config(s);
let config: KubeConfig = get_config(s);

configs.current_context = config.current_context;
configs.api_version = config.api_version;
Expand All @@ -91,7 +91,7 @@ pub fn get() -> Config {
let path = entry.unwrap().path();
if let Some(extension) = path.extension() {
if extension == "yaml" {
let config: Config = get_config(path.to_str().unwrap());
let config: KubeConfig = get_config(path.to_str().unwrap());

configs.contexts.extend(config.contexts);
}
Expand All @@ -101,7 +101,7 @@ pub fn get() -> Config {
configs
}

fn get_config(path: &str) -> Config {
fn get_config(path: &str) -> KubeConfig {
let f = File::open(path).unwrap();

let mut reader = BufReader::new(f);
Expand All @@ -110,12 +110,12 @@ fn get_config(path: &str) -> Config {
.read_to_string(&mut tmp)
.expect("Unable to read file");

let config: Config = serde_yaml::from_str(&tmp.trim()).unwrap();
let config: KubeConfig = serde_yaml::from_str(&tmp.trim()).unwrap();

config
}

pub fn get_current_session() -> Config {
pub fn get_current_session() -> KubeConfig {
let config;
let current;

Expand Down
2 changes: 1 addition & 1 deletion src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Context {
}

#[derive(Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Config {
pub struct KubeConfig {
#[serde(skip_serializing_if = "String::is_empty", default)]
pub kind: String,
#[serde(rename = "apiVersion")]
Expand Down

0 comments on commit 041859a

Please sign in to comment.