fix: could not initilaize kube-rs inside cluster, should infer config now
This commit is contained in:
parent
a8311bb8ca
commit
5513387a1a
3 changed files with 55 additions and 8 deletions
|
|
@ -1,3 +1,9 @@
|
|||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: minecraft-ingress
|
||||
namespace: default
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: Role
|
||||
metadata:
|
||||
|
|
@ -6,7 +12,21 @@ metadata:
|
|||
rules:
|
||||
- apiGroups: [""] # "" indicates the core API group
|
||||
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
|
||||
kind: Deployment
|
||||
|
|
@ -17,4 +37,32 @@ metadata:
|
|||
spec:
|
||||
replicas: 1
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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())),
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue