Skip to content

Commit

Permalink
Merge pull request #138 from dciangot/fix_error_handlings
Browse files Browse the repository at this point in the history
REWORK: error handling and no more global config
  • Loading branch information
dciangot authored Jan 29, 2024
2 parents 5c6f790 + 86a9462 commit 5dc05c9
Show file tree
Hide file tree
Showing 4,379 changed files with 517 additions and 1,308,235 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions .idea/interLink.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
all: interlink vk sidecars

interlink:
go build -o bin/interlink cmd/interlink/main.go
CGO_ENABLED=0 OOS=linux go build -o bin/interlink cmd/interlink/main.go

vk:
go build -o bin/vk
CGO_ENABLED=0 OOS=linux go build -o bin/vk

sidecars:
GOOS=linux GOARCH=amd64 go build -o bin/docker-sd cmd/sidecars/docker/main.go
GOOS=linux GOARCH=amd64 go build -o bin/slurm-sd cmd/sidecars/slurm/main.go
CGO_ENABLED=0 GOOS=linux go build -o bin/docker-sd cmd/sidecars/docker/main.go
CGO_ENABLED=0 GOOS=linux go build -o bin/slurm-sd cmd/sidecars/slurm/main.go

clean:
rm -rf ./bin

all_ppc64le:
GOOS=linux GOARCH=ppc64le go build -o bin/interlink cmd/interlink/main.go
GOOS=linux GOARCH=ppc64le go build -o bin/vk
GOOS=linux GOARCH=ppc64le go build -o bin/docker-sd cmd/sidecars/docker/main.go
GOOS=linux GOARCH=ppc64le go build -o bin/slurm-sd cmd/sidecars/slurm/main.go
CGO_ENABLED=0 GOOS=linux GOARCH=ppc64le go build -o bin/interlink cmd/interlink/main.go
CGO_ENABLED=0 GOOS=linux GOARCH=ppc64le go build -o bin/vk
CGO_ENABLED=0 GOOS=linux GOARCH=ppc64le go build -o bin/docker-sd cmd/sidecars/docker/main.go
CGO_ENABLED=0 GOOS=linux GOARCH=ppc64le go build -o bin/slurm-sd cmd/sidecars/slurm/main.go

start_interlink_slurm:
./bin/interlink &> ./logs/interlink.log &
Expand All @@ -26,3 +26,4 @@ start_interlink_slurm:
start_interlink_docker:
./bin/interlink &> ./logs/interlink.log &
./bin/docker-sd &> ./logs/docker-sd.log &

35 changes: 20 additions & 15 deletions cmd/interlink/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@ import (
"context"
"net/http"

commonIL "github.com/intertwin-eu/interlink/pkg/common"
"github.com/intertwin-eu/interlink/pkg/interlink"
"github.com/sirupsen/logrus"
"github.com/virtual-kubelet/virtual-kubelet/log"
logruslogger "github.com/virtual-kubelet/virtual-kubelet/log/logrus"
)

var Url string
commonIL "github.com/intertwin-eu/interlink/pkg/common"
"github.com/intertwin-eu/interlink/pkg/interlink"
)

func main() {
var cancel context.CancelFunc
interlink.PodStatuses.Statuses = make(map[string]commonIL.PodStatus)

commonIL.NewInterLinkConfig()
interLinkConfig, err := commonIL.NewInterLinkConfig()
if err != nil {
panic(err)
}
logger := logrus.StandardLogger()

if commonIL.InterLinkConfigInst.VerboseLogging {
if interLinkConfig.VerboseLogging {
logger.SetLevel(logrus.DebugLevel)
} else if commonIL.InterLinkConfigInst.ErrorsOnlyLogging {
} else if interLinkConfig.ErrorsOnlyLogging {
logger.SetLevel(logrus.ErrorLevel)
} else {
logger.SetLevel(logrus.InfoLevel)
Expand All @@ -32,16 +34,19 @@ func main() {
interlink.Ctx, cancel = context.WithCancel(context.Background())
defer cancel()

log.G(interlink.Ctx).Info(commonIL.InterLinkConfigInst)
log.G(interlink.Ctx).Info(interLinkConfig)

interLinkAPIs := interlink.InterLinkHandler{
Config: interLinkConfig,
}

mutex := http.NewServeMux()
mutex.HandleFunc("/status", interlink.StatusHandler)
mutex.HandleFunc("/create", interlink.CreateHandler)
mutex.HandleFunc("/delete", interlink.DeleteHandler)
mutex.HandleFunc("/ping", interlink.Ping)
mutex.HandleFunc("/getLogs", interlink.GetLogsHandler)
mutex.HandleFunc("/updateCache", interlink.UpdateCacheHandler)
err := http.ListenAndServe(":"+commonIL.InterLinkConfigInst.Interlinkport, mutex)
mutex.HandleFunc("/status", interLinkAPIs.StatusHandler)
mutex.HandleFunc("/create", interLinkAPIs.CreateHandler)
mutex.HandleFunc("/delete", interLinkAPIs.DeleteHandler)
mutex.HandleFunc("/ping", interLinkAPIs.Ping)
mutex.HandleFunc("/getLogs", interLinkAPIs.GetLogsHandler)
err = http.ListenAndServe(":"+interLinkConfig.Interlinkport, mutex)
if err != nil {
log.G(interlink.Ctx).Fatal(err)
}
Expand Down
34 changes: 20 additions & 14 deletions cmd/sidecars/docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,48 @@ package main
import (
"context"
"net/http"
"strconv"

"github.com/sirupsen/logrus"
"github.com/virtual-kubelet/virtual-kubelet/log"
logruslogger "github.com/virtual-kubelet/virtual-kubelet/log/logrus"

commonIL "github.com/intertwin-eu/interlink/pkg/common"
docker "github.com/intertwin-eu/interlink/pkg/sidecars/docker"
)

func main() {
var cancel context.CancelFunc
logger := logrus.StandardLogger()

commonIL.NewInterLinkConfig()
interLinkConfig, err := commonIL.NewInterLinkConfig()
if err != nil {
log.L.Fatal(err)
}

if commonIL.InterLinkConfigInst.VerboseLogging {
if interLinkConfig.VerboseLogging {
logger.SetLevel(logrus.DebugLevel)
} else if commonIL.InterLinkConfigInst.ErrorsOnlyLogging {
} else if interLinkConfig.ErrorsOnlyLogging {
logger.SetLevel(logrus.ErrorLevel)
} else {
logger.SetLevel(logrus.InfoLevel)
}

log.L = logruslogger.FromLogrus(logrus.NewEntry(logger))

docker.Ctx, cancel = context.WithCancel(context.Background())
Ctx, cancel := context.WithCancel(context.Background())
defer cancel()
log.G(Ctx).Debug("Debug level: " + strconv.FormatBool(interLinkConfig.VerboseLogging))

SidecarAPIs := docker.SidecarHandler{
Config: interLinkConfig,
Ctx: Ctx,
}

mutex := http.NewServeMux()
mutex.HandleFunc("/status", docker.StatusHandler)
mutex.HandleFunc("/create", docker.CreateHandler)
mutex.HandleFunc("/delete", docker.DeleteHandler)
mutex.HandleFunc("/getLogs", docker.GetLogsHandler)
err := http.ListenAndServe(":"+commonIL.InterLinkConfigInst.Sidecarport, mutex)
mutex.HandleFunc("/status", SidecarAPIs.StatusHandler)
mutex.HandleFunc("/create", SidecarAPIs.CreateHandler)
mutex.HandleFunc("/delete", SidecarAPIs.DeleteHandler)
mutex.HandleFunc("/getLogs", SidecarAPIs.GetLogsHandler)
err = http.ListenAndServe(":"+interLinkConfig.Sidecarport, mutex)

if err != nil {
log.L.Fatal(err)
log.G(Ctx).Fatal(err)
}
}
43 changes: 26 additions & 17 deletions cmd/sidecars/slurm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,54 @@ import (
"net/http"
"strconv"

commonIL "github.com/intertwin-eu/interlink/pkg/common"
slurm "github.com/intertwin-eu/interlink/pkg/sidecars/slurm"
"github.com/sirupsen/logrus"
"github.com/virtual-kubelet/virtual-kubelet/log"
logruslogger "github.com/virtual-kubelet/virtual-kubelet/log/logrus"

commonIL "github.com/intertwin-eu/interlink/pkg/common"
slurm "github.com/intertwin-eu/interlink/pkg/sidecars/slurm"
)

func main() {
var cancel context.CancelFunc
slurm.JIDs = make(map[string]*slurm.JidStruct)
logger := logrus.StandardLogger()

commonIL.NewInterLinkConfig()
interLinkConfig, err := commonIL.NewInterLinkConfig()
if err != nil {
panic(err)
}

if commonIL.InterLinkConfigInst.VerboseLogging {
if interLinkConfig.VerboseLogging {
logger.SetLevel(logrus.DebugLevel)
} else if commonIL.InterLinkConfigInst.ErrorsOnlyLogging {
} else if interLinkConfig.ErrorsOnlyLogging {
logger.SetLevel(logrus.ErrorLevel)
} else {
logger.SetLevel(logrus.InfoLevel)
}

log.L = logruslogger.FromLogrus(logrus.NewEntry(logger))
log.G(context.Background()).Debug("Debug level: " + strconv.FormatBool(commonIL.InterLinkConfigInst.VerboseLogging))

slurm.Ctx, cancel = context.WithCancel(context.Background())
JobIDs := make(map[string]*slurm.JidStruct)
Ctx, cancel := context.WithCancel(context.Background())
defer cancel()
log.G(Ctx).Debug("Debug level: " + strconv.FormatBool(interLinkConfig.VerboseLogging))

SidecarAPIs := slurm.SidecarHandler{
Config: interLinkConfig,
JIDs: &JobIDs,
Ctx: Ctx,
}

mutex := http.NewServeMux()
mutex.HandleFunc("/status", slurm.StatusHandler)
mutex.HandleFunc("/create", slurm.SubmitHandler)
mutex.HandleFunc("/delete", slurm.StopHandler)
mutex.HandleFunc("/getLogs", slurm.GetLogsHandler)
mutex.HandleFunc("/status", SidecarAPIs.StatusHandler)
mutex.HandleFunc("/create", SidecarAPIs.SubmitHandler)
mutex.HandleFunc("/delete", SidecarAPIs.StopHandler)
mutex.HandleFunc("/getLogs", SidecarAPIs.GetLogsHandler)

slurm.CreateDirectories()
slurm.Load_JIDs()
slurm.CreateDirectories(interLinkConfig)
slurm.LoadJIDs(interLinkConfig, &JobIDs, Ctx)

err := http.ListenAndServe(":"+commonIL.InterLinkConfigInst.Sidecarport, mutex)
err = http.ListenAndServe(":"+interLinkConfig.Sidecarport, mutex)
if err != nil {
log.G(slurm.Ctx).Fatal(err)
log.G(Ctx).Fatal(err)
}
}
2 changes: 1 addition & 1 deletion docker/Dockerfile.interlink
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR /app

COPY .. .

RUN CGO_ENABLED=0 GOOS=linux go build -mod vendor -o bin/interlink cmd/interlink/main.go
RUN CGO_ENABLED=0 GOOS=linux go build -o bin/interlink cmd/interlink/main.go

# Deploy the application binary into a lean image
FROM gcr.io/distroless/base-debian11:latest AS build-release-stage
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.sidecar-docker
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM golang:1.21 as build-stage

WORKDIR /app
COPY .. .
RUN CGO_ENABLED=0 GOOS=linux go build -mod vendor -o bin/docker-sidecar cmd/sidecars/docker/main.go
RUN CGO_ENABLED=0 GOOS=linux go build -o bin/docker-sidecar cmd/sidecars/docker/main.go

FROM bash:latest as bash-stage

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.vk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WORKDIR /app

COPY .. .

RUN CGO_ENABLED=0 GOOS=linux go build -mod vendor -o bin/vk
RUN CGO_ENABLED=0 GOOS=linux go build -o bin/vk

# Deploy the application binary into a lean image
FROM ubuntu:22.04 AS build-release-stage
Expand Down
4 changes: 2 additions & 2 deletions docker/slurm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM golang:1.21 as build-stage
WORKDIR /app

COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -mod vendor -o bin/slurm-sidecar cmd/sidecars/slurm/main.go
RUN CGO_ENABLED=0 GOOS=linux go build -o bin/slurm-sidecar cmd/sidecars/slurm/main.go


# Deploy the application binary into a lean image
Expand Down Expand Up @@ -48,7 +48,7 @@ ENV INTERLINKCONFIGPATH=/root/InterLinkConfig.yaml

COPY docker/slurm/InterLinkConfig.yaml .

RUN apt install -y software-properties-common \
RUN apt update && apt install -y software-properties-common \
&& add-apt-repository -y ppa:apptainer/ppa \
&& apt install -y apptainer

Expand Down
11 changes: 2 additions & 9 deletions docs-new/docs/tutorial-users/01-quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ Move to example location:

```bash
cd interLink/examples/interlink-docker

mkdir -p interlink/config
cp vk/InterLinkConfig.yaml interlink/config/InterLinkConfig.yaml
```

### Setup Kubernetes cluster

```bash
minikube start --kubernetes-version=1.24.3
minikube start --kubernetes-version=1.26.10
```

### Deploy Interlink
Expand All @@ -48,8 +45,6 @@ You need to provide the interLink IP address that should be reachable from the k
```bash
export INTERLINK_IP_ADDRESS=XXX.XX.X.XXX

sed -i 's/InterlinkURL:.*/InterlinkURL: "http:\/\/'$INTERLINK_IP_ADDRESS'"/g' interlink/config/InterLinkConfig.yaml | sed -i 's/SidecarURL:.*/SidecarURL: "http:\/\/'$INTERLINK_IP_ADDRESS'"/g' interlink/config/InterLinkConfig.yaml

sed -i 's/InterlinkURL:.*/InterlinkURL: "http:\/\/'$INTERLINK_IP_ADDRESS'"/g' vk/InterLinkConfig.yaml | sed -i 's/SidecarURL:.*/SidecarURL: "http:\/\/'$INTERLINK_IP_ADDRESS'"/g' vk/InterLinkConfig.yaml
```

Expand Down Expand Up @@ -134,7 +129,7 @@ __N.B.__ in the demo the oauth2 proxy authN/Z is disabled. DO NOT USE THIS IN PR
### Bootstrap a minikube cluster

```bash
minikube start --kubernetes-version=1.27.1
minikube start --kubernetes-version=1.26.10
```

Once finished you should check that everything went well with a simple `kubectl get node`.
Expand All @@ -158,8 +153,6 @@ In case of this demo setup, that address __is the address of your machine__
```bash
export INTERLINK_IP_ADDRESS=XXX.XX.X.XXX

sed -i 's/InterlinkURL:.*/InterlinkURL: "http:\/\/'$INTERLINK_IP_ADDRESS'"/g' interlink/config/InterLinkConfig.yaml | sed -i 's/SidecarURL:.*/SidecarURL: "http:\/\/'$INTERLINK_IP_ADDRESS'"/g' interlink/config/InterLinkConfig.yaml

sed -i 's/InterlinkURL:.*/InterlinkURL: "http:\/\/'$INTERLINK_IP_ADDRESS'"/g' vk/InterLinkConfig.yaml | sed -i 's/SidecarURL:.*/SidecarURL: "http:\/\/'$INTERLINK_IP_ADDRESS'"/g' vk/InterLinkConfig.yaml
```

Expand Down
12 changes: 8 additions & 4 deletions examples/interlink-docker/interlink/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ services:
context: ../../../
dockerfile: docker/Dockerfile.interlink
restart: always
network_mode: "host"
#network_mode: "host"
ports:
- 3000:3000
volumes:
- type: bind
source: ./config
source: ../vk
target: /etc/interlink
environment:
- INTERLINKCONFIGPATH=/etc/interlink/InterLinkConfig.yaml
Expand All @@ -26,12 +28,14 @@ services:
privileged: true
cap_add:
- SYS_ADMIN
network_mode: "host"
#network_mode: "host"
ports:
- 4000:4000
environment:
- INTERLINKCONFIGPATH=/etc/interlink/InterLinkConfig.yaml
volumes:
- type: bind
source: ./config
source: ../vk
target: /etc/interlink
- type: bind
source: /var/run/docker.sock
Expand Down
4 changes: 2 additions & 2 deletions examples/interlink-docker/vk/InterLinkConfig.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
VKTokenFile: "$HOME/interLink/token"
InterlinkURL: "http://10.25.127.213"
SidecarURL: "http://XXX.XXX.XXX.XXX"
InterlinkURL: "http://XXX.XXX.XXX.XXX"
SidecarURL: "http://docker-sidecar"
InterlinkPort: "3000"
SidecarPort: "4000"
SbatchPath: "/usr/bin/sbatch"
Expand Down
19 changes: 0 additions & 19 deletions examples/interlink-slurm/interlink/config/InterLinkConfig.yaml

This file was deleted.

Loading

0 comments on commit 5dc05c9

Please sign in to comment.