Skip to content

Commit

Permalink
Release 0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
machadovilaca authored Mar 31, 2021
2 parents 0fdb631 + 0539896 commit ad07121
Show file tree
Hide file tree
Showing 22 changed files with 2,891 additions and 1 deletion.
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
on:
release:
types: [published]

name: Publish Docker image
jobs:
push_to_registries:
name: Push Docker image
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: ${{ runner.os }}-buildx-

- name: Get tag
id: tag
uses: dawidd6/action-get-tag@v1

- name: Build and Push
uses: docker/build-push-action@v2
with:
push: true
tags: ghcr.io/${{ github.repository_owner }}/aida-schedulder:${{ steps.tag.outputs.tag }},ghcr.io/${{ github.repository_owner }}/aida-schedulder:latest
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
on:
push:
branches:
- main
- develop
pull_request:
branches:
- develop

name: Test
jobs:
test:
strategy:
matrix:
go-version: [1.16.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.39
- name: Test
run: go test --coverprofile=coverage.out ./...

11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.16-alpine

WORKDIR /code

COPY . .
RUN go build && mv aida-scheduler /aida-scheduler

WORKDIR /
RUN rm -rf /code

CMD /aida-scheduler
108 changes: 107 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,107 @@
# scheduler
# aida-scheduler

[![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)

## Deployment

```shell
kubectl apply -f examples/release_scheduler_crd.yaml
```

### Build custom docker image
```shell
docker build -t aida-scheduler .
```

## Development

### Run the aida-controller

First, make sure you have deployed or are running the aida-controller in the cluster by following the instructions in
the [project repository](https://github.com/aida-dos/aida-controller).

This controller is responsible for the management and reconciliation of the AIDA EdgeDeployments, which are the
the resource type of our workloads.

### Run the aida-scheduler

To develop aida-scheduler in a Kubernetes cluster we use [ksync](https://github.com/ksync/ksync)
to sync files between our local system, and the cluster.

1. Install ksync. You can follow ksync installation steps [here](https://github.com/ksync/ksync#installation).

2. Create a deployment where we will run the scheduler by applying the
[example/dev_scheduler_crd.yaml](example/dev_scheduler_crd.yaml).
```shell
kubectl apply -f example/dev_scheduler_crd.yaml
```

3. If not done before then create a ksync configuration for the current folder.
```shell
ksync create --selector=component=aida-scheduler --reload=false --local-read-only=true $(pwd) /code
```

4. Start ksync update system
```shell
ksync watch
```

5. Run the scheduler in the cluster pod
```shell
kubectl exec -it $(kubectl get pod -n kube-system | grep aida-scheduler | awk '{print $1}') -- sh
cd /code
go run main.go
```

### Manage nodes

The aida-scheduler only manages Edge nodes, because the main purpose is to allow application workload to be deployed
near the source of data to be processed. Therefore, the node controller filters nodes by 'node-role.kubernetes.io/edge'
labels.

- To add the label
```shell
kubectl label node node0 --overwrite node-role.kubernetes.io/edge=
```

- To remove the label
```shell
kubectl label node node0 --overwrite node-role.kubernetes.io/edge-
```

### Deploy workloads

Apply any of the workload [examples](examples)

- No location set
```shell
kubectl apply -f examples/workload_no_set_location.yaml
```

- Required location
```shell
kubectl apply -f examples/workload_required_location.yaml
```

- Preferred location
```shell
kubectl apply -f examples/workload_preferred_location.yaml
```

### Lint
```shell
go install github.com/golangci/golangci-lint/cmd/[email protected]
golangci-lint ./...
```

### Testing and Coverage
```shell
go test --coverprofile=coverage.out ./...
go tool cover -html=coverage.out
```

### Format

```shell
go fmt ./...
```
68 changes: 68 additions & 0 deletions examples/dev_scheduler_crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: aida-scheduler
namespace: kube-system

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: aida-scheduler-as-kube-scheduler
subjects:
- kind: ServiceAccount
name: aida-scheduler
namespace: kube-system
roleRef:
kind: ClusterRole
name: system:kube-scheduler
apiGroup: rbac.authorization.k8s.io

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: aida-scheduler-as-volume-scheduler
subjects:
- kind: ServiceAccount
name: aida-scheduler
namespace: kube-system
roleRef:
kind: ClusterRole
name: system:volume-scheduler
apiGroup: rbac.authorization.k8s.io

---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/name: aida-scheduler
app.kubernetes.io/version: 1.0.0
name: aida-scheduler
namespace: kube-system
spec:
selector:
matchLabels:
app.kubernetes.io/name: aida-scheduler
app.kubernetes.io/version: 1.0.0
replicas: 1
template:
metadata:
labels:
app.kubernetes.io/name: aida-scheduler
app.kubernetes.io/version: 1.0.0
spec:
serviceAccountName: aida-scheduler
containers:
- name: aida-scheduler
image: golang:1.16-alpine
command: [ "/bin/sh", "-c", "--" ]
args: [ "while true; do sleep 30; done;" ]
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-role.kubernetes.io/master
operator: Exists
66 changes: 66 additions & 0 deletions examples/release_scheduler_crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: aida-scheduler
namespace: kube-system

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: aida-scheduler-as-kube-scheduler
subjects:
- kind: ServiceAccount
name: aida-scheduler
namespace: kube-system
roleRef:
kind: ClusterRole
name: system:kube-scheduler
apiGroup: rbac.authorization.k8s.io

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: aida-scheduler-as-volume-scheduler
subjects:
- kind: ServiceAccount
name: aida-scheduler
namespace: kube-system
roleRef:
kind: ClusterRole
name: system:volume-scheduler
apiGroup: rbac.authorization.k8s.io

---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/name: aida-scheduler
app.kubernetes.io/version: latest
name: aida-scheduler
namespace: kube-system
spec:
selector:
matchLabels:
app.kubernetes.io/name: aida-scheduler
app.kubernetes.io/version: latest
replicas: 1
template:
metadata:
labels:
app.kubernetes.io/name: aida-scheduler
app.kubernetes.io/version: latest
spec:
serviceAccountName: aida-scheduler
containers:
- name: aida-scheduler
image: ghcr.io/aida-dos/aida-scheduler/aida-scheduler:latest
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-role.kubernetes.io/master
operator: Exists
11 changes: 11 additions & 0 deletions examples/workload_no_set_location.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: edge.aida.io/v1
kind: Deployment
metadata:
name: no-set-location
spec:
replicas: 1
template:
spec:
containers:
- name: test-app
image: nginx:latest
17 changes: 17 additions & 0 deletions examples/workload_preferred_location.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: edge.aida.io/v1
kind: Deployment
metadata:
name: preferred-location
spec:
replicas: 1
preferredLocation:
cities:
- Braga
countries:
- Portugal
- Germany
template:
spec:
containers:
- name: test-app
image: nginx:latest
17 changes: 17 additions & 0 deletions examples/workload_required_location.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: edge.aida.io/v1
kind: Deployment
metadata:
name: required-location
spec:
replicas: 1
requiredLocation:
cities:
- Braga
- New York
continents:
- Europe
template:
spec:
containers:
- name: test-app
image: nginx:latest
12 changes: 12 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module aida-scheduler

go 1.16

require (
github.com/aida-dos/gountries v0.0.0-20210328164130-bacd2f98d9be
github.com/stretchr/testify v1.4.0
k8s.io/api v0.18.10
k8s.io/apimachinery v0.18.11-rc.0
k8s.io/client-go v0.18.10
k8s.io/klog/v2 v2.8.0
)
Loading

0 comments on commit ad07121

Please sign in to comment.