Skip to content

Commit 9d2270e

Browse files
committed
Refactor: Fix broken persys-scheduler / Implement compute agent / reconciler + scheduler
1 parent fdd1657 commit 9d2270e

36 files changed

Lines changed: 12599 additions & 0 deletions

persys-scheduler/Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Stage 1: Build the application
2+
FROM golang:1.24-alpine AS builder
3+
4+
# Set the working directory
5+
WORKDIR /app
6+
7+
# Copy go.mod and go.sum to download dependencies
8+
COPY go.mod go.sum ./
9+
RUN go mod download
10+
11+
# Copy the rest of the application code
12+
COPY . .
13+
14+
# Build the application
15+
RUN CGO_ENABLED=0 GOOS=linux go build -o persys-scheduler ./cmd/scheduler
16+
17+
# Stage 2: Create the final image
18+
FROM alpine:latest
19+
20+
# Set the working directory
21+
WORKDIR /root/
22+
23+
# Copy the binary from the builder stage
24+
COPY --from=builder /app/persys-scheduler .
25+
26+
# Expose the port the scheduler listens on
27+
EXPOSE 8084
28+
29+
# Command to run the scheduler
30+
CMD ["./persys-scheduler"]

persys-scheduler/Makefile

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Makefile for Go project
2+
3+
# Variables
4+
BINARY_NAME = persys-scheduler
5+
BINARY_DIR = bin
6+
BINARY_PATH = $(BINARY_DIR)/$(BINARY_NAME)
7+
IMAGE_NAME=persys-scheduler
8+
IMAGE_TAG=latest
9+
GO = go
10+
GOFLAGS = -v
11+
PORT = 8084
12+
13+
# Default target
14+
.PHONY: all
15+
all: build
16+
17+
# Ensure bin directory exists
18+
$(BINARY_DIR):
19+
mkdir -p $(BINARY_DIR)
20+
21+
# Build the binary into bin directory
22+
.PHONY: build
23+
build: $(BINARY_DIR)
24+
$(GO) build $(GOFLAGS) -o $(BINARY_PATH) ./cmd/scheduler
25+
26+
# Build the Docker image
27+
.PHONY: docker-build
28+
docker-build:
29+
$(DOCKER) build -t $(IMAGE_NAME):$(IMAGE_TAG) .
30+
@echo "Built Docker image $(IMAGE_NAME):$(IMAGE_TAG)"
31+
32+
# Run the PersysAgent container
33+
.PHONY: docker-run
34+
docker-run:
35+
$(DOCKER) compose up -d
36+
@echo "Started $(BINARY_NAME) container, API on prow:8084"
37+
38+
# Run the application from bin directory
39+
.PHONY: run
40+
run: build
41+
./$(BINARY_PATH)
42+
43+
# Test the code (if you add tests later)
44+
.PHONY: test
45+
test:
46+
$(GO) test $(GOFLAGS) ./...
47+
48+
# Clean up generated files
49+
.PHONY: clean
50+
clean:
51+
$(GO) clean
52+
rm -rf $(BINARY_DIR)
53+
54+
# Format the code
55+
.PHONY: fmt
56+
fmt:
57+
$(GO) fmt ./...
58+
59+
# Vet the code for potential issues
60+
.PHONY: vet
61+
vet:
62+
$(GO) vet ./...
63+
64+
# Update dependencies
65+
.PHONY: deps
66+
deps:
67+
$(GO) mod tidy
68+
$(GO) mod download
69+
70+
# Build and run with a single command from bin directory
71+
.PHONY: dev
72+
dev: build
73+
./$(BINARY_PATH)
74+
75+
# Check for linting issues (requires golangci-lint)
76+
.PHONY: lint
77+
lint:
78+
golangci-lint run
79+
80+
# Install the binary to $GOPATH/bin
81+
.PHONY: install
82+
install:
83+
$(GO) install $(GOFLAGS)
84+
85+
# Help command to display available targets
86+
.PHONY: help
87+
help:
88+
@echo "Available targets:"
89+
@echo " all - Build the project into bin/ (default)"
90+
@echo " build - Build the binary into bin/"
91+
@echo " docker-build - Build Docker image"
92+
@echo " docker-run - Run PersysAgent container"
93+
@echo " run - Build and run the application from bin/"
94+
@echo " test - Run tests"
95+
@echo " clean - Remove generated files and bin/ directory"
96+
@echo " fmt - Format the code"
97+
@echo " vet - Vet the code"
98+
@echo " deps - Update and download dependencies"
99+
@echo " dev - Build and run from bin/ for development"
100+
@echo " lint - Run linter (requires golangci-lint)"
101+
@echo " install - Install the binary to $$GOPATH/bin"
102+
@echo " help - Show this help message"

persys-scheduler/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Persys Scheduler
2+
3+
`persys-scheduler` is the scheduler/control-plane service for Persys workloads.
4+
5+
## Responsibilities
6+
7+
- Accept node registration + heartbeat over gRPC.
8+
- Persist node/workload state in etcd.
9+
- Select nodes for workloads based on status, labels, capabilities, and available resources.
10+
- Reconcile desired state (`Running`/`Stopped`/`Deleted`) with actual state.
11+
- Track retries, assignments, reconciliation records, and events.
12+
13+
## API
14+
15+
Proto: `api/proto/control.proto`
16+
Service: `persys.control.v1.AgentControl`
17+
18+
Implemented RPCs include:
19+
20+
- `RegisterNode`
21+
- `Heartbeat`
22+
- `ApplyWorkload`
23+
- `DeleteWorkload`
24+
- `RetryWorkload`
25+
- `ListNodes`
26+
- `GetNode`
27+
- `ListWorkloads`
28+
- `GetWorkload`
29+
- `GetClusterSummary`
30+
31+
## Default ports
32+
33+
- Metrics + health HTTP: `:8084`
34+
- gRPC control plane: `:8085`
35+
36+
Health endpoints:
37+
38+
- `GET /health`
39+
- `GET /metrics`
40+
41+
## Local run
42+
43+
Start etcd first, then run scheduler.
44+
45+
```bash
46+
./hack/start-etcd-docker.sh
47+
cd persys-scheduler
48+
go run ./cmd/scheduler -insecure
49+
```
50+
51+
`-insecure` disables mTLS for local testing.
52+
53+
## Key environment variables
54+
55+
See `sample.env`.
56+
57+
Most used:
58+
59+
- `ETCD_ENDPOINTS` (default `localhost:2379`)
60+
- `DOMAIN` (default `persys.local`)
61+
- `GRPC_PORT` (default `8085`)
62+
- `METRICS_PORT` (default `8084`)
63+
64+
For mTLS mode:
65+
66+
- `CA_FILE`
67+
- `CFSSL_API_URL`
68+
- `CERT_COMMON_NAME`
69+
- `CERT_ORGANIZATION`
70+
71+
## Build and test
72+
73+
```bash
74+
cd persys-scheduler
75+
go build ./cmd/scheduler
76+
go test ./...
77+
```

0 commit comments

Comments
 (0)