From 72fa4d3224ccece4576d4fc9932d0985aff70e95 Mon Sep 17 00:00:00 2001 From: Hasan Hakkaev Date: Sun, 1 Oct 2023 23:27:28 +0200 Subject: [PATCH] Adapt to new pkg, provider option fixes --- Cargo.lock | 46 ++++++++++++------------- Cargo.toml | 2 +- hack/provider/provider.yaml | 22 ++++++++++-- src/exoscale/exoscale.rs | 68 +++++++++++++++++++++---------------- src/options/options.rs | 7 +--- 5 files changed, 82 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c8e1f22..5db74db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,9 +34,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.5.0" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" dependencies = [ "anstyle", "anstyle-parse", @@ -48,15 +48,15 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b84bf0a05bbb2a83e5eb6fa36bb6e87baa08193c35ff52bbf6b38d8af2890e46" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" [[package]] name = "anstyle-parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" dependencies = [ "utf8parse", ] @@ -72,9 +72,9 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "2.1.0" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" dependencies = [ "anstyle", "windows-sys", @@ -210,9 +210,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.5" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824956d0dca8334758a5b7f7e50518d66ea319330cbceedcf76905c2f6ab30e3" +checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" dependencies = [ "clap_builder", "clap_derive 4.4.2", @@ -220,9 +220,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.5" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "122ec64120a49b4563ccaedcbea7818d069ed8e9aa6d829b82d8a4128936b2ab" +checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" dependencies = [ "anstream", "anstyle", @@ -427,7 +427,7 @@ name = "devpod-provider-exoscale" version = "0.1.0" dependencies = [ "anyhow", - "clap 4.4.5", + "clap 4.4.6", "crossbeam", "exoscale-rs", "openssh-keys", @@ -472,9 +472,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" +checksum = "add4f07d43996f76ef320709726a556a9d4f965d9410d8d0271132d2f8293480" dependencies = [ "errno-dragonfly", "libc", @@ -493,9 +493,9 @@ dependencies = [ [[package]] name = "exoscale-rs" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "153be88d0efc14e26eaef5027d48134d61311241662909e44d8dfb93d9930925" +checksum = "4a271de294678ab1e0f78625d97abcafca57f3941d0b55b59fb08d6f9bc35fd7" dependencies = [ "base64", "hmac", @@ -889,9 +889,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128" +checksum = "3852614a3bd9ca9804678ba6be5e3b8ce76dfc902cae004e3e0c44051b6e88db" [[package]] name = "lock_api" @@ -921,9 +921,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.6.3" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "memoffset" @@ -1297,9 +1297,9 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.38.14" +version = "0.38.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "747c788e9ce8e92b12cd485c49ddf90723550b654b32508f979b71a7b1ecda4f" +checksum = "d2f9da0cbd88f9f09e7814e388301c8414c51c62aa6ce1e4b5c551d49d96e531" dependencies = [ "bitflags 2.4.0", "errno", diff --git a/Cargo.toml b/Cargo.toml index bc09c7e..3b2b85c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" anyhow = { version = "1.0.71", features = [] } clap = { version = "4.3.0", features = ["derive"] } crossbeam = { version = "0.8.2", features = ["crossbeam-channel"] } -exoscale-rs = "2.0.0" +exoscale-rs = "2.0.1" openssh-keys = "0.6.0" openssl = { version = "0.10.52", features = ["vendored"] } petname = "1.1.3" diff --git a/hack/provider/provider.yaml b/hack/provider/provider.yaml index b506e49..b9fc404 100644 --- a/hack/provider/provider.yaml +++ b/hack/provider/provider.yaml @@ -5,7 +5,6 @@ description: |- icon: https://avatars.githubusercontent.com/u/2023286?s=200&v=4 optionGroups: - options: - - ZONE - TEMPLATE - INSTANCE_TYPE - DISK_SIZE @@ -26,7 +25,7 @@ options: description: The Exoscale API secret to use. required: true password: true - ZONE: + EXOSCALE_ZONE: description: The Exoscale Zone to use. required: true default: at-vie-1 @@ -41,7 +40,24 @@ options: - at-vie-2 TEMPLATE: description: The template to use. - default: docker-ce + default: Exoscale Container-Optimized Instance + suggestions: + - Exoscale Container-Optimized Instance + - Linux Arch Rolling + - Linux CentOS Stream 8 64-bit + - Linux CentOS Stream 9 64-bit + - Linux Debian 10 (Buster) 64-bit + - Linux Debian 11 (Bullseye) 64-bit + - Linux Debian 12 (Bookworm) 64-bit + - Linux Ubuntu 20.04 LTS 64-bit + - Linux Ubuntu 22.04 LTS 64-bit + - Linux Ubuntu 23.04 64-bit + - Linux Fedora CoreOS 38 64-bit + - Rocky Linux 8 (Green Obsidian) 64-bit + - Rocky Linux 9 (Blue Onyx) 64-bit + - Linux CentOS 7 64-bit + - Linux RedHat 7.9 BYOL 64-bit + - Linux RedHat 8.2 BYOL 64-bit INSTANCE_TYPE: description: The machine type to use, arm based machines are only available in certain zones. default: tiny diff --git a/src/exoscale/exoscale.rs b/src/exoscale/exoscale.rs index ff6ad0c..4f6092d 100644 --- a/src/exoscale/exoscale.rs +++ b/src/exoscale/exoscale.rs @@ -27,8 +27,10 @@ impl ExoscaleProvider { .context("Please set EXOSCALE_API_KEY environment variable"); let api_secret = env::var("EXOSCALE_API_SECRET") .context("Please set EXOSCALE_API_SECRET environment variable"); + let zone = + env::var("EXOSCALE_ZONE").context("Please set EXOSCALE_ZONE environment variable"); - let mut configuration = Configuration::new(); + let mut configuration = Configuration::new(zone.as_ref().unwrap()); let options = from_env(init); match api_key { @@ -43,6 +45,12 @@ impl ExoscaleProvider { } Err(err) => return Err(anyhow::anyhow!("Error getting API secret: {}", err)), } + match zone { + Ok(zone) => { + configuration.zone = zone; + } + Err(err) => return Err(anyhow::anyhow!("Error getting ZONE: {}", err)), + } let provider = ExoscaleProvider { configuration, options, @@ -78,8 +86,16 @@ impl ExoscaleProvider { .labels .as_ref() .unwrap() - .get(self.options.machine_id.as_str()) - .is_some() + .get("devpod_enabled".to_string().as_str()) + .unwrap() + == "true".to_string().as_str() + && instance + .labels + .as_ref() + .unwrap() + .get("devpod_instance_id".to_string().as_str()) + .unwrap() + == self.options.machine_id.clone().as_str() { Some(instance.clone()) } else { @@ -218,7 +234,15 @@ impl ExoscaleProvider { ); let mut labels = HashMap::new(); - labels.insert(self.options.machine_id.clone(), "true".to_string()); + labels.insert("devpod_instance".to_string(), "true".to_string()); + labels.insert( + "devpod_instance_id".to_string(), + self.options.machine_id.clone(), + ); + labels.insert( + "devpod_instance_folder".to_string(), + self.options.machine_folder.clone(), + ); let request_params = exoscale_rs::models::CreateInstanceRequest { anti_affinity_groups: None, @@ -226,22 +250,22 @@ impl ExoscaleProvider { template, disk_size: self.options.disk_size.parse().unwrap(), labels: Some(labels), - auto_start: None, + auto_start: Option::from(true), security_groups: None, user_data: Some(format!( r#"#cloud-config -users: -- name: devpod - shell: /bin/bash - groups: [ sudo, docker ] - ssh_authorized_keys: - - {} - sudo: [ "ALL=(ALL) NOPASSWD:ALL" ]"#, + users: + - name: devpod + shell: /bin/bash + groups: [ sudo, docker ] + ssh_authorized_keys: + - {} + sudo: [ "ALL=(ALL) NOPASSWD:ALL" ]"#, public_key_base )), deploy_target: None, - public_ip_assignment: None, - name: None, + public_ip_assignment: Some(exoscale_rs::models::PublicIpAssignment::Inet4), + name: Some(self.options.machine_id.clone().to_string()), ssh_key: None, ipv6_enabled: None, ssh_keys: None, @@ -254,23 +278,7 @@ users: }, ) .await?; - /* - let mut still_creating = true; - - while still_creating { - let instance = exoscale_rs::apis::instance_api::get_instance( - &self.configuration, - result.id.as_ref().unwrap(), - ) - .await? - .clone(); - if instance.state == Option::from(exoscale_rs::models::InstanceState::Running) { - still_creating = false; - } else { - std::thread::sleep(std::time::Duration::from_secs(5)); - } - }*/ Ok(()) } } diff --git a/src/options/options.rs b/src/options/options.rs index 106bee0..79f6ac3 100644 --- a/src/options/options.rs +++ b/src/options/options.rs @@ -3,7 +3,6 @@ use std::env; #[derive(Default)] pub struct Options { pub template: String, - pub zone: String, pub instance_type: String, pub disk_size: String, pub machine_id: String, @@ -13,8 +12,6 @@ pub struct Options { pub fn from_env(init: bool) -> Options { let template = from_env_or_error("TEMPLATE"); - let zone = from_env_or_error("ZONE"); - let instance_type = from_env_or_error("INSTANCE_TYPE"); let disk_size = from_env_or_error("DISK_SIZE"); @@ -22,18 +19,16 @@ pub fn from_env(init: bool) -> Options { if init { return Options { template, - zone, instance_type, disk_size, ..Default::default() }; } let mut machine_id = from_env_or_error("MACHINE_ID"); - machine_id = format!("devpod-{}", machine_id); + machine_id = machine_id.to_string(); let machine_folder = from_env_or_error("MACHINE_FOLDER"); Options { template, - zone, instance_type, disk_size, machine_id,