#![warn(missing_docs)]
mod analysis;
mod cli;
mod eks;
mod finding;
mod k8s;
mod output;
mod playbook;
mod version;
use std::process;
use anyhow::Result;
use clap::Parser;
use cli::{Cli, Commands, CreateCommands};
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
match &cli.commands {
Commands::Analyze(args) => {
let aws_config = eks::get_config(&args.region.clone()).await?;
let eks_client = aws_sdk_eks::Client::new(&aws_config);
let cluster = eks::get_cluster(&eks_client, &args.cluster).await?;
let results = analysis::analyze(&aws_config, &cluster).await?;
output::output(&results, &args.format, &args.output).await?;
}
Commands::Create(args) => {
match &args.command {
CreateCommands::Playbook(playbook) => {
let aws_config = eks::get_config(&playbook.region.clone()).await?;
let eks_client = aws_sdk_eks::Client::new(&aws_config);
let cluster = eks::get_cluster(&eks_client, &playbook.cluster).await?;
let cluster_version = cluster.version().unwrap();
if version::LATEST.eq(cluster_version) {
println!("Cluster is already at the latest supported version: {cluster_version}");
println!("Nothing to upgrade at this time");
return Ok(());
}
let results = analysis::analyze(&aws_config, &cluster).await?;
if let Err(err) = playbook::create(playbook, &cluster, results) {
eprintln!("{err}");
process::exit(2);
}
}
}
}
}
Ok(())
}