Skip to content

About

mogenius-operator is a Go (>=1.25) service that coordinates cluster resources, patterns, metrics collection, and auxiliary runtime capabilities for the mogenius platform.

Topics

Resources

Stars

11 stars

Watchers

0 watching

Forks

Latest commit

 

History

5,468 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mogenius

mogenius-operator

Kubernetes cluster manager & runtime control-plane components for the mogenius platform.


Artifact Hub Go Version Release License Build

Go (≥1.25) operator that manages CRDs, Helm deployments, metrics collection, WebSocket communication, and IaC for the mogenius platform.


Architecture

Modular packages under src/:

  • cmd/ – CLI entry points (cluster, nodemetrics, system, config).
  • core/ – lifecycle, reconcilers, socket API, node metrics collector.
  • kubernetes/ – resource CRUD, backups, issuers, cronjobs, etc.
  • crds/ – Custom Resource Definitions (Workspace, User, Grant).
  • k8sclient/ – Kubernetes client provider & kubeconfig.
  • valkeyclient/ – Valkey/Redis caching & time-series helpers.
  • websocket/ – WebSocket multiplexing with auto-reconnect.
  • stream/ – Stream sockets to the platform gateway: terminal, logs, events, port-forward/SSH tunnel, file download.
  • helm/ – Helm SDK integration & chart management.
  • iacmanager/ – Infrastructure-as-Code orchestration.
  • networkmonitor/ – Network traffic collection (eBPF via snoopy, or procdev).
  • containerenumerator/ – Container PID discovery via cgroup inspection.
  • cpumonitor/, podstatscollector/, rammonitor/ – CPU, pod & RAM telemetry.
  • config/ – Immutable config with validation & change callbacks.
  • logging/ – Structured slog with custom handlers & secret masking.
  • secrets/, store/, watcher/, shutdown/, services/, utils/, assert/, version/ – supporting packages.

Local Development

Prerequisites: Go 1.25+, just, access to a Kubernetes cluster with the mogenius namespace.

# 1. Create .env (see Configuration below)
# 2. Optionally scale down in-cluster deployment to avoid conflicts
just scale-down

# 3. Build & run
just build
just run

# Restore in-cluster deployment afterward
just scale-up

Key tasks:

just build            # compile native binary
just run              # run operator locally
just run-node-metrics # run node metrics DaemonSet mode locally
just check            # generate + lint + unit tests
just test-unit
just test-integration
just golangci-lint
just generate         # run go generate (CRD deepcopy)
just scale-down / scale-up

Configuration

Create a .env in the repo root:

MO_API_KEY=<api-key>       # From operator secret (mogenius/mogenius)
MO_CLUSTER_NAME=<name>     # Cluster identifier
MO_CLUSTER_MFA_ID=<id>     # MFA/instance id
MO_API_SERVER=<url>        # Platform API WebSocket URL
MO_EVENT_SERVER=<url>      # Platform Event WebSocket URL
MO_VALKEY_ADDR=<host:port> # Valkey/Redis address

Load (bash/zsh):

if [[ -f .env ]]; then export $(grep -v '^#' .env | xargs); fi

All Environment Variables

Variable Default Description
MO_API_KEY — API key to access the mogenius platform (required, secret)
MO_CLUSTER_NAME — Name of the Kubernetes cluster (required)
MO_CLUSTER_MFA_ID — NanoId of the cluster for MFA purpose (required, secret)
MO_API_SERVER — URL of the platform API WebSocket server (required)
MO_API_SERVER_CLIENTS 1 Number of parallel WebSocket connections to the API server
MO_EVENT_SERVER — URL of the platform event WebSocket server (required)
MO_WATCHER_MAX_OBJECTS_PER_KIND 50000 Resource kinds with more objects are not watched (no informer cache, nothing stored) until they shrink again; checked before an informer starts and while it runs, re-checked every 5 minutes. Protects the operator from OOM, e.g. during an event storm. 0 disables the check
MO_SKIP_TLS_VERIFICATION false Skip TLS verification for API and Event Server
MO_PORT_FORWARD_ALLOW_EXTERNAL_HOSTS false Allow port-forward tunnels to dial arbitrary hosts/IPs on the operator's network (kind=host), not just Kubernetes workloads. Off by default — enabling turns the operator into a proxy into the node's LAN (SSRF surface). Env alias: PORT_FORWARD_ALLOW_EXTERNAL_HOSTS
MO_ENFORCE_USER_RBAC_FOR_FILES_LOGS_TUNNELS false Check the requester's Kubernetes RBAC (via their User CRD subject, SelfSubjectAccessReview) before file operations (pods/exec), the session-less web terminal (pods/exec), pod log streams (pods/log) and workload tunnels (pods/portforward). These run with the operator's identity; exec requests, terminal sessions and SSH are impersonated anyway. Admins pass under MO_SSH_GATEWAY_ALLOW_ADMIN_BYPASS when the request carries the admin flags
MO_VALKEY_ADDR — Address (host:port) of the Valkey/Redis server (required)
MO_VALKEY_PASSWORD — Password for the Valkey/Redis server
MO_HTTP_ADDR :1337 Listen address for the operator HTTP API
MO_FILES_UPLOAD_MAX_BYTES 1073741824 Maximum uncompressed size in bytes of one file upload (1 GiB). Uploads are streamed into the target, so this bounds disk and transfer, not operator memory
MO_STREAM_ALLOWED_HOSTS — Extra stream gateway hosts the operator may connect to, comma-separated (host or *.domain). Stream requests carry the cluster credentials, so only the hosts of MO_API_SERVER/MO_EVENT_SERVER and their parent domain are allowed by default (e.g. k8s-ws.mogenius.com → *.mogenius.com); plain ws:// is refused when the platform connection uses TLS
MO_HTTP_SOCKETAPI_ALL_PATTERNS false Serve every socket api pattern on the unauthenticated HTTP endpoint /socketapi (needed for the local API doc page at /api-doc). Off by default: only the read-only get/nodes-metrics used by the node stats page is served. Never enable in a shared cluster
MO_OWN_NAMESPACE mogenius Namespace the mogenius platform is installed in
OWN_NODE_NAME — Node name the application is running on (set by DaemonSet)
OWN_DEPLOYMENT_NAME mogenius-operator Deployment name the application is running in
CLUSTER_DOMAIN cluster.local Internal cluster domain
MO_HELM_DATA_PATH <workdir>/helm-data Path to Helm data directory
MO_GIT_USER_NAME mogenius git-user Git username for IaC operations
MO_GIT_USER_EMAIL git@mogenius.com Git email for IaC operations
MO_AUDIT_LOG_LIMIT 1000 Maximum number of audit log entries to persist per resource (namespace/name pair), not globally
MO_AUDIT_LOG_TTL 336h Retention of audit log entries as Go duration (336h = 14 days)
MO_ENABLE_AUTO_UPGRADE true Enable automatic operator self-upgrades triggered by the platform
MO_ENABLE_POD_STATS_COLLECTOR true Enable collection of pod CPU/memory stats
MO_ENABLE_TRAFFIC_COLLECTOR false Enable collection of network traffic stats
MO_STATS_RETENTION_MAX_ENTRIES 1440 Max entries per pod-/traffic-/node-stats stream (1440 = 24h at 1-minute cadence)
MO_STATS_RETENTION_HOURS 24 Retention window in hours for stats streams
MO_SNOOPY_IMPLEMENTATION auto Network traffic backend: auto, snoopy (eBPF), or procdev
MO_HOST_PROC_PATH /proc Mount path of the host /proc filesystem (DaemonSet uses /hostproc)
MO_LOG_LEVEL info Log level: mo, debug, info, warn, or error
MO_LOG_FILTER — Comma-separated list of components to enable logs for (empty = all)
MO_ALLOW_COUNTRY_CHECK true Allow the operator to determine its location country via IP lookup
MO_PPROF false Expose Go pprof profiling endpoints at /debug/pprof/ (set to true for debugging)
KUBERNETES_DEBUG false Enable Kubernetes SDK debug output
MO_ENABLE_PATTERNLOGGING — Debug only: write every request datagram unredacted to /tmp/patternlogs.jsonl (see tools/patternbench). The file then holds request secrets too, such as the env of exec and session requests

List all config options at runtime: go run -trimpath src/main.go config


Docker (local image)

docker build -t localk8smanager \
  --build-arg GOOS=linux \
  --build-arg GOARCH=arm64 \
  --build-arg BUILD_TIMESTAMP="$(date -Iseconds)" \
  --build-arg COMMIT_HASH="$(git rev-parse --short HEAD || echo XXX)" \
  --build-arg GIT_BRANCH=local-development \
  --build-arg VERSION="dev-local" \
  -f Dockerfile .

To use the local image, patch the deployment to image: localk8smanager:latest with imagePullPolicy: Never, then restart.


Helm

Install via OCI:

helm -n mogenius upgrade --install mogenius-platform \
  oci://ghcr.io/mogenius/helm-charts/mogenius-operator \
  --create-namespace \
  --set global.cluster_name="<cluster>" \
  --set global.api_key="<api-key>"

Or via Helm repo:

helm repo add mo-public https://helm.mogenius.com/public
helm repo update
helm upgrade --install mogenius-platform mo-public/mogenius-operator \
  --namespace mogenius --create-namespace \
  --set global.cluster_name="<cluster>" \
  --set global.api_key="<api-key>"

Upgrade: helm repo update && helm upgrade mogenius-platform mo-public/mogenius-operator

Uninstall: helm uninstall mogenius-platform


Runtime Image

The operator uses a minimal scratch-based image containing only:

  • mogenius-operator binary (statically linked, CGO_ENABLED=0)
  • mogenius-snoopy binary (Rust + musl, statically linked)
  • nsenter from Alpine + musl dynamic linker (required for snoopy network namespace entry)
  • CA certificates (for TLS/WSS connections)

There is no shell or OS tooling in the image. Use kubectl debug or hostPID: true pods for runtime inspection.


Profiling

To profile memory usage, enable pprof temporarily:

kubectl set env deployment/mogenius-operator -n mogenius MO_PPROF=true
kubectl port-forward -n mogenius deployment/mogenius-operator 1337:1337

# Heap profile:
go tool pprof http://localhost:1337/debug/pprof/heap

# Browser UI:
open http://localhost:1337/debug/pprof/

Disable afterward: kubectl set env deployment/mogenius-operator -n mogenius MO_PPROF-


Troubleshooting

  • Scale down in-cluster deployment before running locally: just scale-down.
  • Auth issues: verify .env secrets match the mogenius/mogenius operator secret.
  • Stale dependencies: go clean -modcache && go mod tidy.

Out-of-band releases

For incidents that cannot wait for the next regular release, an older release line gets a patch release from a maintenance branch. Example: v4.0.1 on top of v4.0.0.

  1. Cut the branch from the release tag and push it:
    git switch --no-track -c release/v4.0 v4.0.0
    git push -u origin release/v4.0
  2. Land the fix as fix: … or fix(deps): …, directly or via PR into release/v4.0. Only fix/feat commits produce a release; chore and ci do not. Keep it to the fix: no features, no breaking changes.
  3. release-please opens chore(release/v4.0): release 4.0.1 against the branch. Merging it tags v4.0.1, and the production build runs as usual. :latest only moves when the tag is the highest stable version.
  4. Port the fix to main if it still applies there, and delete the branch once the incident is closed. The tag stays.

About

mogenius-operator is a Go (>=1.25) service that coordinates cluster resources, patterns, metrics collection, and auxiliary runtime capabilities for the mogenius platform.

Topics

Resources

Stars

11 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages