Skip to content

Commit

Permalink
Merge pull request #80 from interTwin-eu/main
Browse files Browse the repository at this point in the history
dump v0.0.2 from main
  • Loading branch information
dciangot authored Sep 12, 2023
2 parents f142436 + c1d138e commit 3a90615
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 64 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/build_images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ jobs:
# DOCKER_TARGET_PLATFORM: linux/arm64
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
Expand All @@ -28,7 +28,7 @@ jobs:
id: get_repo_owner
run: echo ::set-output name=repo_owner::$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')
- name: Build container base image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: ./
outputs: "type=registry,push=true"
Expand All @@ -43,13 +43,13 @@ jobs:
# DOCKER_TARGET_PLATFORM: linux/arm64
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
Expand All @@ -60,7 +60,7 @@ jobs:
id: get_repo_owner
run: echo ::set-output name=repo_owner::$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')
- name: Build container base image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: ./
outputs: "type=registry,push=true"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
# Checks out a copy of your repository on the ubuntu-latest machine
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# Make sure the actual branch is checked out when running on PR
# ref: ${{ github.event.pull_request.head.sha }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --force --tags
Expand All @@ -24,7 +24,7 @@ jobs:
go-version: stable
# More assembly might be required: Docker logins, GPG, etc. It all depends
# on your needs.
- uses: goreleaser/goreleaser-action@v4
- uses: goreleaser/goreleaser-action@v5
with:
# either 'goreleaser' (default) or 'goreleaser-pro':
distribution: goreleaser
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
# Checks out a copy of your repository on the ubuntu-latest machine
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# Make sure the actual branch is checked out when running on PR
# ref: ${{ github.event.pull_request.head.sha }}
Expand Down
67 changes: 48 additions & 19 deletions README.md

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions cmd/interlink/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"fmt"
"net/http"

commonIL "github.com/intertwin-eu/interlink/pkg/common"
Expand All @@ -26,14 +25,14 @@ func main() {

commonIL.NewInterLinkConfig()

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

mutex := http.NewServeMux()
mutex.HandleFunc("/status", interlink.StatusHandler)
mutex.HandleFunc("/create", interlink.CreateHandler)
mutex.HandleFunc("/delete", interlink.DeleteHandler)
mutex.HandleFunc("/setKubeCFG", interlink.SetKubeCFGHandler)

fmt.Println(commonIL.InterLinkConfigInst)

mutex.HandleFunc("/ping", interlink.Ping)
err := http.ListenAndServe(":"+commonIL.InterLinkConfigInst.Interlinkport, mutex)
if err != nil {
log.G(interlink.Ctx).Fatal(err)
Expand Down
26 changes: 26 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (

// "net/http"

commonIL "github.com/intertwin-eu/interlink/pkg/common"
"github.com/intertwin-eu/interlink/pkg/virtualkubelet"
"github.com/sirupsen/logrus"
"github.com/virtual-kubelet/virtual-kubelet/log"
Expand Down Expand Up @@ -145,6 +146,31 @@ func main() {
localClient := kubernetes.NewForConfigOrDie(kubecfg)

nodeProvider, err := virtualkubelet.NewProvider(cfg.ConfigPath, cfg.NodeName, cfg.OperatingSystem, cfg.InternalIP, cfg.DaemonPort, ctx)
go func() {

ILbindNow := false
ILbindOld := false

for {
err, ILbindNow = commonIL.PingInterLink()

if err != nil {
log.G(ctx).Error(err)
}

if ILbindNow == true && ILbindOld == false {
err = commonIL.NewServiceAccount()
if err != nil {
log.G(ctx).Fatal(err)
}
}

ILbindOld = ILbindNow
time.Sleep(time.Second * 10)

}
}()

if err != nil {
log.G(ctx).Fatal(err)
}
Expand Down
50 changes: 38 additions & 12 deletions pkg/common/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"os"
"time"

"k8s.io/client-go/tools/clientcmd"

"github.com/containerd/containerd/log"

exec "github.com/alexellis/go-execute/pkg/v1"
Expand Down Expand Up @@ -150,6 +152,7 @@ func NewServiceAccount() error {
return err
}

//executing the script to actually retrieve a valid service account
cmd := []string{path + "getSAConfig.sh"}
shell := exec.ExecTask{
Command: "sh",
Expand All @@ -162,25 +165,24 @@ func NewServiceAccount() error {
return errors.New(execResult.Stderr)
}

temp, err := os.ReadFile(path + "kubeconfig-sa")
//checking if the config is valid
_, err = clientcmd.LoadFromFile(path + "kubeconfig-sa")
if err != nil {
log.G(context.Background()).Error(err)
return err
}

sa = string(temp)
config, err := os.ReadFile(path + "kubeconfig-sa")
if err != nil {
log.G(context.Background()).Error(err)
return err
}

sa = string(config)
os.Remove(path + "getSAConfig.sh")
os.Remove(path + "kubeconfig-sa")

requestCounter := 0

for {

if requestCounter == 20 {
log.G(context.Background()).Error("Service Account timed out, exiting")
return errors.New("Service Account timed out, exiting")
}

var returnValue, _ = json.Marshal("Error")
reader := bytes.NewReader([]byte(sa))
req, err := http.NewRequest(http.MethodPost, InterLinkConfigInst.Interlinkurl+":"+InterLinkConfigInst.Interlinkport+"/setKubeCFG", reader)
Expand All @@ -204,8 +206,6 @@ func NewServiceAccount() error {
returnValue, _ = ioutil.ReadAll(resp.Body)
}

requestCounter++

if resp.StatusCode == http.StatusOK {
break
} else {
Expand All @@ -215,3 +215,29 @@ func NewServiceAccount() error {

return nil
}

func PingInterLink() (error, bool) {
req, err := http.NewRequest(http.MethodPost, InterLinkConfigInst.Interlinkurl+":"+InterLinkConfigInst.Interlinkport+"/ping", nil)

if err != nil {
log.G(context.Background()).Error(err)
}

token, err := os.ReadFile(InterLinkConfigInst.VKTokenFile) // just pass the file name
if err != nil {
log.G(context.Background()).Error(err)
return err, false
}
req.Header.Add("Authorization", "Bearer "+string(token))
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err, false
}

if resp.StatusCode == http.StatusOK {
return nil, true
} else {
log.G(context.Background()).Error("Error " + err.Error() + " " + fmt.Sprint(resp.StatusCode))
return nil, false
}
}
12 changes: 12 additions & 0 deletions pkg/interlink/ping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package interlink

import (
"net/http"

"github.com/containerd/containerd/log"
)

func Ping(w http.ResponseWriter, r *http.Request) {
log.G(Ctx).Info("InterLink: received Ping call")
w.WriteHeader(http.StatusOK)
}
7 changes: 1 addition & 6 deletions pkg/sidecars/slurm/aux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ import (
"k8s.io/client-go/rest"
)

type JidStruct struct {
JID string
Pod v1.Pod
}

var prefix string
var Clientset *kubernetes.Clientset
var Ctx context.Context
Expand Down Expand Up @@ -258,7 +253,7 @@ func handle_jid(container v1.Container, output string, pod v1.Pod) error {
log.G(Ctx).Error(err)
return err
}
JID = append(JID, JidStruct{JID: jid[1], Pod: pod})
JID = append(JID, jid[1])

return nil
}
Expand Down
27 changes: 22 additions & 5 deletions pkg/sidecars/slurm/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var JID []JidStruct
var JID []string

func SubmitHandler(w http.ResponseWriter, r *http.Request) {
log.G(Ctx).Info("Slurm Sidecar: received Submit call")
Expand Down Expand Up @@ -116,11 +116,17 @@ func SubmitHandler(w http.ResponseWriter, r *http.Request) {
os.RemoveAll(commonIL.InterLinkConfigInst.DataRootFolder + data.Pod.Namespace + "-" + string(data.Pod.UID))
return
}
JID = append(JID, JidStruct{JID: string(jid), Pod: data.Pod})
JID = append(JID, string(jid))
}
}

w.Write([]byte(nil))
w.WriteHeader(statusCode)

if statusCode != http.StatusOK {
w.Write([]byte("Some errors occurred while creating containers. Check Slurm Sidecar's logs"))
} else {
w.Write([]byte("Containers created"))
}
}

func StopHandler(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -163,6 +169,13 @@ func StopHandler(w http.ResponseWriter, r *http.Request) {
}
}
}

w.WriteHeader(statusCode)
if statusCode != http.StatusOK {
w.Write([]byte("Some errors occurred deleting containers. Check Slurm Sidecar's logs"))
} else {
w.Write([]byte("All containers for submitted Pods have been deleted"))
}
}

func StatusHandler(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -210,7 +223,7 @@ func StatusHandler(w http.ResponseWriter, r *http.Request) {
var flag = false
for _, jid := range JID {

cmd := []string{"-c", "squeue --me | grep " + jid.JID}
cmd := []string{"-c", "squeue --me | grep " + jid}
shell := exec.ExecTask{
Command: "bash",
Args: cmd,
Expand Down Expand Up @@ -248,5 +261,9 @@ func StatusHandler(w http.ResponseWriter, r *http.Request) {
}

w.WriteHeader(statusCode)
w.Write(bodyBytes)
if statusCode != http.StatusOK {
w.Write([]byte("Some errors occurred deleting containers. Check Docker Sidecar's logs"))
} else {
w.Write([]byte("All containers for submitted Pods have been deleted"))
}
}
6 changes: 0 additions & 6 deletions pkg/virtualkubelet/virtualkubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,6 @@ func NewProvider(providerConfig, nodeName, operatingSystem string, internalIP st
func loadConfig(providerConfig, nodeName string, ctx context.Context) (config VirtualKubeletConfig, err error) {

commonIL.NewInterLinkConfig()
err = commonIL.NewServiceAccount()

if err != nil {
log.G(ctx).Fatal(err)
}

log.G(context.Background()).Info("Loading Virtual Kubelet config from " + providerConfig)
data, err := ioutil.ReadFile(providerConfig)
if err != nil {
Expand Down

0 comments on commit 3a90615

Please sign in to comment.