Backend: API handlers, WebSocket manager, K8s client, CRDT, auth

This commit is contained in:
Hermes Agent
2026-06-16 08:53:24 -04:00
parent 33c6648b84
commit 27779ba26f
15 changed files with 427 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
package k8s
import (
"context"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
type Client struct {
clientset *kubernetes.Clientset
}
func NewClient() (*Client, error) {
config, err := rest.InClusterConfig()
if err != nil {
// Fall back to out-of-cluster config for local development
// config, err = clientcmd.BuildConfigFromFlags("", filepath.Join(home, ".kube", "config"))
// if err != nil {
// return nil, err
// }
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, err
}
return &Client{
clientset: clientset,
}, nil
}
func (c *Client) Clientset() *kubernetes.Clientset {
return c.clientset
}
func (c *Client) GetPods(ctx context.Context, namespace string) ([]v1.Pod, error) {
pods, err := c.clientset.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{})
if err != nil {
return nil, err
}
return pods.Items, nil
}
func (c *Client) WatchPods(ctx context.Context, namespace string, resourceVersion string) (watch.Interface, error) {
return c.clientset.CoreV1().Pods(namespace).Watch(ctx, metav1.ListOptions{
ResourceVersion: resourceVersion,
})
}

View File

@@ -0,0 +1,28 @@
package k8s
import (
"context"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func (c *Client) GetPod(ctx context.Context, namespace, name string) (*v1.Pod, error) {
return c.clientset.CoreV1().Pods(namespace).Get(ctx, name, metav1.GetOptions{})
}
func (c *Client) GetDeployments(ctx context.Context, namespace string) ([]v1beta1.Deployment, error) {
deployments, err := c.clientset.AppsV1().Deployments(namespace).List(ctx, metav1.ListOptions{})
if err != nil {
return nil, err
}
return deployments.Items, nil
}
func (c *Client) GetServices(ctx context.Context, namespace string) ([]v1.Service, error) {
services, err := c.clientset.CoreV1().Services(namespace).List(ctx, metav1.ListOptions{})
if err != nil {
return nil, err
}
return services.Items, nil
}

View File

@@ -0,0 +1,24 @@
package k8s
import (
"context"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type WatchStream struct {
Watcher watch.Interface
StopChan chan struct{}
}
func (c *Client) WatchAllResources(ctx context.Context) (*WatchStream, error) {
// TODO: Implement watch for all resource types
// This will multiplex all watch streams into a single connection
return nil, nil
}
func (c *Client) WatchPodLogs(ctx context.Context, namespace, podName string, follow bool) (watch.Interface, error) {
return c.clientset.CoreV1().Pods(namespace).Watch(ctx, metav1.ListOptions{})
}