Skip to content

Commit ad07121

Browse files
Release 0.0.1
2 parents 0fdb631 + 0539896 commit ad07121

22 files changed

+2891
-1
lines changed

.github/workflows/release.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
on:
2+
release:
3+
types: [published]
4+
5+
name: Publish Docker image
6+
jobs:
7+
push_to_registries:
8+
name: Push Docker image
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Set up Docker Buildx
12+
uses: docker/setup-buildx-action@v1
13+
14+
- name: Login to Registry
15+
uses: docker/login-action@v1
16+
with:
17+
registry: ghcr.io
18+
username: ${{ github.repository_owner }}
19+
password: ${{ secrets.GITHUB_TOKEN }}
20+
21+
- name: Cache Docker layers
22+
uses: actions/cache@v2
23+
with:
24+
path: /tmp/.buildx-cache
25+
key: ${{ runner.os }}-buildx-${{ github.sha }}
26+
restore-keys: ${{ runner.os }}-buildx-
27+
28+
- name: Get tag
29+
id: tag
30+
uses: dawidd6/action-get-tag@v1
31+
32+
- name: Build and Push
33+
uses: docker/build-push-action@v2
34+
with:
35+
push: true
36+
tags: ghcr.io/${{ github.repository_owner }}/aida-schedulder:${{ steps.tag.outputs.tag }},ghcr.io/${{ github.repository_owner }}/aida-schedulder:latest

.github/workflows/test.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
- develop
6+
pull_request:
7+
branches:
8+
- develop
9+
10+
name: Test
11+
jobs:
12+
test:
13+
strategy:
14+
matrix:
15+
go-version: [1.16.x]
16+
os: [ubuntu-latest]
17+
runs-on: ${{ matrix.os }}
18+
steps:
19+
- name: Install Go
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: ${{ matrix.go-version }}
23+
- name: Checkout code
24+
uses: actions/checkout@v2
25+
- name: Lint
26+
uses: golangci/golangci-lint-action@v2
27+
with:
28+
version: v1.39
29+
- name: Test
30+
run: go test --coverprofile=coverage.out ./...
31+

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM golang:1.16-alpine
2+
3+
WORKDIR /code
4+
5+
COPY . .
6+
RUN go build && mv aida-scheduler /aida-scheduler
7+
8+
WORKDIR /
9+
RUN rm -rf /code
10+
11+
CMD /aida-scheduler

README.md

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,107 @@
1-
# scheduler
1+
# aida-scheduler
2+
3+
[![Test](https://github.com/aida-dos/aida-scheduler/actions/workflows/test.yml/badge.svg?branch=develop)](https://github.com/aida-dos/aida-scheduler/actions/workflows/test.yml)
4+
5+
## Deployment
6+
7+
```shell
8+
kubectl apply -f examples/release_scheduler_crd.yaml
9+
```
10+
11+
### Build custom docker image
12+
```shell
13+
docker build -t aida-scheduler .
14+
```
15+
16+
## Development
17+
18+
### Run the aida-controller
19+
20+
First, make sure you have deployed or are running the aida-controller in the cluster by following the instructions in
21+
the [project repository](https://github.com/aida-dos/aida-controller).
22+
23+
This controller is responsible for the management and reconciliation of the AIDA EdgeDeployments, which are the
24+
the resource type of our workloads.
25+
26+
### Run the aida-scheduler
27+
28+
To develop aida-scheduler in a Kubernetes cluster we use [ksync](https://github.com/ksync/ksync)
29+
to sync files between our local system, and the cluster.
30+
31+
1. Install ksync. You can follow ksync installation steps [here](https://github.com/ksync/ksync#installation).
32+
33+
2. Create a deployment where we will run the scheduler by applying the
34+
[example/dev_scheduler_crd.yaml](example/dev_scheduler_crd.yaml).
35+
```shell
36+
kubectl apply -f example/dev_scheduler_crd.yaml
37+
```
38+
39+
3. If not done before then create a ksync configuration for the current folder.
40+
```shell
41+
ksync create --selector=component=aida-scheduler --reload=false --local-read-only=true $(pwd) /code
42+
```
43+
44+
4. Start ksync update system
45+
```shell
46+
ksync watch
47+
```
48+
49+
5. Run the scheduler in the cluster pod
50+
```shell
51+
kubectl exec -it $(kubectl get pod -n kube-system | grep aida-scheduler | awk '{print $1}') -- sh
52+
cd /code
53+
go run main.go
54+
```
55+
56+
### Manage nodes
57+
58+
The aida-scheduler only manages Edge nodes, because the main purpose is to allow application workload to be deployed
59+
near the source of data to be processed. Therefore, the node controller filters nodes by 'node-role.kubernetes.io/edge'
60+
labels.
61+
62+
- To add the label
63+
```shell
64+
kubectl label node node0 --overwrite node-role.kubernetes.io/edge=
65+
```
66+
67+
- To remove the label
68+
```shell
69+
kubectl label node node0 --overwrite node-role.kubernetes.io/edge-
70+
```
71+
72+
### Deploy workloads
73+
74+
Apply any of the workload [examples](examples)
75+
76+
- No location set
77+
```shell
78+
kubectl apply -f examples/workload_no_set_location.yaml
79+
```
80+
81+
- Required location
82+
```shell
83+
kubectl apply -f examples/workload_required_location.yaml
84+
```
85+
86+
- Preferred location
87+
```shell
88+
kubectl apply -f examples/workload_preferred_location.yaml
89+
```
90+
91+
### Lint
92+
```shell
93+
go install github.com/golangci/golangci-lint/cmd/[email protected]
94+
golangci-lint ./...
95+
```
96+
97+
### Testing and Coverage
98+
```shell
99+
go test --coverprofile=coverage.out ./...
100+
go tool cover -html=coverage.out
101+
```
102+
103+
### Format
104+
105+
```shell
106+
go fmt ./...
107+
```

examples/dev_scheduler_crd.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: aida-scheduler
5+
namespace: kube-system
6+
7+
---
8+
apiVersion: rbac.authorization.k8s.io/v1
9+
kind: ClusterRoleBinding
10+
metadata:
11+
name: aida-scheduler-as-kube-scheduler
12+
subjects:
13+
- kind: ServiceAccount
14+
name: aida-scheduler
15+
namespace: kube-system
16+
roleRef:
17+
kind: ClusterRole
18+
name: system:kube-scheduler
19+
apiGroup: rbac.authorization.k8s.io
20+
21+
---
22+
apiVersion: rbac.authorization.k8s.io/v1
23+
kind: ClusterRoleBinding
24+
metadata:
25+
name: aida-scheduler-as-volume-scheduler
26+
subjects:
27+
- kind: ServiceAccount
28+
name: aida-scheduler
29+
namespace: kube-system
30+
roleRef:
31+
kind: ClusterRole
32+
name: system:volume-scheduler
33+
apiGroup: rbac.authorization.k8s.io
34+
35+
---
36+
apiVersion: apps/v1
37+
kind: Deployment
38+
metadata:
39+
labels:
40+
app.kubernetes.io/name: aida-scheduler
41+
app.kubernetes.io/version: 1.0.0
42+
name: aida-scheduler
43+
namespace: kube-system
44+
spec:
45+
selector:
46+
matchLabels:
47+
app.kubernetes.io/name: aida-scheduler
48+
app.kubernetes.io/version: 1.0.0
49+
replicas: 1
50+
template:
51+
metadata:
52+
labels:
53+
app.kubernetes.io/name: aida-scheduler
54+
app.kubernetes.io/version: 1.0.0
55+
spec:
56+
serviceAccountName: aida-scheduler
57+
containers:
58+
- name: aida-scheduler
59+
image: golang:1.16-alpine
60+
command: [ "/bin/sh", "-c", "--" ]
61+
args: [ "while true; do sleep 30; done;" ]
62+
affinity:
63+
nodeAffinity:
64+
requiredDuringSchedulingIgnoredDuringExecution:
65+
nodeSelectorTerms:
66+
- matchExpressions:
67+
- key: node-role.kubernetes.io/master
68+
operator: Exists
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: aida-scheduler
5+
namespace: kube-system
6+
7+
---
8+
apiVersion: rbac.authorization.k8s.io/v1
9+
kind: ClusterRoleBinding
10+
metadata:
11+
name: aida-scheduler-as-kube-scheduler
12+
subjects:
13+
- kind: ServiceAccount
14+
name: aida-scheduler
15+
namespace: kube-system
16+
roleRef:
17+
kind: ClusterRole
18+
name: system:kube-scheduler
19+
apiGroup: rbac.authorization.k8s.io
20+
21+
---
22+
apiVersion: rbac.authorization.k8s.io/v1
23+
kind: ClusterRoleBinding
24+
metadata:
25+
name: aida-scheduler-as-volume-scheduler
26+
subjects:
27+
- kind: ServiceAccount
28+
name: aida-scheduler
29+
namespace: kube-system
30+
roleRef:
31+
kind: ClusterRole
32+
name: system:volume-scheduler
33+
apiGroup: rbac.authorization.k8s.io
34+
35+
---
36+
apiVersion: apps/v1
37+
kind: Deployment
38+
metadata:
39+
labels:
40+
app.kubernetes.io/name: aida-scheduler
41+
app.kubernetes.io/version: latest
42+
name: aida-scheduler
43+
namespace: kube-system
44+
spec:
45+
selector:
46+
matchLabels:
47+
app.kubernetes.io/name: aida-scheduler
48+
app.kubernetes.io/version: latest
49+
replicas: 1
50+
template:
51+
metadata:
52+
labels:
53+
app.kubernetes.io/name: aida-scheduler
54+
app.kubernetes.io/version: latest
55+
spec:
56+
serviceAccountName: aida-scheduler
57+
containers:
58+
- name: aida-scheduler
59+
image: ghcr.io/aida-dos/aida-scheduler/aida-scheduler:latest
60+
affinity:
61+
nodeAffinity:
62+
requiredDuringSchedulingIgnoredDuringExecution:
63+
nodeSelectorTerms:
64+
- matchExpressions:
65+
- key: node-role.kubernetes.io/master
66+
operator: Exists
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: edge.aida.io/v1
2+
kind: Deployment
3+
metadata:
4+
name: no-set-location
5+
spec:
6+
replicas: 1
7+
template:
8+
spec:
9+
containers:
10+
- name: test-app
11+
image: nginx:latest
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: edge.aida.io/v1
2+
kind: Deployment
3+
metadata:
4+
name: preferred-location
5+
spec:
6+
replicas: 1
7+
preferredLocation:
8+
cities:
9+
- Braga
10+
countries:
11+
- Portugal
12+
- Germany
13+
template:
14+
spec:
15+
containers:
16+
- name: test-app
17+
image: nginx:latest
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: edge.aida.io/v1
2+
kind: Deployment
3+
metadata:
4+
name: required-location
5+
spec:
6+
replicas: 1
7+
requiredLocation:
8+
cities:
9+
- Braga
10+
- New York
11+
continents:
12+
- Europe
13+
template:
14+
spec:
15+
containers:
16+
- name: test-app
17+
image: nginx:latest

go.mod

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module aida-scheduler
2+
3+
go 1.16
4+
5+
require (
6+
github.com/aida-dos/gountries v0.0.0-20210328164130-bacd2f98d9be
7+
github.com/stretchr/testify v1.4.0
8+
k8s.io/api v0.18.10
9+
k8s.io/apimachinery v0.18.11-rc.0
10+
k8s.io/client-go v0.18.10
11+
k8s.io/klog/v2 v2.8.0
12+
)

0 commit comments

Comments
 (0)