From ed225444e00b70a18a6833bd1e04b5e068662167 Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Tue, 11 Jan 2022 11:35:30 -0500 Subject: [PATCH 1/3] error rather than panic when workflow action index is invalid Signed-off-by: Marques Johansson --- server/dbserver_worker_workflow.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/server/dbserver_worker_workflow.go b/server/dbserver_worker_workflow.go index 0e4bc73a3..5348dcf12 100644 --- a/server/dbserver_worker_workflow.go +++ b/server/dbserver_worker_workflow.go @@ -13,6 +13,22 @@ import ( "google.golang.org/grpc/status" ) +var workflowData = make(map[string]int) + +const ( + errInvalidWorkerID = "invalid worker id" + errInvalidWorkflowID = "invalid workflow id" + errInvalidTaskName = "invalid task name" + errInvalidActionName = "invalid action name" + errInvalidTaskReported = "reported task name does not match the current action details" + errInvalidActionReported = "reported action name does not match the current action details" + errInvalidActionIndex = "invalid action index for workflow" + + msgReceivedStatus = "received action status: %s" + msgCurrentWfContext = "current workflow context" + msgSendWfContext = "send workflow context: %s" +) + // GetWorkflowContexts implements tinkerbell.GetWorkflowContexts. func (s *DBServer) GetWorkflowContexts(req *workflow.WorkflowContextRequest, stream workflow.WorkflowService_GetWorkflowContextsServer) error { wfs, err := getWorkflowsForWorker(stream.Context(), s.db, req.WorkerId) @@ -96,6 +112,9 @@ func (s *DBServer) ReportActionStatus(ctx context.Context, req *workflow.Workflo actionIndex++ } } + if actionIndex == wfContext.TotalNumberOfActions-1 { + return nil, status.Errorf(codes.FailedPrecondition, errInvalidActionIndex) + } action := wfActions.ActionList[actionIndex] if action.GetTaskName() != req.GetTaskName() { return nil, status.Errorf(codes.InvalidArgument, errInvalidTaskReported) From 1e94ce1d408ff7d57e15034dc017bb8eb24f5c29 Mon Sep 17 00:00:00 2001 From: Gaurav Gahlot Date: Fri, 29 Apr 2022 16:56:54 +0530 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20resolve=20conflic?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gaurav Gahlot --- server/dbserver.go | 1 + server/dbserver_worker_workflow.go | 16 ---------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/server/dbserver.go b/server/dbserver.go index 1fc7f8c1b..b30050988 100644 --- a/server/dbserver.go +++ b/server/dbserver.go @@ -18,6 +18,7 @@ const ( errInvalidActionName = "invalid action name" errInvalidTaskReported = "reported task name does not match the current action details" errInvalidActionReported = "reported action name does not match the current action details" + errInvalidActionIndex = "invalid action index for workflow" msgReceivedStatus = "received action status: %s" msgCurrentWfContext = "current workflow context" diff --git a/server/dbserver_worker_workflow.go b/server/dbserver_worker_workflow.go index 5348dcf12..ce89c9f3e 100644 --- a/server/dbserver_worker_workflow.go +++ b/server/dbserver_worker_workflow.go @@ -13,22 +13,6 @@ import ( "google.golang.org/grpc/status" ) -var workflowData = make(map[string]int) - -const ( - errInvalidWorkerID = "invalid worker id" - errInvalidWorkflowID = "invalid workflow id" - errInvalidTaskName = "invalid task name" - errInvalidActionName = "invalid action name" - errInvalidTaskReported = "reported task name does not match the current action details" - errInvalidActionReported = "reported action name does not match the current action details" - errInvalidActionIndex = "invalid action index for workflow" - - msgReceivedStatus = "received action status: %s" - msgCurrentWfContext = "current workflow context" - msgSendWfContext = "send workflow context: %s" -) - // GetWorkflowContexts implements tinkerbell.GetWorkflowContexts. func (s *DBServer) GetWorkflowContexts(req *workflow.WorkflowContextRequest, stream workflow.WorkflowService_GetWorkflowContextsServer) error { wfs, err := getWorkflowsForWorker(stream.Context(), s.db, req.WorkerId) From eed0730f009a7e250ce724930b2b135300e16786 Mon Sep 17 00:00:00 2001 From: Gaurav Gahlot Date: Fri, 29 Apr 2022 17:20:32 +0530 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20check=20if=20the?= =?UTF-8?q?=20total=20number=20of=20actions=20is=20more=20than=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gaurav Gahlot --- server/dbserver_worker_workflow.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/dbserver_worker_workflow.go b/server/dbserver_worker_workflow.go index ce89c9f3e..5e5ea62cb 100644 --- a/server/dbserver_worker_workflow.go +++ b/server/dbserver_worker_workflow.go @@ -96,9 +96,11 @@ func (s *DBServer) ReportActionStatus(ctx context.Context, req *workflow.Workflo actionIndex++ } } - if actionIndex == wfContext.TotalNumberOfActions-1 { + + if wfContext.TotalNumberOfActions > 1 && actionIndex == wfContext.TotalNumberOfActions-1 { return nil, status.Errorf(codes.FailedPrecondition, errInvalidActionIndex) } + action := wfActions.ActionList[actionIndex] if action.GetTaskName() != req.GetTaskName() { return nil, status.Errorf(codes.InvalidArgument, errInvalidTaskReported)