Support running insde kubernetes #5

Merged
tamipes merged 6 commits from pr-kube-yamls into main 2026-06-03 23:29:41 +02:00
3 changed files with 26 additions and 6 deletions
Showing only changes of commit 876b568a54 - Show all commits

View file

@ -0,0 +1,21 @@
on:
push:
branches:
- main
jobs:
build:
runs-on: [ nix ]
steps:
- uses: actions/checkout@v4
- name: Nix build
run: nix build --extra-experimental-features "flakes nix-command" .#docker-image
- name: Setup skopeo
run: curl -o /etc/containers/policy.json --create-dirs https://raw.githubusercontent.com/containers/skopeo/refs/heads/main/default-policy.json
- name: Push Image
run: |
skopeo copy --dest-password "$UPLOAD_TOKEN" --dest-username "$USERNAME" "docker-archive://$(realpath result)" "docker://$IMG_URL:${{ github.sha }}" && \
skopeo copy --dest-password "$UPLOAD_TOKEN" --dest-username "$USERNAME" "docker-archive://$(realpath result)" "docker://$IMG_URL"
env:
USERNAME: tamipes
UPLOAD_TOKEN: ${{ secrets.UPLOAD_TOKEN }}
IMG_URL: git.tami.moe/tamipes/minecraft-ingress

View file

@ -29,9 +29,8 @@ pub struct KubeCache {
impl KubeCache {
/// This initializes the creation of a "kubernetes client"
/// and if it is not possible returns a None.
pub fn create() -> Option<KubeCache> {
let kubeconfig = kube::config::Kubeconfig::read().unwrap();
let client = Client::try_from(kubeconfig).unwrap();
pub async fn create() -> Option<KubeCache> {
let client = Client::try_default().await.unwrap();
let deployments: Api<Deployment> = Api::default_namespaced(client.clone());
let services: Api<Service> = Api::default_namespaced(client);
@ -209,9 +208,9 @@ impl MinecraftAPI<Server> for McApi {
}
impl McApi {
pub fn create() -> Option<Self> {
pub async fn create() -> Option<Self> {
Some(Self {
cache: KubeCache::create()?,
cache: KubeCache::create().await?,
map: Arc::new(tokio::sync::Mutex::new(HashMap::new())),
})
}

View file

@ -39,7 +39,7 @@ async fn main() {
let revision: &'static str = env!("COMMIT_HASH");
tracing::info!(revision);
let api = kube_cache::McApi::create().unwrap();
let api = kube_cache::McApi::create().await.unwrap();
tracing::info!("initialized kube api");
let config: Config = Default::default();