From a4e98b0413d1cee590a1cb3e26ba5d25eab726d0 Mon Sep 17 00:00:00 2001 From: Chris Doherty Date: Thu, 29 Jun 2023 19:49:28 -0500 Subject: [PATCH 1/3] Move workflow pkg --- internal/agent/agent.go | 2 +- internal/agent/agent_test.go | 2 +- internal/agent/mock.go | 2 +- internal/agent/run.go | 3 ++- internal/agent/runtime.go | 2 +- internal/agent/runtime/docker.go | 5 +++-- internal/agent/runtime/docker_test.go | 2 +- internal/agent/runtime/fake.go | 3 ++- internal/agent/transport/fake.go | 3 ++- internal/agent/transport/grpc.go | 2 +- internal/agent/transport/grpc_test.go | 2 +- internal/agent/transport/handler.go | 2 +- internal/agent/transport/mock.go | 2 +- internal/controller/manager.go | 2 +- internal/{ => obsolete}/workflow/convert.go | 0 internal/{ => obsolete}/workflow/convert_test.go | 0 internal/{ => obsolete}/workflow/reconciler.go | 0 internal/{ => obsolete}/workflow/reconciler_test.go | 0 internal/{ => obsolete}/workflow/template_funcs.go | 0 internal/{ => obsolete}/workflow/template_validator.go | 0 internal/{ => obsolete}/workflow/template_validator_test.go | 0 internal/{ => obsolete}/workflow/types.go | 0 internal/server/kubernetes_api_workflow.go | 2 +- internal/{agent => }/workflow/workflow.go | 0 24 files changed, 20 insertions(+), 16 deletions(-) rename internal/{ => obsolete}/workflow/convert.go (100%) rename internal/{ => obsolete}/workflow/convert_test.go (100%) rename internal/{ => obsolete}/workflow/reconciler.go (100%) rename internal/{ => obsolete}/workflow/reconciler_test.go (100%) rename internal/{ => obsolete}/workflow/template_funcs.go (100%) rename internal/{ => obsolete}/workflow/template_validator.go (100%) rename internal/{ => obsolete}/workflow/template_validator_test.go (100%) rename internal/{ => obsolete}/workflow/types.go (100%) rename internal/{agent => }/workflow/workflow.go (100%) diff --git a/internal/agent/agent.go b/internal/agent/agent.go index af49fd549..a1ddf31de 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -7,7 +7,7 @@ import ( "github.com/go-logr/logr" "github.com/tinkerbell/tink/internal/agent/event" - "github.com/tinkerbell/tink/internal/agent/workflow" + "github.com/tinkerbell/tink/internal/workflow" ) // Agent is the core data structure for handling workflow execution on target nodes. It leverages diff --git a/internal/agent/agent_test.go b/internal/agent/agent_test.go index 83ddd6dfd..6a826be0d 100644 --- a/internal/agent/agent_test.go +++ b/internal/agent/agent_test.go @@ -14,7 +14,7 @@ import ( "github.com/tinkerbell/tink/internal/agent/failure" "github.com/tinkerbell/tink/internal/agent/runtime" "github.com/tinkerbell/tink/internal/agent/transport" - "github.com/tinkerbell/tink/internal/agent/workflow" + "github.com/tinkerbell/tink/internal/workflow" "go.uber.org/zap" ) diff --git a/internal/agent/mock.go b/internal/agent/mock.go index c7d50b390..6cad397ea 100644 --- a/internal/agent/mock.go +++ b/internal/agent/mock.go @@ -8,7 +8,7 @@ import ( "sync" "github.com/tinkerbell/tink/internal/agent/transport" - "github.com/tinkerbell/tink/internal/agent/workflow" + "github.com/tinkerbell/tink/internal/workflow" ) // Ensure, that TransportMock does implement Transport. diff --git a/internal/agent/run.go b/internal/agent/run.go index 8543edf41..cfd3290e8 100644 --- a/internal/agent/run.go +++ b/internal/agent/run.go @@ -7,9 +7,10 @@ import ( "time" "github.com/go-logr/logr" + "github.com/tinkerbell/tink/internal/agent/event" "github.com/tinkerbell/tink/internal/agent/failure" - "github.com/tinkerbell/tink/internal/agent/workflow" + "github.com/tinkerbell/tink/internal/workflow" ) // ReasonRuntimeError is the default reason used when no reason is provided by the runtime. diff --git a/internal/agent/runtime.go b/internal/agent/runtime.go index eea77536f..67bc69579 100644 --- a/internal/agent/runtime.go +++ b/internal/agent/runtime.go @@ -3,7 +3,7 @@ package agent import ( "context" - "github.com/tinkerbell/tink/internal/agent/workflow" + "github.com/tinkerbell/tink/internal/workflow" ) // ContainerRuntime is a runtime capable of executing workflow actions. diff --git a/internal/agent/runtime/docker.go b/internal/agent/runtime/docker.go index 4d34f4d42..34ad5dea4 100644 --- a/internal/agent/runtime/docker.go +++ b/internal/agent/runtime/docker.go @@ -12,11 +12,12 @@ import ( "github.com/docker/docker/api/types/mount" "github.com/docker/docker/client" "github.com/go-logr/logr" + "k8s.io/apimachinery/pkg/util/rand" + "github.com/tinkerbell/tink/internal/agent" "github.com/tinkerbell/tink/internal/agent/runtime/internal" - "github.com/tinkerbell/tink/internal/agent/workflow" "github.com/tinkerbell/tink/internal/ptr" - "k8s.io/apimachinery/pkg/util/rand" + "github.com/tinkerbell/tink/internal/workflow" ) var _ agent.ContainerRuntime = &Docker{} diff --git a/internal/agent/runtime/docker_test.go b/internal/agent/runtime/docker_test.go index 4237d6cbe..8992e4a82 100644 --- a/internal/agent/runtime/docker_test.go +++ b/internal/agent/runtime/docker_test.go @@ -13,7 +13,7 @@ import ( "github.com/rs/zerolog" "github.com/tinkerbell/tink/internal/agent/failure" "github.com/tinkerbell/tink/internal/agent/runtime" - "github.com/tinkerbell/tink/internal/agent/workflow" + "github.com/tinkerbell/tink/internal/workflow" "go.uber.org/multierr" "github.com/docker/docker/api/types" diff --git a/internal/agent/runtime/fake.go b/internal/agent/runtime/fake.go index 2798331db..cf2432f42 100644 --- a/internal/agent/runtime/fake.go +++ b/internal/agent/runtime/fake.go @@ -4,8 +4,9 @@ import ( "context" "github.com/go-logr/logr" + "github.com/tinkerbell/tink/internal/agent" - "github.com/tinkerbell/tink/internal/agent/workflow" + "github.com/tinkerbell/tink/internal/workflow" ) var _ agent.ContainerRuntime = Fake{} diff --git a/internal/agent/transport/fake.go b/internal/agent/transport/fake.go index 9e329910f..db9390fc0 100644 --- a/internal/agent/transport/fake.go +++ b/internal/agent/transport/fake.go @@ -4,8 +4,9 @@ import ( "context" "github.com/go-logr/logr" + "github.com/tinkerbell/tink/internal/agent/event" - "github.com/tinkerbell/tink/internal/agent/workflow" + "github.com/tinkerbell/tink/internal/workflow" ) func Noop() Fake { diff --git a/internal/agent/transport/grpc.go b/internal/agent/transport/grpc.go index d0b2c8806..e2b4ff2b7 100644 --- a/internal/agent/transport/grpc.go +++ b/internal/agent/transport/grpc.go @@ -8,8 +8,8 @@ import ( "github.com/avast/retry-go" "github.com/go-logr/logr" "github.com/tinkerbell/tink/internal/agent/event" - "github.com/tinkerbell/tink/internal/agent/workflow" workflowproto "github.com/tinkerbell/tink/internal/proto/workflow/v2" + "github.com/tinkerbell/tink/internal/workflow" ) var _ event.Recorder = &GRPC{} diff --git a/internal/agent/transport/grpc_test.go b/internal/agent/transport/grpc_test.go index 42200ee45..261f571ce 100644 --- a/internal/agent/transport/grpc_test.go +++ b/internal/agent/transport/grpc_test.go @@ -12,8 +12,8 @@ import ( "github.com/rs/zerolog" "github.com/tinkerbell/tink/internal/agent/event" "github.com/tinkerbell/tink/internal/agent/transport" - "github.com/tinkerbell/tink/internal/agent/workflow" workflowproto "github.com/tinkerbell/tink/internal/proto/workflow/v2" + "github.com/tinkerbell/tink/internal/workflow" "google.golang.org/grpc" ) diff --git a/internal/agent/transport/handler.go b/internal/agent/transport/handler.go index 9bbf99f2c..34336a848 100644 --- a/internal/agent/transport/handler.go +++ b/internal/agent/transport/handler.go @@ -4,7 +4,7 @@ import ( "context" "github.com/tinkerbell/tink/internal/agent/event" - "github.com/tinkerbell/tink/internal/agent/workflow" + "github.com/tinkerbell/tink/internal/workflow" ) // WorkflowHandler is responsible for workflow execution. diff --git a/internal/agent/transport/mock.go b/internal/agent/transport/mock.go index e73ba35f4..429a70548 100644 --- a/internal/agent/transport/mock.go +++ b/internal/agent/transport/mock.go @@ -8,7 +8,7 @@ import ( "sync" "github.com/tinkerbell/tink/internal/agent/event" - "github.com/tinkerbell/tink/internal/agent/workflow" + "github.com/tinkerbell/tink/internal/workflow" ) // Ensure, that WorkflowHandlerMock does implement WorkflowHandler. diff --git a/internal/controller/manager.go b/internal/controller/manager.go index bc0d01157..2672a7fae 100644 --- a/internal/controller/manager.go +++ b/internal/controller/manager.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/tinkerbell/tink/api/v1alpha1" - "github.com/tinkerbell/tink/internal/workflow" + "github.com/tinkerbell/tink/internal/obsolete/workflow" "k8s.io/apimachinery/pkg/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" diff --git a/internal/workflow/convert.go b/internal/obsolete/workflow/convert.go similarity index 100% rename from internal/workflow/convert.go rename to internal/obsolete/workflow/convert.go diff --git a/internal/workflow/convert_test.go b/internal/obsolete/workflow/convert_test.go similarity index 100% rename from internal/workflow/convert_test.go rename to internal/obsolete/workflow/convert_test.go diff --git a/internal/workflow/reconciler.go b/internal/obsolete/workflow/reconciler.go similarity index 100% rename from internal/workflow/reconciler.go rename to internal/obsolete/workflow/reconciler.go diff --git a/internal/workflow/reconciler_test.go b/internal/obsolete/workflow/reconciler_test.go similarity index 100% rename from internal/workflow/reconciler_test.go rename to internal/obsolete/workflow/reconciler_test.go diff --git a/internal/workflow/template_funcs.go b/internal/obsolete/workflow/template_funcs.go similarity index 100% rename from internal/workflow/template_funcs.go rename to internal/obsolete/workflow/template_funcs.go diff --git a/internal/workflow/template_validator.go b/internal/obsolete/workflow/template_validator.go similarity index 100% rename from internal/workflow/template_validator.go rename to internal/obsolete/workflow/template_validator.go diff --git a/internal/workflow/template_validator_test.go b/internal/obsolete/workflow/template_validator_test.go similarity index 100% rename from internal/workflow/template_validator_test.go rename to internal/obsolete/workflow/template_validator_test.go diff --git a/internal/workflow/types.go b/internal/obsolete/workflow/types.go similarity index 100% rename from internal/workflow/types.go rename to internal/obsolete/workflow/types.go diff --git a/internal/server/kubernetes_api_workflow.go b/internal/server/kubernetes_api_workflow.go index 17e7fdff1..1fd0719ee 100644 --- a/internal/server/kubernetes_api_workflow.go +++ b/internal/server/kubernetes_api_workflow.go @@ -5,8 +5,8 @@ import ( "github.com/pkg/errors" "github.com/tinkerbell/tink/api/v1alpha1" + "github.com/tinkerbell/tink/internal/obsolete/workflow" "github.com/tinkerbell/tink/internal/proto" - "github.com/tinkerbell/tink/internal/workflow" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/internal/agent/workflow/workflow.go b/internal/workflow/workflow.go similarity index 100% rename from internal/agent/workflow/workflow.go rename to internal/workflow/workflow.go From bad2e7cf386aed59001dabf17009d61143810061 Mon Sep 17 00:00:00 2001 From: Chris Doherty Date: Thu, 29 Jun 2023 19:54:27 -0500 Subject: [PATCH 2/3] Move server pkg --- .gitignore | 1 - .vscode/settings.json | 9 +++++++++ cmd/tink-server/main.go | 5 +++-- internal/e2e/tink_suite_test.go | 9 +++++---- internal/{ => obsolete}/server/index.go | 0 internal/{ => obsolete}/server/index_test.go | 0 internal/{ => obsolete}/server/kubernetes_api.go | 0 internal/{ => obsolete}/server/kubernetes_api_test.go | 0 .../{ => obsolete}/server/kubernetes_api_workflow.go | 0 9 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 .vscode/settings.json rename internal/{ => obsolete}/server/index.go (100%) rename internal/{ => obsolete}/server/index_test.go (100%) rename internal/{ => obsolete}/server/kubernetes_api.go (100%) rename internal/{ => obsolete}/server/kubernetes_api_test.go (100%) rename internal/{ => obsolete}/server/kubernetes_api_workflow.go (100%) diff --git a/.gitignore b/.gitignore index b06fe0235..ad06f794f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ cmd/tink-server/tink-server cmd/tink-worker/tink-worker doc/ .idea -.vscode coverage.txt # Terraform diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..9a0080996 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "gopls": { + "build.buildFlags": [ + "-tags=e2e,integration,all_providers,docker", + ], + "formatting.gofumpt": true, + "formatting.local": "github.com/tinkerbell" + }, +} \ No newline at end of file diff --git a/cmd/tink-server/main.go b/cmd/tink-server/main.go index a9cae0bdc..f8a3294a3 100644 --- a/cmd/tink-server/main.go +++ b/cmd/tink-server/main.go @@ -14,10 +14,11 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" "github.com/spf13/viper" + "go.uber.org/zap" + "github.com/tinkerbell/tink/internal/grpcserver" "github.com/tinkerbell/tink/internal/httpserver" - "github.com/tinkerbell/tink/internal/server" - "go.uber.org/zap" + "github.com/tinkerbell/tink/internal/obsolete/server" ) // version is set at build time. diff --git a/internal/e2e/tink_suite_test.go b/internal/e2e/tink_suite_test.go index c41008e46..8edd9694c 100644 --- a/internal/e2e/tink_suite_test.go +++ b/internal/e2e/tink_suite_test.go @@ -13,15 +13,16 @@ import ( "github.com/go-logr/zapr" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/tinkerbell/tink/api/v1alpha1" - "github.com/tinkerbell/tink/internal/controller" - "github.com/tinkerbell/tink/internal/grpcserver" - "github.com/tinkerbell/tink/internal/server" "go.uber.org/zap" "k8s.io/client-go/kubernetes/scheme" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest" + + "github.com/tinkerbell/tink/api/v1alpha1" + "github.com/tinkerbell/tink/internal/controller" + "github.com/tinkerbell/tink/internal/grpcserver" + "github.com/tinkerbell/tink/internal/obsolete/server" ) var ( diff --git a/internal/server/index.go b/internal/obsolete/server/index.go similarity index 100% rename from internal/server/index.go rename to internal/obsolete/server/index.go diff --git a/internal/server/index_test.go b/internal/obsolete/server/index_test.go similarity index 100% rename from internal/server/index_test.go rename to internal/obsolete/server/index_test.go diff --git a/internal/server/kubernetes_api.go b/internal/obsolete/server/kubernetes_api.go similarity index 100% rename from internal/server/kubernetes_api.go rename to internal/obsolete/server/kubernetes_api.go diff --git a/internal/server/kubernetes_api_test.go b/internal/obsolete/server/kubernetes_api_test.go similarity index 100% rename from internal/server/kubernetes_api_test.go rename to internal/obsolete/server/kubernetes_api_test.go diff --git a/internal/server/kubernetes_api_workflow.go b/internal/obsolete/server/kubernetes_api_workflow.go similarity index 100% rename from internal/server/kubernetes_api_workflow.go rename to internal/obsolete/server/kubernetes_api_workflow.go From bdd2ec7b39a01204031b95a62870713f19c99f3e Mon Sep 17 00:00:00 2001 From: Chris Doherty Date: Thu, 29 Jun 2023 20:15:33 -0500 Subject: [PATCH 3/3] Some server stuff --- internal/server/grpc.go | 22 ++++++++++++++++++++++ internal/server/server.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 internal/server/grpc.go create mode 100644 internal/server/server.go diff --git a/internal/server/grpc.go b/internal/server/grpc.go new file mode 100644 index 000000000..7f02078ba --- /dev/null +++ b/internal/server/grpc.go @@ -0,0 +1,22 @@ +package server + +import ( + "context" + + workflowproto "github.com/tinkerbell/tink/internal/proto/workflow/v2" +) + +type GRPCServer struct { + workflowproto.UnimplementedWorkflowServiceServer +} + +// GetWorkflows creates a stream that will receive workflows intended for the agent identified +// by the GetWorkflowsRequest.agent_id. +func (s *GRPCServer) GetWorkflows(req *workflowproto.GetWorkflowsRequest, stream workflowproto.WorkflowService_GetWorkflowsServer) error { + return nil +} + +// PublishEvent publishes a workflow event. +func (s *GRPCServer) PublishEvent(context.Context, *workflowproto.PublishEventRequest) (*workflowproto.PublishEventResponse, error) { + return nil, nil +} diff --git a/internal/server/server.go b/internal/server/server.go new file mode 100644 index 000000000..66777def3 --- /dev/null +++ b/internal/server/server.go @@ -0,0 +1,28 @@ +package server + +import "github.com/tinkerbell/tink/internal/workflow" + +/* +The server must be notified when an agent connects. +The server must be notified when an agent disconnects. +The server must dispatch workflows to the agent. +The server must be notified of events created by the agent. +The server must ensure a single workflow is dispatched to an agent at a time. +The server must time out workflows. +*/ + +type Transport interface { + Send(workflow.Workflow) error +} + +type Server struct { + agents map[string]Transport +} + +func (s *Server) RegisterAgent(agentID string, trnsport Transport) error { + return nil +} + +func (s *Server) UnregisterAgent(agentID string) error { + return nil +}