Skip to content

Commit

Permalink
fix: change UUID generate
Browse files Browse the repository at this point in the history
  • Loading branch information
illyaks committed May 31, 2024
1 parent 3055d09 commit ddf2eb7
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/api/msg_type/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type DNSMsg struct {
}

type TriggerMsg struct {
UUID string `json:"uuid,omitempty"`
Function api.Function `json:"function,omitempty"`
Params string `json:"params,omitempty"`
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/apiserver/handlers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handlers
import (
"context"
"encoding/json"
"github.com/google/uuid"
"minik8s/pkg/api"
"minik8s/pkg/api/msg_type"
"minik8s/pkg/config"
Expand Down Expand Up @@ -34,6 +35,7 @@ func WatchHandler(key string, value string) {
var msg msg_type.TriggerMsg
msg.Function = function
msg.Params = value
msg.UUID = uuid.NewString()
jsonString, _ := json.Marshal(msg)
publisher.Publish(msg_type.TriggerTopic, string(jsonString))
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/apiserver/handlers/triggerhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handlers
import (
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"minik8s/pkg/api"
"minik8s/pkg/api/msg_type"
"minik8s/pkg/config"
Expand Down Expand Up @@ -106,6 +107,7 @@ func HttpTriggerFunction(context *gin.Context) {
if function.Trigger.Http == true {
var msg msg_type.TriggerMsg
msg.Function = function
msg.UUID = uuid.NewString()
if err := context.ShouldBind(&msg); err != nil {
context.JSON(http.StatusBadRequest, gin.H{
"status": err.Error(),
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller/controllers/serverlesscontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"github.com/IBM/sarama"
"github.com/google/uuid"
"minik8s/pkg/api"
"minik8s/pkg/api/msg_type"
"minik8s/pkg/config"
Expand Down Expand Up @@ -110,7 +109,7 @@ func (this *ServerlessController) triggerNewJob(content []byte) {
freePod.Metadata.Name += "-" + randomString
freePod.Spec.Containers[0].Name += "-" + randomString
var job api.Job
job.JobID = uuid.NewString()
job.JobID = triggerMsg.UUID
job.CreateTime = time.Now().String()
job.Instance = *freePod
job.Params = triggerMsg.Params
Expand Down

0 comments on commit ddf2eb7

Please sign in to comment.