-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
1,415 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: "Build CosmicKube cache server" | ||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
build-server: | ||
name: "Build Cache Server" | ||
runs-on: ubuntu-20.04 | ||
permissions: | ||
packages: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Download Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: '^1.22' | ||
|
||
- name: Build | ||
run: | | ||
cd kube_cache | ||
go build && strip kube_cache | ||
- name: Upload Artifact | ||
uses: actions/upload-artifact@v1 | ||
with: | ||
name: cache_server | ||
path: kube_cache/kube_cache | ||
|
||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Login to DockerHub | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# this will push the docker images to the github container registry | ||
# you will need to give actions permission to push there first | ||
- name: Build and push | ||
id: docker_build | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: . | ||
file: kube_cache/cache.Dockerfile | ||
push: true | ||
tags: | | ||
ghcr.io/pilksoc/kubecache:latest | ||
ghcr.io/pilksoc/kubecache:dev-${{ github.run_number }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
use crate::{ws, Clients, Result}; | ||
use warp::Reply; | ||
|
||
pub async fn ws_handler(ws: warp::ws::Ws, clients: Clients) -> Result<impl Reply> | ||
{ | ||
pub async fn ws_handler(ws: warp::ws::Ws, clients: Clients) -> Result<impl Reply> { | ||
println!("ws_handler"); //debug | ||
|
||
Ok(ws.on_upgrade(move |socket| ws::client_connection(socket, clients))) | ||
} | ||
} | ||
|
||
pub async fn metrics_handler(clients: Clients) -> Result<impl Reply> { | ||
let metricsString = "cosmic_kube_clients{type=\"connected\"} ".to_string() | ||
+ &clients.lock().await.len().to_string() | ||
+ "\n"; | ||
Ok(metricsString) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
extends Node | ||
class_name WebSocketClient | ||
|
||
@export var handshake_headers : PackedStringArray | ||
@export var supported_protocols : PackedStringArray | ||
@export var tls_trusted_certificate : X509Certificate | ||
@export var tls_verify := true | ||
|
||
|
||
var socket = WebSocketPeer.new() | ||
var last_state = WebSocketPeer.STATE_CLOSED | ||
|
||
|
||
signal connected_to_server() | ||
signal connection_closed() | ||
signal message_received(message: Variant) | ||
|
||
|
||
func connect_to_url(url) -> int: | ||
socket.supported_protocols = supported_protocols | ||
socket.handshake_headers = handshake_headers | ||
var tls_options = TLSOptions.client(tls_trusted_certificate) | ||
var err = socket.connect_to_url(url, tls_options) | ||
if err != OK: | ||
print("i tried :(", err) | ||
return err | ||
last_state = socket.get_ready_state() | ||
return OK | ||
|
||
|
||
func send(message) -> int: | ||
print(socket.get_ready_state()) | ||
if typeof(message) == TYPE_STRING: | ||
return socket.send_text(message) | ||
return socket.send(var_to_bytes(message)) | ||
|
||
|
||
func get_message() -> Variant: | ||
if socket.get_available_packet_count() < 1: | ||
return null | ||
var pkt = socket.get_packet() | ||
if socket.was_string_packet(): | ||
return pkt.get_string_from_utf8() | ||
return bytes_to_var(pkt) | ||
|
||
|
||
func close(code := 1000, reason := "") -> void: | ||
socket.close(code, reason) | ||
last_state = socket.get_ready_state() | ||
|
||
|
||
func clear() -> void: | ||
socket = WebSocketPeer.new() | ||
last_state = socket.get_ready_state() | ||
|
||
|
||
func get_socket() -> WebSocketPeer: | ||
return socket | ||
|
||
|
||
func poll() -> void: | ||
if socket.get_ready_state() != socket.STATE_CLOSED: | ||
socket.poll() | ||
var state = socket.get_ready_state() | ||
if last_state != state: | ||
last_state = state | ||
if state == socket.STATE_OPEN: | ||
connected_to_server.emit() | ||
elif state == socket.STATE_CLOSED: | ||
connection_closed.emit() | ||
while socket.get_ready_state() == socket.STATE_OPEN and socket.get_available_packet_count(): | ||
message_received.emit(get_message()) | ||
|
||
|
||
func _ready(): | ||
connect_to_url("ws://localhost:8000/ws") | ||
|
||
func _process(delta): | ||
poll() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.