fix: could not initilaize kube-rs inside cluster, should infer config now

This commit is contained in:
Tamipes 2026-06-03 13:23:37 +02:00
parent a8311bb8ca
commit 5513387a1a
3 changed files with 55 additions and 8 deletions

View file

@ -1,3 +1,9 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: minecraft-ingress
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1
kind: Role kind: Role
metadata: metadata:
@ -6,7 +12,21 @@ metadata:
rules: rules:
- apiGroups: [""] # "" indicates the core API group - apiGroups: [""] # "" indicates the core API group
resources: ["pods","deployments","services"] resources: ["pods","deployments","services"]
verbs: ["get", "list"] verbs: ["get", "list", "patch", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: minecraft-ingress
namespace: default
subjects:
- kind: ServiceAccount
name: minecraft-ingress
namespace: default
roleRef:
kind: Role
name: minecraft-ingress
apiGroup: rbac.authorization.k8s.io
--- ---
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
@ -17,4 +37,32 @@ metadata:
spec: spec:
replicas: 1 replicas: 1
selector: selector:
matchLabels matchLabels:
app: minecraft-ingress
template:
metadata:
labels:
app: minecraft-ingress
spec:
serviceAccountName: minecraft-ingress
containers:
- name: minecraft-ingress
image: git.tami.moe/tamipes/minecraft-ingress:latest
env:
- name: FILTER_CONN
value: '(addr == "87.229.85.222") || (addr == "") || (addr == "ogmur.xyz") || (addr == "@mat:matdoes.dev (hi honeypots) ") || (addr == "@mat:matdoes.dev ") || (addr == "slowstack.tv")'
---
apiVersion: v1
kind: Service
metadata:
name: minecraft-ingress
labels:
app: minecraft-ingress
spec:
ports:
- name: minecraft-ingress
port: 25565
nodePort: 30565
selector:
server: minecraft-ingress
type: NodePort

View file

@ -29,9 +29,8 @@ pub struct KubeCache {
impl KubeCache { impl KubeCache {
/// This initializes the creation of a "kubernetes client" /// This initializes the creation of a "kubernetes client"
/// and if it is not possible returns a None. /// and if it is not possible returns a None.
pub fn create() -> Option<KubeCache> { pub async fn create() -> Option<KubeCache> {
let kubeconfig = kube::config::Kubeconfig::read().unwrap(); let client = Client::try_default().await.unwrap();
let client = Client::try_from(kubeconfig).unwrap();
let deployments: Api<Deployment> = Api::default_namespaced(client.clone()); let deployments: Api<Deployment> = Api::default_namespaced(client.clone());
let services: Api<Service> = Api::default_namespaced(client); let services: Api<Service> = Api::default_namespaced(client);
@ -209,9 +208,9 @@ impl MinecraftAPI<Server> for McApi {
} }
impl McApi { impl McApi {
pub fn create() -> Option<Self> { pub async fn create() -> Option<Self> {
Some(Self { Some(Self {
cache: KubeCache::create()?, cache: KubeCache::create().await?,
map: Arc::new(tokio::sync::Mutex::new(HashMap::new())), 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"); let revision: &'static str = env!("COMMIT_HASH");
tracing::info!(revision); tracing::info!(revision);
let api = kube_cache::McApi::create().unwrap(); let api = kube_cache::McApi::create().await.unwrap();
tracing::info!("initialized kube api"); tracing::info!("initialized kube api");
let config: Config = Default::default(); let config: Config = Default::default();