Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updatek8s can now optionally add config #14

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion database/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (handler *Handler) CreateJob(repliconTypeAPI api.RepliconTableType, jobname
}

//UpdateK8s Updates a job with its k8s id
func (handler *Handler) UpdateK8s(id string, k8s string) error {
func (handler *Handler) UpdateK8s(id string, k8s string, config *api.JobConfig) error {
ctx, _ := context.WithTimeout(context.Background(), 1*time.Second)

update_filter := bson.M{
Expand All @@ -185,6 +185,16 @@ func (handler *Handler) UpdateK8s(id string, k8s string) error {
},
}

if config != nil {
update = bson.M{
"$set": bson.M{
"k8sid": k8s,
"status": api.JobStatusEnum_INIT.String(),
"conf": config,
},
}
}

result, err := handler.Collection.UpdateOne(ctx, update_filter, update)
if err != nil {
log.Println(err.Error())
Expand Down
2 changes: 2 additions & 0 deletions database/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package database

import (
"go.mongodb.org/mongo-driver/bson/primitive"
"k8s.io/client-go/tools/clientcmd/api"
)

// Job The database model for a bakta job
Expand All @@ -22,4 +23,5 @@ type Job struct {
ConfString string
IsDeleted bool
Jobname string
Config *api.Config
}
5 changes: 3 additions & 2 deletions endpoints/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/spf13/viper"
"log"
"os"
"time"

"github.com/spf13/viper"

api "github.com/ag-computational-bio/bakta-web-api-go/bakta/web/api/proto/v1"
"github.com/ag-computational-bio/bakta-web-backend/monitor"
"github.com/ag-computational-bio/bakta-web-backend/objectStorage"
Expand Down Expand Up @@ -94,7 +95,7 @@ func (apiHandler *BaktaJobAPI) StartJob(ctx context.Context, request *api.StartJ
return nil, err
}

err = apiHandler.dbHandler.UpdateK8s(request.Job.GetJobID(), string(k8sJob.GetUID()))
err = apiHandler.dbHandler.UpdateK8s(request.Job.GetJobID(), string(k8sJob.GetUID()), request.GetConfig())
if err != nil {
log.Println(err.Error())
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion scheduler/simple_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (scheduler *SimpleScheduler) StartJob(jobID string, jobConfig *api.JobConfi
return nil, err
}

err = scheduler.databaseHandler.UpdateK8s(jobID, string(scheduledJob.UID))
err = scheduler.databaseHandler.UpdateK8s(jobID, string(scheduledJob.UID), nil)
if err != nil {
log.Println(err.Error())
return nil, err
Expand Down