Skip to content

Commit

Permalink
E2E Tests (#23)
Browse files Browse the repository at this point in the history
After a long slog of trying to get e2e tests running in GHA I've given up for now and will have to do these locally manually.
Multipass doesn't seem to work on GHA, neither in mac or in ubuntu runners.
On mac, it says the cpu doesn't support. In ubuntu it installs but seems to die silently.
I've read varying reports about nested virt support, people saying it is supported but then some say only if enterprise.
  • Loading branch information
byrnedo authored Dec 26, 2024
1 parent 85f537d commit a6d8640
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 42 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
- target: aarch64-apple-darwin
os: macos-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
os: ubuntu-24.04
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
os: ubuntu-24.04
runs-on: ${{ matrix.os }}
env:
TARGET: ${{ matrix.TARGET }}
Expand Down Expand Up @@ -52,7 +52,9 @@ jobs:
EOF
- name: Install rust target
run: rustup target add $TARGET
- name: Build Binary
- name: Normal Tests
run: cargo test
- name: Build Binaries
run: cargo build --locked --release --target ${{ matrix.target }}
- name: Archive artifacts
uses: actions/upload-artifact@v4
Expand Down
4 changes: 2 additions & 2 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[target.x86_64-unknown-linux-gnu]
pre-build = [ # additional commands to run prior to building the package
"apt-get update && apt-get install -y wget unzip",
"apt-get update && apt-get install -y wget unzip libssl-dev",
"wget https://github.com/protocolbuffers/protobuf/releases/download/v27.3/protoc-27.3-linux-x86_64.zip -O /tmp/protoc.zip",
"cd /tmp && unzip protoc.zip -d protoc",
"mv protoc/bin/protoc /usr/local/bin/protoc",
"mv protoc/include/* /usr/local/include/",
]
[target.aarch64-unknown-linux-gnu]
pre-build = [ # additional commands to run prior to building the package
"apt-get update && apt-get install -y wget unzip",
"apt-get update && apt-get install -y wget unzip libssl-dev",
"wget https://github.com/protocolbuffers/protobuf/releases/download/v27.3/protoc-27.3-linux-aarch_64.zip -O /tmp/protoc.zip",
"cd /tmp && unzip protoc.zip -d protoc",
"mv protoc/bin/protoc /usr/local/bin/protoc",
Expand Down
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.ONE_SHELL:
.PHONY: default
default: aarch64

Expand All @@ -22,3 +23,15 @@ lint-fix:
cargo clippy --fix --all --allow-dirty --allow-staged


.PHONY: run-integration-tests
run-integration-tests: SSH_PRIVATE_KEY=/tmp/skate-e2e-key
run-integration-tests:
set -euo pipefail
[ -f ${SSH_PRIVATE_KEY} ] || ssh-keygen -b 2048 -t rsa -f ${SSH_PRIVATE_KEY} -q -N ""
echo "SSH_PRIVATE_KEY=${SSH_PRIVATE_KEY}" > ./hack/.clusterplz.env
# start vms
./hack/clusterplz create || exit 0
./hack/clusterplz skatelet
# the ignored tests are the integration tests. This is not optimal.
SKATE_E2E=1 cargo test --test '*' -v -- --show-output --nocapture --include-ignored

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ brew tap messense/macos-cross-toolchains
brew install x86_64-unknown-linux-gnu
# install aarch64-unknown-linux-gnu toolchain
brew install aarch64-unknown-linux-gnu
#add following to ~/.profile
PATH="${PATH}:/usr/local/Cellar/x86_64-unknown-linux-gnu/13.3.0.reinstall/bin/"
PATH="${PATH}:/usr/local/Cellar/aarch64-unknown-linux-gnu/13.3.0.reinstall/bin/"
# or whatever path brew puts the binaries in
```

```shell
Expand Down
38 changes: 35 additions & 3 deletions hack/clusterplz
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
#!/bin/bash

set -x

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

POSITIONAL_ARGS=()

multipass_bin=$(which multipass)

multipass() {
if [[ "$SUDO_MULTIPASS" -eq 1 ]]; then
sudo $multipass_bin $@
fi
$multipass_bin $@
}

if [ -f $SCRIPT_DIR/.clusterplz.env ]; then
source $SCRIPT_DIR/.clusterplz.env
fi

SSH_PUBLIC_KEY=${SSH_PUBLIC_KEY:-$HOME/.ssh/id_rsa.pub}
SSH_PUBLIC_KEY=${SSH_PUBLIC_KEY:-${SSH_PRIVATE_KEY}.pub}

while [[ $# -gt 0 ]]; do
case $1 in
Expand Down Expand Up @@ -82,10 +93,18 @@ packages:
- libssl-dev
- pkg-config
EOF

had_failures=false
for f in $(seq $nodes); do
multipass launch -c 1 -m 1G -d 7G -n node-$f --cloud-init ./.cluster-plz.yaml
exit_code=$?
if [ $exit_code -gt 0 ]; then
had_failures=true
fi
done

$had_failures && exit 1

snapshot_nodes

for f in $(seq $nodes); do
Expand Down Expand Up @@ -153,10 +172,23 @@ skatelet)
echo "copying skatelet binaries for ${arch}"
for f in $(seq $nodes); do
if [ "$(arch)" = "$arch" ]; then
multipass transfer target/release/skatelet node-$f:
binary=target/release/skatelet
if [ ! -f $binary ]; then
set -x
cargo build --bin skatelet --release --locked
set +x
fi
else
multipass transfer target/${arch}-unknown-linux-gnu/release/skatelet node-$f:
target=${arch}-unknown-linux-gnu
binary=target/$target/release/skatelet
if [ ! -f $binary ]; then
set -x
cross build --bin skatelet --release --locked --target "$target"
set +x
fi
fi

multipass transfer $binary node-$f:
multipass exec -n node-$f -- sudo mv skatelet /usr/local/bin/skatelet

done
Expand Down
6 changes: 6 additions & 0 deletions src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ impl Config {
self.clusters[idx] = cluster.clone();
Ok(())
}

pub fn delete_cluster(&mut self, cluster: &Cluster) -> Result<(), SkateError> {
let idx = self.clusters.iter().position(|c| c.name == cluster.name).ok_or("cluster not found".to_string())?;
self.clusters.remove(idx);
Ok(())
}
}


Expand Down
34 changes: 34 additions & 0 deletions src/delete.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::config::Config;
use anyhow::anyhow;
use clap::{Args, Subcommand};
use dialoguer::Confirm;
use itertools::Itertools;
use crate::deps::{SshManager, With};
use crate::errors::SkateError;
Expand All @@ -27,6 +28,7 @@ pub enum DeleteCommands {
Daemonset(DeleteResourceArgs),
Service(DeleteResourceArgs),
ClusterIssuer(DeleteResourceArgs),
Cluster(DeleteClusterArgs),
}

#[derive(Debug, Args)]
Expand All @@ -36,9 +38,20 @@ pub struct DeleteResourceArgs {
namespace: String,
#[command(flatten)]
config: ConfigFileArgs,
}


#[derive(Debug, Args)]
pub struct DeleteClusterArgs {
name: String,
#[command(flatten)]
config: ConfigFileArgs,
#[arg(long, short, long_help = "Answer yes to confirmation")]
pub yes: bool,
}



pub trait DeleteDeps: With<dyn SshManager> {}

pub struct Delete<D: DeleteDeps> {
Expand All @@ -56,6 +69,7 @@ impl<D: DeleteDeps> Delete<D> {
DeleteCommands::Secret(args) => self.delete_resource(ResourceType::Secret, args).await?,
DeleteCommands::Service(args) => self.delete_resource(ResourceType::Service, args).await?,
DeleteCommands::ClusterIssuer(args) => self.delete_resource(ResourceType::ClusterIssuer, args).await?,
DeleteCommands::Cluster(args) => self.delete_cluster(args).await?,
}
Ok(())
}
Expand Down Expand Up @@ -119,4 +133,24 @@ impl<D: DeleteDeps> Delete<D> {
}
}
}

async fn delete_cluster(&self, args: DeleteClusterArgs) -> Result<(), SkateError> {
let mut config = Config::load(Some(args.config.skateconfig.clone()))?;
let cluster = config.active_cluster(args.config.context.clone())?.clone();

if ! args.yes{
let confirmation = Confirm::new()
.with_prompt(format!("Are you sure you want to delete cluster {}?", args.name))
.wait_for_newline(true)
.interact()
.unwrap();

if !confirmation {
return Ok(())
}

}
config.delete_cluster(&cluster)?;
config.persist(Some(args.config.skateconfig))
}
}
6 changes: 6 additions & 0 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,16 @@ impl Release {

#[cfg(test)]
mod tests {
use std::env;
use crate::github::Client;


#[tokio::test]
async fn test_get_release() {
if env::var("GITHUB_ACTIONS").is_ok() {
println!("skipping test_get_release since running in action, doesn't seem to work there");
return;
}
let client = Client::new();
let release = client.get_latest_release().await;

Expand Down
1 change: 0 additions & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub const CHECKBOX_EMOJI: char = '✔';
pub const CROSS_EMOJI: char = '✖';
pub const EQUAL_EMOJI: char = '~';
pub const INFO_EMOJI: &str = "[i]";
pub const TARGET: &str = include_str!(concat!(env!("OUT_DIR"), "/../output"));

pub fn slugify<S: AsRef<str>>(s: S) -> String {
_slugify(s.as_ref())
Expand Down
Loading

0 comments on commit a6d8640

Please sign in to comment.