Skip to content

Commit

Permalink
Fix Refill and avoid error logs on excluded pod terminated
Browse files Browse the repository at this point in the history
  • Loading branch information
mickours committed Apr 26, 2024
1 parent c9667be commit 74874ce
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
10 changes: 9 additions & 1 deletion connectors/exec/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@ var setup = setupFromEnv

func setupFromEnv() SSHConfig {
user := os.Getenv("BEBIDA_SSH_USER")
if user == "" {
user = os.Getenv("USER")
}
hostname := os.Getenv("BEBIDA_SSH_HOSTNAME")
if hostname == "" {
hostname = "localhost"
}
port := os.Getenv("BEBIDA_SSH_PORT")
if port == "" {
port = "22"
}
// from base64 encoded env var
keyBase64 := os.Getenv("BEBIDA_SSH_PKEY")
return SSHConfig{user: user, hostname: hostname, port: port, keyBase64: keyBase64}
Expand All @@ -29,7 +38,6 @@ func setupFromEnv() SSHConfig {
func ExecuteCommand(cmd string) (string, error) {
sshConfig := setup()
connectionUrl := sshConfig.hostname + ":" + sshConfig.port

key, err := base64.StdEncoding.DecodeString(sshConfig.keyBase64)
if err != nil {
log.Fatalf("unable to decode private key: %v", err)
Expand Down
5 changes: 5 additions & 0 deletions connectors/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ func WatchQueues(channel chan interface{}, defaultPunchNbCore int, defaultPunchD
// case v1.PodRunning:
// channel <- events.PodStarted
case v1.PodSucceeded, v1.PodFailed:
// Exclude pod if explicitly requested
if pod.Annotations[bebida_prefix+"bebida"] == "exclude" {
log.Infof("Found exclusion annotation %s, do exclude this pod", bebida_prefix+"bebida: exclude")
continue
}
nbCores, err := strconv.Atoi(pod.Annotations[bebida_prefix+"resources.cores"])
if err != nil {
log.Warnf("Error %s while parsing resources.cores annotation for Pod %v+\n", err, pod)
Expand Down
6 changes: 5 additions & 1 deletion connectors/oar.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (OAR) Refill(nbResources int) error {
var quotaResource int
if nbResources != -1 {
// Apply quota on the server by changing the file content. It's reloaded for every scheduling round.
cmd := string("oarstat --json | jq '. | length'")
cmd := string("oarnodes --json | jq '. | length'")
out, err := ExecuteCommand(cmd)
if err != nil {
log.Errorf("Unable to list bebida jobs: %s", err)
Expand All @@ -90,6 +90,10 @@ func (OAR) Refill(nbResources int) error {
return err
}
quotaResource = totalResources - nbResources
if quotaResource < 0 {
log.Errorf("Error while computing quota. Quota is negative: %d", quotaResource)
return nil
}
} else {
quotaResource = -1
}
Expand Down

0 comments on commit 74874ce

Please sign in to comment.