Skip to content

Commit

Permalink
Refactored Tink Worker
Browse files Browse the repository at this point in the history
* Created ContainerManager and ContainerLogger abstractions
* Added tests for new interfaces
* Cleaned up worker method arguments

Signed-off-by: Micah Hausler <mhausler@amazon.com>
  • Loading branch information
micahhausler committed Mar 15, 2022
1 parent e1e2af6 commit 43c3fed
Show file tree
Hide file tree
Showing 12 changed files with 1,051 additions and 388 deletions.
35 changes: 30 additions & 5 deletions cmd/tink-worker/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ package cmd
import (
"context"
"fmt"
"os"
"strings"
"time"

dockerCli "github.com/docker/docker/client"
"github.com/packethost/pkg/log"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/tinkerbell/tink/client"
"github.com/tinkerbell/tink/cmd/tink-worker/internal"
"github.com/tinkerbell/tink/cmd/tink-worker/worker"
pb "github.com/tinkerbell/tink/protos/workflow"
"google.golang.org/grpc"
)
Expand Down Expand Up @@ -68,10 +70,33 @@ func NewRootCommand(version string, logger log.Logger) *cobra.Command {
}
rClient := pb.NewWorkflowServiceClient(conn)

regConn := internal.NewRegistryConnDetails(registry, user, pwd, logger)
worker := internal.NewWorker(rClient, regConn, logger, registry, retries, retryInterval, maxFileSize)

err = worker.ProcessWorkflowActions(ctx, workerID, captureActionLogs)
dockerClient, err := dockerCli.NewClientWithOpts(dockerCli.FromEnv, dockerCli.WithAPIVersionNegotiation())
if err != nil {
return err
}
containerManager := worker.NewContainerManager(
logger,
dockerClient,
worker.RegistryConnDetails{
Registry: registry,
User: user,
Pwd: pwd,
})

containerLogger := worker.NewContainerLogger(dockerClient, logger, os.Stdout)

w := worker.NewWorker(
workerID,
rClient,
containerManager,
containerLogger,
logger,
worker.WithMaxFileSize(maxFileSize),
worker.WithRetries(retryInterval, retries),
worker.WithLogCapture(captureActionLogs),
worker.WithPrivileged(true))

err = w.ProcessWorkflowActions(ctx)
if err != nil {
return errors.Wrap(err, "worker Finished with error")
}
Expand Down
116 changes: 0 additions & 116 deletions cmd/tink-worker/internal/action.go

This file was deleted.

94 changes: 0 additions & 94 deletions cmd/tink-worker/internal/registry.go

This file was deleted.

78 changes: 0 additions & 78 deletions cmd/tink-worker/internal/registry_test.go

This file was deleted.

Loading

0 comments on commit 43c3fed

Please sign in to comment.